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 roundValueToDecimalPlaces (double value, int decimal_places, bool round_up=true)
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, QChar position=' ')
 get the most suitable modification given an amino acid, a mass and a position
static bool isAminoAcidChar (Enums::AminoAcidChar x)
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 327 of file utils.cpp.

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

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

◆ appendToFile()

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

Definition at line 263 of file utils.cpp.

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

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

498{
499 if(value)
500 return "TRUE";
501 return "FALSE";
502}

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

417{
418 QString debug_text =
419 QString(
420 "%1 %2 min = %3 s = %4 ms = %5 "
421 "µs\n")
422 .arg(msg)
423 .arg(std::chrono::duration_cast<std::chrono::minutes>(chrono_finish - chrono_start).count())
424 .arg(std::chrono::duration_cast<std::chrono::seconds>(chrono_finish - chrono_start).count())
425 .arg(
426 std::chrono::duration_cast<std::chrono::milliseconds>(chrono_finish - chrono_start).count())
427 .arg(std::chrono::duration_cast<std::chrono::microseconds>(chrono_finish - chrono_start)
428 .count());
429
430 return debug_text;
431}

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

401{
402
403 time_t tt;
404
405 tt = std::chrono::system_clock::to_time_t(chrono_time);
406
407 QString debug_text = QString("%1 - %2\n").arg(msg).arg(QString::fromLatin1(ctime(&tt)));
408
409 return debug_text;
410}

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

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

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

◆ fileReaderTypeAsString()

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

Definition at line 548 of file utils.cpp.

549{
550
551 if(file_reader_type == Enums::FileReaderType::pwiz)
552 return "pwiz";
553 else if(file_reader_type == Enums::FileReaderType::xy)
554 return "xy";
555 else if(file_reader_type == Enums::FileReaderType::tims)
556 return "tims";
557 else if(file_reader_type == Enums::FileReaderType::tims_frames)
558 return "tims_frames";
559 else
560 return "unknown";
561}
@ pwiz
using libpwizlite
Definition types.h:170
@ tims
TimsMsRunReader : each scan is returned as a mass spectrum.
Definition types.h:174

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

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

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()

◆ guessAaModificationPbyMonoisotopicMassDelta()

pappso::AaModificationP pappso::Utils::guessAaModificationPbyMonoisotopicMassDelta ( Enums::AminoAcidChar aa,
pappso::pappso_double mass,
QChar position = ' ' )
static

get the most suitable modification given an amino acid, a mass and a position

@aa amino acid @mass float m/z @position protein or peptide position in ['^','$', '[', ']'], default is a space

Definition at line 678 of file utils.cpp.

681{
682 if((position != '[') && (!Utils::isAminoAcidChar(aa)))
683 {
684 throw pappso::PappsoException(
685 QObject::tr("Utils::guessAaModificationPbyMonoisotopicMassDelta => "
686 "not an amino acid %1")
687 .arg((char)aa));
688 }
690
691 pappso::AaModificationP oxidation =
692 pappso::AaModification::getInstance("MOD:00425"); // MOD:00425 15.994915
694 pappso::MzRange(oxidation->getMass(), precision).contains(mass))
695 {
696 return oxidation;
697 }
698 pappso::AaModificationP iodoacetamide =
699 pappso::AaModification::getInstance("MOD:00397"); // 57.021465
700 if(pappso::MzRange(iodoacetamide->getMass(), precision).contains(mass))
701 {
702 return iodoacetamide;
703 }
704 pappso::AaModificationP acetylated =
705 pappso::AaModification::getInstance("MOD:00408"); // 42.010567
706 if(pappso::MzRange(acetylated->getMass(), precision).contains(mass))
707 {
708 return acetylated;
709 }
710 pappso::AaModificationP phosphorylated =
711 pappso::AaModification::getInstance("MOD:00696"); // 79.96633
712 if(pappso::MzRange(phosphorylated->getMass(), precision).contains(mass))
713 {
714 return phosphorylated;
715 }
716 pappso::AaModificationP ammonia = pappso::AaModification::getInstance("MOD:01160"); //-17.026548
717 if(pappso::MzRange(ammonia->getMass(), precision).contains(mass))
718 {
719 return ammonia;
720 }
721 pappso::AaModificationP dehydrated =
722 pappso::AaModification::getInstance("MOD:00704"); //-18.010565
723 pappso::AaModificationP glu_pyroglu =
724 pappso::AaModification::getInstance("MOD:00420"); // Glu->pyro-Glu
725 if(pappso::MzRange(dehydrated->getMass(), precision).contains(mass))
726 {
727 if((aa == Enums::AminoAcidChar::glutamic_acid) && (position == '^'))
728 {
729 return glu_pyroglu;
730 }
731 else
732 {
733 return dehydrated;
734 }
735 }
736 pappso::AaModificationP dimethylated =
737 pappso::AaModification::getInstance("MOD:00429"); // 28.0313
738 if(pappso::MzRange(dimethylated->getMass(), precision).contains(mass))
739 {
740 return dimethylated;
741 }
742
743 pappso::AaModificationP dimethylated_medium = pappso::AaModification::getInstance("MOD:00552");
744 if(pappso::MzRange(dimethylated_medium->getMass(), precision).contains(mass))
745 {
746 return dimethylated_medium;
747 }
748
749 pappso::AaModificationP dimethylated_heavy = pappso::AaModification::getInstance("MOD:00638");
750 if(pappso::MzRange(dimethylated_heavy->getMass(), precision).contains(mass))
751 {
752 return dimethylated_heavy;
753 }
754 pappso::AaModificationP DimethylpyrroleAdduct = pappso::AaModification::getInstance("MOD:00628");
755 if(pappso::MzRange(DimethylpyrroleAdduct->getMass(), precision).contains(mass))
756 {
757 return DimethylpyrroleAdduct;
758 }
759
760 // modification not found, creating customized mod :
762
763 throw pappso::ExceptionNotFound(
764 QObject::tr("Utils::guessAaModificationPbyMonoisotopicMassDelta => "
765 "modification not found for mass %1")
766 .arg(mass));
767}
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
static bool isAminoAcidChar(Enums::AminoAcidChar x)
Definition utils.cpp:822
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(), pappso::Enums::glutamic_acid, isAminoAcidChar(), 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().

◆ isAminoAcidChar()

bool pappso::Utils::isAminoAcidChar ( Enums::AminoAcidChar x)
static

Definition at line 822 of file utils.cpp.

823{
824 switch(x)
825 {
848 return true;
849
850 default:
851 return false;
852 }
853}

References pappso::Enums::alanine, pappso::Enums::arginine, pappso::Enums::asparagine, pappso::Enums::aspartic_acid, pappso::Enums::cysteine, pappso::Enums::glutamic_acid, pappso::Enums::glutamine, pappso::Enums::glycine, pappso::Enums::histidine, pappso::Enums::isoleucine, pappso::Enums::leucine, pappso::Enums::lysine, pappso::Enums::methionine, pappso::Enums::phenylalanine, pappso::Enums::proline, pappso::Enums::pyrrolysine, pappso::Enums::selenocysteine, pappso::Enums::serine, pappso::Enums::threonine, pappso::Enums::tryptophan, pappso::Enums::tyrosine, pappso::Enums::valine, and pappso::x.

Referenced by pappso::cbor::psm::SageReader::getVariableModificationList(), and guessAaModificationPbyMonoisotopicMassDelta().

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

506{
507
508 if(mz_format == Enums::MsDataFormat::mzML)
509 return "mzML";
510 else if(mz_format == Enums::MsDataFormat::mzXML)
511 return "mzXML";
512 else if(mz_format == Enums::MsDataFormat::MGF)
513 return "MGF";
514 else if(mz_format == Enums::MsDataFormat::SQLite3)
515 return "SQLite3";
516 else if(mz_format == Enums::MsDataFormat::xy)
517 return "xy";
518 else if(mz_format == Enums::MsDataFormat::mz5)
519 return "mz5";
520 else if(mz_format == Enums::MsDataFormat::msn)
521 return "msn";
522 else if(mz_format == Enums::MsDataFormat::abSciexWiff)
523 return "abSciexWiff";
524 else if(mz_format == Enums::MsDataFormat::abSciexT2D)
525 return "abSciexT2D";
526 else if(mz_format == Enums::MsDataFormat::agilentMassHunter)
527 return "agilentMassHunter";
528 else if(mz_format == Enums::MsDataFormat::thermoRaw)
529 return "thermoRaw";
530 else if(mz_format == Enums::MsDataFormat::watersRaw)
531 return "watersRaw";
532 else if(mz_format == Enums::MsDataFormat::brukerFid)
533 return "brukerFid";
534 else if(mz_format == Enums::MsDataFormat::brukerYep)
535 return "brukerYep";
536 else if(mz_format == Enums::MsDataFormat::brukerBaf)
537 return "brukerBaf";
538 else if(mz_format == Enums::MsDataFormat::brukerTims)
539 return "brukerTims";
540 else if(mz_format == Enums::MsDataFormat::brukerBafAscii)
541 return "brukerBafAscii";
542 else
543 return "unknown";
544}
@ SQLite3
SQLite3 format.
Definition types.h:147
@ MGF
Mascot format.
Definition types.h:146

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

393{
394 return std::nextafter(value, value + 1);
395}

◆ pointerToString()

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

Definition at line 318 of file utils.cpp.

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

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

◆ roundToDecimal32bitsAsLongLongInt()

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

Definition at line 151 of file utils.cpp.

152{
153 pappso::pappso_double test_decimal = 100000000000;
154 if(sizeof(int *) == 4)
155 { // 32bits
156 test_decimal = 100000000;
157 }
158 return (floor(input * test_decimal));
159}
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 141 of file utils.cpp.

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

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

◆ roundValueToDecimalPlaces()

double pappso::Utils::roundValueToDecimalPlaces ( double value,
int decimal_places,
bool round_up = true )
static

Definition at line 372 of file utils.cpp.

373{
374 if(decimal_places < 0)
375 return value;
376
377 double multiplier = std::pow(10.0, decimal_places);
378
379 if(round_up)
380 {
381 // Strict ceiling: round UP.
382 return std::ceil(value * multiplier) / multiplier;
383 }
384 else
385 {
386 // Add a tiny epsilon (1e-9) to counteract the "1.005" floating-point trap
387 return std::round(value * multiplier + 1e-9) / multiplier;
388 }
389}

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

◆ splitMzStringToDoubleVectorWithSpaces()

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

Definition at line 435 of file utils.cpp.

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

◆ splitSizetStringToSizetVectorWithSpaces()

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

Definition at line 466 of file utils.cpp.

467{
468 // qDebug() << "Parsing text:" << text;
469
470 QStringList string_list = text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
471
472 // qDebug() << "string list size:" << string_list.size()
473 //<< "values:" << string_list;
474
475 std::vector<std::size_t> sizet_vector;
476
477 for(int iter = 0; iter < string_list.size(); ++iter)
478 {
479 QString current_string = string_list.at(iter);
480
481 bool ok = false;
482
483 std::size_t current_sizet = current_string.toUInt(&ok);
484
485 if(!current_sizet && !ok)
486 {
487 ++error_count;
488 continue;
489 }
490
491 sizet_vector.push_back(current_sizet);
492 }
493
494 return sizet_vector;
495}

◆ toJson()

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

convert vector of double into json array

Definition at line 811 of file utils.cpp.

812{
813 QJsonArray result;
814 for(auto i = myVec.begin(); i != myVec.end(); i++)
815 {
816 result.push_back((*i));
817 }
818 return result;
819}

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

585{
586 switch(m_ionType)
587 {
589 return "y";
590 break;
592 return "yP";
593 break;
595 return "y*";
596 break;
598 return "yO";
599 break;
601 return "b*";
602 break;
604 return "bO";
605 break;
607 return "a";
608 break;
610 return "a*";
611 break;
613 return "aO";
614 break;
616 return "c";
617 break;
618 // SvgIon.moxygen - mN
620 return "z";
621 break;
623 return "b";
624 break;
626 return "bP";
627 break;
629 return "x";
630 break;
631 default:
632 throw PappsoException(QString("Enums::PeptideIon name not implemented"));
633 break;
634 }
635}
@ a
Nter aldimine ions.
Definition types.h:276
@ y
Cter amino ions.
Definition types.h:281
@ c
Nter amino ions.
Definition types.h:280
@ astar
Nter aldimine ions + NH3 loss.
Definition types.h:277
@ ystar
Cter amino ions + NH3 loss.
Definition types.h:282
@ yo
Cter amino ions + H2O loss.
Definition types.h:283
@ bstar
Nter acylium ions + NH3 loss.
Definition types.h:274
@ b
Nter acylium ions.
Definition types.h:273
@ x
Cter acylium ions.
Definition types.h:286
@ bo
Nter acylium ions + H2O loss.
Definition types.h:275
@ ao
Nter aldimine ions + H2O loss.
Definition types.h:278
@ z
Cter carbocations.
Definition types.h:284

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

659{
660 auto it = precisionUnitMap.find(precision_unit);
661 if(it != precisionUnitMap.end())
662 {
663 return it->second;
664 }
665
666 throw pappso::ExceptionNotFound(QObject::tr("precision unit not found in precisionUnitMap"));
667}
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 639 of file utils.cpp.

640{
641 switch(type)
642 {
644 return "both";
645 break;
647 return "native";
648 break;
650 return "symmetric";
651 break;
652 default:
653 return "synthetic";
654 }
655}
@ 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 564 of file utils.cpp.

565{
566 switch(type)
567 {
569 return "AL";
570 break;
572 return "NA";
573 break;
575 return "RA";
576 break;
577 default:
578 return "ER";
579 }
580}
@ 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 167 of file utils.cpp.

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

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

772{
773 if(unimod_accession == "UNIMOD:1")
774 {
775
776 return pappso::AaModification::getInstance("MOD:00394");
777 }
778 if(unimod_accession == "UNIMOD:4")
779 {
780
781 return pappso::AaModification::getInstance("MOD:00397");
782 }
783 if(unimod_accession == "UNIMOD:7")
784 {
785
786 return pappso::AaModification::getInstance("MOD:00400");
787 }
788 if(unimod_accession == "UNIMOD:27")
789 {
790
791 return pappso::AaModification::getInstance("MOD:00420");
792 }
793 // UNIMOD:28 => MOD:00040
794 if(unimod_accession == "UNIMOD:28")
795 {
796
797 return pappso::AaModification::getInstance("MOD:00040");
798 }
799
800 if(unimod_accession == "UNIMOD:35")
801 {
802
803 return pappso::AaModification::getInstance("MOD:00425");
804 }
805 qInfo() << "unimod_accession:" << unimod_accession << " not found";
806 return nullptr;
807}

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

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

◆ writeToFile() [1/2]

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

Definition at line 217 of file utils.cpp.

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

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

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

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

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

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: