libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
3 *
4 * This file is part of the PAPPSOms++ library.
5 *
6 * PAPPSOms++ is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * PAPPSOms++ is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Contributors:
20 * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
21 *implementation
22 ******************************************************************************/
23
24
25#pragma once
26
27
28/////////////////////// StdLib includes
29#include <chrono>
30
31/////////////////////// Qt includes
32#include <QString>
33#include <QByteArray>
34#include <QRegularExpression>
35#include <QTextStream>
36
37
38/////////////////////// Local includes
43
44
45namespace pappso
46{
47
48class Trace;
49
51{
52 public:
53 static QString getVersion();
54 static QRegularExpression unsignedDoubleNumberNoExponentialRegExp;
55 static QRegularExpression anythingButDigitDotDash;
56 static QRegularExpression signedDoubleNumberExponentialRegExp;
57
58 //! Regular expression matching <numerical value><non-numerical*><numerical
59 //! value>
60 static QRegularExpression xyMassDataFormatRegExp;
61
62 //! Regular expression matching <m/z value><non-numerical*>
63 static QRegularExpression mzListDataFormatRegExp;
64
65 //! Regular expression matching <size_t><non-numerical*>
66 static QRegularExpression sizetListDataFormatRegExp;
67
68 //! Regular expression that tracks the end of line in text files.
69 static QRegularExpression endOfLineRegExp;
70
71 static const QString getLexicalOrderedString(unsigned int num);
72 static void writeLexicalOrderedString(QTextStream *p_out, unsigned int num);
73
74 static int zeroDecimalsInValue(pappso_double value);
75 static pappso_double roundToDecimals(pappso_double value, int decimal_places);
76 static long long int roundToDecimal32bitsAsLongLongInt(pappso_double input);
77
78 static std::string toUtf8StandardString(const QString &text);
79
80 static bool writeToFile(const QString &text, const QString &file_name);
81 static bool writeToFile(const std::vector<double> &data, int decimals, const QString &file_name);
82 static bool appendToFile(const QString &text, const QString &file_name);
83 static std::size_t extractScanNumberFromMzmlNativeId(const QString &spectrum_native_id);
84
85 static QString pointerToString(const void *const pointer);
86
87 static bool almostEqual(double value1, double value2, int decimalPlaces = 10);
88
89 static double nearestGreater(double value);
90
91 static QString chronoTimePointDebugString(
92 const QString &msg,
93 std::chrono::system_clock::time_point chrono_time = std::chrono::system_clock::now());
94
95 static QString chronoIntervalDebugString(
96 const QString &msg,
97 std::chrono::system_clock::time_point chrono_start,
98 std::chrono::system_clock::time_point chrono_finish = std::chrono::system_clock::now());
99
100 static std::vector<double> splitMzStringToDoubleVectorWithSpaces(const QString &text,
101 std::size_t &error_count);
102
103 static std::vector<std::size_t> splitSizetStringToSizetVectorWithSpaces(const QString &text,
104 std::size_t &error_count);
105
106 /** @brief convenient function to transform a boolean to QString "TRUE" or
107 * "FALSE" QString returned is readable by R
108 * @return QString "TRUE" or "FALSE"
109 */
110 static QString booleanToString(bool value);
111
112 /** @brief Convenience function to return a string describing the MzFormat of
113 * a file
114 * @return QString like "brukerTims" for enum value MzFormat::brukerTims.
115 */
116 static QString msDataFormatAsString(Enums::MsDataFormat mz_format);
117 static QString fileReaderTypeAsString(Enums::FileReaderType file_reader_type);
118
119 /** @brief Convenience function to return a string describing the specglob
120 alingment type
121 * @return QString
122 */
123 static QString toString(specglob::SpectralAlignmentType type);
124
125 /** @brief Convenience function to return a string describing the specglob
126 * experimental spectrum data point
127 * @return QString
128 */
130
131
132 /** @brief Convenience function to return a string naming the precision
133 * @return QString
134 */
135 static QString toString(Enums::PrecisionUnit precision_unit);
136
137 /** @brief Convenience function to return a string describing the ion type
138 * @return QString
139 */
140 static QString toString(Enums::PeptideIon m_ionType);
141
142
144 pappso_double mass);
145
146
147 static AaModificationP translateAaModificationFromUnimod(const QString &unimod_accession);
148
149
150 /** @brief convert vector of double into json array
151 */
152 static QJsonArray toJson(const std::vector<double> &myVec);
153};
154
155} // namespace pappso
A simple container of DataPoint instances.
Definition trace.h:152
static std::size_t extractScanNumberFromMzmlNativeId(const QString &spectrum_native_id)
Definition utils.cpp:285
static QString chronoTimePointDebugString(const QString &msg, std::chrono::system_clock::time_point chrono_time=std::chrono::system_clock::now())
Definition utils.cpp:379
static QString toString(specglob::SpectralAlignmentType type)
Convenience function to return a string describing the specglob alingment type.
Definition utils.cpp:544
static QString pointerToString(const void *const pointer)
Definition utils.cpp:317
static QString msDataFormatAsString(Enums::MsDataFormat mz_format)
Convenience function to return a string describing the MzFormat of a file.
Definition utils.cpp:485
static pappso_double roundToDecimals(pappso_double value, int decimal_places)
Definition utils.cpp:140
static QRegularExpression anythingButDigitDotDash
Definition utils.h:55
static bool almostEqual(double value1, double value2, int decimalPlaces=10)
Tell if both double values, are equal within the double representation capabilities of the platform.
Definition utils.cpp:326
static AaModificationP guessAaModificationPbyMonoisotopicMassDelta(Enums::AminoAcidChar aa, pappso_double mass)
Definition utils.cpp:658
static std::vector< double > splitMzStringToDoubleVectorWithSpaces(const QString &text, std::size_t &error_count)
Definition utils.cpp:415
static double nearestGreater(double value)
Definition utils.cpp:372
static std::string toUtf8StandardString(const QString &text)
Definition utils.cpp:166
static bool appendToFile(const QString &text, const QString &file_name)
Definition utils.cpp:262
static QString fileReaderTypeAsString(Enums::FileReaderType file_reader_type)
Definition utils.cpp:528
static QString booleanToString(bool value)
convenient function to transform a boolean to QString "TRUE" or "FALSE" QString returned is readable ...
Definition utils.cpp:477
static AaModificationP translateAaModificationFromUnimod(const QString &unimod_accession)
Definition utils.cpp:734
static QString chronoIntervalDebugString(const QString &msg, std::chrono::system_clock::time_point chrono_start, std::chrono::system_clock::time_point chrono_finish=std::chrono::system_clock::now())
Definition utils.cpp:394
static long long int roundToDecimal32bitsAsLongLongInt(pappso_double input)
Definition utils.cpp:150
static bool writeToFile(const QString &text, const QString &file_name)
Definition utils.cpp:216
static std::vector< std::size_t > splitSizetStringToSizetVectorWithSpaces(const QString &text, std::size_t &error_count)
Definition utils.cpp:446
static QRegularExpression signedDoubleNumberExponentialRegExp
Definition utils.h:56
static QRegularExpression xyMassDataFormatRegExp
Regular expression matching <numerical value><non-numerical*><numericalvalue>.
Definition utils.h:60
static QRegularExpression mzListDataFormatRegExp
Regular expression matching <m/z value><non-numerical*>.
Definition utils.h:63
static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
Definition utils.h:54
static const QString getLexicalOrderedString(unsigned int num)
Definition utils.cpp:72
static QJsonArray toJson(const std::vector< double > &myVec)
convert vector of double into json array
Definition utils.cpp:774
static QRegularExpression sizetListDataFormatRegExp
Regular expression matching <size_t><non-numerical*>.
Definition utils.h:66
static void writeLexicalOrderedString(QTextStream *p_out, unsigned int num)
Definition utils.cpp:84
static int zeroDecimalsInValue(pappso_double value)
Determine the number of zero decimals between the decimal point and the first non-zero decimal.
Definition utils.cpp:102
static QRegularExpression endOfLineRegExp
Regular expression that tracks the end of line in text files.
Definition utils.h:69
static QString getVersion()
Definition utils.cpp:650
#define PMSPP_LIB_DECL
PeptideIon
Enums::PeptideIon enum defines all types of ions (Nter or Cter).
Definition types.h:286
ExperimentalSpectrumDataPointType
Definition types.h:78
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
const AaModification * AaModificationP
double pappso_double
A type definition for doubles.
Definition types.h:60