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> getPathnameContent(const std::string &pathname, const bool asc = true)

Get information about name, size, type and modified date of all entries in a folder.

Note

Elements “.” and “..” are not part of the content

Parameters
  • pathname[in] Folder pathname

  • asc[in] Sort entries in ascending order

Returns

A container with the desired information

static std::string getParentPathname(const std::string &pathname)

Get parent pathname from a pathname string.

Parameters

pathname[in] Input string pathname

Returns

A string representation of the parent pathname

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 size_t directorySize(const std::string &pathname)

Count the number of elements in a folder.

Note

Elements “.” and “..” are not counted

Parameters

pathname[in] Pathname to a folder

Returns

The numbers of elements found

static std::pair<std::string, 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 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.