#include <utils.h>
|
static const QString | getLexicalOrderedString (unsigned int num) |
|
static void | writeLexicalOrderedString (QTextStream *p_out, unsigned int num) |
|
static int | zeroDecimalsInValue (pappso_double value) |
| 0.11 would return 0 (no empty decimal) 2.001 would return 2 1000.0001254 would return 3 More...
|
|
static pappso_double | roundToDecimals (pappso_double value, int decimal_places) |
|
static long long int | roundToDecimal32bitsAsLongLongInt (pappso::pappso_double input) |
|
static std::string | toUtf8StandardString (const QString &text) |
|
static bool | writeToFile (const QString &text, const QString &file_name) |
|
static bool | appendToFile (const QString &text, const QString &file_name) |
|
static std::size_t | extractScanNumberFromMzmlNativeId (const QString &spectrum_native_id) |
|
static QString | pointerToString (const void *const pointer) |
|
static bool | almostEqual (double value1, double value2, int decimalPlaces=10) |
|
static double | nearestGreater (double value) |
|
static QString | chronoTimePointDebugString (const QString &msg, std::chrono::system_clock::time_point chrono_time=std::chrono::system_clock::now()) |
|
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()) |
|
static std::vector< double > | splitMzStringToDoubleVectorWithSpaces (const QString &text, std::size_t &error_count) |
|
static std::vector< std::size_t > | splitSizetStringToSizetVectorWithSpaces (const QString &text, std::size_t &error_count) |
|
static QString | booleanToString (bool value) |
| convenient function to transform a boolean to QString "TRUE" or "FALSE" QString returned is readable by R More...
|
|
Definition at line 48 of file utils.h.
◆ almostEqual()
bool pappso::Utils::almostEqual |
( |
double |
value1, |
|
|
double |
value2, |
|
|
int |
decimalPlaces = 10 |
|
) |
| |
|
static |
Tell if both double values, are equal within the double representation capabilities of the platform.
Definition at line 260 of file utils.cpp.
261{
262
263
264
265
266
267
268
269
270
271
272
273
274 double valueSum = std::abs(value1 + value2);
275
276
277
278 double valueDiff = std::abs(value1 - value2);
279
280
281
282 double epsilon = std::numeric_limits<double>::epsilon();
283
284
285
286 double scaleFactor = epsilon * valueSum * decimalPlaces;
287
288
289
290
291
292
293
294 bool res = valueDiff < scaleFactor
295
296 || valueDiff < std::numeric_limits<double>::min();
297
298
299
300
302}
References pappso::res.
◆ appendToFile()
bool pappso::Utils::appendToFile |
( |
const QString & |
text, |
|
|
const QString & |
file_name |
|
) |
| |
|
static |
Definition at line 194 of file utils.cpp.
195{
196
197 QFile file(file_name);
198
199 if(file.open(QFile::WriteOnly | QFile::Append))
200 {
201
202 QTextStream out(&file);
203
204 out << text;
205
206 out.flush();
207 file.close();
208
209 return true;
210 }
211
212 return false;
213}
◆ booleanToString()
QString pappso::Utils::booleanToString |
( |
bool |
value | ) |
|
|
static |
convenient function to transform a boolean to QString "TRUE" or "FALSE" QString returned is readable by R
- Returns
- QString "TRUE" or "FALSE"
Definition at line 423 of file utils.cpp.
424{
425 if(value)
426 return "TRUE";
427 return "FALSE";
428}
◆ chronoIntervalDebugString()
QString pappso::Utils::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() |
|
) |
| |
|
static |
Definition at line 329 of file utils.cpp.
333{
334 QString debug_text =
335 QString(
336 "%1 %2 min = %3 s = %4 ms = %5 "
337 "µs\n")
338 .arg(msg)
339 .arg(std::chrono::duration_cast<std::chrono::minutes>(chrono_finish -
340 chrono_start)
341 .count())
342 .arg(std::chrono::duration_cast<std::chrono::seconds>(chrono_finish -
343 chrono_start)
344 .count())
345 .arg(std::chrono::duration_cast<std::chrono::milliseconds>(chrono_finish -
346 chrono_start)
347 .count())
348 .arg(std::chrono::duration_cast<std::chrono::microseconds>(chrono_finish -
349 chrono_start)
350 .count());
351
352 return debug_text;
353}
◆ chronoTimePointDebugString()
QString pappso::Utils::chronoTimePointDebugString |
( |
const QString & |
msg, |
|
|
std::chrono::system_clock::time_point |
chrono_time = std::chrono::system_clock::now() |
|
) |
| |
|
static |
Definition at line 313 of file utils.cpp.
315{
316
317 time_t tt;
318
319 tt = std::chrono::system_clock::to_time_t(chrono_time);
320
321 QString debug_text =
322 QString("%1 - %2\n").arg(msg).arg(QString::fromLatin1(ctime(&tt)));
323
324 return debug_text;
325}
◆ extractScanNumberFromMzmlNativeId()
std::size_t pappso::Utils::extractScanNumberFromMzmlNativeId |
( |
const QString & |
spectrum_native_id | ) |
|
|
static |
TODO activate this in a future release to ensure scan number for(auto i = 0; i < native_id_list.size(); i += 2) { if(native_id_list[i] == "scan") { return native_id_list[i + 1].toULong(); } }
throw ExceptionNotFound( QObject::tr("scan number not found in mzML native id %1") .arg(spectrum_native_id));
Definition at line 217 of file utils.cpp.
218{
219 qDebug() << " " << spectrum_native_id;
220 QStringList native_id_list = spectrum_native_id.split("=");
221 if(native_id_list.size() < 2)
222 {
223 throw ExceptionNotFound(
224 QObject::tr("scan number not found in mzML native id %1")
225 .arg(spectrum_native_id));
226 }
227 else
228 {
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243 return native_id_list.back().toULong();
244 }
245 return 0;
246}
◆ getLexicalOrderedString()
const QString pappso::Utils::getLexicalOrderedString |
( |
unsigned int |
num | ) |
|
|
static |
◆ nearestGreater()
double pappso::Utils::nearestGreater |
( |
double |
value | ) |
|
|
static |
Definition at line 306 of file utils.cpp.
307{
308 return std::nextafter(value, value + 1);
309}
◆ pointerToString()
QString pappso::Utils::pointerToString |
( |
const void *const |
pointer | ) |
|
|
static |
◆ roundToDecimal32bitsAsLongLongInt()
Definition at line 130 of file utils.cpp.
131{
133 if(sizeof(int *) == 4)
134 {
135 test_decimal = 100000000;
136 }
137 return (floor(input * test_decimal));
138}
double pappso_double
A type definition for doubles.
◆ roundToDecimals()
◆ splitMzStringToDoubleVectorWithSpaces()
std::vector< double > pappso::Utils::splitMzStringToDoubleVectorWithSpaces |
( |
const QString & |
text, |
|
|
std::size_t & |
error_count |
|
) |
| |
|
static |
Definition at line 357 of file utils.cpp.
359{
360
361 QStringList string_list =
362 text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
363
364
365
366 std::vector<double> double_vector;
367
368 for(int iter = 0; iter < string_list.size(); ++iter)
369 {
370 QString current_string = string_list.at(iter);
371
372 bool ok = false;
373
374 double current_double = current_string.toDouble(&ok);
375
376 if(!current_double && !ok)
377 {
378 ++error_count;
379 continue;
380 }
381
382 double_vector.push_back(current_double);
383 }
384
385 return double_vector;
386}
◆ splitSizetStringToSizetVectorWithSpaces()
std::vector< std::size_t > pappso::Utils::splitSizetStringToSizetVectorWithSpaces |
( |
const QString & |
text, |
|
|
std::size_t & |
error_count |
|
) |
| |
|
static |
Definition at line 390 of file utils.cpp.
392{
393
394
395 QStringList string_list =
396 text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
397
398
399
400
401 std::vector<std::size_t> sizet_vector;
402
403 for(int iter = 0; iter < string_list.size(); ++iter)
404 {
405 QString current_string = string_list.at(iter);
406
407 bool ok = false;
408
409 std::size_t current_sizet = current_string.toUInt(&ok);
410
411 if(!current_sizet && !ok)
412 {
413 ++error_count;
414 continue;
415 }
416
417 sizet_vector.push_back(current_sizet);
418 }
419
420 return sizet_vector;
421}
◆ toUtf8StandardString()
std::string pappso::Utils::toUtf8StandardString |
( |
const QString & |
text | ) |
|
|
static |
◆ writeLexicalOrderedString()
void pappso::Utils::writeLexicalOrderedString |
( |
QTextStream * |
p_out, |
|
|
unsigned int |
num |
|
) |
| |
|
static |
◆ writeToFile()
bool pappso::Utils::writeToFile |
( |
const QString & |
text, |
|
|
const QString & |
file_name |
|
) |
| |
|
static |
Definition at line 171 of file utils.cpp.
172{
173
174 QFile file(file_name);
175
176 if(file.open(QFile::WriteOnly | QFile::Truncate))
177 {
178
179 QTextStream out(&file);
180
181 out << text;
182
183 out.flush();
184 file.close();
185
186 return true;
187 }
188
189 return false;
190}
◆ zeroDecimalsInValue()
0.11 would return 0 (no empty decimal) 2.001 would return 2 1000.0001254 would return 3
Determine the number of zero decimals between the decimal point and the first non-zero decimal.
- Parameters
-
value | the value to be analyzed |
- Returns
- the number of '0' decimals between the decimal separator '.' and the first non-0 decimal
Definition at line 81 of file utils.cpp.
82{
83
84
85 int intPart = static_cast<int>(value);
86
87
88
89 double decimalPart = value - intPart;
90
91
92
93 int count = 0;
94
95 while(decimalPart > 0)
96 {
97 ++count;
98
99 decimalPart *= 10;
100
101
102
103 if(decimalPart >= 1)
104 {
105
106
107
108 break;
109 }
110 }
111
112
113
114 return count;
115}
Referenced by pappso::MzIntegrationParams::createArbitraryBins().
◆ endOfLineRegExp
QRegularExpression pappso::Utils::endOfLineRegExp = QRegularExpression("^\\s+$") |
|
static |
◆ mzListDataFormatRegExp
QRegularExpression pappso::Utils::mzListDataFormatRegExp |
|
static |
Regular expression matching <m/z value><non-numerical*>
Definition at line 56 of file utils.h.
◆ sizetListDataFormatRegExp
QRegularExpression pappso::Utils::sizetListDataFormatRegExp |
|
static |
Regular expression matching <size_t><non-numerical*>
Definition at line 59 of file utils.h.
◆ xyMassDataFormatRegExp
QRegularExpression pappso::Utils::xyMassDataFormatRegExp |
|
static |
The documentation for this class was generated from the following files: