A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
genesis::utils Namespace Reference

Classes

class  BaseInputSource
 Abstract base class for reading byte data from input sources. More...
 
class  Bitvector
 
class  BmpWriter
 Write Bitmap image files. More...
 
class  CharLookup
 Simple lookup table providing a value lookup for each ASCII char (0-127). More...
 
class  Color
 
class  ColorPalette
 
class  CsvReader
 Read Comma Separated Values (CSV) data and other delimiter-separated formats. More...
 
class  Deserializer
 
class  EuclideanKmeans
 
class  FileInputSource
 Input source for reading byte data from a file. More...
 
class  GeoCoordinate
 Geographical coordinates in degrees. More...
 
class  Histogram
 Histogram class for accumulating and summarizing data. More...
 
class  HistogramAccumulator
 Histogram helper class that collects data and builds a fitting Histogram. More...
 
class  IndexedList
 http://www.boost.org/doc/libs/1_59_0/doc/html/container/non_standard_containers.html More...
 
class  IndexedListIterator
 
class  InputBuffer
 
class  InputStream
 Stream interface for reading data from an InputSource, that keeps track of line and column counters. More...
 
class  IteratorDeletions
 Take a TwobitVector sequence and iterate over all possible deletions of its values. More...
 
class  IteratorInsertions
 
class  IteratorSubstitutions
 
class  JsonDocument
 Store a Json value of any kind. More...
 
class  JsonIterator
 Template for a random access iterator for the JsonDocument class. More...
 
class  JsonReader
 Read Json data into a JsonDocument. More...
 
class  JsonWriter
 Write Json data from a JsonDocument. More...
 
class  Kmeans
 
class  Logging
 Logging class with easy and fast usage. More...
 
struct  LoggingDetails
 POD stuct containing the settings for which information is included with each logging message. More...
 
class  LoggingScopeLevel
 Class that sets the Logging Level to a value von construction and set it back on destruction. This is used by the log scope level macro. More...
 
class  Matrix
 
class  MatrixReader
 
struct  MeanStddevPair
 Store a mean and a standard deviation value. More...
 
struct  MinMaxPair
 Store a pair of min and max values. More...
 
class  NexusBlock
 
class  NexusDocument
 
class  NexusTaxa
 
class  NexusTrees
 
class  NexusWriter
 
class  Options
 Simple Options class for application-wide configuration and settings. More...
 
struct  PcaData
 Helper stucture that collects the output of principal_component_analysis(). More...
 
struct  Quartiles
 Store the values of quartiles: q0 == min, q1 == 25%, q2 == 50%, q3 == 75%, q4 == max. More...
 
class  Range
 
class  RangeMinimumQuery
 Class that allows to efficiently find the index of the minimum element within an interval of an array of integer values. More...
 
class  Serializer
 
class  SHA1
 Calculate SHA1 hashes for strings and files. More...
 
class  SortedVector
 Sorted vector of unique elements. More...
 
class  StreamInputSource
 Input source for reading byte data from an istream. More...
 
class  StringInputSource
 Input source for reading byte data from a string. More...
 
class  Style
 Simple text style class for colorized and bold output to a terminal. More...
 
struct  SvgBox
 
struct  SvgCircle
 
class  SvgDefinitions
 
class  SvgDocument
 
struct  SvgDrawingOptions
 
struct  SvgEllipse
 
struct  SvgFill
 
struct  SvgFont
 
struct  SvgGradientLinear
 
struct  SvgGradientStop
 
struct  SvgGroup
 
struct  SvgImage
 
struct  SvgLine
 
struct  SvgMargin
 
class  SvgObject
 
struct  SvgPath
 
struct  SvgPoint
 
struct  SvgPolygon
 
struct  SvgPolyline
 
struct  SvgRect
 
struct  SvgSize
 
struct  SvgStroke
 
struct  SvgText
 
struct  SvgTransform
 
struct  SvgUse
 
class  SynchronousReader
 Read bytes from an InputSource into a char buffer. More...
 
class  Table
 
struct  TableLayout
 
struct  Tickmarks
 Helper class to find "nice" tickmark intervals for creating scales and axes. More...
 
struct  TridiagonalDecompositionData
 Helper structure used for the eigenvalue decomposition in reduce_to_tridiagonal_matrix() and tridiagonal_ql_algorithm(). See there for details. More...
 
class  TwobitVector
 
class  XmlComment
 
class  XmlDocument
 
class  XmlElement
 
class  XmlMarkup
 
class  XmlValue
 
class  XmlWriter
 Write Xml data. More...
 

Functions

template<typename T >
constexpr T abs_diff (T const &lhs, T const &rhs)
 Calculate the absolute differenence between two values. More...
 
template<typename InputStream >
void affirm_char_or_throw (InputStream &source, char criterion, SkipWhitespace skip_ws=SkipWhitespace::kNone)
 Lexing function that checks whether the current char from the stream equals the provided one. More...
 
template<typename InputStream >
void affirm_char_or_throw (InputStream &source, std::function< bool(char)> criterion, SkipWhitespace skip_ws=SkipWhitespace::kNone)
 Lexing function that checks whether the current char from the stream fulfills the provided criterion. More...
 
bool almost_equal_relative (double lhs, double rhs, double max_rel_diff=std::numeric_limits< double >::epsilon())
 Check whether two doubles are almost equal, using a relative epsilon to compare them. More...
 
std::string bitstring (TwobitVector const &vec)
 Return a string with a bit-representation of a TwobitVector. More...
 
std::string bitstring (TwobitVector::WordType const &vec)
 Return a string with a bit-representation of a TwobitVector::WordType. More...
 
bool char_is_digit (const char c)
 Return whether a char is a digit (0-9). More...
 
bool char_is_number_part (char const c)
 Return whether a char is valid in a number, i.e., a digit, a dot, plus, minus, or 'e'/'E'. More...
 
bool char_is_sign (const char c)
 Return whether a char is a sign (+-). More...
 
bool char_match_ci (const char c1, const char c2)
 Return whether two chars are the same, case insensitive. More...
 
Color color_from_bytes (unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
 Create a Color given three or four values in the range [ 0, 255 ] for each of the components red, green and blue, and optionally alpha. More...
 
Color color_from_hex (std::string const &hex_color, std::string const &prefix="#")
 Create a Color given a hex color string in the format "#003366[ff]". More...
 
Color color_from_name_web (std::string const &name)
 Retrieve a named web color by name. More...
 
Color color_from_name_xkcd (std::string const &name)
 Retrieve a named xkcd color by name. More...
 
std::vector< Color > const & color_list (ColorList palette)
 
std::vector< Color > const & color_list (std::string const &palette)
 
std::vector< Color > const & color_list_inferno ()
 
std::vector< Color > const & color_list_magma ()
 
std::vector< Color > const & color_list_plasma ()
 
std::vector< Color > const & color_list_spectral ()
 
std::vector< Color > const & color_list_viridis ()
 
std::vector< Colorcolor_palette_web ()
 
std::vector< Colorcolor_palette_xkcd ()
 
std::string color_to_hex (Color const &c, std::string const &prefix="#", bool uppercase=false, bool with_alpha=false)
 Return a hex string representation of a Color in the format "#003366[ff]". More...
 
template<class C , class T >
bool contains (const C &v, const T &x)
 Returns whether a container object has a certain element. More...
 
GeoCoordinate convert_geo_coordinate (std::string const &latitude, std::string const &longitude)
 Parse strings of geographic coordinates. More...
 
GeoCoordinate convert_geo_coordinate (std::string const &coordinate)
 Parse a string of geographic coordinates. More...
 
double convert_single_geo_coordinate (std::string const &h1, std::string const &d, std::string const &m, std::string const &s, std::string const &h2, GeoCoordinateComponent component)
 Local helper function that takes parts of the regex matches and converts them to double. More...
 
std::vector< Colorconvert_to_palette_ (NamedColorList const &list)
 Local helper function to convert a list of byte colors into a proper Color vector. More...
 
Matrix< double > correlation_matrix (Matrix< double > const &data)
 Calculate the correlation Matrix of a given data Matrix. More...
 
size_t count_substring_occurrences (std::string const &str, std::string const &sub)
 Return the number of (possibly overlapping) occurrences of a substring in a string. More...
 
Matrix< double > covariance_matrix (Matrix< double > const &data)
 Calculate the covariance Matrix of a given data Matrix. More...
 
std::string current_date ()
 Returns the current date as a string in the format "2014-12-31". More...
 
std::string current_time ()
 Returns the current time as a string in the format "13:37:42". More...
 
std::string deescape (std::string const &text)
 Return a string where backslash-escaped characters are transformed into their respective string form. More...
 
char deescape (char c)
 Return the de-escaped char for a backslash-escaped char. More...
 
void dir_create (std::string const &path)
 Create a directory. More...
 
bool dir_exists (std::string const &dir)
 Return true iff the directory exists. More...
 
std::vector< std::string > dir_list_contents (std::string const &dir, bool full_path=false, std::string const &regex="")
 Get a list of files and directories in a directory. More...
 
std::vector< std::string > dir_list_contents_ (std::string const &dir, bool full_path, std::string const &regex, std::function< bool(std::string const &)> condition)
 
std::vector< std::string > dir_list_directories (std::string const &dir, bool full_path=false, std::string const &regex="")
 Get a list of directories in a directory. More...
 
std::vector< std::string > dir_list_files (std::string const &dir, bool full_path=false, std::string const &regex="")
 Get a list of files in a directory. More...
 
std::string dir_normalize_path (std::string const &path)
 Normalize a dir name, i.e., make sure that the given path ends with exaclty one slash. More...
 
TableLayout double_frame (bool condensed)
 
TableLayout double_grid (bool condensed)
 
double earth_movers_distance (const Histogram &h1, const Histogram &h2, bool norm)
 
bool ends_with (std::string const &text, std::string const &ending)
 Return whether a string ends with another string. More...
 
bool equal_ranges (Histogram const &lhs, Histogram const &rhs)
 
template<class T >
bool equals (SortedVector< T > const &lhs, SortedVector< T > const &rhs)
 
bool equals_ci (std::string const &lhs, std::string const &rhs)
 Compare two strings case insensitive. More...
 
template<class Container , class UnaryPredicate >
void erase_if (Container &c, UnaryPredicate p)
 Erases all elements from the container that satisfy a given predicate. An element is erased, if the predicate evaluates to true for it. The predicate needs to have a signature similar to (T const&)->bool. More...
 
std::string escape (std::string const &text)
 Return a string where special chars are replaces by their escape sequence. More...
 
TableLayout extended_frame (bool condensed)
 
TableLayout extended_grid (bool condensed)
 
void file_append (std::string const &content, std::string const &filename)
 Append the content of a string to a file. More...
 
std::string file_basename (std::string const &filename)
 Remove directory name from file name if present. More...
 
bool file_exists (std::string const &filename)
 Return true iff the file exists. More...
 
std::string file_extension (std::string const &filename)
 Return the extension name of a file. More...
 
std::string file_filename (std::string const &filename)
 Remove extension if present. More...
 
std::unordered_map
< std::string, std::string > 
file_info (std::string const &filename)
 Return information about a file. More...
 
void file_output_stream (std::string const &filename, std::ofstream &out_stream, std::ios_base::openmode mode=std::ios_base::out)
 Helper function to obtain an output stream to a file. More...
 
std::string file_path (std::string const &filename)
 Return the path leading to a file. More...
 
std::string file_read (std::string const &filename)
 Return the contents of a file as a string. More...
 
size_t file_size (std::string const &filename)
 Return the size of a file. More...
 
void file_write (std::string const &content, std::string const &filename)
 Write the content of a string to a file. More...
 
double fisher_transformation (double correlation_coefficient)
 Apply Fisher z-transformation to a correlation coefficient. More...
 
std::vector< double > fisher_transformation (std::vector< double > const &correlation_coefficients)
 Apply Fisher z-transformation to a vector of correlation coefficients. More...
 
TwobitVector from_nucleic_acids (std::string const &sequence)
 Turn a string of nucleic acids into a TwobitVector. More...
 
double geo_distance (GeoCoordinate const &c1, GeoCoordinate const &c2)
 Calculate the distance (in km) between two points on Earth. More...
 
std::string get_attribute_string (Style const &s)
 Internal helper function that returns the attribute string of a Style based on its properties. More...
 
static std::array< std::pair
< std::string, std::string >
, 17 >::const_iterator 
get_background_color_iterator (std::string name)
 Internal helper function that returns an iterator into the background color list. More...
 
NamedColorList::const_iterator get_color_list_iterator_ (NamedColorList const &list, std::string name)
 Internal helper function. More...
 
static std::array< std::pair
< std::string, std::string >
, 17 >::const_iterator 
get_foreground_color_iterator (std::string name)
 Internal helper function that returns an iterator into the foreground color list. More...
 
Color gradient (std::map< double, Color > const &ranges, double value)
 Returns a Color that is created using a color gradient. More...
 
std::string head (std::string const &text, size_t lines=10)
 Return the first lines of the text. More...
 
Color heat_gradient (double percentage)
 Return a Color that represents a heat gradient for a given percentage value. More...
 
std::string indent (std::string const &text, std::string const &indentation=" ")
 Indent each line of text with indentation and return the result. More...
 
size_t int_pow (size_t base, size_t exp)
 Calculate the power base^exp for positive integer values. More...
 
Color interpolate (Color const &color1, Color const &color2, double fraction)
 Linearily interpolate between two Colors. More...
 
bool is_dir (std::string const &path)
 Return true iff the provided path is a directory. More...
 
bool is_file (std::string const &path)
 Return true iff the provided path is a file. More...
 
template<class T >
bool is_subset_of (SortedVector< T > const &subset, SortedVector< T > const &superset)
 
template<class T >
bool is_subset_or_equal (SortedVector< T > const &subset, SortedVector< T > const &superset)
 
bool is_valid_filname (std::string const &filename)
 Check whether a file name is valid. More...
 
bool is_valid_int_pow (size_t base, size_t exp)
 Return whether the given power can be stored within a size_t. More...
 
bool is_web_color_name (std::string const &name)
 Return true iff the given name is a named web color. More...
 
bool is_xkcd_color_name (std::string const &name)
 Return true iff the given name is a named xkcd color. More...
 
utils::Range< IteratorDeletionsiterate_deletions (TwobitVector const &vector)
 
utils::Range< IteratorInsertionsiterate_insertions (TwobitVector const &vector)
 
utils::Range
< IteratorSubstitutions
iterate_substitutions (TwobitVector const &vector)
 
template<typename T >
std::string join (T const &v, std::string const &delimiter)
 Return a string where the elements of a container v are joined using the string delimiter in between them. More...
 
long logging_progress_value (long value=-1)
 Hack function to make sure that the value arugment in LOG_PROG is only evaluated once. More...
 
template<typename T , typename... Args>
std::unique_ptr< T > make_unique (Args &&...args)
 Returns a std::unique_ptr for a given type. More...
 
template<typename T = double, typename A = double, typename B = double>
Matrix< T > matrix_addition (Matrix< A > const &a, Matrix< B > const &b)
 Calculate the element-wise sum of two Matrices. More...
 
template<typename T = double, typename A = double, typename B = double>
Matrix< T > matrix_addition (Matrix< A > const &matrix, B const &scalar)
 Calculate the element-wise sum of a Matrix and a scalar. More...
 
std::vector< MeanStddevPairmatrix_col_mean_stddev (Matrix< double > const &data, double epsilon=-1.0)
 Calcualte the column-wise mean and standard deviation of a Matrix. More...
 
template<typename T >
std::vector< MinMaxPair< T > > matrix_col_minmax (Matrix< T > const &data)
 Calculate the column-wise min and max values of a Matrix. More...
 
double matrix_col_pearson_correlation_coefficient (Matrix< double > const &mat1, size_t col1, Matrix< double > const &mat2, size_t col2)
 Calculate the Pearson Correlation Coefficient between two columns of two Matrices. More...
 
Quartiles matrix_col_quartiles (Matrix< double > const &data, size_t col)
 
std::vector< Quartilesmatrix_col_quartiles (Matrix< double > const &data)
 
double matrix_col_spearmans_rank_correlation_coefficient (Matrix< double > const &mat1, size_t col1, Matrix< double > const &mat2, size_t col2)
 Calculate Spearman's Rank Correlation Coefficient between two columns of two Matrices. More...
 
template<typename T >
std::vector< T > matrix_col_sums (Matrix< T > const &data)
 Calculate the sum of each column and return the result as a vector. More...
 
template<typename T >
bool matrix_is_symmetric (Matrix< T > const &data)
 Return whether a Matrix is symmetric, i.e., whether it is square and m[ i, j ] == m[ j, i ] holds for all entries. More...
 
MeanStddevPair matrix_mean_stddev (Matrix< double > const &data, double epsilon=-1.0)
 Calcualte the mean and standard deviation of all elements in a Matrix. More...
 
template<typename T >
MinMaxPair< T > matrix_minmax (Matrix< T > const &data)
 Calculate the min and max values of a Matrix. More...
 
template<typename T = double, typename A = double, typename B = double>
Matrix< T > matrix_multiplication (Matrix< A > const &a, Matrix< B > const &b)
 Calculate the product of two Matrices. More...
 
template<typename T = double, typename A = double, typename B = double>
std::vector< T > matrix_multiplication (std::vector< A > const &a, Matrix< B > const &b)
 Calculate the product of a vector a with a Matrices b, as if the vector was a Matrix with only one row. More...
 
template<typename T = double, typename A = double, typename B = double>
std::vector< T > matrix_multiplication (Matrix< A > const &a, std::vector< B > const &b)
 Calculate the product of a Matrices a with a vector b, as if the vector was a Matrix with only one column. More...
 
template<typename T = double, typename A = double, typename B = double>
Matrix< T > matrix_multiplication (Matrix< A > const &matrix, B const &scalar)
 Calculate the element-wise multiplication of a Matrix and a scalar. More...
 
Quartiles matrix_quartiles (Matrix< double > const &data)
 Calculate the Quartiles of the elmements in Matrix of double. More...
 
std::vector< MeanStddevPairmatrix_row_mean_stddev (Matrix< double > const &data, double epsilon=-1.0)
 Calcualte the row-wise mean and standard deviation of a Matrix. More...
 
template<typename T >
std::vector< MinMaxPair< T > > matrix_row_minmax (Matrix< T > const &data)
 Calculate the row-wise min and max values of a Matrix. More...
 
double matrix_row_pearson_correlation_coefficient (Matrix< double > const &mat1, size_t row1, Matrix< double > const &mat2, size_t row2)
 Calculate the Pearson Correlation Coefficient between two row of two Matrices. More...
 
Quartiles matrix_row_quartiles (Matrix< double > const &data, size_t row)
 
std::vector< Quartilesmatrix_row_quartiles (Matrix< double > const &data)
 
double matrix_row_spearmans_rank_correlation_coefficient (Matrix< double > const &mat1, size_t row1, Matrix< double > const &mat2, size_t row2)
 Calculate Spearman's Rank Correlation Coefficient between two row of two Matrices. More...
 
template<typename T >
std::vector< T > matrix_row_sums (Matrix< T > const &data)
 Calculate the sum of each row and return the result as a vector. More...
 
template<typename T >
Matrix< T > matrix_sort_by_col_sum_symmetric (Matrix< T > const &data)
 Sort rows and columns of a Matrix by the sum or the columns. More...
 
template<typename T >
Matrix< T > matrix_sort_by_row_sum_symmetric (Matrix< T > const &data)
 Sort rows and columns of a Matrix by the sum or the rows. More...
 
template<typename T = double, typename A = double, typename B = double>
Matrix< T > matrix_subtraction (Matrix< A > const &a, Matrix< B > const &b)
 Calculate the element-wise difference of two Matrices. More...
 
template<typename T >
matrix_sum (Matrix< T > const &data)
 Calculate the sum of all elements in a Matrix. More...
 
template<typename T >
void matrix_swap_cols (Matrix< T > &data, size_t col_a, size_t col_b)
 Swap (interchange) two columns of a Matrix, given their indices. More...
 
template<typename T >
void matrix_swap_rows (Matrix< T > &data, size_t row_a, size_t row_b)
 Swap (interchange) two rows of a Matrix, given their indices. More...
 
template<typename T >
Matrix< T > matrix_transpose (Matrix< T > const &data)
 Transpose a Matrix. More...
 
size_t max_bin (const Histogram &h)
 
double max_value (const Histogram &h)
 
double mean (const Histogram &h)
 Compute the bin-weighted arithmetic mean. More...
 
MeanStddevPair mean_stddev (std::vector< double > const &vec, double epsilon=-1.0)
 Calcualte the mean and standard deviation of a vector of double. More...
 
double median (const Histogram &h)
 
double median (std::vector< double > const &vec, size_t l, size_t r)
 Local helper function to get the median in between a range. More...
 
double median (std::vector< double > const &vec)
 Calculate the median value of a vector of double. More...
 
size_t min_bin (const Histogram &h)
 
double min_value (const Histogram &h)
 
TableLayout minimal_layout ()
 
void normalize (Histogram &h, double total)
 
std::vector< MinMaxPair< double > > normalize_cols (Matrix< double > &data)
 Normalize the columns of a Matrix so that all values are in the range [ 0.0, 1.0 ]. More...
 
std::vector< MinMaxPair< double > > normalize_rows (Matrix< double > &data)
 Normalize the rows of a Matrix so that all values are in the range [ 0.0, 1.0 ]. More...
 
void offset (Histogram &h, double value)
 
bool operator!= (NexusTaxa const &lhs, NexusTaxa const &rhs)
 
template<class T >
bool operator!= (SortedVector< T > const &lhs, SortedVector< T > const &rhs)
 
bool operator!= (JsonDocument const &lhs, JsonDocument const &rhs) noexcept
 
bool operator!= (JsonDocument const &v, std::nullptr_t) noexcept
 
bool operator!= (std::nullptr_t, JsonDocument const &v) noexcept
 
bool operator!= (Color const &lhs, Color const &rhs)
 
bool operator& (SkipWhitespace lhs, SkipWhitespace rhs)
 And-operator to check whether a SkipWhitespace is set. More...
 
Bitvector operator& (Bitvector const &lhs, Bitvector const &rhs)
 
Bitvector operator- (Bitvector const &lhs, Bitvector const &rhs)
 Set-minus of two Bitvectors. More...
 
bool operator< (JsonDocument const &lhs, JsonDocument const &rhs) noexcept
 
bool operator< (JsonDocument::const_reference lhs, JsonDocument::const_reference rhs) noexcept
 
bool operator< (const JsonDocument::ValueType lhs, const JsonDocument::ValueType rhs) noexcept
 
std::ostream & operator<< (std::ostream &os, const Histogram &h)
 
std::ostream & operator<< (std::ostream &os, const HistogramAccumulator &h)
 
std::ostream & operator<< (std::ostream &os, NexusBlock const &block)
 
std::ostream & operator<< (std::ostream &os, Color const &h)
 Write a textual representation of the Color the a stream, in the format "(r, g, b, a)". More...
 
template<typename T >
std::ostream & operator<< (std::ostream &os, const Matrix< T > &matrix)
 
std::ostream & operator<< (std::ostream &out, Table const &table)
 
std::ostream & operator<< (std::ostream &os, GeoCoordinate const &coord)
 
std::ostream & operator<< (std::ostream &s, Bitvector const &rhs)
 
std::ostream & operator<< (std::ostream &out, Style const &style)
 Print the properties of a Style object to a stream. More...
 
std::ostream & operator<< (std::ostream &out, TableLayout::Binder const &binder)
 
bool operator<= (JsonDocument const &lhs, JsonDocument const &rhs) noexcept
 
template<class T >
bool operator== (SortedVector< T > const &lhs, SortedVector< T > const &rhs)
 
bool operator== (NexusTaxa const &lhs, NexusTaxa const &rhs)
 
bool operator== (JsonDocument const &lhs, JsonDocument const &rhs) noexcept
 
bool operator== (JsonDocument const &v, std::nullptr_t) noexcept
 
bool operator== (std::nullptr_t, JsonDocument const &v) noexcept
 
bool operator== (Color const &lhs, Color const &rhs)
 
bool operator== (JsonDocument::const_reference lhs, JsonDocument::const_reference rhs) noexcept
 
bool operator> (JsonDocument const &lhs, JsonDocument const &rhs) noexcept
 
bool operator>= (JsonDocument const &lhs, JsonDocument const &rhs) noexcept
 
Bitvector operator^ (Bitvector const &lhs, Bitvector const &rhs)
 
Bitvector operator| (Bitvector const &lhs, Bitvector const &rhs)
 
template<class T >
parse_float (utils::InputStream &source)
 Read a floating point number from a stream and return it. More...
 
template<class T >
parse_integer (utils::InputStream &source)
 Alias for parse_signed_integer(). More...
 
std::string parse_number_string (utils::InputStream &source)
 Read a general number string from an input stream. More...
 
std::string parse_quoted_string (utils::InputStream &source, bool use_escapes=true, bool use_twin_quotes=false, bool include_qmarks=false)
 Read a string in quotation marks from a stream and return it. More...
 
template<class T >
parse_signed_integer (utils::InputStream &source)
 Read a signed integer from a stream and return it. More...
 
template<class T >
parse_unsigned_integer (utils::InputStream &source)
 Read an unsigned integer from a stream and return it. More...
 
double pearson_correlation_coefficient (std::vector< double > const &vec_a, std::vector< double > const &vec_b)
 Calculate the Pearson Correlation Coefficient between the entries of two vectors. More...
 
PcaData principal_component_analysis (Matrix< double > const &data, size_t components=0, PcaStandardization standardization=PcaStandardization::kCorrelation)
 Perfom a Principal Component Analysis on a given data Matrix. More...
 
template<typename T >
void print (std::ostream &out, Matrix< T > const &matrix, size_t rows=10, size_t cols=10)
 Print a Matrix to an out stream. See print( Matrix<T> const&, size_t, size_t ) for details. More...
 
template<typename T >
std::string print (Matrix< T > const &matrix, size_t rows=10, size_t cols=10)
 Print a Matrix to a std::string. More...
 
Quartiles quartiles (std::vector< double > const &vec)
 Calculate the Quartiles of a vector of double. More...
 
std::vector< size_t > ranking_dense (std::vector< double > const &vec)
 Return the ranking of the given values, using Dense ranking ("1223" ranking). More...
 
std::vector< double > ranking_fractional (std::vector< double > const &vec)
 Return the ranking of the given values, using Fractional ranking ("1 2.5 2.5 4" ranking). More...
 
std::vector< size_t > ranking_modified (std::vector< double > const &vec)
 Return the ranking of the given values, using Modified competition ranking ("1334" ranking). More...
 
std::vector< size_t > ranking_ordinal (std::vector< double > const &vec)
 Return the ranking of the given values, using Ordinal ranking ("1234" ranking). More...
 
std::vector< size_t > ranking_standard (std::vector< double > const &vec)
 Return the ranking of the given values, using Standard competition ranking ("1224" ranking). More...
 
template<typename InputStream >
char read_char_or_throw (InputStream &source, char criterion, SkipWhitespace skip_ws=SkipWhitespace::kNone)
 Lexing function that reads a single char from the stream and checks whether it equals the provided one. More...
 
template<typename InputStream >
char read_char_or_throw (InputStream &source, std::function< bool(char)> criterion, SkipWhitespace skip_ws=SkipWhitespace::kNone)
 Lexing function that reads a single char from the stream and checks whether it fulfills the provided criterion. More...
 
template<typename InputStream >
std::string read_to_end_of_line (InputStream &source)
 Lexing function that reads until the end of the line (i.e., to the new line char), and returns the read chars (excluding the new line char). More...
 
template<typename InputStream >
std::string read_until (InputStream &source, char criterion)
 Lexing function that reads from the stream until its current char equals the provided one. The read chars are returned. More...
 
template<typename InputStream >
std::string read_until (InputStream &source, std::function< bool(char)> criterion)
 Lexing function that reads from the stream until its current char fulfills the provided criterion. The read chars are returned. More...
 
template<typename InputStream >
std::string read_while (InputStream &source, char criterion)
 Lexing function that reads from the stream while its current char equals the provided one. The read chars are returned. More...
 
template<typename InputStream >
std::string read_while (InputStream &source, std::function< bool(char)> criterion)
 Lexing function that reads from the stream while its current char fulfills the provided criterion. The read chars are returned. More...
 
TridiagonalDecompositionData reduce_to_tridiagonal_matrix (Matrix< double > &data)
 Triangular decomposition of a symmetric matrix. More...
 
std::string repeat (std::string const &word, size_t times)
 Take a string and repeat it a given number of times. More...
 
std::string replace_all (std::string const &text, std::string const &search, std::string const &replace)
 Return a copy of a string, where all occurrences of a search string are replaced by a replace string. More...
 
std::string replace_all_chars (std::string const &text, std::string const &search_chars, char replace)
 Replace all occurrences of the search_chars in text by the replace char. More...
 
double round_to (double x, size_t accuracy_order)
 Retun the value of x, rounded to the decimal digit given by accuracy_order. More...
 
std::string sanitize_filname (std::string const &filename)
 Remove or replace all invalid parts of a filename. More...
 
std::string sanitize_geo_coordinate (std::string const &coordinate, bool two_components=true)
 Replace non-ascii symbols used in geographic coordinates by their ascii equivalents. More...
 
void scale (Histogram &h, double factor)
 
std::vector< size_t > select_without_replacement (size_t k, size_t n)
 Select k many unique numbers out of the range [ 0, n ). More...
 
double sigma (const Histogram &h)
 Compute the bin-weighted standard deviation. More...
 
template<typename T >
constexpr int signum (T x, std::false_type)
 Implementation of signum(T x) for unsigned types. See there for details. More...
 
template<typename T >
constexpr int signum (T x, std::true_type)
 Implementation of signum(T x) for signed types. See there for details. More...
 
template<typename T >
constexpr int signum (T x)
 Get the sign of a value, which is either -1, 0, or 1. More...
 
TableLayout simple_frame (bool condensed)
 
TableLayout simple_grid (bool condensed)
 
TableLayout simple_layout (bool condensed)
 
template<typename InputStream >
void skip_to_end_of_line (InputStream &source)
 Lexing function that advances the stream to the end of the line, i.e., to the new line char. More...
 
template<typename InputStream >
void skip_until (InputStream &source, char criterion)
 Lexing function that advances the stream until its current char equals the provided one. More...
 
template<typename InputStream >
void skip_until (InputStream &source, std::function< bool(char)> criterion)
 Lexing function that advances the stream until its current char fulfills the provided criterion. More...
 
template<typename InputStream >
void skip_while (InputStream &source, char criterion)
 Lexing function that advances the stream while its current char equals the provided one. More...
 
template<typename InputStream >
void skip_while (InputStream &source, std::function< bool(char)> criterion)
 Lexing function that advances the stream while its current char fulfills the provided criterion. More...
 
template<typename RandomAccessIterator , typename Comparator >
std::vector< size_t > sort_indices (RandomAccessIterator first, RandomAccessIterator last, Comparator comparator)
 Get the indices to the sorted order of the given range. More...
 
template<typename RandomAccessIterator >
std::vector< size_t > sort_indices (RandomAccessIterator first, RandomAccessIterator last)
 Get the indices to the sorted order of the given range. More...
 
double spearmans_rank_correlation_coefficient (std::vector< double > const &vec_a, std::vector< double > const &vec_b)
 Calculate Spearman's Rank Correlation Coefficient between the entries of two vectors. More...
 
std::vector< std::string > split (std::string const &str, std::string const &delimiters=" ", const bool trim_empty=true)
 Spilt a string into parts, given a set of delimiter chars. More...
 
template<typename RandomAccessIterator , typename Comparator >
std::vector< size_t > stable_sort_indices (RandomAccessIterator first, RandomAccessIterator last, Comparator comparator)
 Get the indices to the stable sorted order of the given range. More...
 
template<typename RandomAccessIterator >
std::vector< size_t > stable_sort_indices (RandomAccessIterator first, RandomAccessIterator last)
 Get the indices to the stable sorted order of the given range. More...
 
std::vector< MeanStddevPairstandardize_cols (Matrix< double > &data, bool scale_means=true, bool scale_std=true)
 Standardize the columns of a Matrix by subtracting the mean and scaling to unit variance. More...
 
std::vector< MeanStddevPairstandardize_rows (Matrix< double > &data, bool scale_means=true, bool scale_std=true)
 Standardize the rows of a Matrix by subtracting the mean and scaling to unit variance. More...
 
bool starts_with (std::string const &text, std::string const &start)
 Return whether a string starts with another string. More...
 
double sum (const Histogram &h)
 
Matrix< double > sums_of_squares_and_cross_products_matrix (Matrix< double > const &data)
 Calculate the Sums of Squares and Cross Products Matrix (SSCP Matrix). More...
 
template<typename T >
std::string svg_attribute (std::string const &name, T const &value, std::string const &unit="")
 
std::string svg_comment (std::string const &content)
 
void swap (Histogram &lhs, Histogram &rhs) noexcept
 
void swap (HistogramAccumulator &lhs, HistogramAccumulator &rhs) noexcept
 
void swap (Style &lhs, Style &rhs) noexcept
 
void swap (Color &lhs, Color &rhs) noexcept
 
void swap (NexusTaxa &lhs, NexusTaxa &rhs)
 
void swap (NexusTrees &lhs, NexusTrees &rhs)
 
std::string tail (std::string const &text, size_t lines=10)
 Return the last lines of the text. More...
 
std::string to_lower (std::string const &str)
 Return an all-lowercase copy of the given string, locale-aware. More...
 
char to_lower_ascii (char c)
 Return the lower case of a given char, ascii-only. More...
 
std::string to_lower_ascii (std::string const &str)
 Return an all-lowercase copy of the given string, ascii-only. More...
 
void to_lower_ascii_inplace (std::string &str)
 Turn the given string to all-lowercase, ascii-only. More...
 
void to_lower_inplace (std::string &str)
 Turn the given string to all-lowercase, locale-aware. More...
 
std::string to_nucleic_acids (TwobitVector const &vec)
 Turn a TwobitVector into its string representation of nucleic acids. More...
 
template<typename T >
std::string to_string (T const &v)
 Return a string representation of a given value. More...
 
std::string to_string_leading_zeros (size_t value, size_t length=6)
 Return a string representation of a size_t value with a fixed length, that is, by adding leading zeros. More...
 
std::string to_string_precise (double value, int precision=6)
 Return a precise string representation of the input value, using the provided precision value (determining its decimal places). More...
 
std::string to_string_rounded (double value, int precision=6)
 Return a string representation of the input value, using the provided precision value (determining its decimal places) to round, and truncate trailing zeros. More...
 
std::string to_upper (std::string const &str)
 Return an all-uppercase copy of the given string, locale-aware. More...
 
char to_upper_ascii (char c)
 Return the upper case of a given char, ascii-only. More...
 
std::string to_upper_ascii (std::string const &str)
 Return an all-uppercase copy of the given string, ascii-only. More...
 
void to_upper_ascii_inplace (std::string &str)
 Turn the given string to all-uppercase, ascii-only. More...
 
void to_upper_inplace (std::string &str)
 Turn the given string to all-uppercase, locale-aware. More...
 
TwobitVector::ValueType translate_from_nucleic_acid (char site)
 Translate a char into TwobitVector::ValueType. More...
 
char translate_to_nucleic_acid (TwobitVector::ValueType value)
 Translate a TwobitVector::ValueType into its char representation. More...
 
size_t triangular_index (size_t i, size_t j, size_t n)
 Given indices i and j in a quadratic Matrix, find the corresponding linear index. More...
 
std::pair< size_t, size_t > triangular_indices (size_t k, size_t n)
 Given a linear index in a upper triangular Matrix, find the corresponding Matrix indices. More...
 
size_t triangular_size (size_t n)
 Calculate the number of linear indices needed for a triangular Matrix of size n. More...
 
void tridiagonal_ql_algorithm (Matrix< double > &data, TridiagonalDecompositionData &tri, size_t max_iterations=1000)
 Reduce a symmetric matrix to a symmetric tridiagonal matrix. More...
 
std::string trim (std::string const &s, std::string const &delimiters=" \f\n\r\t\v")
 Return a copy of the input string, with trimmed white spaces. More...
 
std::string trim_left (std::string const &s, std::string const &delimiters=" \f\n\r\t\v")
 Return a copy of the input string, with right trimmed white spaces. More...
 
std::string trim_right (std::string const &s, std::string const &delimiters=" \f\n\r\t\v")
 Return a copy of the input string, with left trimmed white spaces. More...
 
template<typename T >
std::string xml_attribute (std::string const &name, T const &value)
 
std::string xml_comment (std::string const &content)
 
std::string xml_deescape (std::string const &txt)
 De-escape special XML characters. More...
 
std::string xml_escape (std::string const &txt)
 Escape special XML characters. More...
 
const XmlCommentxml_value_to_comment (const XmlValue *v)
 Converts a pointer to an XmlValue to XmlComment if appropriate. More...
 
const XmlElementxml_value_to_element (const XmlValue *v)
 Converts a pointer to an XmlValue to XmlElement if appropriate. More...
 
const XmlMarkupxml_value_to_markup (const XmlValue *v)
 Converts a pointer to an XmlValue to XmlMarkup if appropriate. More...
 

Enumerations

enum  ColorList {
  kMagma, kInferno, kPlasma, kViridis,
  kSpectral
}
 
enum  GeoCoordinateComponent { kLatitude, kLongitude }
 Local helper enum that indicates which component of a coordinate we are dealing with. More...
 
enum  PcaStandardization { kCorrelation, kCovariance, kSSCP }
 Setting for principal_component_analysis() to determine which form of standardization of the data to use prior to perfoming the PCA. More...
 
enum  SkipWhitespace : unsigned char { kNone = 0, kLeading = 1, kTrailing = 2, kSurrounding = 3 }
 Option to determine how to treat surrounding whitespace when scanning an input stream. More...
 

Typedefs

using InputReader = SynchronousReader
 Alias for the either AsynchronousReader or SynchronousReader, depending on the threading setting. More...
 
using NamedColorList = std::vector< std::pair< std::string, ColorBytes >>
 

Variables

const std::vector< Colorcolor_list_inferno_
 
const std::vector< Colorcolor_list_magma_
 
const std::vector< Colorcolor_list_plasma_
 
const std::vector< Colorcolor_list_spectral_
 
const std::vector< Colorcolor_list_viridis_
 
const NamedColorList color_list_web_
 Struct that stores a static const map of named web colors. More...
 
const NamedColorList color_list_xkcd_
 Struct that stores a static const map of named xkcd colors. More...
 
constexpr double EARTH_MEAN_RADIUS = 6371.0
 Earth is not flat! More...
 
constexpr double PI = 3.141592653589793238463
 Make the world go round. More...
 

Function Documentation

constexpr T genesis::utils::abs_diff ( T const &  lhs,
T const &  rhs 
)
inline

Calculate the absolute differenence between two values.

This function is particularly useful for unsigned types, as subtracting them and then using std::abs() does not work for them.

Definition at line 231 of file common.hpp.

void genesis::utils::affirm_char_or_throw ( InputStream &  source,
char  criterion,
SkipWhitespace  skip_ws = SkipWhitespace::kNone 
)
inline

Lexing function that checks whether the current char from the stream equals the provided one.

If not, the function throws std::runtime_error. The stream is not advanced (i.e., it stays at its current position). For a similar function that reads (i.e., also advances) the current char from the stream, see read_char_or_throw().

Using the parameter skip_ws, it is possible to skip leading and/or trailing whitespaces before/after treating the criterion char. See SkipWhitespace for more information.

Definition at line 380 of file scanner.hpp.

void genesis::utils::affirm_char_or_throw ( InputStream &  source,
std::function< bool(char)>  criterion,
SkipWhitespace  skip_ws = SkipWhitespace::kNone 
)
inline

Lexing function that checks whether the current char from the stream fulfills the provided criterion.

If not, the function throws std::runtime_error. The stream is not advanced (i.e., it stays at its current position). For a similar function that reads (i.e., also advances) the current char from the stream, see read_char_or_throw().

Using the parameter skip_ws, it is possible to skip leading and/or trailing whitespaces before/after treating the criterion char. See SkipWhitespace for more information.

Definition at line 415 of file scanner.hpp.

bool genesis::utils::almost_equal_relative ( double  lhs,
double  rhs,
double  max_rel_diff = std::numeric_limits<double>::epsilon() 
)
inline

Check whether two doubles are almost equal, using a relative epsilon to compare them.

Definition at line 277 of file common.hpp.

std::string bitstring ( TwobitVector const &  vec)

Return a string with a bit-representation of a TwobitVector.

It returns the words of the vector with bits in the order of the underlying integer type. This is mainly useful for debugging and testing.

Definition at line 124 of file utils/math/twobit_vector/functions.cpp.

std::string bitstring ( TwobitVector::WordType const &  vec)

Return a string with a bit-representation of a TwobitVector::WordType.

It returns the word with bits in the order of the underlying integer type. This is mainly useful for debugging and testing.

Definition at line 140 of file utils/math/twobit_vector/functions.cpp.

bool genesis::utils::char_is_digit ( const char  c)
inline

Return whether a char is a digit (0-9).

Definition at line 46 of file char.hpp.

bool genesis::utils::char_is_number_part ( char const  c)
inline

Return whether a char is valid in a number, i.e., a digit, a dot, plus, minus, or 'e'/'E'.

Definition at line 62 of file char.hpp.

bool genesis::utils::char_is_sign ( const char  c)
inline

Return whether a char is a sign (+-).

Definition at line 54 of file char.hpp.

bool genesis::utils::char_match_ci ( const char  c1,
const char  c2 
)
inline

Return whether two chars are the same, case insensitive.

Definition at line 70 of file char.hpp.

Color color_from_bytes ( unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

Create a Color given three or four values in the range [ 0, 255 ] for each of the components red, green and blue, and optionally alpha.

Definition at line 54 of file utils/tools/color/functions.cpp.

Color color_from_hex ( std::string const &  hex_color,
std::string const &  prefix = "#" 
)

Create a Color given a hex color string in the format "#003366[ff]".

The hash sign in the beginning can be replaced by any given prefix. If the string is not correctly formatted, an std::invalid_argument exception is thrown. If the string contains only RGB, alpha is set to 1.0.

Definition at line 64 of file utils/tools/color/functions.cpp.

Color color_from_name_web ( std::string const &  name)

Retrieve a named web color by name.

Names are filtered so that spaces, underscores and the letter case are ignored. If the color name does not exist, an std::invalid_argument exception is thrown.

Definition at line 1239 of file names.cpp.

Color color_from_name_xkcd ( std::string const &  name)

Retrieve a named xkcd color by name.

Names are filtered so that spaces, underscores and the letter case are ignored. If the color name does not exist, an std::invalid_argument exception is thrown.

The colors are taken from an [https://xkcd.com/](xkcd) color survey. They were published under Public Domain, http://creativecommons.org/publicdomain/zero/1.0/. See https://xkcd.com/color/rgb/ and https://blog.xkcd.com/2010/05/03/color-survey-results/ for details. See also our Acknowledgements.

Definition at line 1250 of file names.cpp.

std::vector< Color > const & color_list ( ColorList  palette)

Definition at line 1157 of file lists.cpp.

std::vector< Color > const & color_list ( std::string const &  palette)

Definition at line 1178 of file lists.cpp.

std::vector< Color > const & color_list_inferno ( )

Definition at line 1133 of file lists.cpp.

std::vector< Color > const & color_list_magma ( )

Definition at line 1128 of file lists.cpp.

std::vector< Color > const & color_list_plasma ( )

Definition at line 1138 of file lists.cpp.

std::vector< Color > const & color_list_spectral ( )

Definition at line 1148 of file lists.cpp.

std::vector< Color > const & color_list_viridis ( )

Definition at line 1143 of file lists.cpp.

std::vector< Color > color_palette_web ( )

Definition at line 1261 of file names.cpp.

std::vector< Color > color_palette_xkcd ( )

Definition at line 1266 of file names.cpp.

std::string color_to_hex ( Color const &  c,
std::string const &  prefix = "#",
bool  uppercase = false,
bool  with_alpha = false 
)

Return a hex string representation of a Color in the format "#003366[ff]".

The hash sign in the beginning can be replaced by any given prefix. If uppercase is set to true, any outputted alphabetical chars (that is, A to F for hex strings) are uppercase. if with_alpha is set to true, two additional hex digits are printed for the alpha channel.

Definition at line 101 of file utils/tools/color/functions.cpp.

bool genesis::utils::contains ( const C &  v,
const T &  x 
)
inline

Returns whether a container object has a certain element.

The usage of std::find just to check for presence of a certain item is a bit cumbersome. This template simply takes any container and a value and returns true iff the value is present in the container.

Definition at line 56 of file algorithm.hpp.

GeoCoordinate convert_geo_coordinate ( std::string const &  latitude,
std::string const &  longitude 
)

Parse strings of geographic coordinates.

This is the same as convert_geo_coordinate( std::string const& ), with the only different being that the two components (NW and EW) are given separately. See there for details.

Definition at line 250 of file utils/tools/geodesy/functions.cpp.

GeoCoordinate convert_geo_coordinate ( std::string const &  coordinate)

Parse a string of geographic coordinates.

The function accepts many different formats for geographical coordinates. Some exemplary valid cases:

  • 50d4m17.698N 14d24m2.826E
  • 40:26:46N,79:56:55W
  • 40:26:46.302N 179:56:55.903W
  • 49°59'56.948"N, 15°48'22.989"E
  • 50d4m17.698N 14d24m2.826E
  • 49.9991522N, 150.8063858E
  • 40°26′47″N 79°58′36″W
  • 40d 26′ 47″ N 79d 58′ 36″ W
  • 40.446195N 79.948862W
  • 40,446195° 79,948862°
  • 40° 26.7717 / -79° 56.93172
  • 40.446195, -79.948862
  • N 49° 59.94913', E 15° 48.38315'

The hemispheres can be given as [NS] for the first component and [EW] for the second, and can either preceed or follow the numeric values. Degrees, Minutes and Seconds can be separated by the letters [dms], by degree (°), prime ( ′ ), single quotation mark ('), double prime (), double quoation mark ("), or by colons (:), respectively. The two components (NS and EW) can be separated by comma (,) or slash (/).

There are some caveats: The hemisphere strings (NESW) have to be in capitial letters, while the letters used for degrees, minute and seconds (dms) have to be lower case. This constraint avoids ambiguity between seconds (s) and south (S). Also, either the decimal separator can be a comma, or the separator between components, but not both. This again avoids ambiguity while parsing.

Definition at line 255 of file utils/tools/geodesy/functions.cpp.

double genesis::utils::convert_single_geo_coordinate ( std::string const &  h1,
std::string const &  d,
std::string const &  m,
std::string const &  s,
std::string const &  h2,
GeoCoordinateComponent  component 
)

Local helper function that takes parts of the regex matches and converts them to double.

The strings h1, d, m, s and h2 are the matches of the regex. The parameter component is the hemisphere of this coordinate component, NS or EW, which is determined by whether the matches are the first or the second component of the coordinate.

Definition at line 70 of file utils/tools/geodesy/functions.cpp.

std::vector<Color> genesis::utils::convert_to_palette_ ( NamedColorList const &  list)

Local helper function to convert a list of byte colors into a proper Color vector.

Definition at line 1212 of file names.cpp.

Matrix< double > correlation_matrix ( Matrix< double > const &  data)

Calculate the correlation Matrix of a given data Matrix.

This is done by standardizing the mean and variance of the given data and then calculating the sums_of_squares_and_cross_products_matrix().

Definition at line 311 of file statistics.cpp.

size_t count_substring_occurrences ( std::string const &  str,
std::string const &  sub 
)

Return the number of (possibly overlapping) occurrences of a substring in a string.

Definition at line 103 of file string.cpp.

Matrix< double > covariance_matrix ( Matrix< double > const &  data)

Calculate the covariance Matrix of a given data Matrix.

This is done by standardizing the mean of the given data and then calculating the sums_of_squares_and_cross_products_matrix().

Definition at line 329 of file statistics.cpp.

std::string current_date ( )

Returns the current date as a string in the format "2014-12-31".

Definition at line 39 of file date_time.cpp.

std::string current_time ( )

Returns the current time as a string in the format "13:37:42".

Definition at line 51 of file date_time.cpp.

std::string deescape ( std::string const &  text)

Return a string where backslash-escaped characters are transformed into their respective string form.

All occurrences of backslash + char in the string are de-escaped. That is, all \n, \t and \r are turned into their respective control sequences, while all other chars folloing a backslash are translated into the char itself (so that e.g., quotation marks or backslashes themself can be escaped).

Also see deescape( char c ).

Definition at line 335 of file string.cpp.

char deescape ( char  c)

Return the de-escaped char for a backslash-escaped char.

The function takes the char that follows a backslash in an escaped string and returns its de-escaped char. That is, n is turned into a new line (\n), t is turned into a tab (\t) and r is turned into a carrier return (\r). All other chars (e.g., quotation marks or the backslash itself) are simply returned as-is.

Definition at line 357 of file string.cpp.

void dir_create ( std::string const &  path)

Create a directory.

If the directory already exists, nothing happens. If the path exists, but is not a directory, a std::runtime_error is thrown. If the creation fails for some other reason, also a std::runtime_error is thrown.

Definition at line 175 of file fs.cpp.

bool dir_exists ( std::string const &  dir)

Return true iff the directory exists.

Definition at line 150 of file fs.cpp.

std::vector< std::string > dir_list_contents ( std::string const &  dir,
bool  full_path = false,
std::string const &  regex = "" 
)

Get a list of files and directories in a directory.

If full_path is set to true, the path of the provided dir is prepended to the resulting list. If a non-empy regex is provided, file names are filtered by this regular expression.

If the directory is not readable, the function throws std::runtime_error.

Definition at line 238 of file fs.cpp.

std::vector<std::string> genesis::utils::dir_list_contents_ ( std::string const &  dir,
bool  full_path,
std::string const &  regex,
std::function< bool(std::string const &)>  condition 
)

Definition at line 197 of file fs.cpp.

std::vector< std::string > dir_list_directories ( std::string const &  dir,
bool  full_path = false,
std::string const &  regex = "" 
)

Get a list of directories in a directory.

Behaves the same as dir_list_contents(), except tat only directories are listed (i.e., no files). See there for an explanation of the arguments.

Definition at line 259 of file fs.cpp.

std::vector< std::string > dir_list_files ( std::string const &  dir,
bool  full_path = false,
std::string const &  regex = "" 
)

Get a list of files in a directory.

Behaves the same as dir_list_contents(), except tat only files are listed (i.e., no directories). See there for an explanation of the arguments.

Definition at line 249 of file fs.cpp.

std::string dir_normalize_path ( std::string const &  path)

Normalize a dir name, i.e., make sure that the given path ends with exaclty one slash.

Definition at line 192 of file fs.cpp.

TableLayout double_frame ( bool  condensed)

Definition at line 573 of file utils/text/table.cpp.

TableLayout double_grid ( bool  condensed)

Definition at line 554 of file utils/text/table.cpp.

double earth_movers_distance ( const Histogram &  h1,
const Histogram &  h2,
bool  norm 
)

Definition at line 48 of file utils/math/histogram/distances.cpp.

bool ends_with ( std::string const &  text,
std::string const &  ending 
)

Return whether a string ends with another string.

Definition at line 69 of file string.cpp.

bool equal_ranges ( Histogram const &  lhs,
Histogram const &  rhs 
)

Definition at line 55 of file histogram.cpp.

bool genesis::utils::equals ( SortedVector< T > const &  lhs,
SortedVector< T > const &  rhs 
)

Definition at line 64 of file utils/containers/sorted_vector/operators.hpp.

bool equals_ci ( std::string const &  lhs,
std::string const &  rhs 
)

Compare two strings case insensitive.

Definition at line 47 of file string.cpp.

void genesis::utils::erase_if ( Container &  c,
UnaryPredicate  p 
)
inline

Erases all elements from the container that satisfy a given predicate. An element is erased, if the predicate evaluates to true for it. The predicate needs to have a signature similar to (T const&)->bool.

Parameters
cThe container to modify.
pThe predicate to satisfy.

Definition at line 70 of file algorithm.hpp.

std::string escape ( std::string const &  text)

Return a string where special chars are replaces by their escape sequence.

All new lines are transformed into either \r or \n, tabs into \t. Double quotation marks are preceeded by a backslash, also the backslash itself will be escaped, so that "</tt> becomes <tt>\\" and \ becomes \\.

Definition at line 323 of file string.cpp.

TableLayout extended_frame ( bool  condensed)

Definition at line 523 of file utils/text/table.cpp.

TableLayout extended_grid ( bool  condensed)

Definition at line 504 of file utils/text/table.cpp.

void file_append ( std::string const &  content,
std::string const &  filename 
)

Append the content of a string to a file.

If the file is not writable, the function throws std::runtime_error.

Definition at line 120 of file fs.cpp.

std::string file_basename ( std::string const &  filename)

Remove directory name from file name if present.

Definition at line 318 of file fs.cpp.

bool file_exists ( std::string const &  filename)

Return true iff the file exists.

Definition at line 69 of file fs.cpp.

std::string file_extension ( std::string const &  filename)

Return the extension name of a file.

Also see file_filename().

Definition at line 351 of file fs.cpp.

std::string file_filename ( std::string const &  filename)

Remove extension if present.

Caveat: Does not remove the path. So, if the filename itself does not contain an extension separator ".", but the path does, this will yield an unwanted result. Call file_basename() first.

Definition at line 335 of file fs.cpp.

std::unordered_map< std::string, std::string > file_info ( std::string const &  filename)

Return information about a file.

Definition at line 276 of file fs.cpp.

void genesis::utils::file_output_stream ( std::string const &  filename,
std::ofstream &  out_stream,
std::ios_base::openmode  mode = std::ios_base::out 
)
inline

Helper function to obtain an output stream to a file.

This function is used internally by all file writers. It makes sure that the file is writable, and throws an exception otherwise.

Furthermore, the function checks whether the file already exists. If it exists and Options::allow_file_overwriting() is not explicitly activated, the function throws, too. This is a safty measure to ensure that users cannot accidentally overwrite their files.

Parameters
[in]filenamePath to the file to write to.
[out]out_streamReference to the target output stream. Unfortunately, we cannot return streams, as they do not offer copy or move, so we have to do it this way.
[in]modeMode flag as used by std::ostream.
See Also
Options::allow_file_overwriting( bool )

Definition at line 67 of file output_stream.hpp.

std::string file_path ( std::string const &  filename)

Return the path leading to a file.

Does not resolve the path. Simply splits at the last directory separator.

Definition at line 304 of file fs.cpp.

std::string file_read ( std::string const &  filename)

Return the contents of a file as a string.

If the file is not readable, the function throws std::runtime_error.

Definition at line 80 of file fs.cpp.

size_t file_size ( std::string const &  filename)

Return the size of a file.

Definition at line 292 of file fs.cpp.

void file_write ( std::string const &  content,
std::string const &  filename 
)

Write the content of a string to a file.

If the file cannot be written to, the function throws an exception. Also, by default, if the file already exists, an exception is thrown. See Options::allow_file_overwriting() to change this behaviour.

Definition at line 106 of file fs.cpp.

double fisher_transformation ( double  correlation_coefficient)

Apply Fisher z-transformation to a correlation coefficient.

The coefficient can be calculated with pearson_correlation_coefficient() or spearmans_rank_correlation_coefficient() and has to be in range [ -1.0, 1.0 ].

There is also a version of this function for a vector of coefficients. See also matrix_col_pearson_correlation_coefficient(), matrix_row_pearson_correlation_coefficient(), matrix_col_spearmans_rank_correlation_coefficient() and matrix_row_spearmans_rank_correlation_coefficient() for matrix versions.

Definition at line 210 of file common.cpp.

std::vector< double > fisher_transformation ( std::vector< double > const &  correlation_coefficients)

Apply Fisher z-transformation to a vector of correlation coefficients.

See the single value version for details.

Definition at line 225 of file common.cpp.

TwobitVector from_nucleic_acids ( std::string const &  sequence)

Turn a string of nucleic acids into a TwobitVector.

Definition at line 93 of file utils/math/twobit_vector/functions.cpp.

double geo_distance ( GeoCoordinate const &  c1,
GeoCoordinate const &  c2 
)

Calculate the distance (in km) between two points on Earth.

Uses the Haversine formula. See convert_geo_coordinate() for a conversion function for geographical coordinates.

Definition at line 316 of file utils/tools/geodesy/functions.cpp.

std::string genesis::utils::get_attribute_string ( Style const &  s)

Internal helper function that returns the attribute string of a Style based on its properties.

Definition at line 193 of file style.cpp.

static std::array<std::pair<std::string, std::string>, 17>::const_iterator genesis::utils::get_background_color_iterator ( std::string  name)
static

Internal helper function that returns an iterator into the background color list.

Definition at line 69 of file style.cpp.

NamedColorList::const_iterator genesis::utils::get_color_list_iterator_ ( NamedColorList const &  list,
std::string  name 
)

Internal helper function.

Returns an iterator into the vector if the given name is a named color or an iterator to the end of the color map if it is not a named color.

Definition at line 1187 of file names.cpp.

static std::array<std::pair<std::string, std::string>, 17>::const_iterator genesis::utils::get_foreground_color_iterator ( std::string  name)
static

Internal helper function that returns an iterator into the foreground color list.

Definition at line 51 of file style.cpp.

Color gradient ( std::map< double, Color > const &  ranges,
double  value 
)

Returns a Color that is created using a color gradient.

The function takes a color gradient in form of a map from double to Color. The keys in the map are offset positions (stops) with specific Colors assigned to them. An arbitrary number of keys in between these boundaries is allowed.

Each key is associated with a Color value, which indicates the color at that position.

Example:

// Prepare gradient ranges.
auto ranges = std::map<double, Color>();
ranges[ 0.0 ] = Color( 0.0, 1.0, 0.0 );
ranges[ 0.5 ] = Color( 1.0, 1.0, 0.0 );
ranges[ 1.0 ] = Color( 1.0, 0.0, 0.0 );

// Get color at 30% of the green-yellow-red gradient.
Color c = gradient( ranges, 0.3 );

This map defines the same gradient that is used for heat_gradient. The range boundaries do not have to be [ 0.0, 1.0 ]. They can be set to any range that is needed to reflect the range of possible values.

The second parameter of this function then takes the position at which the gradient is evaluated. Values outside of the interval that is defined by the range are set to the closest interval border value.

For example, given the range map above, a value of 0.0 gives green; 0.5 gives yellow; 1.0 gives red; values in between are interpolated linearily.

Definition at line 159 of file utils/tools/color/functions.cpp.

std::string head ( std::string const &  text,
size_t  lines 
)

Return the first lines of the text.

Definition at line 81 of file string.cpp.

Color heat_gradient ( double  percentage)

Return a Color that represents a heat gradient for a given percentage value.

Given a percentage value in the range of [ 0.0, 1.0], the functions represents the heat of that value. For 0.0, the heat gradient value is green, for 0.5 yellow and for 1.0 red. The values in between are interpolated linearily.

Definition at line 192 of file utils/tools/color/functions.cpp.

std::string indent ( std::string const &  text,
std::string const &  indentation = "    " 
)

Indent each line of text with indentation and return the result.

By default, four spaces are used to indent. Whether the text ends with a new line or not is not changed. Any trailing indentation chars are trimmed, in order to not have trailing whitespaces in the result (except for the new line, if the text ends in one).

Definition at line 158 of file string.cpp.

size_t genesis::utils::int_pow ( size_t  base,
size_t  exp 
)
inline

Calculate the power base^exp for positive integer values.

Remark: This overflows quite easily. The function does not check whether the desired power actually fits within size_t. Use is_valid_int_pow() to check for this first.

Rationale for this function: One could argue that int powers are not really useful, particularly because of the fast overflow. However, using doubles leads to rounding errors, at least for bigger numbers. So, within the valid range, this function is more accurate. Also, it is faster.

Definition at line 311 of file common.hpp.

Color interpolate ( Color const &  color1,
Color const &  color2,
double  fraction 
)

Linearily interpolate between two Colors.

Definition at line 143 of file utils/tools/color/functions.cpp.

bool is_dir ( std::string const &  path)

Return true iff the provided path is a directory.

Internally, this function simply return the value of dir_exists(), as this already does the needed check. Thus, it is an alias.

Definition at line 142 of file fs.cpp.

bool is_file ( std::string const &  path)

Return true iff the provided path is a file.

Internally, this function simply return the value of file_exists(), as this already does the needed check. Thus, it is an alias.

Definition at line 61 of file fs.cpp.

bool genesis::utils::is_subset_of ( SortedVector< T > const &  subset,
SortedVector< T > const &  superset 
)

Definition at line 70 of file utils/containers/sorted_vector/operators.hpp.

bool genesis::utils::is_subset_or_equal ( SortedVector< T > const &  subset,
SortedVector< T > const &  superset 
)

Definition at line 98 of file utils/containers/sorted_vector/operators.hpp.

bool is_valid_filname ( std::string const &  filename)

Check whether a file name is valid.

Validating filenames depends on the operating system and file system of the disk. Thus, this is usually not an easy task. This function only checks some basics and is meant to catch the most common problems.

The function is meant to be called on the file name itself, without the directory path leading to it. File extensions are allowed. Thus, you might need to call file_basename() before in order to get the file name without the path.

Invalid filenames are:

  • Those with spaces at the beginning or end, or only consisting of spaces (or empty).
  • Those which contain any of the chars < > : " \ / | ? *.
  • Those which contain any non-printable character, as determined via isprint().

This might be too converative for some system, or allow too much for others. It however should return true for filenames that work on most systems.

Definition at line 386 of file fs.cpp.

bool genesis::utils::is_valid_int_pow ( size_t  base,
size_t  exp 
)
inline

Return whether the given power can be stored within a size_t.

Use int_pow() to calculate the actual value of the power.

Definition at line 331 of file common.hpp.

bool is_web_color_name ( std::string const &  name)

Return true iff the given name is a named web color.

Names are filtered so that spaces, underscores and the letter case are ignored.

Definition at line 1229 of file names.cpp.

bool is_xkcd_color_name ( std::string const &  name)

Return true iff the given name is a named xkcd color.

Names are filtered so that spaces, underscores and the letter case are ignored. See color_from_name_xkcd() for details on this color list.

Definition at line 1234 of file names.cpp.

utils::Range< IteratorDeletions > genesis::utils::iterate_deletions ( TwobitVector const &  vector)
inline

Definition at line 220 of file iterator_deletions.hpp.

utils::Range< IteratorInsertions > genesis::utils::iterate_insertions ( TwobitVector const &  vector)
inline

Definition at line 249 of file iterator_insertions.hpp.

utils::Range< IteratorSubstitutions > genesis::utils::iterate_substitutions ( TwobitVector const &  vector)
inline

Definition at line 239 of file iterator_substitutions.hpp.

std::string genesis::utils::join ( T const &  v,
std::string const &  delimiter 
)

Return a string where the elements of a container v are joined using the string delimiter in between them.

The container is iterated via its range based for loop, thus it needs to have begin() and end() functions.

For turning the elements of the container into a string, their operator << is used. Thus, this function can used with all types that support this operator.

Definition at line 318 of file string.hpp.

long genesis::utils::logging_progress_value ( long  value = -1)
inline

Hack function to make sure that the value arugment in LOG_PROG is only evaluated once.

Without this function, LOG_PROG would include two appearances of its variable value, which means that a statement like

LOG_PROG(++i, n) << "of progress.";

would lead to a double evaluation of the increment statement ++i. That is not intended, thus we need this hack function.

Definition at line 162 of file logging.hpp.

std::unique_ptr<T> genesis::utils::make_unique ( Args &&...  args)

Returns a std::unique_ptr for a given type.

Since this is not available in C++11, we need our own implementation. It is following http://herbsutter.com/gotw/_102/

Definition at line 68 of file std.hpp.

Matrix<T> genesis::utils::matrix_addition ( Matrix< A > const &  a,
Matrix< B > const &  b 
)

Calculate the element-wise sum of two Matrices.

The two matrices need to have the same dimensions.

Definition at line 332 of file utils/math/matrix/operators.hpp.

Matrix<T> genesis::utils::matrix_addition ( Matrix< A > const &  matrix,
B const &  scalar 
)

Calculate the element-wise sum of a Matrix and a scalar.

Definition at line 351 of file utils/math/matrix/operators.hpp.

std::vector< MeanStddevPair > matrix_col_mean_stddev ( Matrix< double > const &  data,
double  epsilon = -1.0 
)

Calcualte the column-wise mean and standard deviation of a Matrix.

If the resulting standard deviation is below the given epsilon (e.g, 0.0000001), it is "corrected" to be 1.0 instead. This is an inelegant (but usual) way to handle near-zero values, which for some use cases would cause problems like a division by zero later on. By default, epsilon is -1.0, which deactivates this check - a standard deviation can never be below 0.0.

See also matrix_row_mean_stddev() and matrix_mean_stddev().

Definition at line 160 of file statistics.cpp.

std::vector<MinMaxPair<T> > genesis::utils::matrix_col_minmax ( Matrix< T > const &  data)

Calculate the column-wise min and max values of a Matrix.

See also matrix_row_minmax() and matrix_minmax().

Definition at line 71 of file statistics.hpp.

double matrix_col_pearson_correlation_coefficient ( Matrix< double > const &  mat1,
size_t  col1,
Matrix< double > const &  mat2,
size_t  col2 
)

Calculate the Pearson Correlation Coefficient between two columns of two Matrices.

Both Matrices need to have the same number of rows. Then, the function calculates the PCC between column col1 of Matrix mat1 and column col2 of Matrix mat2.

Definition at line 369 of file statistics.cpp.

Quartiles matrix_col_quartiles ( Matrix< double > const &  data,
size_t  col 
)

Definition at line 283 of file statistics.cpp.

std::vector< Quartiles > matrix_col_quartiles ( Matrix< double > const &  data)

Definition at line 294 of file statistics.cpp.

double matrix_col_spearmans_rank_correlation_coefficient ( Matrix< double > const &  mat1,
size_t  col1,
Matrix< double > const &  mat2,
size_t  col2 
)

Calculate Spearman's Rank Correlation Coefficient between two columns of two Matrices.

Both Matrices need to have the same number of rows. Then, the function calculates Spearman's Rho between column col1 of Matrix mat1 and column col2 of Matrix mat2.

Definition at line 407 of file statistics.cpp.

std::vector<T> genesis::utils::matrix_col_sums ( Matrix< T > const &  data)

Calculate the sum of each column and return the result as a vector.

See also matrix_row_sums() and matrix_sum().

Definition at line 170 of file statistics.hpp.

bool genesis::utils::matrix_is_symmetric ( Matrix< T > const &  data)

Return whether a Matrix is symmetric, i.e., whether it is square and m[ i, j ] == m[ j, i ] holds for all entries.

Definition at line 141 of file utils/math/matrix/operators.hpp.

MeanStddevPair matrix_mean_stddev ( Matrix< double > const &  data,
double  epsilon = -1.0 
)

Calcualte the mean and standard deviation of all elements in a Matrix.

If the resulting standard deviation is below the given epsilon (e.g, 0.0000001), it is "corrected" to be 1.0 instead. This is an inelegant (but usual) way to handle near-zero values, which for some use cases would cause problems like a division by zero later on. By default, epsilon is -1.0, which deactivates this check - a standard deviation can never be below 0.0.

See also matrix_row_mean_stddev() and matrix_col_mean_stddev().

Definition at line 155 of file statistics.cpp.

MinMaxPair<T> genesis::utils::matrix_minmax ( Matrix< T > const &  data)

Calculate the min and max values of a Matrix.

See also matrix_col_minmax() and matrix_row_minmax().

Definition at line 53 of file statistics.hpp.

Matrix<T> genesis::utils::matrix_multiplication ( Matrix< A > const &  a,
Matrix< B > const &  b 
)

Calculate the product of two Matrices.

The two matrices need to have fitting dimensions, i.e., a[ l, m ] x b[ m, n ], which results in a Matrix of dimensions r[ l, n ].

Definition at line 394 of file utils/math/matrix/operators.hpp.

std::vector<T> genesis::utils::matrix_multiplication ( std::vector< A > const &  a,
Matrix< B > const &  b 
)

Calculate the product of a vector a with a Matrices b, as if the vector was a Matrix with only one row.

Thus, the two arguments need to have fitting dimensions, i.e., a[ m ] x b[ m, n ]. The resulting vector has size n, which represent the columns of the result Matrix.

Definition at line 424 of file utils/math/matrix/operators.hpp.

std::vector<T> genesis::utils::matrix_multiplication ( Matrix< A > const &  a,
std::vector< B > const &  b 
)

Calculate the product of a Matrices a with a vector b, as if the vector was a Matrix with only one column.

Thus, the two arguments need to have fitting dimensions, i.e., a[ l, m ] x b[ m ]. The resulting vector has size l, which represent the rows of the result Matrix.

Definition at line 448 of file utils/math/matrix/operators.hpp.

Matrix<T> genesis::utils::matrix_multiplication ( Matrix< A > const &  matrix,
B const &  scalar 
)

Calculate the element-wise multiplication of a Matrix and a scalar.

Definition at line 468 of file utils/math/matrix/operators.hpp.

Quartiles matrix_quartiles ( Matrix< double > const &  data)

Calculate the Quartiles of the elmements in Matrix of double.

Definition at line 250 of file statistics.cpp.

std::vector< MeanStddevPair > matrix_row_mean_stddev ( Matrix< double > const &  data,
double  epsilon = -1.0 
)

Calcualte the row-wise mean and standard deviation of a Matrix.

If the resulting standard deviation is below the given epsilon (e.g, 0.0000001), it is "corrected" to be 1.0 instead. This is an inelegant (but usual) way to handle near-zero values, which for some use cases would cause problems like a division by zero later on. By default, epsilon is -1.0, which deactivates this check - a standard deviation can never be below 0.0.

See also matrix_col_mean_stddev() and matrix_mean_stddev().

Definition at line 203 of file statistics.cpp.

std::vector<MinMaxPair<T> > genesis::utils::matrix_row_minmax ( Matrix< T > const &  data)

Calculate the row-wise min and max values of a Matrix.

See also matrix_col_minmax() and matrix_minmax().

Definition at line 106 of file statistics.hpp.

double matrix_row_pearson_correlation_coefficient ( Matrix< double > const &  mat1,
size_t  row1,
Matrix< double > const &  mat2,
size_t  row2 
)

Calculate the Pearson Correlation Coefficient between two row of two Matrices.

Both Matrices need to have the same number of columns. Then, the function calculates the PCC between row row1 of Matrix mat1 and row row2 of Matrix mat2.

Definition at line 388 of file statistics.cpp.

Quartiles matrix_row_quartiles ( Matrix< double > const &  data,
size_t  row 
)

Definition at line 259 of file statistics.cpp.

std::vector< Quartiles > matrix_row_quartiles ( Matrix< double > const &  data)

Definition at line 270 of file statistics.cpp.

double matrix_row_spearmans_rank_correlation_coefficient ( Matrix< double > const &  mat1,
size_t  row1,
Matrix< double > const &  mat2,
size_t  row2 
)

Calculate Spearman's Rank Correlation Coefficient between two row of two Matrices.

Both Matrices need to have the same number of columns. Then, the function calculates Spearman's Rho between row row1 of Matrix mat1 and row row2 of Matrix mat2.

Definition at line 425 of file statistics.cpp.

std::vector<T> genesis::utils::matrix_row_sums ( Matrix< T > const &  data)

Calculate the sum of each row and return the result as a vector.

See also matrix_col_sums() and matrix_sum().

Definition at line 152 of file statistics.hpp.

Matrix<T> genesis::utils::matrix_sort_by_col_sum_symmetric ( Matrix< T > const &  data)

Sort rows and columns of a Matrix by the sum or the columns.

This is an operation for square matrices: It takes the row sum as sorting criterion, and sorts the rows and the columns according to that order. This is mostly useful for symmetric matrices, where m[ i, j ] == m[ j, i ]. In those cases, the sorting is stable with respect to the symmetry.

See also matrix_sort_by_col_sum_symmetric(). In case of symmetric matrices, it should yield the same Matrix.

Definition at line 303 of file utils/math/matrix/operators.hpp.

Matrix<T> genesis::utils::matrix_sort_by_row_sum_symmetric ( Matrix< T > const &  data)

Sort rows and columns of a Matrix by the sum or the rows.

This is an operation for square matrices: It takes the row sum as sorting criterion, and sorts the rows and the columns according to that order. This is mostly useful for symmetric matrices, where m[ i, j ] == m[ j, i ]. In those cases, the sorting is stable with respect to the symmetry.

See also matrix_sort_by_col_sum_symmetric(). In case of symmetric matrices, it should yield the same Matrix.

Definition at line 272 of file utils/math/matrix/operators.hpp.

Matrix<T> genesis::utils::matrix_subtraction ( Matrix< A > const &  a,
Matrix< B > const &  b 
)

Calculate the element-wise difference of two Matrices.

The two matrices need to have the same dimensions.

Definition at line 368 of file utils/math/matrix/operators.hpp.

T genesis::utils::matrix_sum ( Matrix< T > const &  data)

Calculate the sum of all elements in a Matrix.

See also matrix_col_sums() and matrix_row_sums().

Definition at line 136 of file statistics.hpp.

void genesis::utils::matrix_swap_cols ( Matrix< T > &  data,
size_t  col_a,
size_t  col_b 
)

Swap (interchange) two columns of a Matrix, given their indices.

Definition at line 248 of file utils/math/matrix/operators.hpp.

void genesis::utils::matrix_swap_rows ( Matrix< T > &  data,
size_t  row_a,
size_t  row_b 
)

Swap (interchange) two rows of a Matrix, given their indices.

Definition at line 232 of file utils/math/matrix/operators.hpp.

Matrix<T> genesis::utils::matrix_transpose ( Matrix< T > const &  data)

Transpose a Matrix.

Definition at line 125 of file utils/math/matrix/operators.hpp.

size_t max_bin ( const Histogram &  h)

Definition at line 63 of file utils/math/histogram/stats.cpp.

double max_value ( const Histogram &  h)

Definition at line 53 of file utils/math/histogram/stats.cpp.

double mean ( const Histogram &  h)

Compute the bin-weighted arithmetic mean.

The histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation. The accuracy of the result is limited by the bin width.

Definition at line 91 of file utils/math/histogram/stats.cpp.

MeanStddevPair mean_stddev ( std::vector< double > const &  vec,
double  epsilon = -1.0 
)

Calcualte the mean and standard deviation of a vector of double.

If the resulting standard deviation is below the given epsilon (e.g, 0.0000001), it is "corrected" to be 1.0 instead. This is an inelegant (but usual) way to handle near-zero values, which for some use cases would cause problems like a division by zero later on. By default, epsilon is -1.0, which deactivates this check - a standard deviation can never be below 0.0.

Definition at line 47 of file common.cpp.

double median ( const Histogram &  h)

Definition at line 68 of file utils/math/histogram/stats.cpp.

double genesis::utils::median ( std::vector< double > const &  vec,
size_t  l,
size_t  r 
)

Local helper function to get the median in between a range.

Both l and r are inclusive.

Yes, that would be very much a perfect use case for a proper template function. But I am too lazy right now.

Definition at line 85 of file common.cpp.

double median ( std::vector< double > const &  vec)

Calculate the median value of a vector of double.

The vector has to be sorted.

Definition at line 112 of file common.cpp.

size_t min_bin ( const Histogram &  h)

Definition at line 58 of file utils/math/histogram/stats.cpp.

double min_value ( const Histogram &  h)

Definition at line 48 of file utils/math/histogram/stats.cpp.

TableLayout minimal_layout ( )

Definition at line 439 of file utils/text/table.cpp.

void normalize ( Histogram &  h,
double  total 
)

Definition at line 61 of file operations.cpp.

std::vector< MinMaxPair< double > > normalize_cols ( Matrix< double > &  data)

Normalize the columns of a Matrix so that all values are in the range [ 0.0, 1.0 ].

The Matrix is manipulated inline. For each column, the new values of the Matrix are calculated as $ x_{new} = \frac{ x - x_{min} }{ x_{max} - x_{min} } $.

The function returns a vector containing the min and max values of the columns before normalization, see matrix_col_minmax().

Parameters
dataInput data Matrix; normalization is done inline.
Returns
Vector containing the min and max values for each column before normalization.

Definition at line 51 of file statistics.cpp.

std::vector< MinMaxPair< double > > normalize_rows ( Matrix< double > &  data)

Normalize the rows of a Matrix so that all values are in the range [ 0.0, 1.0 ].

The Matrix is manipulated inline. For each row, the new values of the Matrix are calculated as $ x_{new} = \frac{ x - x_{min} }{ x_{max} - x_{min} } $.

The function returns a vector containing the min and max values of the rows before normalization, see matrix_row_minmax().

Parameters
dataInput data Matrix; normalization is done inline.
Returns
Vector containing the min and max values for each row before normalization.

Definition at line 70 of file statistics.cpp.

void offset ( Histogram &  h,
double  value 
)

Definition at line 47 of file operations.cpp.

bool genesis::utils::operator!= ( NexusTaxa const &  lhs,
NexusTaxa const &  rhs 
)

Definition at line 104 of file taxa.hpp.

bool genesis::utils::operator!= ( SortedVector< T > const &  lhs,
SortedVector< T > const &  rhs 
)

Definition at line 58 of file utils/containers/sorted_vector/operators.hpp.

bool genesis::utils::operator!= ( JsonDocument const &  lhs,
JsonDocument const &  rhs 
)
noexcept
bool genesis::utils::operator!= ( JsonDocument const &  v,
std::nullptr_t   
)
noexcept
bool genesis::utils::operator!= ( std::nullptr_t  ,
JsonDocument const &  v 
)
noexcept
bool genesis::utils::operator!= ( Color const &  lhs,
Color const &  rhs 
)
inline

Definition at line 211 of file color.hpp.

bool genesis::utils::operator& ( SkipWhitespace  lhs,
SkipWhitespace  rhs 
)
inline

And-operator to check whether a SkipWhitespace is set.

Typical usage:

SkipWhitespace option;
if( option & SkipWhitespace::kTrailing ) {
    // Do stuff...
}

See SkipWhitespace for more information.

Definition at line 95 of file scanner.hpp.

Bitvector operator& ( Bitvector const &  lhs,
Bitvector const &  rhs 
)

Definition at line 105 of file bitvector.cpp.

Bitvector operator- ( Bitvector const &  lhs,
Bitvector const &  rhs 
)

Set-minus of two Bitvectors.

Definition at line 151 of file bitvector.cpp.

bool genesis::utils::operator< ( JsonDocument const &  lhs,
JsonDocument const &  rhs 
)
noexcept
bool genesis::utils::operator< ( JsonDocument::const_reference  lhs,
JsonDocument::const_reference  rhs 
)
noexcept

Compares whether one JSON value lhs is less than another JSON value rhs according to the following rules:

  • If lhs and rhs have the same type, the values are compared using the default < operator.
  • Integer and floating-point numbers are automatically converted before comparison
  • In case lhs and rhs have different types, the values are ignored and the order of the types is considered, see operator<(const JsonDocument::ValueType, const JsonDocument::ValueType). %

Definition at line 792 of file json/document.cpp.

bool genesis::utils::operator< ( const JsonDocument::ValueType  lhs,
const JsonDocument::ValueType  rhs 
)
noexcept

Returns an ordering that is similar to Python:

  • order: null < boolean < number < object < array < string
  • furthermore, each type is not smaller than itself %

Definition at line 858 of file json/document.cpp.

std::ostream & operator<< ( std::ostream &  os,
const Histogram &  h 
)

Definition at line 45 of file utils/math/histogram/operators.cpp.

std::ostream & operator<< ( std::ostream &  os,
const HistogramAccumulator &  h 
)

Definition at line 59 of file utils/math/histogram/operators.cpp.

std::ostream& genesis::utils::operator<< ( std::ostream &  os,
NexusBlock const &  block 
)
inline

Definition at line 80 of file block.hpp.

std::ostream & operator<< ( std::ostream &  os,
Color const &  color 
)

Write a textual representation of the Color the a stream, in the format "(r, g, b, a)".

Definition at line 130 of file utils/tools/color/functions.cpp.

std::ostream& genesis::utils::operator<< ( std::ostream &  os,
const Matrix< T > &  matrix 
)

Definition at line 161 of file utils/math/matrix/operators.hpp.

std::ostream & operator<< ( std::ostream &  out,
Table const &  table 
)

Definition at line 255 of file utils/text/table.cpp.

std::ostream & operator<< ( std::ostream &  os,
GeoCoordinate const &  coord 
)

Definition at line 343 of file utils/tools/geodesy/functions.cpp.

std::ostream & operator<< ( std::ostream &  s,
Bitvector const &  rhs 
)

Definition at line 354 of file bitvector.cpp.

std::ostream & operator<< ( std::ostream &  out,
Style const &  style 
)

Print the properties of a Style object to a stream.

The application of Styles is usually done by invoking its operator(). However, in order to be able to show its properties at a glance, this operator instead prints them:

Style s( "blue" );
std::cout << s;

will print this information instead of a stylized text.

Definition at line 380 of file style.cpp.

std::ostream& genesis::utils::operator<< ( std::ostream &  out,
TableLayout::Binder const &  binder 
)

Definition at line 405 of file utils/text/table.cpp.

bool genesis::utils::operator<= ( JsonDocument const &  lhs,
JsonDocument const &  rhs 
)
noexcept
bool genesis::utils::operator== ( SortedVector< T > const &  lhs,
SortedVector< T > const &  rhs 
)

Definition at line 44 of file utils/containers/sorted_vector/operators.hpp.

bool genesis::utils::operator== ( NexusTaxa const &  lhs,
NexusTaxa const &  rhs 
)

Definition at line 99 of file taxa.hpp.

bool genesis::utils::operator== ( JsonDocument const &  lhs,
JsonDocument const &  rhs 
)
noexcept
bool genesis::utils::operator== ( JsonDocument const &  v,
std::nullptr_t   
)
noexcept
bool genesis::utils::operator== ( std::nullptr_t  ,
JsonDocument const &  v 
)
noexcept
bool genesis::utils::operator== ( Color const &  lhs,
Color const &  rhs 
)
inline

Definition at line 206 of file color.hpp.

bool genesis::utils::operator== ( JsonDocument::const_reference  lhs,
JsonDocument::const_reference  rhs 
)
noexcept

Compares two JSON values for equality according to the following rules:

  • Two JSON values are equal if (1) they are from the same type and (2) their stored values are the same.
  • Integer and floating-point numbers are automatically converted before comparison. Floating-point numbers are compared indirectly: two floating-point numbers f1 and f2 are considered equal if neither f1 > f2 nor f2 > f1 holds.
  • Two JSON null values are equal. %

Definition at line 729 of file json/document.cpp.

bool genesis::utils::operator> ( JsonDocument const &  lhs,
JsonDocument const &  rhs 
)
noexcept
bool genesis::utils::operator>= ( JsonDocument const &  lhs,
JsonDocument const &  rhs 
)
noexcept
Bitvector operator^ ( Bitvector const &  lhs,
Bitvector const &  rhs 
)

Definition at line 135 of file bitvector.cpp.

Bitvector operator| ( Bitvector const &  lhs,
Bitvector const &  rhs 
)

Definition at line 120 of file bitvector.cpp.

T genesis::utils::parse_float ( utils::InputStream &  source)

Read a floating point number from a stream and return it.

The number is expected to be in the following format:

[+-][123][.456][eE[+-]789]

The function stops reading at the first non-fitting digit. It throws an std::overflow_error or underflow_error in case that the exponent (the part after the 'E') does not fit into integer value range.

Definition at line 155 of file parser.hpp.

T genesis::utils::parse_integer ( utils::InputStream &  source)

Alias for parse_signed_integer().

Definition at line 134 of file parser.hpp.

std::string parse_number_string ( utils::InputStream &  source)

Read a general number string from an input stream.

The function reads from the input as long as it is a valid number of the format

[+-][123][.456][eE[+-]789]

and returns this string. This is useful for intermediately parsing a number and then checking whether it is valid. Use parse_float() to turn such a number string into an actual float/double.

Definition at line 48 of file parser.cpp.

std::string parse_quoted_string ( utils::InputStream &  source,
bool  use_escapes = true,
bool  use_twin_quotes = false,
bool  include_qmarks = false 
)

Read a string in quotation marks from a stream and return it.

The first char of the stream is considered to be the opening quotation mark. Everything up until the closing quotation mark (the same char again, whatever it is) is then read. The stream is then pointing to the char right after the closing quotation mark.

If the string ends prematurely, i.e., without the closing quotation mark, or right after a backslash if use_escapes is used, the function throws an std::runtime_error.

Parameters
sourceStream to read from.
use_escapesIf this optional parameter is set to true, chars preceeded by a backslash \ are considered to be "escaped". If the char following the backslash is any of r, n or t, it is turned into its respective white space equivalent, while all other chars are copied verbatim to the return string. Thus, by escaping it, a the string can also include the quotation mark itself. Default of this parameter is true.
use_twin_quotesIf this optional parameter is set to true, the quotation mark itself can be escaped using two consecutive quotation marks. This works in addition to escaping it with a backslash (when use_escapes is used).
include_qmarksThe optional parameter include_qmarks demtermines whether the quotation marks are included in the output or not. Default is false.

Definition at line 116 of file parser.cpp.

T genesis::utils::parse_signed_integer ( utils::InputStream &  source)

Read a signed integer from a stream and return it.

The function expects a sequence of digits, possibly with a leading + or -. The first char after that has to be a digit, otherwise the function throws std::runtime_error. It stops reading at the first non-digit. In case the value range is too small, the function throws std::overflow_error, or underflow_error, respectively.

Definition at line 91 of file parser.hpp.

T genesis::utils::parse_unsigned_integer ( utils::InputStream &  source)

Read an unsigned integer from a stream and return it.

The function expects a sequence of digits. The current char in the stream has to be a digit, otherwise the function throws std::runtime_error. It stops reading at the first non-digit. In case the value range is too small, the function throws std::overflow_error.

Definition at line 56 of file parser.hpp.

double pearson_correlation_coefficient ( std::vector< double > const &  vec_a,
std::vector< double > const &  vec_b 
)

Calculate the Pearson Correlation Coefficient between the entries of two vectors.

Both vectors need to have the same size. Then, the function calculates the PCC between the pairs of entries of both vectors.

Definition at line 162 of file common.cpp.

PcaData principal_component_analysis ( Matrix< double > const &  data,
size_t  components = 0,
PcaStandardization  standardization = PcaStandardization::kCorrelation 
)

Perfom a Principal Component Analysis on a given data Matrix.

Principal Components Analysis or the Karhunen-Loeve expansion is a classical method for dimensionality reduction or exploratory data analysis. One reference among many is: F. Murtagh and A. Heck, Multivariate Data Analysis, Kluwer Academic, Dordrecht, 1987.

Parameters
dataMatrix with the data, samples in rows, features in columns.
componentsIntended number of PCA components to calculate. If 0 (default), all PCA components are calculated, i.e., as many components as data has columns.
standardizationIndicate the standardization algorithm to perfom on the data before calculating the PCA components, see PcaStandardization.
Returns
A struct that contains the eigenvalues and corresponding eigenvectors (i.e., the PCA components), and a Matrix with the projected data. See PcaData for details.

Definition at line 242 of file pca.cpp.

void genesis::utils::print ( std::ostream &  out,
Matrix< T > const &  matrix,
size_t  rows = 10,
size_t  cols = 10 
)

Print a Matrix to an out stream. See print( Matrix<T> const&, size_t, size_t ) for details.

Definition at line 180 of file utils/math/matrix/operators.hpp.

std::string genesis::utils::print ( Matrix< T > const &  matrix,
size_t  rows = 10,
size_t  cols = 10 
)

Print a Matrix to a std::string.

If rows == 0, all rows are printed. Otherwise, only the given number of rows is printed, followed by an ellipsis (...). The same applies to the columns, using cols.

See also print( std::ostream&, Matrix<T> const&, size_t, size_t ).

Definition at line 217 of file utils/math/matrix/operators.hpp.

Quartiles quartiles ( std::vector< double > const &  vec)

Calculate the Quartiles of a vector of double.

The vector has to be sorted.

Definition at line 126 of file common.cpp.

std::vector< size_t > ranking_dense ( std::vector< double > const &  vec)

Return the ranking of the given values, using Dense ranking ("1223" ranking).

See https://en.wikipedia.org/wiki/Ranking for details.

See Also
ranking_standard(), ranking_modified(), ranking_ordinal(), ranking_fractional() for other ranking methods.

Definition at line 301 of file common.cpp.

std::vector< double > ranking_fractional ( std::vector< double > const &  vec)

Return the ranking of the given values, using Fractional ranking ("1 2.5 2.5 4" ranking).

See https://en.wikipedia.org/wiki/Ranking for details. This is the only raking method that returns float values instead of integer values.

See Also
ranking_standard(), ranking_modified(), ranking_dense(), ranking_ordinal() for other ranking methods.

Definition at line 348 of file common.cpp.

std::vector< size_t > ranking_modified ( std::vector< double > const &  vec)

Return the ranking of the given values, using Modified competition ranking ("1334" ranking).

See https://en.wikipedia.org/wiki/Ranking for details.

See Also
ranking_standard(), ranking_dense(), ranking_ordinal(), ranking_fractional() for other ranking methods.

Definition at line 266 of file common.cpp.

std::vector< size_t > ranking_ordinal ( std::vector< double > const &  vec)

Return the ranking of the given values, using Ordinal ranking ("1234" ranking).

See https://en.wikipedia.org/wiki/Ranking for details.

See Also
ranking_standard(), ranking_modified(), ranking_dense(), ranking_fractional() for other ranking methods.

Definition at line 329 of file common.cpp.

std::vector< size_t > ranking_standard ( std::vector< double > const &  vec)

Return the ranking of the given values, using Standard competition ranking ("1224" ranking).

See https://en.wikipedia.org/wiki/Ranking for details.

See Also
ranking_modified(), ranking_dense(), ranking_ordinal(), ranking_fractional() for other ranking methods.

Definition at line 238 of file common.cpp.

char genesis::utils::read_char_or_throw ( InputStream &  source,
char  criterion,
SkipWhitespace  skip_ws = SkipWhitespace::kNone 
)
inline

Lexing function that reads a single char from the stream and checks whether it equals the provided one.

If not, the function throws std::runtime_error. The stream is advanced by one position and the char is returned. For a similar function that checks the value of the current char but does not advance in the stream, see affirm_char_or_throw().

Using the parameter skip_ws, it is possible to skip leading and/or trailing whitespaces before/after treating the criterion char. See SkipWhitespace for more information.

Definition at line 297 of file scanner.hpp.

char genesis::utils::read_char_or_throw ( InputStream &  source,
std::function< bool(char)>  criterion,
SkipWhitespace  skip_ws = SkipWhitespace::kNone 
)
inline

Lexing function that reads a single char from the stream and checks whether it fulfills the provided criterion.

If not, the function throws std::runtime_error. The stream is advanced by one position and the char is returned. For a similar function that checks the value of the current char but does not advance in the stream, see affirm_char_or_throw().

Using the parameter skip_ws, it is possible to skip leading and/or trailing whitespaces before/after treating the criterion char. See SkipWhitespace for more information.

Definition at line 336 of file scanner.hpp.

std::string genesis::utils::read_to_end_of_line ( InputStream &  source)
inline

Lexing function that reads until the end of the line (i.e., to the new line char), and returns the read chars (excluding the new line char).

The stream is left at the new line char. If the stream is already at its last line, this function reads to the end of the stream.

Definition at line 132 of file scanner.hpp.

std::string genesis::utils::read_until ( InputStream &  source,
char  criterion 
)
inline

Lexing function that reads from the stream until its current char equals the provided one. The read chars are returned.

Definition at line 252 of file scanner.hpp.

std::string genesis::utils::read_until ( InputStream &  source,
std::function< bool(char)>  criterion 
)
inline

Lexing function that reads from the stream until its current char fulfills the provided criterion. The read chars are returned.

Definition at line 269 of file scanner.hpp.

std::string genesis::utils::read_while ( InputStream &  source,
char  criterion 
)
inline

Lexing function that reads from the stream while its current char equals the provided one. The read chars are returned.

Definition at line 214 of file scanner.hpp.

std::string genesis::utils::read_while ( InputStream &  source,
std::function< bool(char)>  criterion 
)
inline

Lexing function that reads from the stream while its current char fulfills the provided criterion. The read chars are returned.

Definition at line 231 of file scanner.hpp.

TridiagonalDecompositionData reduce_to_tridiagonal_matrix ( Matrix< double > &  data)

Triangular decomposition of a symmetric matrix.

This function performs an intermediate step that is usually followed by an execution of the tridiagonal_ql_algorithm().

It uses the Householder reduction of matrix a to tridiagonal form, according to

Martin et al., Num. Math. 11, 181-195, 1968.
Ref: Smith et al., Matrix Eigensystem Routines -- EISPACK Guide
Springer-Verlag, 1976, pp. 489-494.
W H Press et al., Numerical Recipes in C, Cambridge U P, 1988, pp. 373-374.

There, the function is called tred2().

The implementation of this function is largely borrowed from http://www.classification-society.org/csna/mda-sw/pca.c published as Public Domain by Fionn Murtagh.

Parameters
dataInput data matrix. Operations are performed inline, that is, the matrix is changed during execution of the function.

Definition at line 49 of file pca.cpp.

std::string repeat ( std::string const &  word,
size_t  times 
)

Take a string and repeat it a given number of times.

Definition at line 378 of file string.cpp.

std::string replace_all ( std::string const &  text,
std::string const &  search,
std::string const &  replace 
)

Return a copy of a string, where all occurrences of a search string are replaced by a replace string.

Definition at line 166 of file string.cpp.

std::string replace_all_chars ( std::string const &  text,
std::string const &  search_chars,
char  replace 
)

Replace all occurrences of the search_chars in text by the replace char.

Definition at line 200 of file string.cpp.

double genesis::utils::round_to ( double  x,
size_t  accuracy_order 
)
inline

Retun the value of x, rounded to the decimal digit given by accuracy_order.

Definition at line 295 of file common.hpp.

std::string sanitize_filname ( std::string const &  filename)

Remove or replace all invalid parts of a filename.

Similar to is_valid_filname(), this function is not meant to be an ultimate solution to valid filenames. See there for details.

The function is meant to be called on the file name itself, without the directory path leading to it. File extensions are allowed. Thus, you might need to call file_basename() before in order to get the file name without the path.

This function does the following:

  • All non-printable characters are removed.
  • Spaces at the beginning and end are removed.
  • All invalid chars are replaced by an underscore. See is_valid_filname() for a list of those chars.

If after this procedure the filename is empty, an exception is thrown. This is meant to save the user from checking this, or from running into trouble when trying to write to this "file" - because an empty filename will point to a directory name.

Definition at line 435 of file fs.cpp.

std::string sanitize_geo_coordinate ( std::string const &  coordinate,
bool  two_components = true 
)

Replace non-ascii symbols used in geographic coordinates by their ascii equivalents.

The function replaces symbols such as degrees, primes, double primes by simple letters ('dms') that serve the same function.

Furthermore, if two_components is true (default), the function assumes that the given coordinate contains two components (North/South and East/West). In that case, if there is exaclty one comma in the input, it is replaced by a slash. This is meant to avoid ambiguity in parsing of a coordinate that uses commas as decimal separator. Hence, when sanitizing a coordinate with only one component, two_components needs to be set to false in order to avoid replacing a single decimal separator comma by a slash.

Definition at line 198 of file utils/tools/geodesy/functions.cpp.

void scale ( Histogram &  h,
double  factor 
)

Definition at line 54 of file operations.cpp.

std::vector< size_t > select_without_replacement ( size_t  k,
size_t  n 
)

Select k many unique numbers out of the range [ 0, n ).

In other words, select k numbers out of the sequence of n numbers, without replacement.

The implementation is based on Algorithm 3.4.2S of Knuth's book Seminumeric Algorithms.

Parameters
kDesired sample size.
nTotal population size.
Returns
List of k unique numbers out of the range [ 0, n ).

Definition at line 46 of file random.cpp.

double sigma ( const Histogram &  h)

Compute the bin-weighted standard deviation.

The histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation. The accuracy of the result is limited by the bin width.

Definition at line 114 of file utils/math/histogram/stats.cpp.

constexpr int genesis::utils::signum ( x,
std::false_type   
)
inline

Implementation of signum(T x) for unsigned types. See there for details.

Definition at line 240 of file common.hpp.

constexpr int genesis::utils::signum ( x,
std::true_type   
)
inline

Implementation of signum(T x) for signed types. See there for details.

Definition at line 252 of file common.hpp.

constexpr int genesis::utils::signum ( x)
inline

Get the sign of a value, which is either -1, 0, or 1.

Works for all numerical types. We use two tagged implementations for signed and unsigned types in order to avoid compiler warnings. See http://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c for details.

Definition at line 269 of file common.hpp.

TableLayout simple_frame ( bool  condensed)

Definition at line 483 of file utils/text/table.cpp.

TableLayout simple_grid ( bool  condensed)

Definition at line 464 of file utils/text/table.cpp.

TableLayout simple_layout ( bool  condensed)

Definition at line 445 of file utils/text/table.cpp.

void genesis::utils::skip_to_end_of_line ( InputStream &  source)
inline

Lexing function that advances the stream to the end of the line, i.e., to the new line char.

If the stream is already at its last line, this function moves to the end of the stream.

Definition at line 116 of file scanner.hpp.

void genesis::utils::skip_until ( InputStream &  source,
char  criterion 
)
inline

Lexing function that advances the stream until its current char equals the provided one.

Definition at line 182 of file scanner.hpp.

void genesis::utils::skip_until ( InputStream &  source,
std::function< bool(char)>  criterion 
)
inline

Lexing function that advances the stream until its current char fulfills the provided criterion.

Definition at line 196 of file scanner.hpp.

void genesis::utils::skip_while ( InputStream &  source,
char  criterion 
)
inline

Lexing function that advances the stream while its current char equals the provided one.

Definition at line 151 of file scanner.hpp.

void genesis::utils::skip_while ( InputStream &  source,
std::function< bool(char)>  criterion 
)
inline

Lexing function that advances the stream while its current char fulfills the provided criterion.

Definition at line 165 of file scanner.hpp.

std::vector<size_t> genesis::utils::sort_indices ( RandomAccessIterator  first,
RandomAccessIterator  last,
Comparator  comparator 
)
inline

Get the indices to the sorted order of the given range.

This function returns a list of indices into the given range, so that their order gives the sorted content of the elements in [ first, last ), using std::less for comparisons.

For example,

for( auto i: sort_indices(v) ) {
    cout << *( first + i ) << endl;
}

outputs the elements in the range in sorted order, without actually moving any elements in the range. This is useful if the same sorting order needs to be applied to some other container.

There is also an overload of this function that takes an additional parameter comparator. It can be used to specify the function for comparing two values of the range.

Furthermore, there are variants that use std::stable_sort instead, see stable_sort_indices().

Definition at line 92 of file algorithm.hpp.

std::vector<size_t> genesis::utils::sort_indices ( RandomAccessIterator  first,
RandomAccessIterator  last 
)
inline

Get the indices to the sorted order of the given range.

This function returns a list of indices into the given range, so that their order gives the sorted content of the elements in [ first, last ), using std::less for comparisons.

For example,

for( auto i: sort_indices(v) ) {
    cout << *( first + i ) << endl;
}

outputs the elements in the range in sorted order, without actually moving any elements in the range. This is useful if the same sorting order needs to be applied to some other container.

There is also an overload of this function that takes an additional parameter comparator. It can be used to specify the function for comparing two values of the range.

Furthermore, there are variants that use std::stable_sort instead, see stable_sort_indices().

Definition at line 134 of file algorithm.hpp.

double spearmans_rank_correlation_coefficient ( std::vector< double > const &  vec_a,
std::vector< double > const &  vec_b 
)

Calculate Spearman's Rank Correlation Coefficient between the entries of two vectors.

Both vectors need to have the same size. Then, the function calculates Spearmans's Rho between the pairs of entries of both vectors.

Definition at line 199 of file common.cpp.

std::vector< std::string > split ( std::string const &  str,
std::string const &  delimiters = " ",
const bool  trim_empty = true 
)

Spilt a string into parts, given a set of delimiter chars.

The string str is split using any of the chars in delimiters and returned as a vector of strings. If trim_empty is set, empty strings resulting from adjacent delimiter chars are excluded from the output.

Definition at line 121 of file string.cpp.

std::vector<size_t> genesis::utils::stable_sort_indices ( RandomAccessIterator  first,
RandomAccessIterator  last,
Comparator  comparator 
)
inline

Get the indices to the stable sorted order of the given range.

This function returns a list of indices into the given range, so that their order gives the stable sorted content of the elements in [ first, last ), using std::less for comparisons.

For example,

for( auto i: stable_sort_indices(v) ) {
    cout << *( first + i ) << endl;
}

outputs the elements in the range in stable sorted order, without actually moving any elements in the range. This is useful if the same sorting order needs to be applied to some other container.

There is also an overload of this function that takes an additional parameter comparator. It can be used to specify the function for comparing two values of the range.

Furthermore, there are variants that use normal std::sort instead, see sort_indices().

Definition at line 149 of file algorithm.hpp.

std::vector<size_t> genesis::utils::stable_sort_indices ( RandomAccessIterator  first,
RandomAccessIterator  last 
)
inline

Get the indices to the stable sorted order of the given range.

This function returns a list of indices into the given range, so that their order gives the stable sorted content of the elements in [ first, last ), using std::less for comparisons.

For example,

for( auto i: stable_sort_indices(v) ) {
    cout << *( first + i ) << endl;
}

outputs the elements in the range in stable sorted order, without actually moving any elements in the range. This is useful if the same sorting order needs to be applied to some other container.

There is also an overload of this function that takes an additional parameter comparator. It can be used to specify the function for comparing two values of the range.

Furthermore, there are variants that use normal std::sort instead, see sort_indices().

Definition at line 191 of file algorithm.hpp.

std::vector< MeanStddevPair > standardize_cols ( Matrix< double > &  data,
bool  scale_means = true,
bool  scale_std = true 
)

Standardize the columns of a Matrix by subtracting the mean and scaling to unit variance.

The function performs a column-wise z-transformation on the given data.

The function returns a vector containing the mean and standard deviation of the columns before standardization, see MeanStddevPair. If both scale_means and scale_std are set to false, the original data is not manipulated, while the returned vector still contains the means and standard deviations. See also matrix_col_mean_stddev().

Parameters
dataInput data Matrix; standardizing is done inline.
scale_meansIf true (default), center the data by subtracting the mean per column.
scale_stdIf true (default), scale the data to unit variance (or equivalently, unit standard deviation) per column.
Returns
Vector containing the mean and standard deviation for each column before standardization.

Definition at line 93 of file statistics.cpp.

std::vector< MeanStddevPair > standardize_rows ( Matrix< double > &  data,
bool  scale_means = true,
bool  scale_std = true 
)

Standardize the rows of a Matrix by subtracting the mean and scaling to unit variance.

The function performs a row-wise z-transformation on the given data.

The function returns a vector containing the mean and standard deviation of the rows before standardization, see MeanStddevPair. If both scale_means and scale_std are set to false, the original data is not manipulated, while the returned vector still contains the means and standard deviations. See also matrix_row_mean_stddev().

Parameters
dataInput data Matrix; standardizing is done inline.
scale_meansIf true (default), center the data by subtracting the mean per column.
scale_stdIf true (default), scale the data to unit variance (or equivalently, unit standard deviation) per column.
Returns
Vector containing the mean and standard deviation for each column before standardization.

Definition at line 122 of file statistics.cpp.

bool starts_with ( std::string const &  text,
std::string const &  start 
)

Return whether a string starts with another string.

Definition at line 61 of file string.cpp.

double sum ( const Histogram &  h)

Definition at line 140 of file utils/math/histogram/stats.cpp.

Matrix< double > sums_of_squares_and_cross_products_matrix ( Matrix< double > const &  data)

Calculate the Sums of Squares and Cross Products Matrix (SSCP Matrix).

Definition at line 347 of file statistics.cpp.

std::string genesis::utils::svg_attribute ( std::string const &  name,
T const &  value,
std::string const &  unit = "" 
)

Definition at line 214 of file utils/formats/svg/helper.hpp.

std::string genesis::utils::svg_comment ( std::string const &  content)
inline

Definition at line 208 of file utils/formats/svg/helper.hpp.

void swap ( Histogram &  lhs,
Histogram &  rhs 
)
noexcept

Definition at line 47 of file histogram.cpp.

void genesis::utils::swap ( HistogramAccumulator &  lhs,
HistogramAccumulator &  rhs 
)
inlinenoexcept

Definition at line 153 of file accumulator.hpp.

void genesis::utils::swap ( Style &  lhs,
Style &  rhs 
)
inlinenoexcept

Definition at line 198 of file style.hpp.

void genesis::utils::swap ( Color &  lhs,
Color &  rhs 
)
inlinenoexcept

Definition at line 201 of file color.hpp.

void genesis::utils::swap ( NexusTaxa &  lhs,
NexusTaxa &  rhs 
)
inline

Definition at line 207 of file taxa.hpp.

void genesis::utils::swap ( NexusTrees &  lhs,
NexusTrees &  rhs 
)
inline

Definition at line 242 of file trees.hpp.

std::string tail ( std::string const &  text,
size_t  lines 
)

Return the last lines of the text.

Definition at line 90 of file string.cpp.

std::string to_lower ( std::string const &  str)

Return an all-lowercase copy of the given string, locale-aware.

Definition at line 249 of file string.cpp.

char to_lower_ascii ( char  c)

Return the lower case of a given char, ascii-only.

Definition at line 281 of file string.cpp.

std::string to_lower_ascii ( std::string const &  str)

Return an all-lowercase copy of the given string, ascii-only.

Definition at line 291 of file string.cpp.

void to_lower_ascii_inplace ( std::string &  str)

Turn the given string to all-lowercase, ascii-only.

Definition at line 300 of file string.cpp.

void to_lower_inplace ( std::string &  str)

Turn the given string to all-lowercase, locale-aware.

Definition at line 258 of file string.cpp.

std::string to_nucleic_acids ( TwobitVector const &  vec)

Turn a TwobitVector into its string representation of nucleic acids.

Definition at line 107 of file utils/math/twobit_vector/functions.cpp.

std::string genesis::utils::to_string ( T const &  v)

Return a string representation of a given value.

This function template is a drop-in replacement for std::to_string, with the difference that it treats floating point numbers more nicely: Instead of printing a fixed amount of digits, it only prints digits without trailing zeros.

If you also want to round the value, or need more precision, see to_string_precise() and to_string_rounded().

As it uses operator << on the given value, it is suitable for any class or value for which this stream operator is available. Thus, this function can also be used for conveniently returning a string where otherwise some stream operations would have been necessary.

Definition at line 300 of file string.hpp.

std::string to_string_leading_zeros ( size_t  value,
size_t  length = 6 
)

Return a string representation of a size_t value with a fixed length, that is, by adding leading zeros.

If value is already longer than length, the result will also be longer.

Definition at line 391 of file string.cpp.

std::string to_string_precise ( double  value,
int  precision = 6 
)

Return a precise string representation of the input value, using the provided precision value (determining its decimal places).

This function rounds the value to the given precision, and then returns its string representation with possible trailing zeros. Thus, it uses fixed precision. This is useful for e.g., output in a table format.

For a version of this function that truncates trailing zeros, see to_string_rounded(). Also, see to_string() if you simply want to output a string representation of a double.

Definition at line 398 of file string.cpp.

std::string to_string_rounded ( double  value,
int  precision = 6 
)

Return a string representation of the input value, using the provided precision value (determining its decimal places) to round, and truncate trailing zeros.

This function rounds the value to the given precision, and then returns its string representation without trailing zeros. This is useful for output that keeps a certain amount of significant decimal digits, while making the output as short as possible.

If you want to round, but also keep trailing zeros, see to_string_precise(). Also, see to_string() if you simply want to output a string representation of a double.

Definition at line 406 of file string.cpp.

std::string to_upper ( std::string const &  str)

Return an all-uppercase copy of the given string, locale-aware.

Definition at line 265 of file string.cpp.

char to_upper_ascii ( char  c)

Return the upper case of a given char, ascii-only.

Definition at line 286 of file string.cpp.

std::string to_upper_ascii ( std::string const &  str)

Return an all-uppercase copy of the given string, ascii-only.

Definition at line 307 of file string.cpp.

void to_upper_ascii_inplace ( std::string &  str)

Turn the given string to all-uppercase, ascii-only.

Definition at line 316 of file string.cpp.

void to_upper_inplace ( std::string &  str)

Turn the given string to all-uppercase, locale-aware.

Definition at line 274 of file string.cpp.

TwobitVector::ValueType translate_from_nucleic_acid ( char  site)

Translate a char into TwobitVector::ValueType.

Valid chars are A, C, G, T, and their lower case variants.

Definition at line 49 of file utils/math/twobit_vector/functions.cpp.

char translate_to_nucleic_acid ( TwobitVector::ValueType  value)

Translate a TwobitVector::ValueType into its char representation.

This gives one of the values A, C, G and T.

Definition at line 78 of file utils/math/twobit_vector/functions.cpp.

size_t triangular_index ( size_t  i,
size_t  j,
size_t  n 
)

Given indices i and j in a quadratic Matrix, find the corresponding linear index.

See triangular_indices() for the opposite function, which also explains the details, and triangular_size() to calculate the maximal k that will occur in a trian Matrix of a given size n.

Parameters
i,jIndices of the Matrix for which to calculate the linear index k.
nSize of the quadratic Matrix, i.e., the row/column length.
Returns
Linear index k for the given i and j.

Definition at line 53 of file utils/math/matrix/operators.cpp.

std::pair< size_t, size_t > triangular_indices ( size_t  k,
size_t  n 
)

Given a linear index in a upper triangular Matrix, find the corresponding Matrix indices.

Given an upper triangle Matrix of size n == 5

0  k0  k1  k2  k3
0   0  k4  k5  k6
0   0   0  k7  k8
0   0   0   0  k9
0   0   0   0   0

and given a k (like above), find the corresponding indices i and j for this k, e.g.,

k == 0 --> i == 0, j == 1
k == 5 --> i == 1, j == 3
k == 9 --> i == 3, j == 4
...

Because the calculation involves solving triangular numbers, the function internally operates on double values. This is a bit smelly, but seems to work (tested with n == 100,000).

See also triangular_index() for the opposite function, and triangular_size() to calculate the maximal k that will occur in a trian Matrix of a given size n.

Parameters
kLinear index in the upper triangle of a quadratic Matrix.
nSize of the quadratic Matrix, i.e., the row/column length.
Returns
Pair ( i, j ) of the indices for the given k.

Definition at line 43 of file utils/math/matrix/operators.cpp.

size_t triangular_size ( size_t  n)

Calculate the number of linear indices needed for a triangular Matrix of size n.

Given an upper triangle Matrix of size n == 5

0  k0  k1  k2  k3
0   0  k4  k5  k6
0   0   0  k7  k8
0   0   0   0  k9
0   0   0   0   0

we need 10 indices k == 0..9 to linearly describe the positions in the triangle. This function returns this number of indices for a given n.

See also triangular_indices() for calculating the Matrix indices i and j for a given k.

Parameters
nSize of the quadratic Matrix, i.e., the row/column length.
Returns
Number of needed linear indices k to describe a triangle of the Matrix.

Definition at line 59 of file utils/math/matrix/operators.cpp.

void tridiagonal_ql_algorithm ( Matrix< double > &  data,
TridiagonalDecompositionData &  tri,
size_t  max_iterations = 1000 
)

Reduce a symmetric matrix to a symmetric tridiagonal matrix.

Uses the data and the intermediate result after executing reduce_to_tridiagonal_matrix() in order to run the algorithm. See there for details.

Both parameters are modified during the algorithm. After it is finished, tri.eigenvalues contains the eigenvalus and data the associated eigenvectors of the original data.

The implementation of this function is largely borrowed from http://www.classification-society.org/csna/mda-sw/pca.c published as Public Domain by Fionn Murtagh.

Parameters
dataInput data matrix. Operations are performed inline, that is, the matrix is changed during execution of the function.
triTridiagonal matrix coming from reduce_to_tridiagonal_matrix().
max_iterationsMaximum number of iterations to perform, default is 1000. If set to 0, the algorithm continues until convergence. As convergence is not given for all data, this might result in an infinite loop.

Definition at line 150 of file pca.cpp.

std::string trim ( std::string const &  s,
std::string const &  delimiters 
)

Return a copy of the input string, with trimmed white spaces.

Definition at line 238 of file string.cpp.

std::string trim_left ( std::string const &  s,
std::string const &  delimiters 
)

Return a copy of the input string, with right trimmed white spaces.

Definition at line 226 of file string.cpp.

std::string trim_right ( std::string const &  s,
std::string const &  delimiters 
)

Return a copy of the input string, with left trimmed white spaces.

Definition at line 214 of file string.cpp.

std::string genesis::utils::xml_attribute ( std::string const &  name,
T const &  value 
)

Definition at line 52 of file utils/formats/xml/helper.hpp.

std::string xml_comment ( std::string const &  content)

Definition at line 70 of file utils/formats/xml/helper.cpp.

std::string xml_deescape ( std::string const &  txt)

De-escape special XML characters.

Definition at line 59 of file utils/formats/xml/helper.cpp.

std::string xml_escape ( std::string const &  txt)

Escape special XML characters.

Definition at line 45 of file utils/formats/xml/helper.cpp.

const XmlComment * xml_value_to_comment ( const XmlValue *  v)

Converts a pointer to an XmlValue to XmlComment if appropriate.

Throws if the dynamic type of the object is not actually an XmlComment object.

Definition at line 47 of file xml/document.cpp.

const XmlElement * xml_value_to_element ( const XmlValue *  v)

Converts a pointer to an XmlValue to XmlElement if appropriate.

Throws if the dynamic type of the object is not actually an XmlElement object.

Definition at line 77 of file xml/document.cpp.

const XmlMarkup * xml_value_to_markup ( const XmlValue *  v)

Converts a pointer to an XmlValue to XmlMarkup if appropriate.

Throws if the dynamic type of the object is not actually an XmlMarkup object.

Definition at line 62 of file xml/document.cpp.

Typedef Documentation

Alias for the either AsynchronousReader or SynchronousReader, depending on the threading setting.

This typedef is an alias for AsynchronousReader, if threading is available, that is, if the GENESIS_PTHREADS macro definition is set. If not, it is an alias for SynchronousReader.

Using this typedef instead of one of the two reader classes directly thus makes it possible to ignore the GENESIS_PTHREADS setting when using them. It serves as an abstraction. For example, InputStream uses the typedef this way.

Definition at line 87 of file input_reader.hpp.

using NamedColorList = std::vector<std::pair<std::string, ColorBytes>>

Definition at line 59 of file names.cpp.

Enumeration Type Documentation

enum ColorList
strong
Enumerator
kMagma 
kInferno 
kPlasma 
kViridis 
kSpectral 

Definition at line 56 of file lists.hpp.

Local helper enum that indicates which component of a coordinate we are dealing with.

Enumerator
kLatitude 
kLongitude 

Definition at line 57 of file utils/tools/geodesy/functions.cpp.

enum PcaStandardization
strong

Setting for principal_component_analysis() to determine which form of standardization of the data to use prior to perfoming the PCA.

Enumerator
kCorrelation 

Standardize the mean and variance of the data before performing the PCA.

Best to use when the data has widely varying scales in between the columns, i.e., if the columns present data from different domains. Also, see correlation_matrix().

kCovariance 

Standardize the mean, but not the variance of the data before performing the PCA.

Best to use when the data has similar scales in between the columns, i.e., if the columns present data from the same domain. Also, see covariance_matrix().

kSSCP 

Do not perform any standardization prior to performing the PCA.

Not recommended. Also, see sums_of_squares_and_cross_products_matrix().

Definition at line 49 of file pca.hpp.

enum SkipWhitespace : unsigned char
strong

Option to determine how to treat surrounding whitespace when scanning an input stream.

This helper enum is used in the input stream scanner functions read_char_or_throw() and affirm_char_or_throw() in order to indicate how they treat whitespace while looking for chars.

For checking whether a partcular option is set, it is possible to use the binary and operator &:

if( option & SkipWhitespace::kTrailing ) {
    // ...
}

Of course, simply comparing the values also works.

Enumerator
kNone 

Skip no whitespace. Thus, immediately treat the current input char.

kLeading 

Skip all whitespace in the input stream, then treat the next non-white char.

kTrailing 

Treat the current char in the input stream, then skip the following whitespace.

kSurrounding 

Skip whitespace, treat the first non-white char, then skip all following whitespace.

Definition at line 60 of file scanner.hpp.

Variable Documentation

const std::vector<Color> color_list_inferno_

Definition at line 315 of file lists.cpp.

const std::vector<Color> color_list_magma_

Definition at line 56 of file lists.cpp.

const std::vector<Color> color_list_plasma_

Definition at line 574 of file lists.cpp.

const std::vector<Color> color_list_spectral_
Initial value:
= {{
{ 0.61960784313725492, 0.003921568627450980, 0.25882352941176473 },
{ 0.83529411764705885, 0.24313725490196078 , 0.30980392156862746 },
{ 0.95686274509803926, 0.42745098039215684 , 0.2627450980392157 },
{ 0.99215686274509807, 0.68235294117647061 , 0.38039215686274508 },
{ 0.99607843137254903, 0.8784313725490196 , 0.54509803921568623 },
{ 1.0 , 1.0 , 0.74901960784313726 },
{ 0.90196078431372551, 0.96078431372549022 , 0.59607843137254901 },
{ 0.6705882352941176 , 0.8666666666666667 , 0.64313725490196083 },
{ 0.4 , 0.76078431372549016 , 0.6470588235294118 },
{ 0.19607843137254902, 0.53333333333333333 , 0.74117647058823533 },
{ 0.36862745098039218, 0.30980392156862746 , 0.63529411764705879 }
}}

Definition at line 1096 of file lists.cpp.

const std::vector<Color> color_list_viridis_

Definition at line 833 of file lists.cpp.

const NamedColorList color_list_web_

Struct that stores a static const map of named web colors.

The map stores all 140 color names of the HTML web colors. It is mainly used as a simple way to create a color scheme in form of a vector of colors.

Definition at line 71 of file names.cpp.

const NamedColorList color_list_xkcd_

Struct that stores a static const map of named xkcd colors.

They were published under Public Domain, http://creativecommons.org/publicdomain/zero/1.0/. See https://xkcd.com/color/rgb/ and https://blog.xkcd.com/2010/05/03/color-survey-results/ for details.

Definition at line 225 of file names.cpp.

constexpr double EARTH_MEAN_RADIUS = 6371.0

Earth is not flat!

Definition at line 49 of file utils/tools/geodesy/functions.hpp.

constexpr double PI = 3.141592653589793238463

Make the world go round.

Definition at line 49 of file common.hpp.