CycloBranch
utilities.h File Reference

Auxiliary funtions and structures. More...

#include <fstream>
#include <iostream>
#include <vector>
#include <deque>
#include <map>
#include <unordered_map>
#include <string>
#include <sstream>
#include <iomanip>
#include <cfloat>
#include <cmath>
#include <QString>
#include <QByteArray>
#include <QMetaType>
#include <QAbstractItemModel>
#include <QModelIndex>
#include <boost/regex.hpp>

Go to the source code of this file.

Classes

struct  cCoordinateInfo
 Store aggregated information about a coordinate. More...
 
struct  compareStringBySize
 Compare items in a string vector by size. More...
 

Macros

#define WIN   0
 
#define UNX   1
 
#define OSX   2
 
#define OS_TYPE   WIN
 

Enumerations

enum  eVendorType { unknownvendor = 0 , bruker = 1 , waters = 2 }
 Vendor types.
 
enum  eModeType {
  denovoengine = 0 , singlecomparison = 1 , databasesearch = 2 , dereplication = 3 ,
  compoundsearch = 4
}
 Running modes of the application.
 
enum  ePeptideType {
  linear = 0 , cyclic = 1 , branched = 2 , branchcyclic = 3 ,
  linearpolyketide = 4 , cyclicpolyketide = 5 , other = 6
}
 The types of peptides supported by the application.
 

Functions

void storeIntVector (vector< int > &v, ofstream &os)
 Store a vector of integers into an output stream. More...
 
void loadIntVector (vector< int > &v, ifstream &is)
 Load a vector of integers from an input stream. More...
 
void storeDoubleVector (vector< double > &v, ofstream &os)
 Store a vector of doubles into an output stream. More...
 
void loadDoubleVector (vector< double > &v, ifstream &is)
 Load a vector of doubles from an input stream. More...
 
void storeString (string &s, ofstream &os)
 Store a string into an output stream. More...
 
void loadString (string &s, ifstream &is)
 Load a string from an input stream. More...
 
void storeStringVector (vector< string > &v, ofstream &os)
 Store a vector of strings into an output stream. More...
 
void loadStringVector (vector< string > &v, ifstream &is)
 Load a vector of strings from an input stream. More...
 
void storeStringIntMap (map< string, int > &map, ofstream &os)
 Store a map<string, int> into an output stream. More...
 
void loadStringIntMap (map< string, int > &map, ifstream &is)
 Load a map<string, int> from an input stream. More...
 
void storeStringIntMapVector (vector< map< string, int > > &vector, ofstream &os)
 Store a vector of map<string, int> into an output stream. More...
 
void loadStringIntMapVector (vector< map< string, int > > &vector, ifstream &is)
 Load a vector of map<string, int> from an input stream. More...
 
void storeIntStringMap (map< int, string > &map, ofstream &os)
 Store a map<int, string> into an output stream. More...
 
void loadIntStringMap (map< int, string > &map, ifstream &is)
 Load a map<int, string> from an input stream. More...
 
void convertStringIntUnorderedMapToStringVector (unordered_map< string, int > &map, vector< string > &vector)
 Convert an unordered_map<string, int> to a vector<string>. More...
 
bool isWhiteSpace (char c)
 Check if c is a white space. More...
 
bool isWhiteSpaceExceptSpace (char c)
 Check if c is a white space (except normal space). More...
 
string & removeWhiteSpacesExceptSpaces (string &s)
 Remove white spaces except normal spaces from a string. More...
 
bool checkRegex (ePeptideType peptidetype, string &sequence, string &errormessage)
 Check the syntax of a peptide sequence. More...
 
bool checkFile (string filename)
 Check if a file exists. More...
 
bool compareDoubles (double &first, double &second, double epsilon=0.0000001f)
 Check if two doubles are equal. More...
 
bool compareStringVectors (vector< string > &first, vector< string > &second)
 Check if two vectors of strings are equal. More...
 
bool compareMapsIntDouble (map< int, double > &first, map< int, double > &second, double epsilon=0.0000001f)
 Check if two maps of doubles are equal. More...
 
void parseBranch (ePeptideType peptidetype, string &composition, vector< string > &vectorcomposition, int &branchstart, int &branchend)
 Parse a position of a branch from a peptide sequence. More...
 
ePeptideType getPeptideTypeFromString (string &s)
 Convert a string to peptide type. More...
 
string getStringFromPeptideType (ePeptideType peptidetype)
 Convert the peptide type to a string. More...
 
double cropPrecisionToSixDecimals (double value)
 Crop a precision of a double to six decimal places. More...
 
QByteArray cropDecimalsByteArray (double value)
 Crop decimals of a double. More...
 
QByteArray cropPrecisionToSixDecimalsByteArray (double value)
 Crop a precision of a double to six decimal places. More...
 
string getShortFileName (string filename)
 Get a short filename from a string. More...
 
 Q_DECLARE_METATYPE (vector< cCoordinateInfo >)
 Register vector<cCoordinateInfo> by Qt.
 
double fact (int value)
 Get factorial of a value. More...
 
double median (vector< double > &vector)
 Get median from a vector of doubles. More...
 
string stripHTML (string &htmlstring)
 Strip HTML tags from a HTML string. More...
 
void stripIsomers (string &peptidesequence)
 Strip isomers of building blocks from an input peptide sequence. More...
 
void stripIsomersFromStringVector (vector< string > &acronyms)
 Strip isomers of building blocks from an input string vector. More...
 
bool proxyModelCheckInt (QAbstractItemModel *model, int index, int row, int column, QString str, const QModelIndex &parent)
 Proxy model - int comparator. More...
 
bool proxyModelCheckDouble (QAbstractItemModel *model, int index, int row, int column, QString str, const QModelIndex &parent)
 Proxy model - double comparator. More...
 
bool proxyModelCheckString (QAbstractItemModel *model, int index, int row, int column, QString &itemstr, QString str, const QModelIndex &parent, bool wholeword, Qt::CaseSensitivity casesensitive)
 Proxy model - string comparator. More...
 
bool isCompatibleVersion (int fileversionpart1, int fileversionpart2, int fileversionpart3, int lastcompatiblepart1, int lastcompatiblepart2, int lastcompatiblepart3)
 Check the compatibility of CycloBranch version. More...
 
string fixLabelCharge (string &str, int sourcecharge, int targetcharge)
 Fix the name of a multiply charged ion in MS mode. More...
 

Variables

const double pi = 3.141592653589793
 The pi value.
 
const double econst = 2.718281828459045
 The e constant.
 
const int defaultwinsizex = 1350
 Default window size x.
 
const int defaultwinsizey = 875
 Default window size y.
 
QString appname
 The name of the application.
 
QString appversion
 The version of the application.
 
QString lastcompatibleappversion
 Last compatible version of the application.
 
QString installdir
 A directory where the application is installed under Linux or OSX.
 

Detailed Description

Auxiliary funtions and structures.

Function Documentation

◆ checkFile()

bool checkFile ( string  filename)

Check if a file exists.

Parameters
filenamefilename
Return values
booltrue if the file exists, false otherwise

◆ checkRegex()

bool checkRegex ( ePeptideType  peptidetype,
string &  sequence,
string &  errormessage 
)

Check the syntax of a peptide sequence.

Parameters
peptidetypepeptide type
sequencepeptide sequence
errormessagean error message if false is returned
Return values
booltrue when the syntax is correct, false otherwise

◆ compareDoubles()

bool compareDoubles ( double &  first,
double &  second,
double  epsilon = 0.0000001f 
)

Check if two doubles are equal.

Parameters
firstfirst value
secondsecond value
epsilonepsilon value for comparison
Return values
booltrue if the values are equal

◆ compareMapsIntDouble()

bool compareMapsIntDouble ( map< int, double > &  first,
map< int, double > &  second,
double  epsilon = 0.0000001f 
)

Check if two maps of doubles are equal.

Parameters
firstfirst map
secondsecond map
epsilonepsilon value for double comparison
Return values
booltrue if the maps are equal

◆ compareStringVectors()

bool compareStringVectors ( vector< string > &  first,
vector< string > &  second 
)

Check if two vectors of strings are equal.

Parameters
firstfirst vector
secondsecond vector
Return values
booltrue if the vectors are equal

◆ convertStringIntUnorderedMapToStringVector()

void convertStringIntUnorderedMapToStringVector ( unordered_map< string, int > &  map,
vector< string > &  vector 
)

Convert an unordered_map<string, int> to a vector<string>.

Parameters
mapan input map
vectoran output vector

◆ cropDecimalsByteArray()

QByteArray cropDecimalsByteArray ( double  value)

Crop decimals of a double.

Parameters
valuean input value
Return values
QByteArraya value with the limited precision

◆ cropPrecisionToSixDecimals()

double cropPrecisionToSixDecimals ( double  value)

Crop a precision of a double to six decimal places.

Parameters
valuean input value
Return values
doublea value with the limited precision

◆ cropPrecisionToSixDecimalsByteArray()

QByteArray cropPrecisionToSixDecimalsByteArray ( double  value)

Crop a precision of a double to six decimal places.

Parameters
valuean input value
Return values
QByteArraya value with the limited precision

◆ fact()

double fact ( int  value)

Get factorial of a value.

Parameters
valuevalue
Return values
doublefactorial of the value

◆ fixLabelCharge()

string fixLabelCharge ( string &  str,
int  sourcecharge,
int  targetcharge 
)

Fix the name of a multiply charged ion in MS mode.

Parameters
stroriginal ion name
sourcechargesource charge
targetchargetarget charge
Return values
stringfixed name

◆ getPeptideTypeFromString()

ePeptideType getPeptideTypeFromString ( string &  s)

Convert a string to peptide type.

Parameters
sstring
Return values
ePeptideTypetype of peptide

◆ getShortFileName()

string getShortFileName ( string  filename)

Get a short filename from a string.

Parameters
filenamelong filename
Return values
stringshort filename

◆ getStringFromPeptideType()

string getStringFromPeptideType ( ePeptideType  peptidetype)

Convert the peptide type to a string.

Parameters
peptidetypetype of peptide
Return values
stringstring

◆ isCompatibleVersion()

bool isCompatibleVersion ( int  fileversionpart1,
int  fileversionpart2,
int  fileversionpart3,
int  lastcompatiblepart1,
int  lastcompatiblepart2,
int  lastcompatiblepart3 
)

Check the compatibility of CycloBranch version.

Parameters
fileversionpart1tested version (part 1)
fileversionpart2tested version (part 2)
fileversionpart3tested version (part 3)
lastcompatiblepart1last compatible version (part 1)
lastcompatiblepart2last compatible version (part 2)
lastcompatiblepart3last compatible version (part 3)
Return values
booltrue if the versions are compatible

◆ isWhiteSpace()

bool isWhiteSpace ( char  c)

Check if c is a white space.

Parameters
cchar
Return values
booltrue if c is a white space; false otherwise.

◆ isWhiteSpaceExceptSpace()

bool isWhiteSpaceExceptSpace ( char  c)

Check if c is a white space (except normal space).

Parameters
cchar
Return values
booltrue if c is a white space (except normal space); false otherwise.

◆ loadDoubleVector()

void loadDoubleVector ( vector< double > &  v,
ifstream &  is 
)

Load a vector of doubles from an input stream.

Parameters
vreference to a vector of doubles
isreference to an input stream

◆ loadIntStringMap()

void loadIntStringMap ( map< int, string > &  map,
ifstream &  is 
)

Load a map<int, string> from an input stream.

Parameters
mapreference to a map
isreference to an input stream

◆ loadIntVector()

void loadIntVector ( vector< int > &  v,
ifstream &  is 
)

Load a vector of integers from an input stream.

Parameters
vreference to a vector of integers
isreference to an input stream

◆ loadString()

void loadString ( string &  s,
ifstream &  is 
)

Load a string from an input stream.

Parameters
sreference to a string
isreference to an input stream

◆ loadStringIntMap()

void loadStringIntMap ( map< string, int > &  map,
ifstream &  is 
)

Load a map<string, int> from an input stream.

Parameters
mapreference to a map
isreference to an input stream

◆ loadStringIntMapVector()

void loadStringIntMapVector ( vector< map< string, int > > &  vector,
ifstream &  is 
)

Load a vector of map<string, int> from an input stream.

Parameters
vectorreference to a vector
isreference to an input stream

◆ loadStringVector()

void loadStringVector ( vector< string > &  v,
ifstream &  is 
)

Load a vector of strings from an input stream.

Parameters
vreference to a vector of strings
isreference to an input stream

◆ median()

double median ( vector< double > &  vector)

Get median from a vector of doubles.

Parameters
vectorvector of doubles
Return values
doublemedian value

◆ parseBranch()

void parseBranch ( ePeptideType  peptidetype,
string &  composition,
vector< string > &  vectorcomposition,
int &  branchstart,
int &  branchend 
)

Parse a position of a branch from a peptide sequence.

Parameters
peptidetypepeptide type
compositiona peptide sequence where all blocks "[blockX]-[blockY]" were replaced by ids "1-2"; but "\‍(" and "\‍)" are still included
vectorcompositionan output vector with ids of blocks represented as strings
branchstartstart position of a branch (an output value)
branchendend position of a branch (an output value)

◆ proxyModelCheckDouble()

bool proxyModelCheckDouble ( QAbstractItemModel *  model,
int  index,
int  row,
int  column,
QString  str,
const QModelIndex &  parent 
)

Proxy model - double comparator.

Parameters
modelmodel
indexindex
rowrow
columncolumn
strquery string
parentparent
Return values
booltrue if the item is valid

◆ proxyModelCheckInt()

bool proxyModelCheckInt ( QAbstractItemModel *  model,
int  index,
int  row,
int  column,
QString  str,
const QModelIndex &  parent 
)

Proxy model - int comparator.

Parameters
modelmodel
indexindex
rowrow
columncolumn
strquery string
parentparent
Return values
booltrue if the item is valid

◆ proxyModelCheckString()

bool proxyModelCheckString ( QAbstractItemModel *  model,
int  index,
int  row,
int  column,
QString &  itemstr,
QString  str,
const QModelIndex &  parent,
bool  wholeword,
Qt::CaseSensitivity  casesensitive 
)

Proxy model - string comparator.

Parameters
modelmodel
indexindex
rowrow
columncolumn
itemstrstring of current item
strquery string
parentparent
wholewordwholeword
casesensitivecasesensitive
Return values
booltrue if the item is valid

◆ removeWhiteSpacesExceptSpaces()

string & removeWhiteSpacesExceptSpaces ( string &  s)

Remove white spaces except normal spaces from a string.

Parameters
sreference to a string
Return values
stringreference to the input string

◆ storeDoubleVector()

void storeDoubleVector ( vector< double > &  v,
ofstream &  os 
)

Store a vector of doubles into an output stream.

Parameters
vreference to a vector of doubles
osreference to an output stream

◆ storeIntStringMap()

void storeIntStringMap ( map< int, string > &  map,
ofstream &  os 
)

Store a map<int, string> into an output stream.

Parameters
mapreference to a map
osreference to an output stream

◆ storeIntVector()

void storeIntVector ( vector< int > &  v,
ofstream &  os 
)

Store a vector of integers into an output stream.

Parameters
vreference to a vector of integers
osreference to an output stream

◆ storeString()

void storeString ( string &  s,
ofstream &  os 
)

Store a string into an output stream.

Parameters
sreference to a string
osreference to an output stream

◆ storeStringIntMap()

void storeStringIntMap ( map< string, int > &  map,
ofstream &  os 
)

Store a map<string, int> into an output stream.

Parameters
mapreference to a map
osreference to an output stream

◆ storeStringIntMapVector()

void storeStringIntMapVector ( vector< map< string, int > > &  vector,
ofstream &  os 
)

Store a vector of map<string, int> into an output stream.

Parameters
vectorreference to a vector
osreference to an output stream

◆ storeStringVector()

void storeStringVector ( vector< string > &  v,
ofstream &  os 
)

Store a vector of strings into an output stream.

Parameters
vreference to a vector of strings
osreference to an output stream

◆ stripHTML()

string stripHTML ( string &  htmlstring)

Strip HTML tags from a HTML string.

Parameters
htmlstringreference to a string with HTML tags
Return values
stringstripped string

◆ stripIsomers()

void stripIsomers ( string &  peptidesequence)

Strip isomers of building blocks from an input peptide sequence.

Parameters
peptidesequencea peptide sequence

◆ stripIsomersFromStringVector()

void stripIsomersFromStringVector ( vector< string > &  acronyms)

Strip isomers of building blocks from an input string vector.

Parameters
acronymsvector of building block acronyms with isomers