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
  • [in] value: input string

  • [in] type: desired type

  • [out] cast: 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
  • [inout] Param_handler_IO: OpenMS’ DefaultParamHandler object to update

  • [in] parameters_I: user parameters

  • [in] param_handler_name: 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
  • [inout] Param_IO: OpenMS’ Param object to update

  • [in] parameters_I: 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
  • [in] str_I: Input string

  • [out] cast: 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

Parameters

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

Return

True if str ends with suffix. Otherwise false.

Parameters
  • [in] str: Input string

  • [in] suffix: Suffix

  • [in] case_sensitive: Case sensitive string comparison

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

Return

A container with the desired information

Parameters
  • [in] pathname: Folder pathname

  • [in] asc: Sort entries in ascending order

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

Get parent pathname from a pathname string.

Return

A string representation of the parent pathname

Parameters
  • [in] pathname: Input string 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’}

Exceptions
  • std::invalid_argument: Sizes of indices and v differ

Parameters
  • [in] indices: The vector of indices that decides the sorting

  • [inout] v: 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.

Return

True if ‘a’ is lexicographically less than ‘b’. Otherwise false.

Parameters
  • [in] a: left-side string

  • [in] b: right-side string

static size_t directorySize(const std::string &pathname)

Count the number of elements in a folder.

Note

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

Return

The numbers of elements found

Parameters
  • [in] pathname: Pathname to a folder

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.

Return

The absolute path to log file and boolean flag whether the path to directory was created

Parameters
  • [in] filename: Log filename

static std::string getSmartPeakVersion()

Returns the build version of SmartPeak package if available.