libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::Utils Class Reference

#include <utils.h>

Static Public Member Functions

static QString getVersion ()
 
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
 
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
 
static QString msDataFormatAsString (MsDataFormat mz_format)
 Convenience function to return a string describing the MzFormat of a file.
 
static QString fileReaderTypeAsString (FileReaderType file_reader_type)
 
static QString toString (specglob::SpectralAlignmentType type)
 Convenience function to return a string describing the specglob alingment type.
 
static QString toString (specglob::ExperimentalSpectrumDataPointType type)
 Convenience function to return a string describing the specglob experimental spectrum data point.
 

Static Public Attributes

static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
 
static QRegularExpression anythingButDigitDotDash
 
static QRegularExpression signedDoubleNumberExponentialRegExp
 
static QRegularExpression xyMassDataFormatRegExp
 
static QRegularExpression mzListDataFormatRegExp
 Regular expression matching <m/z value><non-numerical*>
 
static QRegularExpression sizetListDataFormatRegExp
 Regular expression matching <size_t><non-numerical*>
 
static QRegularExpression endOfLineRegExp = QRegularExpression("^\\s+$")
 Regular expression that tracks the end of line in text files.
 

Detailed Description

Definition at line 49 of file utils.h.

Member Function Documentation

◆ 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 305 of file utils.cpp.

306{
307 // QString value1String = QString("%1").arg(value1,
308 // 0, 'f', 60);
309 // QString value2String = QString("%1").arg(value2,
310 // 0, 'f', 60);
311
312 // qWarning() << __FILE__ << __LINE__ << __FUNCTION__
313 //<< "value1:" << value1String << "value2:" << value2String;
314
315 // The machine epsilon has to be scaled to the magnitude of the values used
316 // and multiplied by the desired precision in ULPs (units in the last place)
317 // (decimal places).
318
319 double valueSum = std::abs(value1 + value2);
320 // QString valueSumString = QString("%1").arg(valueSum,
321 // 0, 'f', 60);
322
323 double valueDiff = std::abs(value1 - value2);
324 // QString valueDiffString = QString("%1").arg(valueDiff,
325 // 0, 'f', 60);
326
327 double epsilon = std::numeric_limits<double>::epsilon();
328 // QString epsilonString = QString("%1").arg(epsilon,
329 // 0, 'f', 60);
330
331 double scaleFactor = epsilon * valueSum * decimalPlaces;
332 // QString scaleFactorString = QString("%1").arg(scaleFactor,
333 // 0, 'f', 60);
334
335 // qWarning() << "valueDiff:" << valueDiffString << "valueSum:" <<
336 // valueSumString <<
337 //"epsilon:" << epsilonString << "scaleFactor:" << scaleFactorString;
338
339 bool res = valueDiff < scaleFactor
340 // unless the result is subnormal:
341 || valueDiff < std::numeric_limits<double>::min();
342
343 // qWarning() << __FILE__ << __LINE__ << __FUNCTION__
344 //<< "returning res:" << res;
345
346 return res;
347}

References pappso::res.

Referenced by pappso::Trace::removeZeroYDataPoints().

◆ appendToFile()

bool pappso::Utils::appendToFile ( const QString & text,
const QString & file_name )
static

Definition at line 239 of file utils.cpp.

240{
241
242 QFile file(file_name);
243
244 if(file.open(QFile::WriteOnly | QFile::Append))
245 {
246
247 QTextStream out(&file);
248
249 out << text;
250
251 out.flush();
252 file.close();
253
254 return true;
255 }
256
257 return false;
258}

◆ 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 468 of file utils.cpp.

469{
470 if(value)
471 return "TRUE";
472 return "FALSE";
473}

◆ 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 374 of file utils.cpp.

378{
379 QString debug_text =
380 QString(
381 "%1 %2 min = %3 s = %4 ms = %5 "
382 "µs\n")
383 .arg(msg)
384 .arg(std::chrono::duration_cast<std::chrono::minutes>(chrono_finish -
385 chrono_start)
386 .count())
387 .arg(std::chrono::duration_cast<std::chrono::seconds>(chrono_finish -
388 chrono_start)
389 .count())
390 .arg(std::chrono::duration_cast<std::chrono::milliseconds>(chrono_finish -
391 chrono_start)
392 .count())
393 .arg(std::chrono::duration_cast<std::chrono::microseconds>(chrono_finish -
394 chrono_start)
395 .count());
396
397 return debug_text;
398}

◆ 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 358 of file utils.cpp.

360{
361
362 time_t tt;
363
364 tt = std::chrono::system_clock::to_time_t(chrono_time);
365
366 QString debug_text =
367 QString("%1 - %2\n").arg(msg).arg(QString::fromLatin1(ctime(&tt)));
368
369 return debug_text;
370}

◆ 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 262 of file utils.cpp.

263{
264 qDebug() << " " << spectrum_native_id;
265 QStringList native_id_list = spectrum_native_id.split("=");
266 if(native_id_list.size() < 2)
267 {
268 throw ExceptionNotFound(
269 QObject::tr("scan number not found in mzML native id %1")
270 .arg(spectrum_native_id));
271 }
272 else
273 {
274 /** TODO activate this in a future release to ensure scan number
275 for(auto i = 0; i < native_id_list.size(); i += 2)
276 {
277 if(native_id_list[i] == "scan")
278 {
279 return native_id_list[i + 1].toULong();
280 }
281 }
282
283 throw ExceptionNotFound(
284 QObject::tr("scan number not found in mzML native id %1")
285 .arg(spectrum_native_id));
286
287*/
288 return native_id_list.back().toULong();
289 }
290 return 0;
291}

◆ fileReaderTypeAsString()

QString pappso::Utils::fileReaderTypeAsString ( FileReaderType file_reader_type)
static

Definition at line 519 of file utils.cpp.

520{
521
522 if(file_reader_type == FileReaderType::pwiz)
523 return "pwiz";
524 else if(file_reader_type == FileReaderType::xy)
525 return "xy";
526 else if(file_reader_type == FileReaderType::tims)
527 return "tims";
528 else if(file_reader_type == FileReaderType::tims_frames)
529 return "tims_frames";
530 else
531 return "unknown";
532}
@ pwiz
using libpwizlite
@ tims
TimsMsRunReader : each scan is returned as a mass spectrum.

References pappso::pwiz, pappso::tims, pappso::tims_frames, and pappso::xy.

Referenced by pappso::MsFileAccessor::getMsRunIds().

◆ getLexicalOrderedString()

const QString pappso::Utils::getLexicalOrderedString ( unsigned int num)
static

Definition at line 74 of file utils.cpp.

75{
76 int size = log10(num);
77 size += 97;
78 QLatin1Char latin1_char(size);
79 QString base(latin1_char);
80 base.append(QString().setNum(num));
81 return (base);
82}

References pappso::log10.

Referenced by pappso::GrpGroup::getGroupingId(), pappso::GrpPeptide::getGroupingId(), pappso::GrpProtein::getGroupingId(), pappso::GrpSubGroup::getGroupingId(), pappso::BafAsciiFileReader::getMsRunIds(), pappso::PwizMsFileReader::getMsRunIds(), and pappso::XyMsFileReader::getMsRunIds().

◆ getVersion()

QString pappso::Utils::getVersion ( )
static

Definition at line 573 of file utils.cpp.

574{
575 QString version(PAPPSOMSPP_VERSION);
576 return version;
577}

◆ msDataFormatAsString()

QString pappso::Utils::msDataFormatAsString ( MsDataFormat mz_format)
static

Convenience function to return a string describing the MzFormat of a file.

 

Returns
QString like "brukerTims" for enum value MzFormat::brukerTims.

Definition at line 476 of file utils.cpp.

477{
478
479 if(mz_format == MsDataFormat::mzML)
480 return "mzML";
481 else if(mz_format == MsDataFormat::mzXML)
482 return "mzXML";
483 else if(mz_format == MsDataFormat::MGF)
484 return "MGF";
485 else if(mz_format == MsDataFormat::SQLite3)
486 return "SQLite3";
487 else if(mz_format == MsDataFormat::xy)
488 return "xy";
489 else if(mz_format == MsDataFormat::mz5)
490 return "mz5";
491 else if(mz_format == MsDataFormat::msn)
492 return "msn";
493 else if(mz_format == MsDataFormat::abSciexWiff)
494 return "abSciexWiff";
495 else if(mz_format == MsDataFormat::abSciexT2D)
496 return "abSciexT2D";
497 else if(mz_format == MsDataFormat::agilentMassHunter)
498 return "agilentMassHunter";
499 else if(mz_format == MsDataFormat::thermoRaw)
500 return "thermoRaw";
501 else if(mz_format == MsDataFormat::watersRaw)
502 return "watersRaw";
503 else if(mz_format == MsDataFormat::brukerFid)
504 return "brukerFid";
505 else if(mz_format == MsDataFormat::brukerYep)
506 return "brukerYep";
507 else if(mz_format == MsDataFormat::brukerBaf)
508 return "brukerBaf";
509 else if(mz_format == MsDataFormat::brukerTims)
510 return "brukerTims";
511 else if(mz_format == MsDataFormat::brukerBafAscii)
512 return "brukerBafAscii";
513 else
514 return "unknown";
515}
@ xy
(x,y) format
@ SQLite3
SQLite3 format.
@ MGF
Mascot format.

References pappso::abSciexT2D, pappso::abSciexWiff, pappso::agilentMassHunter, pappso::brukerBaf, pappso::brukerBafAscii, pappso::brukerFid, pappso::brukerTims, pappso::brukerYep, pappso::MGF, pappso::msn, pappso::mz5, pappso::mzML, pappso::mzXML, pappso::SQLite3, pappso::thermoRaw, pappso::watersRaw, and pappso::xy.

◆ nearestGreater()

double pappso::Utils::nearestGreater ( double value)
static

Definition at line 351 of file utils.cpp.

352{
353 return std::nextafter(value, value + 1);
354}

◆ pointerToString()

QString pappso::Utils::pointerToString ( const void *const pointer)
static

Definition at line 295 of file utils.cpp.

296{
297 return QString("%1").arg(
298 (quintptr)pointer, QT_POINTER_SIZE * 2, 16, QChar('0'));
299}

Referenced by pappso::MsRunDataSetTreeNode::toString(), and pappso::QualifiedMassSpectrum::toString().

◆ roundToDecimal32bitsAsLongLongInt()

long long int pappso::Utils::roundToDecimal32bitsAsLongLongInt ( pappso::pappso_double input)
static

Definition at line 153 of file utils.cpp.

154{
155 pappso::pappso_double test_decimal = 100000000000;
156 if(sizeof(int *) == 4)
157 { // 32bits
158 test_decimal = 100000000;
159 }
160 return (floor(input * test_decimal));
161}
double pappso_double
A type definition for doubles.
Definition types.h:50

◆ roundToDecimals()

pappso_double pappso::Utils::roundToDecimals ( pappso_double value,
int decimal_places )
static

Definition at line 142 of file utils.cpp.

143{
144 if(decimal_places < 0)
145 return value;
146
147 return ceil((value * pow(10, decimal_places)) - 0.49) /
148 pow(10, decimal_places);
149}

Referenced by pappso::MassSpectrumMinusCombiner::combine(), pappso::MassSpectrumPlusCombiner::combine(), pappso::TraceMinusCombiner::combine(), and pappso::TracePlusCombiner::combine().

◆ splitMzStringToDoubleVectorWithSpaces()

std::vector< double > pappso::Utils::splitMzStringToDoubleVectorWithSpaces ( const QString & text,
std::size_t & error_count )
static

Definition at line 402 of file utils.cpp.

404{
405
406 QStringList string_list =
407 text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
408
409 // qDebug() << "string list:" << string_list;
410
411 std::vector<double> double_vector;
412
413 for(int iter = 0; iter < string_list.size(); ++iter)
414 {
415 QString current_string = string_list.at(iter);
416
417 bool ok = false;
418
419 double current_double = current_string.toDouble(&ok);
420
421 if(!current_double && !ok)
422 {
423 ++error_count;
424 continue;
425 }
426
427 double_vector.push_back(current_double);
428 }
429
430 return double_vector;
431}

◆ splitSizetStringToSizetVectorWithSpaces()

std::vector< std::size_t > pappso::Utils::splitSizetStringToSizetVectorWithSpaces ( const QString & text,
std::size_t & error_count )
static

Definition at line 435 of file utils.cpp.

437{
438 // qDebug() << "Parsing text:" << text;
439
440 QStringList string_list =
441 text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
442
443 // qDebug() << "string list size:" << string_list.size()
444 //<< "values:" << string_list;
445
446 std::vector<std::size_t> sizet_vector;
447
448 for(int iter = 0; iter < string_list.size(); ++iter)
449 {
450 QString current_string = string_list.at(iter);
451
452 bool ok = false;
453
454 std::size_t current_sizet = current_string.toUInt(&ok);
455
456 if(!current_sizet && !ok)
457 {
458 ++error_count;
459 continue;
460 }
461
462 sizet_vector.push_back(current_sizet);
463 }
464
465 return sizet_vector;
466}

◆ toString() [1/2]

QString pappso::Utils::toString ( specglob::ExperimentalSpectrumDataPointType type)
static

Convenience function to return a string describing the specglob experimental spectrum data point.

Returns
QString

Definition at line 554 of file utils.cpp.

555{
556 switch(type)
557 {
559 return "both";
560 break;
562 return "native";
563 break;
565 return "symmetric";
566 break;
567 default:
568 return "synthetic";
569 }
570}
@ both
both, the ion and the complement exists in the original spectrum
@ symmetric
new peak : computed symmetric mass from a corresponding native peak

References pappso::specglob::both, pappso::specglob::native, and pappso::specglob::symmetric.

◆ toString() [2/2]

QString pappso::Utils::toString ( specglob::SpectralAlignmentType type)
static

Convenience function to return a string describing the specglob alingment type.

Returns
QString

Definition at line 535 of file utils.cpp.

536{
537 switch(type)
538 {
540 return "AL";
541 break;
543 return "NA";
544 break;
546 return "RA";
547 break;
548 default:
549 return "ER";
550 }
551}
@ nonAlign
the type of alignment to put in origin matrix NON Alignment (0 - NA)

References pappso::specglob::align, pappso::specglob::nonAlign, and pappso::specglob::reAlign.

Referenced by pappso::specglob::PeptideModel::toProForma(), and pappso::specglob::PeptideModel::toString().

◆ toUtf8StandardString()

std::string pappso::Utils::toUtf8StandardString ( const QString & text)
static

Definition at line 165 of file utils.cpp.

166{
167 std::string env_backup;
168 try
169 {
170#ifdef MXE
171 // std::locale::global(std::locale("C")); // set locale to default locale
172 env_backup = std::setlocale(LC_ALL, nullptr);
173 std::setlocale(LC_ALL, "C");
174#else
175 std::locale::global(std::locale("C")); // set locale to default locale
176#endif
177 }
178 catch(std::exception &error)
179 {
181 QObject::tr("Error trying to set local to C : %1").arg(error.what()));
182 }
183 // Now perform the conversion.
184 QByteArray byte_array = text.toUtf8();
185 std::string stdText = "";
186
187 for(char c : byte_array)
188 {
189 stdText += c;
190 }
191
192 try
193 {
194#ifdef MXE
195 // std::locale::global(std::locale("C")); // set locale to default locale
196 std::setlocale(LC_ALL, env_backup.c_str());
197#else // Set back the locale to the backed-up one.
198 std::locale::global(
199 std::locale("")); // sets locale according to OS environment
200#endif
201 }
202 catch(std::exception &error)
203 {
204
206 QObject::tr("Error trying to set local to original system one %1 : %2")
207 .arg(env_backup.c_str())
208 .arg(error.what()));
209 }
210
211 return stdText;
212}

References pappso::c.

Referenced by pappso::PwizMsFileReader::initialize(), and pappso::PwizMsRunReader::initialize().

◆ writeLexicalOrderedString()

void pappso::Utils::writeLexicalOrderedString ( QTextStream * p_out,
unsigned int num )
static

Definition at line 86 of file utils.cpp.

87{
88 *p_out << (char)(log10(num) + 97) << num;
89}

References pappso::log10.

◆ writeToFile()

bool pappso::Utils::writeToFile ( const QString & text,
const QString & file_name )
static

Definition at line 216 of file utils.cpp.

217{
218
219 QFile file(file_name);
220
221 if(file.open(QFile::WriteOnly | QFile::Truncate))
222 {
223
224 QTextStream out(&file);
225
226 out << text;
227
228 out.flush();
229 file.close();
230
231 return true;
232 }
233
234 return false;
235}

◆ zeroDecimalsInValue()

int pappso::Utils::zeroDecimalsInValue ( pappso_double value)
static

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
valuethe value to be analyzed
Returns
the number of '0' decimals between the decimal separator '.' and the first non-0 decimal

Definition at line 104 of file utils.cpp.

105{
106 // qDebug() << qSetRealNumberPrecision(10) << "Double value: " << value;
107
108 int intPart = static_cast<int>(value);
109
110 // qDebug() << "int part:" << intPart;
111
112 double decimalPart = value - intPart;
113
114 // qDebug() << qSetRealNumberPrecision(10) << "decimal part: " << decimalPart;
115
116 int count = 0;
117
118 while(decimalPart > 0)
119 {
120 ++count;
121
122 decimalPart *= 10;
123
124 // qDebug() << "Iteration " << count << "decimal part:" << decimalPart;
125
126 if(decimalPart >= 1)
127 {
128 // qDebug() << "Because decimal part " << decimalPart
129 //<< "is >= 1, breaking loop while count is " << count << ".";
130
131 break;
132 }
133 }
134
135 // qDebug() << "Returning count:" << count - 1;
136
137 return count - 1;
138}

Referenced by pappso::MzIntegrationParams::createArbitraryBins(), pappso::BasePlotWidget::drawXScopeSpanFeatures(), and pappso::BasePlotWidget::drawYScopeSpanFeatures().

Member Data Documentation

◆ anythingButDigitDotDash

QRegularExpression pappso::Utils::anythingButDigitDotDash
static
Initial value:
=
QRegularExpression("[^\\d^\\.^-]+")

Definition at line 54 of file utils.h.

◆ endOfLineRegExp

QRegularExpression pappso::Utils::endOfLineRegExp = QRegularExpression("^\\s+$")
static

Regular expression that tracks the end of line in text files.

Definition at line 68 of file utils.h.

Referenced by pappso::XyMsRunReader::accept(), pappso::BafAsciiFileReader::initialize(), pappso::XyMsFileReader::initialize(), and pappso::XyMsRunReader::qualifiedMassSpectrumFromXyMSDataFile().

◆ mzListDataFormatRegExp

QRegularExpression pappso::Utils::mzListDataFormatRegExp
static

Regular expression matching <m/z value><non-numerical*>

Definition at line 62 of file utils.h.

◆ signedDoubleNumberExponentialRegExp

QRegularExpression pappso::Utils::signedDoubleNumberExponentialRegExp
static
Initial value:
=
QRegularExpression("-?\\d*\\.?\\d*[e-]?\\d*")

Definition at line 55 of file utils.h.

◆ sizetListDataFormatRegExp

QRegularExpression pappso::Utils::sizetListDataFormatRegExp
static

Regular expression matching <size_t><non-numerical*>

Definition at line 65 of file utils.h.

◆ unsignedDoubleNumberNoExponentialRegExp

QRegularExpression pappso::Utils::unsignedDoubleNumberNoExponentialRegExp
static
Initial value:
=
QRegularExpression("\\d*\\.?\\d+")

Definition at line 53 of file utils.h.

Referenced by pappso::BafAsciiMsRunReader::craftLineParserRegExpPattern(), and pappso::BafAsciiFileReader::initialize().

◆ xyMassDataFormatRegExp

QRegularExpression pappso::Utils::xyMassDataFormatRegExp
static
Initial value:
=
QRegularExpression(
QString("^(%1)(%2)(%3)")
static QRegularExpression anythingButDigitDotDash
Definition utils.h:54
static QRegularExpression signedDoubleNumberExponentialRegExp
Definition utils.h:55
static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
Definition utils.h:53

Regular expression matching <numerical value><non-numerical*><numerical value>

Definition at line 59 of file utils.h.

Referenced by pappso::XyMsRunReader::accept(), pappso::DataPoint::initialize(), pappso::XyMsFileReader::initialize(), and pappso::XyMsRunReader::qualifiedMassSpectrumFromXyMSDataFile().


The documentation for this class was generated from the following files: