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

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

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

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

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

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

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

548{
549
550 if(file_reader_type == Enums::FileReaderType::pwiz)
551 return "pwiz";
552 else if(file_reader_type == Enums::FileReaderType::xy)
553 return "xy";
554 else if(file_reader_type == Enums::FileReaderType::tims)
555 return "tims";
556 else if(file_reader_type == Enums::FileReaderType::tims_frames)
557 return "tims_frames";
558 else
559 return "unknown";
560}
@ 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 677 of file utils.cpp.

679{
681
682 pappso::AaModificationP oxidation =
683 pappso::AaModification::getInstance("MOD:00425"); // MOD:00425 15.994915
685 pappso::MzRange(oxidation->getMass(), precision).contains(mass))
686 {
687 return oxidation;
688 }
689 pappso::AaModificationP iodoacetamide =
690 pappso::AaModification::getInstance("MOD:00397"); // 57.021465
691 if(pappso::MzRange(iodoacetamide->getMass(), precision).contains(mass))
692 {
693 return iodoacetamide;
694 }
695 pappso::AaModificationP acetylated =
696 pappso::AaModification::getInstance("MOD:00408"); // 42.010567
697 if(pappso::MzRange(acetylated->getMass(), precision).contains(mass))
698 {
699 return acetylated;
700 }
701 pappso::AaModificationP phosphorylated =
702 pappso::AaModification::getInstance("MOD:00696"); // 79.96633
703 if(pappso::MzRange(phosphorylated->getMass(), precision).contains(mass))
704 {
705 return phosphorylated;
706 }
707 pappso::AaModificationP ammonia = pappso::AaModification::getInstance("MOD:01160"); //-17.026548
708 if(pappso::MzRange(ammonia->getMass(), precision).contains(mass))
709 {
710 return ammonia;
711 }
712 pappso::AaModificationP dehydrated =
713 pappso::AaModification::getInstance("MOD:00704"); //-18.010565
714 if(pappso::MzRange(dehydrated->getMass(), precision).contains(mass))
715 {
716 return dehydrated;
717 }
718 pappso::AaModificationP dimethylated =
719 pappso::AaModification::getInstance("MOD:00429"); // 28.0313
720 if(pappso::MzRange(dimethylated->getMass(), precision).contains(mass))
721 {
722 return dimethylated;
723 }
724
725 pappso::AaModificationP dimethylated_medium = pappso::AaModification::getInstance("MOD:00552");
726 if(pappso::MzRange(dimethylated_medium->getMass(), precision).contains(mass))
727 {
728 return dimethylated_medium;
729 }
730
731 pappso::AaModificationP dimethylated_heavy = pappso::AaModification::getInstance("MOD:00638");
732 if(pappso::MzRange(dimethylated_heavy->getMass(), precision).contains(mass))
733 {
734 return dimethylated_heavy;
735 }
736 pappso::AaModificationP DimethylpyrroleAdduct = pappso::AaModification::getInstance("MOD:00628");
737 if(pappso::MzRange(DimethylpyrroleAdduct->getMass(), precision).contains(mass))
738 {
739 return DimethylpyrroleAdduct;
740 }
741
742 // modification not found, creating customized mod :
744
745 throw pappso::ExceptionNotFound(
746 QObject::tr("Utils::guessAaModificationPbyMonoisotopicMassDelta => "
747 "modification not found for mass %1")
748 .arg(mass));
749}
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 504 of file utils.cpp.

505{
506
507 if(mz_format == Enums::MsDataFormat::mzML)
508 return "mzML";
509 else if(mz_format == Enums::MsDataFormat::mzXML)
510 return "mzXML";
511 else if(mz_format == Enums::MsDataFormat::MGF)
512 return "MGF";
513 else if(mz_format == Enums::MsDataFormat::SQLite3)
514 return "SQLite3";
515 else if(mz_format == Enums::MsDataFormat::xy)
516 return "xy";
517 else if(mz_format == Enums::MsDataFormat::mz5)
518 return "mz5";
519 else if(mz_format == Enums::MsDataFormat::msn)
520 return "msn";
521 else if(mz_format == Enums::MsDataFormat::abSciexWiff)
522 return "abSciexWiff";
523 else if(mz_format == Enums::MsDataFormat::abSciexT2D)
524 return "abSciexT2D";
525 else if(mz_format == Enums::MsDataFormat::agilentMassHunter)
526 return "agilentMassHunter";
527 else if(mz_format == Enums::MsDataFormat::thermoRaw)
528 return "thermoRaw";
529 else if(mz_format == Enums::MsDataFormat::watersRaw)
530 return "watersRaw";
531 else if(mz_format == Enums::MsDataFormat::brukerFid)
532 return "brukerFid";
533 else if(mz_format == Enums::MsDataFormat::brukerYep)
534 return "brukerYep";
535 else if(mz_format == Enums::MsDataFormat::brukerBaf)
536 return "brukerBaf";
537 else if(mz_format == Enums::MsDataFormat::brukerTims)
538 return "brukerTims";
539 else if(mz_format == Enums::MsDataFormat::brukerBafAscii)
540 return "brukerBafAscii";
541 else
542 return "unknown";
543}
@ 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 391 of file utils.cpp.

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

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

◆ roundValueToDecimalPlaces()

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

Definition at line 371 of file utils.cpp.

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

Referenced by pappso::MzIntegrationParams::createArbitraryBins().

◆ splitMzStringToDoubleVectorWithSpaces()

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

Definition at line 434 of file utils.cpp.

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

◆ splitSizetStringToSizetVectorWithSpaces()

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

Definition at line 465 of file utils.cpp.

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

◆ toJson()

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

convert vector of double into json array

Definition at line 793 of file utils.cpp.

794{
795 QJsonArray result;
796 for(auto i = myVec.begin(); i != myVec.end(); i++)
797 {
798 result.push_back((*i));
799 }
800 return result;
801}

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

584{
585 switch(m_ionType)
586 {
588 return "y";
589 break;
591 return "yP";
592 break;
594 return "y*";
595 break;
597 return "yO";
598 break;
600 return "b*";
601 break;
603 return "bO";
604 break;
606 return "a";
607 break;
609 return "a*";
610 break;
612 return "aO";
613 break;
615 return "c";
616 break;
617 // SvgIon.moxygen - mN
619 return "z";
620 break;
622 return "b";
623 break;
625 return "bP";
626 break;
628 return "x";
629 break;
630 default:
631 throw PappsoException(QString("Enums::PeptideIon name not implemented"));
632 break;
633 }
634}
@ 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 657 of file utils.cpp.

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

639{
640 switch(type)
641 {
643 return "both";
644 break;
646 return "native";
647 break;
649 return "symmetric";
650 break;
651 default:
652 return "synthetic";
653 }
654}
@ 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 563 of file utils.cpp.

564{
565 switch(type)
566 {
568 return "AL";
569 break;
571 return "NA";
572 break;
574 return "RA";
575 break;
576 default:
577 return "ER";
578 }
579}
@ 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 753 of file utils.cpp.

754{
755 if(unimod_accession == "UNIMOD:1")
756 {
757
758 return pappso::AaModification::getInstance("MOD:00394");
759 }
760 if(unimod_accession == "UNIMOD:4")
761 {
762
763 return pappso::AaModification::getInstance("MOD:00397");
764 }
765 if(unimod_accession == "UNIMOD:7")
766 {
767
768 return pappso::AaModification::getInstance("MOD:00400");
769 }
770 if(unimod_accession == "UNIMOD:27")
771 {
772
773 return pappso::AaModification::getInstance("MOD:00420");
774 }
775 // UNIMOD:28 => MOD:00040
776 if(unimod_accession == "UNIMOD:28")
777 {
778
779 return pappso::AaModification::getInstance("MOD:00040");
780 }
781
782 if(unimod_accession == "UNIMOD:35")
783 {
784
785 return pappso::AaModification::getInstance("MOD:00425");
786 }
787 qInfo() << "unimod_accession:" << unimod_accession << " not found";
788 return nullptr;
789}

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: