Class Utilities¶
Defined in File Utilities.h
Class Documentation¶
-
class Utilities¶
-
Public Static Functions
-
static void castString(const std::string &value, const std::string &type, CastValue &cast)¶
Cast a string to the desired type and return the evaluation.
The type check is case insensitive.
Note
a value “true” or “false” of type “string” will be converted to bool
- Parameters
value – [in] input string
type – [in] desired type
cast – [out] result
-
static void setUserParameters(OpenMS::DefaultParamHandler &Param_handler_IO, const ParameterSet &user_parameters_I, const std::string param_handler_name_I = "")¶
Update a OpenMS’ DefaultParamHandler object with user parameters.
- Parameters
Param_handler_IO – [inout] OpenMS’ DefaultParamHandler object to update
parameters_I – [in] user parameters
param_handler_name – [in] set if user parameter have different name entry.
-
static void updateParameters(OpenMS::Param &Param_IO, const FunctionParameters ¶meters_I)¶
Update a Param object.
The type check is case insensitive.
Note
a value “true” or “false” of type “string” will be converted to bool
- Parameters
Param_IO – [inout] OpenMS’ Param object to update
parameters_I – [in] List of parameters to update
-
static CastValue OpenMSDataValueToCastValue(const OpenMS::DataValue &openms_datavalue)¶
Convert a OpenMS::DataValue to SmartPeak’s CastValue.
- Parameters
openms_datavalue – [in] OpenMSDataValue to convert
- Returns
SmartPeak’s CastValue
-
static void parseString(const std::string &str_I, CastValue &cast)¶
Parse string and return the eval.
The type check is case insensitive.
Note
a value “true” or “false” of type “string” will be converted to bool
- Parameters
str_I – [in] Input string
cast – [out] The evaluated string
-
static std::vector<std::string> splitString(const std::string &s, const char sep)¶
-
static std::string trimString(const std::string &s, const std::string &whitespaces =
" \\\)¶
-
template<typename T>
static inline std::map<std::string, float> calculateValidationMetrics(const std::vector<T> &y_true, const std::vector<T> &y_pred)¶
-
template<typename T>
static inline std::array<size_t, 4> computeConfusionMatrix(const std::vector<T> &y_true, const std::vector<T> &y_pred)¶
-
template<typename T>
static inline bool assert_close(const T &lhs, const T &rhs, double rel_tol = 1e-4, double abs_tol = 1e-4)¶ Test absolute and relative closeness of values.
References: http://realtimecollisiondetection.net/blog/?p=89
- Param
-
static std::vector<OpenMS::MRMFeatureSelector::SelectorParameters> extractSelectorParameters(const FunctionParameters ¶ms, const FunctionParameters &score_weights)¶
-
template<typename Iterator>
static inline std::string join(Iterator first, Iterator last, const std::string &delimiter = "")¶
-
static bool testStoredQuantitationMethods(const std::string &pathname)¶
-
static bool endsWith(std::string str, std::string suffix, const bool case_sensitive = true)¶
Check if str ends with suffix.
Useful for filtering filenames by the extension
- Parameters
str – [in] Input string
suffix – [in] Suffix
case_sensitive – [in] Case sensitive string comparison
- Returns
True if str ends with suffix. Otherwise false.
-
static std::array<std::vector<std::string>, 4> getFolderContents(const std::filesystem::path &folder_path, bool only_directories)¶
Retrieves information about files in a given directory.
- Parameters
folder_path – [in] Given path to inspect and scan where the first element is “name”, “extension”, “size” and “last_write_time”, the second element can either be “ascending” or “descending”.
- Returns
List of files found where each string of vectors is a representation of a file’s name, size, type and date.
-
static std::string getParentPath(const std::filesystem::path &p)¶
Get the parent path from a given path, the given path is returned when the parent path isn’t existent.
- Parameters
p – [in] Path to a directory of interest.
parent_path – [out] The parent path of the given path as a standard string.
-
template<typename T>
static inline void sortPairs(const std::vector<size_t> &indices, std::vector<T> &v)¶ Moves the elements in vector v according to indices.
Example: indices: {3, 4, 2, 0, 1} old v: {‘a’, ‘b’, ‘c’, ‘d’, ‘e’} new v: {‘d’, ‘e’, ‘c’, ‘a’, ‘b’}
- Throws
std::invalid_argument – Sizes of indices and v differ
- Parameters
indices – [in] The vector of indices that decides the sorting
v – [inout] The vector of elements to be sorted
-
static bool is_less_than_icase(const std::string &a, const std::string &b)¶
Case-insensitive string comparison.
Equivalent to a.compare(b) < 0, ignoring letter case.
- Parameters
a – [in] left-side string
b – [in] right-side string
- Returns
True if ‘a’ is lexicographically less than ‘b’. Otherwise false.
-
static void getDirectoryInfo(const std::filesystem::path &p, std::tuple<float, uintmax_t> &directory_info)¶
Retrieves basic information on a given directory.
- Parameters
p – [in] Path to inspect
directory_info – [out] A tuple where the first element is the total size of files in the directory, and the second is the total entries in the directory (files and directories).
-
static bool isHiddenEntry(const std::filesystem::path &entry_path)¶
Check whether a path is hidden.
- Parameters
entry_path – [in] path to inspect
- Returns
True if a hidden entry is encountered
-
static std::pair<std::filesystem::path, bool> getLogFilepath(const std::string &filename)¶
Constructs an absolute filepath to an application logs.
Default locations of logs:
Windows: C:<user>
Linux and MacOS: ~/.SmartPeak User can change default location and specify directory where the logs are stored by setting SMARTPEAK_LOGS env variable. If directory specified by the path doesn’t exist, the function will create one.
- Parameters
filename – [in] Log filename
- Returns
The absolute path to log file and boolean flag whether the path to directory was created
-
static void getEnvVariable(const char *env_name, std::string *path)¶
Get a value fromt the current environment.
- Parameters
env_name – [in] environment variable name
path – [out] variable’s value
-
static std::string getSmartPeakVersion()¶
Returns the build version of SmartPeak package if available.
-
static std::string str2upper(const std::string &str)¶
Converts an input string to upper case string.
- Parameters
str – [in] input string
- Returns
formated string
-
static void removeTrailing(std::string &str, std::string to_remove)¶
Remove trailing characters.
- Parameters
to_remove – [in] string to remove from given string.
str – [inout] string on which the modification is done.
-
static Filenames buildFilenamesFromDirectory(ApplicationHandler &application_handler, const std::filesystem::path &path)¶
Construct filename using the default files organisation.
Can be used to create an empty session from a directory.
-
static std::string makeUniqueStringFromTime()¶
Returns a unique string based on the current time.
- Parameters
a – [out] unique string in the format : Y-m-d_H-M-S_TIME_SINCE_EPOCHS
-
static std::filesystem::path createEmptyTempDirectory()¶
return an empty, temporary directory.
-
static void prepareFileParameter(ParameterSet ¶meter_set, const std::string &function_parameter, const std::string ¶meter_name, const std::filesystem::path main_path)¶
for parameter that is supposed to be file path, make it full path if it exists.
-
static void prepareFileParameterList(ParameterSet ¶meter_set, const std::string &function_parameter, const std::string ¶meter_name, const std::filesystem::path main_path)¶
for parameter that is supposed to be file path, make it full path if it exists (list version).
-
static std::string getCurrentTime()¶
Returns current time.
- Returns
Current time in the format : H-M-S_d-m-Y
-
static std::string sha256(const std::string str)¶
Calculates sha256 hash on a given string.
- Parameters
str – [in] string to perfrom the sha256 hashing on
- Returns
hashed string
-
static void createServerSessionFile(std::filesystem::path file_path)¶
Creates .serversession.ssi file.
- Parameters
file_path – [in] pull path to the location of where to create the .serversession.ssi if not existing
-
static void writeToServerSessionFile(std::filesystem::path file_path, std::string usr_id, std::string dataset_name, std::string workflow_status, std::string started_at, std::string finished_at, std::string path_to_exports, std::string log_file)¶
Writes comma seperated values to .serversession.ssi file.
- Parameters
file_path – [in] pull path to the location of where to create the .serversession.ssi if not existing
user_id – [in] user id as provided in the login dialog
dataset_name – [in] the name of the dataset name
workflow_status – [in] workflow status if the current/last workflow run
started_at – [in] the start time of the workflow
finished_at – [in] the end time of the workflow
path_to_exports – [in] the full path to the exported reports
log_file – [in] full path to the generated log file
-
static bool checkLastServerWorkflowRun(std::filesystem::path file_path, std::string &username)¶
Checks for the last workflow status.
- Parameters
file_path – [in] pull path to the location of the dataset
username – [in] user id of the current user
-
static void loadRawDataAndFeatures(ApplicationHandler &application_handler, SessionHandler &session_handler, WorkflowManager &workflow_manager, EventDispatcher &event_dispatcher)¶
Loads processed raw data and features.
- Parameters
application_handler – [in] application handler
session_handler – [in] session handler
workflow_manager – [in] workflow manager
event_dispatcher – [in] event dispatcher
-
static bool isList(const std::string &str, const std::regex &re)¶
returns true if the string is a list of items matching the regex.
-
static std::string replaceAll(const std::string &str, const std::string search, const std::string &replace)¶
replace all instance of one string with another string.
- Parameters
str – [in] the string to look into
search – [in] the string to look for
replace – [in] the string to replace with
-
template<char Separator, typename ...Columns>
static bool checkCSVHeader(const std::filesystem::path &filename, const Columns&... columns)¶ Check if a csv file has required headers.
-
static bool hasBOMMarker(const std::filesystem::path &filename)¶
returns true if file has BOM marker
-
static void castString(const std::string &value, const std::string &type, CastValue &cast)¶