pappso::Utils Class Reference

`#include <utils.h>`

## Static Public Member Functions

static const QString | getLexicalOrderedString (unsigned int num)
static void | writeLexicalOrderedString (QTextStream *p_out, unsigned int num)
static int | zeroDecimalsInValue (pappso_double value)
| 0.11 would return 0 (no empty decimal) 2.001 would return 2 1000.0001254 would return 3 More...
static pappso_double | roundToDecimals (pappso_double value, int decimal_places)
static long long int | roundToDecimal32bitsAsLongLongInt (pappso::pappso_double input)
static std::string | toUtf8StandardString (const QString &text)
static bool | writeToFile (const QString &text, const QString &file_name)
static bool | appendToFile (const QString &text, const QString &file_name)
static std::size_t | extractScanNumberFromMzmlNativeId (const QString &spectrum_native_id)
static QString | pointerToString (const void *const pointer)
static bool | almostEqual (double value1, double value2, int decimalPlaces=10)
static double | nearestGreater (double value)
static QString | chronoTimePointDebugString (const QString &msg, std::chrono::system_clock::time_point chrono_time=std::chrono::system_clock::now())
static QString | chronoIntervalDebugString (const QString &msg, std::chrono::system_clock::time_point chrono_start, std::chrono::system_clock::time_point chrono_finish=std::chrono::system_clock::now())
static std::vector< double > | splitMzStringToDoubleVectorWithSpaces (const QString &text, std::size_t &error_count)
static std::vector< std::size_t > | splitSizetStringToSizetVectorWithSpaces (const QString &text, std::size_t &error_count)
static QString | booleanToString (bool value)
| convenient function to transform a boolean to QString "TRUE" or "FALSE" QString returned is readable by R More...

## Static Public Attributes

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

## Detailed Description

Definition at line 48 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 245 of file utils.cpp.

{
// QString value1String = QString("%1").arg(value1,
// 0, 'f', 60);
// QString value2String = QString("%1").arg(value2,
// 0, 'f', 60);
// qWarning() << __FILE__ << __LINE__ << __FUNCTION__
//<< "value1:" << value1String << "value2:" << value2String;
// The machine epsilon has to be scaled to the magnitude of the values used
// and multiplied by the desired precision in ULPs (units in the last place)
// (decimal places).
double valueSum = std::abs(value1 + value2);
// QString valueSumString = QString("%1").arg(valueSum,
// 0, 'f', 60);
double valueDiff = std::abs(value1 - value2);
// QString valueDiffString = QString("%1").arg(valueDiff,
// 0, 'f', 60);
double epsilon = std::numeric_limits<double>::epsilon();
// QString epsilonString = QString("%1").arg(epsilon,
// 0, 'f', 60);
double scaleFactor = epsilon * valueSum * decimalPlaces;
// QString scaleFactorString = QString("%1").arg(scaleFactor,
// 0, 'f', 60);
// qWarning() << "valueDiff:" << valueDiffString << "valueSum:" <<
// valueSumString <<
//"epsilon:" << epsilonString << "scaleFactor:" << scaleFactorString;
bool res = valueDiff < scaleFactor
// unless the result is subnormal:
|| valueDiff < std::numeric_limits<double>::min();
// qWarning() << __FILE__ << __LINE__ << __FUNCTION__
//<< "returning res:" << res;
return res;
}
pappso::PrecisionUnit::res
@ res

References pappso::res.

## appendToFile()

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

static

Definition at line 179 of file utils.cpp.

{
QFile file(file_name);
if(file.open(QFile::WriteOnly | QFile::Append))
{
QTextStream out(&file);
out << text;
out.flush();
file.close();
return true;
}
return false;
}

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

{
if(value)
return "TRUE";
return "FALSE";
}

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

{
QString debug_text =
QString(
"%1 %2 min = %3 s = %4 ms = %5 "
"µs\n")
.arg(msg)
.arg(std::chrono::duration_cast<std::chrono::minutes>(chrono_finish -
chrono_start)
.count())
.arg(std::chrono::duration_cast<std::chrono::seconds>(chrono_finish -
chrono_start)
.count())
.arg(std::chrono::duration_cast<std::chrono::milliseconds>(chrono_finish -
chrono_start)
.count())
.arg(std::chrono::duration_cast<std::chrono::microseconds>(chrono_finish -
chrono_start)
.count());
return debug_text;
}

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

{
time_t tt;
tt = std::chrono::system_clock::to_time_t(chrono_time);
QString debug_text =
QString("%1 - %2\n").arg(msg).arg(QString::fromLatin1(ctime(&tt)));
return debug_text;
}

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

{
qDebug() << " " << spectrum_native_id;
QStringList native_id_list = spectrum_native_id.split("=");
if(native_id_list.size() < 2)
{
throw ExceptionNotFound(
QObject::tr("scan number not found in mzML native id %1")
.arg(spectrum_native_id));
}
else
{
/** 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));
*/
return native_id_list.back().toULong();
}
return 0;
}

## getLexicalOrderedString()

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

static

Definition at line 52 of file utils.cpp.

{
int size = log10(num);
size += 97;
QString base(size);
base.append(QString().setNum(num));
return (base);
}
pappso::AxisScale::log10
@ log10

References pappso::log10.

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

## nearestGreater()

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

static

Definition at line 291 of file utils.cpp.

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

## pointerToString()

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

static

Definition at line 235 of file utils.cpp.

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

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

## roundToDecimal32bitsAsLongLongInt()

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

static

Definition at line 115 of file utils.cpp.

{
pappso::pappso_double test_decimal = 100000000000;
if(sizeof(int *) == 4)
{ // 32bits
test_decimal = 100000000;
}
return (floor(input * test_decimal));
}
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48

## roundToDecimals()

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

static

Definition at line 104 of file utils.cpp.

{
if(decimal_places < 0)
return value;
return ceil((value * pow(10, decimal_places)) - 0.49) /
pow(10, decimal_places);
}

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

## splitMzStringToDoubleVectorWithSpaces()

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

static

Definition at line 342 of file utils.cpp.

{
QStringList string_list =
text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
// qDebug() << "string list:" << string_list;
std::vector<double> double_vector;
for(int iter = 0; iter < string_list.size(); ++iter)
{
QString current_string = string_list.at(iter);
bool ok = false;
double current_double = current_string.toDouble(&ok);
if(!current_double && !ok)
{
++error_count;
continue;
}
double_vector.push_back(current_double);
}
return double_vector;
}

## splitSizetStringToSizetVectorWithSpaces()

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

static

Definition at line 375 of file utils.cpp.

{
// qDebug() << "Parsing text:" << text;
QStringList string_list =
text.split(QRegularExpression("[\\s]+"), Qt::SkipEmptyParts);
// qDebug() << "string list size:" << string_list.size()
//<< "values:" << string_list;
std::vector<std::size_t> sizet_vector;
for(int iter = 0; iter < string_list.size(); ++iter)
{
QString current_string = string_list.at(iter);
bool ok = false;
std::size_t current_sizet = current_string.toUInt(&ok);
if(!current_sizet && !ok)
{
++error_count;
continue;
}
sizet_vector.push_back(current_sizet);
}
return sizet_vector;
}

## toUtf8StandardString()

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

static

Definition at line 127 of file utils.cpp.

{
std::string env_backup = setlocale(LC_ALL, "");
// struct lconv *lc_backup = localeconv();
// qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
//<< "env_backup=" << env_backup.c_str() << "lc_backup->decimal_point"
//<< lc_backup->decimal_point;
// Force locale to be "C".
setlocale(LC_ALL, "C");
// Now perform the conversion.
QByteArray byte_array = text.toUtf8();
std::string stdText = "";
for(char c : byte_array)
{
stdText += c;
}
// Set back the locale to the backed-up one.
setlocale(LC_ALL, env_backup.c_str());
return stdText;
}
pappso::PeptideIonNter::c
@ c

References pappso::c.

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

## writeLexicalOrderedString()

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

static

Definition at line 63 of file utils.cpp.

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

References pappso::log10.

## writeToFile()

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

static

Definition at line 156 of file utils.cpp.

{
QFile file(file_name);
if(file.open(QFile::WriteOnly | QFile::Truncate))
{
QTextStream out(&file);
out << text;
out.flush();
file.close();
return true;
}
return false;
}

## zeroDecimalsInValue()

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

static

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

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

Parameters

  value | the value to be analyzed

Returns
  the number of '0' decimals between the decimal separator '.' and the first non-0 decimal

Definition at line 81 of file utils.cpp.

{
int intPart = static_cast<int>(value);
double decimalPart = value - intPart;
int count = -1;
while(1)
{
++count;
decimalPart *= 10;
if(decimalPart > 1)
return count;
}
return count;
}

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

## Member Data Documentation

## endOfLineRegExp

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

static

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

Definition at line 62 of file utils.h.

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

## mzListDataFormatRegExp

QRegularExpression pappso::Utils::mzListDataFormatRegExp

static

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

Definition at line 56 of file utils.h.

## sizetListDataFormatRegExp

QRegularExpression pappso::Utils::sizetListDataFormatRegExp

static

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

Definition at line 59 of file utils.h.

## xyMassDataFormatRegExp

QRegularExpression pappso::Utils::xyMassDataFormatRegExp

static

Initial value:
=
QRegularExpression("^(\\d*\\.?\\d+)([^\\d^\\.^-]+)(-?\\d*\\.?\\d*[e-]?\\d*)")

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

Definition at line 53 of file utils.h.

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

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

- pappsomspp/utils.h
- pappsomspp/utils.cpp