Class Utilities

Class Documentation

class SmartPeak::Utilities

Public Functions

Utilities() = delete
~Utilities() = delete
Utilities(const Utilities&) = delete
Utilities &operator=(const Utilities&) = delete
Utilities(Utilities&&) = delete
Utilities &operator=(Utilities&&) = delete

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 &parameters_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 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 void parseList(const std::string &line, std::regex &re, CastValue &cast)
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 &params, 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)

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 void makeHumanReadable(ImEntry &directory_entry)

Modify ImEntry to a human readable format.

Parameters

directory_entry[inout] directory entry on which the modification is done.

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.