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_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 (Enums::MsDataFormat mz_format)
 Convenience function to return a string describing the MzFormat of a file.
 
static QString fileReaderTypeAsString (Enums::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 QString toString (Enums::PrecisionUnit precision_unit)
 Convenience function to return a string naming the precision.
 
static QString toString (Enums::PeptideIon m_ionType)
 Convenience function to return a string describing the ion type.
 
static AaModificationP guessAaModificationPbyMonoisotopicMassDelta (Enums::AminoAcidChar aa, pappso_double mass)
 
static AaModificationP translateAaModificationFromUnimod (const QString &unimod_accession)
 

Static Public Attributes

static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
 
static QRegularExpression anythingButDigitDotDash = QRegularExpression("[^\\d^\\.^-]+")
 
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 50 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 299 of file utils.cpp.

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

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

◆ appendToFile()

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

Definition at line 235 of file utils.cpp.

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

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

451{
452 if(value)
453 return "TRUE";
454 return "FALSE";
455}

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

370{
371 QString debug_text =
372 QString(
373 "%1 %2 min = %3 s = %4 ms = %5 "
374 "µs\n")
375 .arg(msg)
376 .arg(std::chrono::duration_cast<std::chrono::minutes>(chrono_finish - chrono_start).count())
377 .arg(std::chrono::duration_cast<std::chrono::seconds>(chrono_finish - chrono_start).count())
378 .arg(
379 std::chrono::duration_cast<std::chrono::milliseconds>(chrono_finish - chrono_start).count())
380 .arg(std::chrono::duration_cast<std::chrono::microseconds>(chrono_finish - chrono_start)
381 .count());
382
383 return debug_text;
384}

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

354{
355
356 time_t tt;
357
358 tt = std::chrono::system_clock::to_time_t(chrono_time);
359
360 QString debug_text = QString("%1 - %2\n").arg(msg).arg(QString::fromLatin1(ctime(&tt)));
361
362 return debug_text;
363}

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

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

Referenced by pappso::masschroq::PrecursorParser::setQualifiedMassSpectrum().

◆ fileReaderTypeAsString()

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

Definition at line 501 of file utils.cpp.

502{
503
504 if(file_reader_type == Enums::FileReaderType::pwiz)
505 return "pwiz";
506 else if(file_reader_type == Enums::FileReaderType::xy)
507 return "xy";
508 else if(file_reader_type == Enums::FileReaderType::tims)
509 return "tims";
510 else if(file_reader_type == Enums::FileReaderType::tims_frames)
511 return "tims_frames";
512 else
513 return "unknown";
514}
@ pwiz
using libpwizlite
Definition types.h:178
@ tims
TimsMsRunReader : each scan is returned as a mass spectrum.
Definition types.h:181

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

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

◆ getLexicalOrderedString()

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

Definition at line 72 of file utils.cpp.

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

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

◆ guessAaModificationPbyMonoisotopicMassDelta()

pappso::AaModificationP pappso::Utils::guessAaModificationPbyMonoisotopicMassDelta ( Enums::AminoAcidChar aa,
pappso::pappso_double mass )
static

Definition at line 631 of file utils.cpp.

633{
635
636 pappso::AaModificationP oxidation =
637 pappso::AaModification::getInstance("MOD:00425"); // MOD:00425 15.994915
639 pappso::MzRange(oxidation->getMass(), precision).contains(mass))
640 {
641 return oxidation;
642 }
643 pappso::AaModificationP iodoacetamide =
644 pappso::AaModification::getInstance("MOD:00397"); // 57.021465
645 if(pappso::MzRange(iodoacetamide->getMass(), precision).contains(mass))
646 {
647 return iodoacetamide;
648 }
649 pappso::AaModificationP acetylated =
650 pappso::AaModification::getInstance("MOD:00408"); // 42.010567
651 if(pappso::MzRange(acetylated->getMass(), precision).contains(mass))
652 {
653 return acetylated;
654 }
655 pappso::AaModificationP phosphorylated =
656 pappso::AaModification::getInstance("MOD:00696"); // 79.96633
657 if(pappso::MzRange(phosphorylated->getMass(), precision).contains(mass))
658 {
659 return phosphorylated;
660 }
661 pappso::AaModificationP ammonia = pappso::AaModification::getInstance("MOD:01160"); //-17.026548
662 if(pappso::MzRange(ammonia->getMass(), precision).contains(mass))
663 {
664 return ammonia;
665 }
666 pappso::AaModificationP dehydrated =
667 pappso::AaModification::getInstance("MOD:00704"); //-18.010565
668 if(pappso::MzRange(dehydrated->getMass(), precision).contains(mass))
669 {
670 return dehydrated;
671 }
672 pappso::AaModificationP dimethylated =
673 pappso::AaModification::getInstance("MOD:00429"); // 28.0313
674 if(pappso::MzRange(dimethylated->getMass(), precision).contains(mass))
675 {
676 return dimethylated;
677 }
678
679 pappso::AaModificationP dimethylated_medium = pappso::AaModification::getInstance("MOD:00552");
680 if(pappso::MzRange(dimethylated_medium->getMass(), precision).contains(mass))
681 {
682 return dimethylated_medium;
683 }
684
685 pappso::AaModificationP dimethylated_heavy = pappso::AaModification::getInstance("MOD:00638");
686 if(pappso::MzRange(dimethylated_heavy->getMass(), precision).contains(mass))
687 {
688 return dimethylated_heavy;
689 }
690 pappso::AaModificationP DimethylpyrroleAdduct = pappso::AaModification::getInstance("MOD:00628");
691 if(pappso::MzRange(DimethylpyrroleAdduct->getMass(), precision).contains(mass))
692 {
693 return DimethylpyrroleAdduct;
694 }
695
696 // modification not found, creating customized mod :
698
699 throw pappso::ExceptionNotFound(
700 QObject::tr("Utils::guessAaModificationPbyMonoisotopicMassDelta => "
701 "modification not found for mass %1")
702 .arg(mass));
703}
pappso_double getMass() const
static AaModificationP getInstance(const QString &accession)
static AaModificationP getInstanceCustomizedMod(pappso_double modificationMass)
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
const AaModification * AaModificationP
const PrecisionBase * PrecisionPtr
Definition precision.h:122

References pappso::MzRange::contains(), pappso::PrecisionFactory::getDaltonInstance(), pappso::AaModification::getInstance(), pappso::AaModification::getInstanceCustomizedMod(), pappso::AaModification::getMass(), and pappso::Enums::methionine.

Referenced by pappso::cbor::psm::SageReader::getStaticModificationList(), pappso::cbor::psm::SageReader::getVariableModificationList(), and pappso::PeptideProFormaParser::parseStringToPeptide().

◆ msDataFormatAsString()

QString pappso::Utils::msDataFormatAsString ( Enums::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 458 of file utils.cpp.

459{
460
461 if(mz_format == Enums::MsDataFormat::mzML)
462 return "mzML";
463 else if(mz_format == Enums::MsDataFormat::mzXML)
464 return "mzXML";
465 else if(mz_format == Enums::MsDataFormat::MGF)
466 return "MGF";
467 else if(mz_format == Enums::MsDataFormat::SQLite3)
468 return "SQLite3";
469 else if(mz_format == Enums::MsDataFormat::xy)
470 return "xy";
471 else if(mz_format == Enums::MsDataFormat::mz5)
472 return "mz5";
473 else if(mz_format == Enums::MsDataFormat::msn)
474 return "msn";
475 else if(mz_format == Enums::MsDataFormat::abSciexWiff)
476 return "abSciexWiff";
477 else if(mz_format == Enums::MsDataFormat::abSciexT2D)
478 return "abSciexT2D";
479 else if(mz_format == Enums::MsDataFormat::agilentMassHunter)
480 return "agilentMassHunter";
481 else if(mz_format == Enums::MsDataFormat::thermoRaw)
482 return "thermoRaw";
483 else if(mz_format == Enums::MsDataFormat::watersRaw)
484 return "watersRaw";
485 else if(mz_format == Enums::MsDataFormat::brukerFid)
486 return "brukerFid";
487 else if(mz_format == Enums::MsDataFormat::brukerYep)
488 return "brukerYep";
489 else if(mz_format == Enums::MsDataFormat::brukerBaf)
490 return "brukerBaf";
491 else if(mz_format == Enums::MsDataFormat::brukerTims)
492 return "brukerTims";
493 else if(mz_format == Enums::MsDataFormat::brukerBafAscii)
494 return "brukerBafAscii";
495 else
496 return "unknown";
497}
@ SQLite3
SQLite3 format.
Definition types.h:155
@ MGF
Mascot format.
Definition types.h:154

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

◆ nearestGreater()

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

Definition at line 345 of file utils.cpp.

346{
347 return std::nextafter(value, value + 1);
348}

◆ pointerToString()

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

Definition at line 290 of file utils.cpp.

291{
292 return QString("%1").arg((quintptr)pointer, QT_POINTER_SIZE * 2, 16, QChar('0'));
293}

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

◆ roundToDecimal32bitsAsLongLongInt()

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

Definition at line 150 of file utils.cpp.

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

◆ roundToDecimals()

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

Definition at line 140 of file utils.cpp.

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

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

389{
390
391 QStringList string_list = text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
392
393 // qDebug() << "string list:" << string_list;
394
395 std::vector<double> double_vector;
396
397 for(int iter = 0; iter < string_list.size(); ++iter)
398 {
399 QString current_string = string_list.at(iter);
400
401 bool ok = false;
402
403 double current_double = current_string.toDouble(&ok);
404
405 if(!current_double && !ok)
406 {
407 ++error_count;
408 continue;
409 }
410
411 double_vector.push_back(current_double);
412 }
413
414 return double_vector;
415}

◆ splitSizetStringToSizetVectorWithSpaces()

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

Definition at line 419 of file utils.cpp.

420{
421 // qDebug() << "Parsing text:" << text;
422
423 QStringList string_list = text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
424
425 // qDebug() << "string list size:" << string_list.size()
426 //<< "values:" << string_list;
427
428 std::vector<std::size_t> sizet_vector;
429
430 for(int iter = 0; iter < string_list.size(); ++iter)
431 {
432 QString current_string = string_list.at(iter);
433
434 bool ok = false;
435
436 std::size_t current_sizet = current_string.toUInt(&ok);
437
438 if(!current_sizet && !ok)
439 {
440 ++error_count;
441 continue;
442 }
443
444 sizet_vector.push_back(current_sizet);
445 }
446
447 return sizet_vector;
448}

◆ toString() [1/4]

QString pappso::Utils::toString ( Enums::PeptideIon m_ionType)
static

Convenience function to return a string describing the ion type.

Returns
QString

Definition at line 537 of file utils.cpp.

538{
539 switch(m_ionType)
540 {
542 return "y";
543 break;
545 return "yP";
546 break;
548 return "y*";
549 break;
551 return "yO";
552 break;
554 return "b*";
555 break;
557 return "bO";
558 break;
560 return "a";
561 break;
563 return "a*";
564 break;
566 return "aO";
567 break;
569 return "c";
570 break;
571 // SvgIon.moxygen - mN
573 return "z";
574 break;
576 return "b";
577 break;
579 return "bP";
580 break;
582 return "x";
583 break;
584 default:
585 throw PappsoException(QString("Enums::PeptideIon name not implemented"));
586 break;
587 }
588}
@ a
Nter aldimine ions.
Definition types.h:290
@ y
Cter amino ions.
Definition types.h:295
@ c
Nter amino ions.
Definition types.h:294
@ astar
Nter aldimine ions + NH3 loss.
Definition types.h:291
@ ystar
Cter amino ions + NH3 loss.
Definition types.h:296
@ yo
Cter amino ions + H2O loss.
Definition types.h:297
@ bstar
Nter acylium ions + NH3 loss.
Definition types.h:288
@ b
Nter acylium ions.
Definition types.h:287
@ x
Cter acylium ions.
Definition types.h:300
@ bo
Nter acylium ions + H2O loss.
Definition types.h:289
@ ao
Nter aldimine ions + H2O loss.
Definition types.h:292
@ z
Cter carbocations.
Definition types.h:298

References pappso::Enums::a, pappso::Enums::ao, pappso::Enums::astar, pappso::Enums::b, pappso::Enums::bo, pappso::Enums::bp, pappso::Enums::bstar, pappso::Enums::c, pappso::Enums::x, pappso::Enums::y, pappso::Enums::yo, pappso::Enums::yp, pappso::Enums::ystar, and pappso::Enums::z.

◆ toString() [2/4]

QString pappso::Utils::toString ( Enums::PrecisionUnit precision_unit)
static

Convenience function to return a string naming the precision.

Returns
QString

Definition at line 611 of file utils.cpp.

612{
613 auto it = precisionUnitMap.find(precision_unit);
614 if(it != precisionUnitMap.end())
615 {
616 return it->second;
617 }
618
619 throw pappso::ExceptionNotFound(QObject::tr("precision unit not found in precisionUnitMap"));
620}
std::map< Enums::PrecisionUnit, QString > precisionUnitMap
Definition precision.cpp:43

References pappso::precisionUnitMap.

◆ toString() [3/4]

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

593{
594 switch(type)
595 {
597 return "both";
598 break;
600 return "native";
601 break;
603 return "symmetric";
604 break;
605 default:
606 return "synthetic";
607 }
608}
@ both
both, the ion and the complement exists in the original spectrum
Definition types.h:83
@ symmetric
new peak : computed symmetric mass from a corresponding native peak
Definition types.h:81

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

◆ toString() [4/4]

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

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

Returns
QString

Definition at line 517 of file utils.cpp.

518{
519 switch(type)
520 {
522 return "AL";
523 break;
525 return "NA";
526 break;
528 return "RA";
529 break;
530 default:
531 return "ER";
532 }
533}
@ nonAlign
the type of alignment to put in origin matrix NON Alignment (0 - NA)
Definition types.h:49
@ reAlign
Re Alignment (1 - RE)
Definition types.h:51

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

Referenced by pappso::cbor::psm::PsmFeatures::parameterMapReady(), pappso::specglob::PeptideModel::toProForma(), and pappso::specglob::PeptideModel::toString().

◆ toUtf8StandardString()

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

Definition at line 162 of file utils.cpp.

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

References pappso::c.

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

◆ translateAaModificationFromUnimod()

pappso::AaModificationP pappso::Utils::translateAaModificationFromUnimod ( const QString & unimod_accession)
static

Definition at line 707 of file utils.cpp.

708{
709 if(unimod_accession == "UNIMOD:1")
710 {
711
712 return pappso::AaModification::getInstance("MOD:00394");
713 }
714 if(unimod_accession == "UNIMOD:4")
715 {
716
717 return pappso::AaModification::getInstance("MOD:00397");
718 }
719 if(unimod_accession == "UNIMOD:7")
720 {
721
722 return pappso::AaModification::getInstance("MOD:00400");
723 }
724 if(unimod_accession == "UNIMOD:27")
725 {
726
727 return pappso::AaModification::getInstance("MOD:00420");
728 }
729 // UNIMOD:28 => MOD:00040
730 if(unimod_accession == "UNIMOD:28")
731 {
732
733 return pappso::AaModification::getInstance("MOD:00040");
734 }
735
736 if(unimod_accession == "UNIMOD:35")
737 {
738
739 return pappso::AaModification::getInstance("MOD:00425");
740 }
741 qInfo() << "unimod_accession:" << unimod_accession << " not found";
742 return nullptr;
743}

References pappso::AaModification::getInstance().

◆ writeLexicalOrderedString()

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

Definition at line 84 of file utils.cpp.

85{
86 *p_out << (char)(log10(num) + 97) << num;
87}

◆ writeToFile()

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

Definition at line 212 of file utils.cpp.

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

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

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

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

Member Data Documentation

◆ anythingButDigitDotDash

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

Definition at line 55 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 69 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 63 of file utils.h.

◆ signedDoubleNumberExponentialRegExp

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

Definition at line 56 of file utils.h.

◆ sizetListDataFormatRegExp

QRegularExpression pappso::Utils::sizetListDataFormatRegExp
static

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

Definition at line 66 of file utils.h.

◆ unsignedDoubleNumberNoExponentialRegExp

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

Definition at line 54 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:55
static QRegularExpression signedDoubleNumberExponentialRegExp
Definition utils.h:56
static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
Definition utils.h:54

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

Definition at line 60 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: