CycloBranch
utilities.h
Go to the documentation of this file.
1
7#ifndef _UTILITIES_H
8#define _UTILITIES_H
9
10#include <fstream>
11#include <iostream>
12#include <vector>
13#include <deque>
14#include <map>
15#include <unordered_map>
16#include <string>
17#include <sstream>
18#include <iomanip>
19#include <cfloat>
20#include <cmath>
21#include <QString>
22#include <QByteArray>
23#include <QMetaType>
24#include <QAbstractItemModel>
25#include <QModelIndex>
26#include <boost/regex.hpp>
27
28class cBrick;
29
30
31#define WIN 0 // Windows
32#define UNX 1 // Linux/UNIX
33#define OSX 2 // Mac OS X
34
35
36#ifdef LINUX
37 #define OS_TYPE UNX
38 #define sscanf_s sscanf
39 #define sprintf_s sprintf
40#else
41 #ifdef MACOSX
42 #define OS_TYPE OSX
43 #define sscanf_s sscanf
44 #define sprintf_s sprintf
45 #else
46 #define OS_TYPE WIN
47 #endif
48#endif
49
50
51using namespace std;
52using namespace boost;
53
54
58const double pi = 3.141592653589793;
59
60
64const double econst = 2.718281828459045;
65
66
70const int defaultwinsizex = 1350;
71
72
76const int defaultwinsizey = 875;
77
78
83 unknownvendor = 0,
84 bruker = 1,
85 waters = 2
86};
87
88
93 denovoengine = 0,
94 singlecomparison = 1,
95 databasesearch = 2,
96 dereplication = 3,
97 compoundsearch = 4
98};
99
100
105 linear = 0,
106 cyclic = 1,
107 branched = 2,
108 branchcyclic = 3,
109 linearpolyketide = 4,
110 cyclicpolyketide = 5,
111 other = 6
112};
113
114
118extern QString appname;
119
120
124extern QString appversion;
125
126
130extern QString lastcompatibleappversion;
131
132
136extern QString installdir;
137
138
144void storeIntVector(vector<int>& v, ofstream& os);
145
146
152void loadIntVector(vector<int>& v, ifstream& is);
153
154
160void storeDoubleVector(vector<double>& v, ofstream& os);
161
162
168void loadDoubleVector(vector<double>& v, ifstream& is);
169
170
176void storeString(string& s, ofstream& os);
177
178
184void loadString(string& s, ifstream& is);
185
186
192void storeStringVector(vector<string>& v, ofstream& os);
193
194
200void loadStringVector(vector<string>& v, ifstream& is);
201
202
208void storeStringIntMap(map<string, int>& map, ofstream& os);
209
210
216void loadStringIntMap(map<string, int>& map, ifstream& is);
217
218
224void storeStringIntMapVector(vector< map<string, int> >& vector, ofstream& os);
225
226
232void loadStringIntMapVector(vector< map<string, int> >& vector, ifstream& is);
233
234
240void storeIntStringMap(map<int, string>& map, ofstream& os);
241
242
248void loadIntStringMap(map<int, string>& map, ifstream& is);
249
250
256void convertStringIntUnorderedMapToStringVector(unordered_map<string, int>& map, vector<string>& vector);
257
258
264bool isWhiteSpace(char c);
265
266
272bool isWhiteSpaceExceptSpace(char c);
273
274
280string& removeWhiteSpacesExceptSpaces(string& s);
281
282
290bool checkRegex(ePeptideType peptidetype, string& sequence, string& errormessage);
291
292
298bool checkFile(string filename);
299
300
308bool compareDoubles(double& first, double& second, double epsilon = 0.0000001f);
309
310
317bool compareStringVectors(vector<string>& first, vector<string>& second);
318
319
327bool compareMapsIntDouble(map<int, double>& first, map<int, double>& second, double epsilon = 0.0000001f);
328
329
338void parseBranch(ePeptideType peptidetype, string& composition, vector<string>& vectorcomposition, int& branchstart, int& branchend);
339
340
347
348
354string getStringFromPeptideType(ePeptideType peptidetype);
355
356
362double cropPrecisionToSixDecimals(double value);
363
364
370QByteArray cropDecimalsByteArray(double value);
371
372
378QByteArray cropPrecisionToSixDecimalsByteArray(double value);
379
380
386string getShortFileName(string filename);
387
388
393
397 int id;
398
399
403 int x;
404
405
409 int y;
410
411
416
417
422
423
428
429
434 id = 0;
435 x = 0;
436 y = 0;
439 description = "";
440 }
441
442};
443
444
448Q_DECLARE_METATYPE(vector<cCoordinateInfo>);
449
450
456double fact(int value);
457
458
464double median(vector<double>& vector);
465
466
472string stripHTML(string& htmlstring);
473
474
479void stripIsomers(string& peptidesequence);
480
481
486void stripIsomersFromStringVector(vector<string>& acronyms);
487
488
493
500 bool operator()(const std::string& first, const std::string& second) {
501 size_t size1 = first.size();
502 size_t size2 = second.size();
503 if (first.size() < second.size()) {
504 return true;
505 }
506 if (first.size() > second.size()) {
507 return false;
508 }
509 return first.compare(second) < 0;
510 }
511
512};
513
514
525bool proxyModelCheckInt(QAbstractItemModel* model, int index, int row, int column, QString str, const QModelIndex& parent);
526
527
538bool proxyModelCheckDouble(QAbstractItemModel* model, int index, int row, int column, QString str, const QModelIndex& parent);
539
540
554bool proxyModelCheckString(QAbstractItemModel* model, int index, int row, int column, QString& itemstr, QString str, const QModelIndex& parent, bool wholeword, Qt::CaseSensitivity casesensitive);
555
556
567bool isCompatibleVersion(int fileversionpart1, int fileversionpart2, int fileversionpart3, int lastcompatiblepart1, int lastcompatiblepart2, int lastcompatiblepart3);
568
569
577string fixLabelCharge(string& str, int sourcecharge, int targetcharge);
578
579
580#endif
581
The class representing a building block (brick).
Definition: cBrick.h:41
Store aggregated information about a coordinate.
Definition: utilities.h:392
double relativeintensity
relative intensity
Definition: utilities.h:415
cCoordinateInfo()
The constructor.
Definition: utilities.h:433
int id
scan id
Definition: utilities.h:397
int x
x coordinate
Definition: utilities.h:403
int y
y coordinate
Definition: utilities.h:409
double absoluteintensity
absolute intensity
Definition: utilities.h:421
string description
description
Definition: utilities.h:427
Compare items in a string vector by size.
Definition: utilities.h:492
bool operator()(const std::string &first, const std::string &second)
Comparison function.
Definition: utilities.h:500
QByteArray cropDecimalsByteArray(double value)
Crop decimals of a double.
Definition: utilities.cpp:415
double median(vector< double > &vector)
Get median from a vector of doubles.
Definition: utilities.cpp:450
void storeDoubleVector(vector< double > &v, ofstream &os)
Store a vector of doubles into an output stream.
Definition: utilities.cpp:40
QString installdir
A directory where the application is installed under Linux or OSX.
Definition: utilities.cpp:13
void loadStringIntMapVector(vector< map< string, int > > &vector, ifstream &is)
Load a vector of map<string, int> from an input stream.
Definition: utilities.cpp:130
bool compareDoubles(double &first, double &second, double epsilon=0.0000001f)
Check if two doubles are equal.
Definition: utilities.cpp:243
bool checkRegex(ePeptideType peptidetype, string &sequence, string &errormessage)
Check the syntax of a peptide sequence.
Definition: utilities.cpp:191
eModeType
Running modes of the application.
Definition: utilities.h:92
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.
Definition: utilities.cpp:600
bool isCompatibleVersion(int fileversionpart1, int fileversionpart2, int fileversionpart3, int lastcompatiblepart1, int lastcompatiblepart2, int lastcompatiblepart3)
Check the compatibility of CycloBranch version.
Definition: utilities.cpp:641
QString appname
The name of the application.
Definition: utilities.cpp:6
bool compareMapsIntDouble(map< int, double > &first, map< int, double > &second, double epsilon=0.0000001f)
Check if two maps of doubles are equal.
Definition: utilities.cpp:272
void storeIntVector(vector< int > &v, ofstream &os)
Store a vector of integers into an output stream.
Definition: utilities.cpp:21
bool proxyModelCheckInt(QAbstractItemModel *model, int index, int row, int column, QString str, const QModelIndex &parent)
Proxy model - int comparator.
Definition: utilities.cpp:532
QString appversion
The version of the application.
Definition: utilities.cpp:7
const double pi
The pi value.
Definition: utilities.h:58
void storeString(string &s, ofstream &os)
Store a string into an output stream.
Definition: utilities.cpp:59
void loadStringIntMap(map< string, int > &map, ifstream &is)
Load a map<string, int> from an input stream.
Definition: utilities.cpp:107
Q_DECLARE_METATYPE(vector< cCoordinateInfo >)
Register vector<cCoordinateInfo> by Qt.
void loadDoubleVector(vector< double > &v, ifstream &is)
Load a vector of doubles from an input stream.
Definition: utilities.cpp:49
bool checkFile(string filename)
Check if a file exists.
Definition: utilities.cpp:237
QByteArray cropPrecisionToSixDecimalsByteArray(double value)
Crop a precision of a double to six decimal places.
Definition: utilities.cpp:423
void loadStringVector(vector< string > &v, ifstream &is)
Load a vector of strings from an input stream.
Definition: utilities.cpp:83
void storeStringIntMap(map< string, int > &map, ofstream &os)
Store a map<string, int> into an output stream.
Definition: utilities.cpp:93
void stripIsomers(string &peptidesequence)
Strip isomers of building blocks from an input peptide sequence.
Definition: utilities.cpp:486
double cropPrecisionToSixDecimals(double value)
Crop a precision of a double to six decimal places.
Definition: utilities.cpp:406
void storeStringVector(vector< string > &v, ofstream &os)
Store a vector of strings into an output stream.
Definition: utilities.cpp:74
string fixLabelCharge(string &str, int sourcecharge, int targetcharge)
Fix the name of a multiply charged ion in MS mode.
Definition: utilities.cpp:665
void convertStringIntUnorderedMapToStringVector(unordered_map< string, int > &map, vector< string > &vector)
Convert an unordered_map<string, int> to a vector<string>.
Definition: utilities.cpp:164
void parseBranch(ePeptideType peptidetype, string &composition, vector< string > &vectorcomposition, int &branchstart, int &branchend)
Parse a position of a branch from a peptide sequence.
Definition: utilities.cpp:295
void storeIntStringMap(map< int, string > &map, ofstream &os)
Store a map<int, string> into an output stream.
Definition: utilities.cpp:140
string getShortFileName(string filename)
Get a short filename from a string.
Definition: utilities.cpp:431
const double econst
The e constant.
Definition: utilities.h:64
bool isWhiteSpace(char c)
Check if c is a white space.
Definition: utilities.cpp:175
ePeptideType
The types of peptides supported by the application.
Definition: utilities.h:104
void storeStringIntMapVector(vector< map< string, int > > &vector, ofstream &os)
Store a vector of map<string, int> into an output stream.
Definition: utilities.cpp:121
ePeptideType getPeptideTypeFromString(string &s)
Convert a string to peptide type.
Definition: utilities.cpp:355
string & removeWhiteSpacesExceptSpaces(string &s)
Remove white spaces except normal spaces from a string.
Definition: utilities.cpp:185
void loadString(string &s, ifstream &is)
Load a string from an input stream.
Definition: utilities.cpp:66
void stripIsomersFromStringVector(vector< string > &acronyms)
Strip isomers of building blocks from an input string vector.
Definition: utilities.cpp:519
eVendorType
Vendor types.
Definition: utilities.h:82
QString lastcompatibleappversion
Last compatible version of the application.
Definition: utilities.cpp:9
const int defaultwinsizex
Default window size x.
Definition: utilities.h:70
bool proxyModelCheckDouble(QAbstractItemModel *model, int index, int row, int column, QString str, const QModelIndex &parent)
Proxy model - double comparator.
Definition: utilities.cpp:566
bool compareStringVectors(vector< string > &first, vector< string > &second)
Check if two vectors of strings are equal.
Definition: utilities.cpp:256
string stripHTML(string &htmlstring)
Strip HTML tags from a HTML string.
Definition: utilities.cpp:465
const int defaultwinsizey
Default window size y.
Definition: utilities.h:76
void loadIntStringMap(map< int, string > &map, ifstream &is)
Load a map<int, string> from an input stream.
Definition: utilities.cpp:150
bool isWhiteSpaceExceptSpace(char c)
Check if c is a white space (except normal space).
Definition: utilities.cpp:180
string getStringFromPeptideType(ePeptideType peptidetype)
Convert the peptide type to a string.
Definition: utilities.cpp:382
double fact(int value)
Get factorial of a value.
Definition: utilities.cpp:440
void loadIntVector(vector< int > &v, ifstream &is)
Load a vector of integers from an input stream.
Definition: utilities.cpp:30