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)
 Determine the number of zero decimals between the decimal point and the first non-zero decimal.
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 writeToFile (const std::vector< double > &data, int decimals, 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)
 Tell if both double values, are equal within the double representation capabilities of the platform.
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 QJsonArray toJson (const std::vector< double > &myVec)
 convert vector of double into json array

Static Public Attributes

static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
static QRegularExpression anythingButDigitDotDash = QRegularExpression("[^\\d^\\.^-]+")
static QRegularExpression signedDoubleNumberExponentialRegExp
static QRegularExpression xyMassDataFormatRegExp
 Regular expression matching <numerical value><non-numerical*><numerical value>.
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 326 of file utils.cpp.

327{
328 // QString value1String = QString("%1").arg(value1,
329 // 0, 'f', 60);
330 // QString value2String = QString("%1").arg(value2,
331 // 0, 'f', 60);
332
333 // qWarning() << __FILE__ << __LINE__ << __FUNCTION__
334 //<< "value1:" << value1String << "value2:" << value2String;
335
336 // The machine epsilon has to be scaled to the magnitude of the values used
337 // and multiplied by the desired precision in ULPs (units in the last place)
338 // (decimal places).
339
340 double valueSum = std::abs(value1 + value2);
341 // QString valueSumString = QString("%1").arg(valueSum,
342 // 0, 'f', 60);
343
344 double valueDiff = std::abs(value1 - value2);
345 // QString valueDiffString = QString("%1").arg(valueDiff,
346 // 0, 'f', 60);
347
348 double epsilon = std::numeric_limits<double>::epsilon();
349 // QString epsilonString = QString("%1").arg(epsilon,
350 // 0, 'f', 60);
351
352 double scaleFactor = epsilon * valueSum * decimalPlaces;
353 // QString scaleFactorString = QString("%1").arg(scaleFactor,
354 // 0, 'f', 60);
355
356 // qWarning() << "valueDiff:" << valueDiffString << "valueSum:" <<
357 // valueSumString <<
358 //"epsilon:" << epsilonString << "scaleFactor:" << scaleFactorString;
359
360 bool res = valueDiff < scaleFactor
361 // unless the result is subnormal:
362 || valueDiff < std::numeric_limits<double>::min();
363
364 // qWarning() << __FILE__ << __LINE__ << __FUNCTION__
365 //<< "returning res:" << res;
366
367 return res;
368}

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

◆ appendToFile()

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

Definition at line 262 of file utils.cpp.

263{
264
265 QFile file(file_name);
266
267 if(file.open(QFile::WriteOnly | QFile::Append))
268 {
269
270 QTextStream out(&file);
271
272 out << text;
273
274 out.flush();
275 file.close();
276
277 return true;
278 }
279
280 return false;
281}

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

478{
479 if(value)
480 return "TRUE";
481 return "FALSE";
482}

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

397{
398 QString debug_text =
399 QString(
400 "%1 %2 min = %3 s = %4 ms = %5 "
401 "µs\n")
402 .arg(msg)
403 .arg(std::chrono::duration_cast<std::chrono::minutes>(chrono_finish - chrono_start).count())
404 .arg(std::chrono::duration_cast<std::chrono::seconds>(chrono_finish - chrono_start).count())
405 .arg(
406 std::chrono::duration_cast<std::chrono::milliseconds>(chrono_finish - chrono_start).count())
407 .arg(std::chrono::duration_cast<std::chrono::microseconds>(chrono_finish - chrono_start)
408 .count());
409
410 return debug_text;
411}

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

381{
382
383 time_t tt;
384
385 tt = std::chrono::system_clock::to_time_t(chrono_time);
386
387 QString debug_text = QString("%1 - %2\n").arg(msg).arg(QString::fromLatin1(ctime(&tt)));
388
389 return debug_text;
390}

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

286{
287 qDebug() << " " << spectrum_native_id;
288 QStringList native_id_list = spectrum_native_id.split("=");
289 if(native_id_list.size() < 2)
290 {
291 throw ExceptionNotFound(
292 QObject::tr("scan number not found in mzML native id %1").arg(spectrum_native_id));
293 }
294 else
295 {
296 /** TODO activate this in a future release to ensure scan number
297 for(auto i = 0; i < native_id_list.size(); i += 2)
298 {
299 if(native_id_list[i] == "scan")
300 {
301 return native_id_list[i + 1].toULong();
302 }
303 }
304
305 throw ExceptionNotFound(
306 QObject::tr("scan number not found in mzML native id %1")
307 .arg(spectrum_native_id));
308
309*/
310 return native_id_list.back().toULong();
311 }
312 return 0;
313}

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

◆ fileReaderTypeAsString()

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

Definition at line 528 of file utils.cpp.

529{
530
531 if(file_reader_type == Enums::FileReaderType::pwiz)
532 return "pwiz";
533 else if(file_reader_type == Enums::FileReaderType::xy)
534 return "xy";
535 else if(file_reader_type == Enums::FileReaderType::tims)
536 return "tims";
537 else if(file_reader_type == Enums::FileReaderType::tims_frames)
538 return "tims_frames";
539 else
540 return "unknown";
541}
@ pwiz
using libpwizlite
Definition types.h:177
@ 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.

◆ 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::MzcborMsFileReader::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 658 of file utils.cpp.

660{
662
663 pappso::AaModificationP oxidation =
664 pappso::AaModification::getInstance("MOD:00425"); // MOD:00425 15.994915
666 pappso::MzRange(oxidation->getMass(), precision).contains(mass))
667 {
668 return oxidation;
669 }
670 pappso::AaModificationP iodoacetamide =
671 pappso::AaModification::getInstance("MOD:00397"); // 57.021465
672 if(pappso::MzRange(iodoacetamide->getMass(), precision).contains(mass))
673 {
674 return iodoacetamide;
675 }
676 pappso::AaModificationP acetylated =
677 pappso::AaModification::getInstance("MOD:00408"); // 42.010567
678 if(pappso::MzRange(acetylated->getMass(), precision).contains(mass))
679 {
680 return acetylated;
681 }
682 pappso::AaModificationP phosphorylated =
683 pappso::AaModification::getInstance("MOD:00696"); // 79.96633
684 if(pappso::MzRange(phosphorylated->getMass(), precision).contains(mass))
685 {
686 return phosphorylated;
687 }
688 pappso::AaModificationP ammonia = pappso::AaModification::getInstance("MOD:01160"); //-17.026548
689 if(pappso::MzRange(ammonia->getMass(), precision).contains(mass))
690 {
691 return ammonia;
692 }
693 pappso::AaModificationP dehydrated =
694 pappso::AaModification::getInstance("MOD:00704"); //-18.010565
695 if(pappso::MzRange(dehydrated->getMass(), precision).contains(mass))
696 {
697 return dehydrated;
698 }
699 pappso::AaModificationP dimethylated =
700 pappso::AaModification::getInstance("MOD:00429"); // 28.0313
701 if(pappso::MzRange(dimethylated->getMass(), precision).contains(mass))
702 {
703 return dimethylated;
704 }
705
706 pappso::AaModificationP dimethylated_medium = pappso::AaModification::getInstance("MOD:00552");
707 if(pappso::MzRange(dimethylated_medium->getMass(), precision).contains(mass))
708 {
709 return dimethylated_medium;
710 }
711
712 pappso::AaModificationP dimethylated_heavy = pappso::AaModification::getInstance("MOD:00638");
713 if(pappso::MzRange(dimethylated_heavy->getMass(), precision).contains(mass))
714 {
715 return dimethylated_heavy;
716 }
717 pappso::AaModificationP DimethylpyrroleAdduct = pappso::AaModification::getInstance("MOD:00628");
718 if(pappso::MzRange(DimethylpyrroleAdduct->getMass(), precision).contains(mass))
719 {
720 return DimethylpyrroleAdduct;
721 }
722
723 // modification not found, creating customized mod :
725
726 throw pappso::ExceptionNotFound(
727 QObject::tr("Utils::guessAaModificationPbyMonoisotopicMassDelta => "
728 "modification not found for mass %1")
729 .arg(mass));
730}
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(), pappso::PeptideProFormaParser::parseStringToPeptide(), and pappso::cbor::psm::MzIdentMlReader::readPeptide().

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

486{
487
488 if(mz_format == Enums::MsDataFormat::mzML)
489 return "mzML";
490 else if(mz_format == Enums::MsDataFormat::mzXML)
491 return "mzXML";
492 else if(mz_format == Enums::MsDataFormat::MGF)
493 return "MGF";
494 else if(mz_format == Enums::MsDataFormat::SQLite3)
495 return "SQLite3";
496 else if(mz_format == Enums::MsDataFormat::xy)
497 return "xy";
498 else if(mz_format == Enums::MsDataFormat::mz5)
499 return "mz5";
500 else if(mz_format == Enums::MsDataFormat::msn)
501 return "msn";
502 else if(mz_format == Enums::MsDataFormat::abSciexWiff)
503 return "abSciexWiff";
504 else if(mz_format == Enums::MsDataFormat::abSciexT2D)
505 return "abSciexT2D";
506 else if(mz_format == Enums::MsDataFormat::agilentMassHunter)
507 return "agilentMassHunter";
508 else if(mz_format == Enums::MsDataFormat::thermoRaw)
509 return "thermoRaw";
510 else if(mz_format == Enums::MsDataFormat::watersRaw)
511 return "watersRaw";
512 else if(mz_format == Enums::MsDataFormat::brukerFid)
513 return "brukerFid";
514 else if(mz_format == Enums::MsDataFormat::brukerYep)
515 return "brukerYep";
516 else if(mz_format == Enums::MsDataFormat::brukerBaf)
517 return "brukerBaf";
518 else if(mz_format == Enums::MsDataFormat::brukerTims)
519 return "brukerTims";
520 else if(mz_format == Enums::MsDataFormat::brukerBafAscii)
521 return "brukerBafAscii";
522 else
523 return "unknown";
524}
@ SQLite3
SQLite3 format.
Definition types.h:153
@ MGF
Mascot format.
Definition types.h:152

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

373{
374 return std::nextafter(value, value + 1);
375}

◆ pointerToString()

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

Definition at line 317 of file utils.cpp.

318{
319 return QString("%1").arg((quintptr)pointer, QT_POINTER_SIZE * 2, 16, QChar('0'));
320}

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:60

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

416{
417
418 QStringList string_list = text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
419
420 // qDebug() << "string list:" << string_list;
421
422 std::vector<double> double_vector;
423
424 for(int iter = 0; iter < string_list.size(); ++iter)
425 {
426 QString current_string = string_list.at(iter);
427
428 bool ok = false;
429
430 double current_double = current_string.toDouble(&ok);
431
432 if(!current_double && !ok)
433 {
434 ++error_count;
435 continue;
436 }
437
438 double_vector.push_back(current_double);
439 }
440
441 return double_vector;
442}

◆ splitSizetStringToSizetVectorWithSpaces()

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

Definition at line 446 of file utils.cpp.

447{
448 // qDebug() << "Parsing text:" << text;
449
450 QStringList string_list = text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
451
452 // qDebug() << "string list size:" << string_list.size()
453 //<< "values:" << string_list;
454
455 std::vector<std::size_t> sizet_vector;
456
457 for(int iter = 0; iter < string_list.size(); ++iter)
458 {
459 QString current_string = string_list.at(iter);
460
461 bool ok = false;
462
463 std::size_t current_sizet = current_string.toUInt(&ok);
464
465 if(!current_sizet && !ok)
466 {
467 ++error_count;
468 continue;
469 }
470
471 sizet_vector.push_back(current_sizet);
472 }
473
474 return sizet_vector;
475}

◆ toJson()

QJsonArray pappso::Utils::toJson ( const std::vector< double > & myVec)
static

convert vector of double into json array

Definition at line 774 of file utils.cpp.

775{
776 QJsonArray result;
777 for(auto i = myVec.begin(); i != myVec.end(); i++)
778 {
779 result.push_back((*i));
780 }
781 return result;
782}

Referenced by pappso::MassSpectrumWidget::getJsonPsmIsotope().

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

565{
566 switch(m_ionType)
567 {
569 return "y";
570 break;
572 return "yP";
573 break;
575 return "y*";
576 break;
578 return "yO";
579 break;
581 return "b*";
582 break;
584 return "bO";
585 break;
587 return "a";
588 break;
590 return "a*";
591 break;
593 return "aO";
594 break;
596 return "c";
597 break;
598 // SvgIon.moxygen - mN
600 return "z";
601 break;
603 return "b";
604 break;
606 return "bP";
607 break;
609 return "x";
610 break;
611 default:
612 throw PappsoException(QString("Enums::PeptideIon name not implemented"));
613 break;
614 }
615}
@ 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 638 of file utils.cpp.

639{
640 auto it = precisionUnitMap.find(precision_unit);
641 if(it != precisionUnitMap.end())
642 {
643 return it->second;
644 }
645
646 throw pappso::ExceptionNotFound(QObject::tr("precision unit not found in precisionUnitMap"));
647}
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 619 of file utils.cpp.

620{
621 switch(type)
622 {
624 return "both";
625 break;
627 return "native";
628 break;
630 return "symmetric";
631 break;
632 default:
633 return "synthetic";
634 }
635}
@ 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 544 of file utils.cpp.

545{
546 switch(type)
547 {
549 return "AL";
550 break;
552 return "NA";
553 break;
555 return "RA";
556 break;
557 default:
558 return "ER";
559 }
560}
@ 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::MassSpectrumWidget::getJsonPsmIsotope(), pappso::Peptide::getMassIonSerie(), pappso::cbor::psm::PsmFeatures::parameterMapReady(), pappso::cbor::psm::PsmIonSeries::parameterMapReady(), pappso::cbor::psm::PsmIonSeriesScan::process(), pappso::specglob::PeptideModel::toProForma(), and pappso::specglob::PeptideModel::toString().

◆ toUtf8StandardString()

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

Definition at line 166 of file utils.cpp.

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

◆ translateAaModificationFromUnimod()

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

Definition at line 734 of file utils.cpp.

735{
736 if(unimod_accession == "UNIMOD:1")
737 {
738
739 return pappso::AaModification::getInstance("MOD:00394");
740 }
741 if(unimod_accession == "UNIMOD:4")
742 {
743
744 return pappso::AaModification::getInstance("MOD:00397");
745 }
746 if(unimod_accession == "UNIMOD:7")
747 {
748
749 return pappso::AaModification::getInstance("MOD:00400");
750 }
751 if(unimod_accession == "UNIMOD:27")
752 {
753
754 return pappso::AaModification::getInstance("MOD:00420");
755 }
756 // UNIMOD:28 => MOD:00040
757 if(unimod_accession == "UNIMOD:28")
758 {
759
760 return pappso::AaModification::getInstance("MOD:00040");
761 }
762
763 if(unimod_accession == "UNIMOD:35")
764 {
765
766 return pappso::AaModification::getInstance("MOD:00425");
767 }
768 qInfo() << "unimod_accession:" << unimod_accession << " not found";
769 return nullptr;
770}

References pappso::AaModification::getInstance().

Referenced by pappso::cbor::psm::MzIdentMlReader::readPeptide().

◆ 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() [1/2]

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}

Referenced by pappso::MzIntegrationParams::createArbitraryBins(), and pappso::MzIntegrationParams::createDataBasedBins().

◆ writeToFile() [2/2]

bool pappso::Utils::writeToFile ( const std::vector< double > & data,
int decimals,
const QString & file_name )
static

Definition at line 239 of file utils.cpp.

240{
241 QFile file(file_name);
242
243 if(file.open(QFile::WriteOnly | QFile::Append))
244 {
245 file.open(QIODevice::WriteOnly);
246
247 QTextStream fileStream(&file);
248
249 for(auto &&value : data)
250 fileStream << QString("%1\n").arg(value, 0, 'f', decimals);
251
252 fileStream.flush();
253 file.close();
254
255 return true;
256 }
257
258 return false;
259}

◆ zeroDecimalsInValue()

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

Determine the number of zero decimals between the decimal point and the first non-zero decimal.

0.11 would return 0 (no empty decimal) 2.001 would return 2 1000.0001254 would return 3

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: