libpappsomspp
Library for mass spectrometry
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 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 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 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 69 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 241 of file utils.cpp.

268 {
269 
270  time_t tt;
271 
272  tt = std::chrono::system_clock::to_time_t(chrono_time);
273 
274  QString debug_text =
275  QString("%1 - %2\n").arg(msg).arg(QString::fromLatin1(ctime(&tt)));
276 
277  return debug_text;
278 }
279 
280 
281 QString
283  const QString &msg,

References pappso::res.

◆ appendToFile()

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

Definition at line 188 of file utils.cpp.

191 {
192  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
193  << " " << spectrum_native_id;
194  QStringList native_id_list = spectrum_native_id.split("=");
195  if(native_id_list.size() < 2)
196  {
197  throw ExceptionNotFound(
198  QObject::tr("scan number not found in mzML native id %1")
199  .arg(spectrum_native_id));
200  }
201  else
202  {
203  return native_id_list.back().toULong();
204  }
205  return 0;
206 }
207 

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

312 {
313 
314  QStringList string_list =
315  text.split(QRegularExpression("[\\s]+"), QString::SkipEmptyParts);
316 
317  // qDebug() << "string list:" << string_list;
318 
319  std::vector<double> double_vector;
320 
321  for(int iter = 0; iter < string_list.size(); ++iter)
322  {
323  QString current_string = string_list.at(iter);
324 
325  bool ok = false;
326 
327  double current_double = current_string.toDouble(&ok);

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

◆ extractScanNumberFromMzmlNativeId()

std::size_t pappso::Utils::extractScanNumberFromMzmlNativeId ( const QString &  spectrum_native_id)
static

Definition at line 211 of file utils.cpp.

211 {
212  return QString("%1").arg(
213  (quintptr)pointer, QT_POINTER_SIZE * 2, 16, QChar('0'));
214 }
215 
216 
217 //! Tell if both double values, are equal within the double representation
218 //! capabilities of the platform.
219 bool
220 Utils::almostEqual(double value1, double value2, int decimalPlaces)
221 {
222  // QString value1String = QString("%1").arg(value1,
223  // 0, 'f', 60);
224  // QString value2String = QString("%1").arg(value2,
225  // 0, 'f', 60);
226 
227  // qWarning() << __FILE__ << __LINE__ << __FUNCTION__

◆ getLexicalOrderedString()

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

◆ pointerToString()

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

Definition at line 231 of file utils.cpp.

Referenced by pappso::MsRunDataSetTreeNode::toString().

◆ roundToDecimals()

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

◆ splitMzStringToDoubleVectorWithSpaces()

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

Definition at line 331 of file utils.cpp.

345 {
346  // qDebug() << "Parsing text:" << text;
347 
348  QStringList string_list =
349  text.split(QRegularExpression("[\\s]+"), QString::SkipEmptyParts);
350 
351  // qDebug() << "string list size:" << string_list.size()
352  //<< "values:" << string_list;
353 
354  std::vector<std::size_t> sizet_vector;
355 
356  for(int iter = 0; iter < string_list.size(); ++iter)
357  {
358  QString current_string = string_list.at(iter);
359 
360  bool ok = false;

◆ splitSizetStringToSizetVectorWithSpaces()

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

Definition at line 364 of file utils.cpp.

365  {
366  ++error_count;
367  continue;
368  }
369 
370  sizet_vector.push_back(current_sizet);
371  }
372 
373  return sizet_vector;
374 }
375 
376 
377 } // namespace pappso

◆ toUtf8StandardString()

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

Definition at line 136 of file utils.cpp.

145 {
146 
147  QFile file(file_name);
148 
149  if(file.open(QFile::WriteOnly | QFile::Truncate))
150  {
151 
152  QTextStream out(&file);
153 
154  out << text;
155 
156  out.flush();
157  file.close();
158 
159  return true;
160  }
161 

Referenced by pappso::PwizMsFileReader::initialize().

◆ writeLexicalOrderedString()

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

Definition at line 84 of file utils.cpp.

90  {

◆ writeToFile()

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

Definition at line 165 of file utils.cpp.

168 {
169 
170  QFile file(file_name);
171 
172  if(file.open(QFile::WriteOnly | QFile::Append))
173  {
174 
175  QTextStream out(&file);
176 
177  out << text;
178 
179  out.flush();
180  file.close();
181 
182  return true;
183  }
184 

◆ zeroDecimalsInValue()

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

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

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

Parameters
valuethe value to be analyzed
Returns
the number of '0' decimals between the decimal separator '.' and the first non-0 decimal

Definition at line 102 of file utils.cpp.

105 {
106  if(decimal_places < 0)
107  return value;
108 
109  return ceil((value * pow(10, decimal_places)) - 0.49) /
110  pow(10, decimal_places);
111 }
112 
113 
114 std::string
115 Utils::toUtf8StandardString(const QString &text)
116 {
117  std::string env_backup = setlocale(LC_ALL, "");
118 
119  // struct lconv *lc_backup = localeconv();
120  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
121  //<< "env_backup=" << env_backup.c_str() << "lc_backup->decimal_point"

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 83 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 77 of file utils.h.

◆ sizetListDataFormatRegExp

QRegularExpression pappso::Utils::sizetListDataFormatRegExp
static

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

Definition at line 80 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 74 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:
pappso::Utils::almostEqual
static bool almostEqual(double value1, double value2, int decimalPlaces=10)
Definition: utils.cpp:241
pappso::Utils::chronoIntervalDebugString
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())
Definition: utils.cpp:303
pappso::Utils::toUtf8StandardString
static std::string toUtf8StandardString(const QString &text)
Definition: utils.cpp:136