libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::BafAsciiMsRunReader Class Reference

#include <bafasciimsrunreader.h>

Inheritance diagram for pappso::BafAsciiMsRunReader:
pappso::MsRunReader

Public Member Functions

 BafAsciiMsRunReader (MsRunIdCstSPtr &msrun_id_csp)
 
virtual ~BafAsciiMsRunReader ()
 
virtual MassSpectrumSPtr massSpectrumSPtr (std::size_t spectrum_index) override
 get a MassSpectrumSPtr class given its spectrum index
 
virtual MassSpectrumCstSPtr massSpectrumCstSPtr (std::size_t spectrum_index) override
 
virtual QualifiedMassSpectrum qualifiedMassSpectrum (std::size_t spectrum_index, bool want_binary_data=true) const override
 get a QualifiedMassSpectrum class given its scan number
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
 
virtual void readSpectrumCollection2 (const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) override
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum index
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum
 
virtual void readSpectrumCollectionByMsLevel (SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels
 
virtual std::size_t spectrumListSize () const override
 get the totat number of spectrum conained in the MSrun data file
 
virtual bool releaseDevice () override
 release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object
 
virtual bool acquireDevice () override
 acquire data back end device
 
- Public Member Functions inherited from pappso::MsRunReader
 MsRunReader (const MsRunIdCstSPtr &ms_run_id)
 
 MsRunReader (const MsRunReader &other)
 
virtual ~MsRunReader ()
 
const MsRunIdCstSPtrgetMsRunId () const
 
virtual std::size_t scanNumber2SpectrumIndex (std::size_t scan_number)
 if possible, converts a scan number into a spectrum index This is a convenient function to help transition from the old scan number (not implemented by all vendors) to more secure spectrum index (not vendor dependant). It is better to not rely on this function.
 
virtual bool hasScanNumbers () const
 tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided functions can check if scan numbers are available in the current file
 
virtual std::vector< double > getRetentionTimeLine ()
 retention timeline get retention times along the MSrun in seconds
 
virtual Trace getTicChromatogram ()
 get a TIC chromatogram
 
void setMonoThread (bool is_mono_thread)
 set only one is_mono_thread to true
 
bool isMonoThread () const
 

Protected Member Functions

QString craftLineParserRegExpPattern () const
 
QRegularExpression craftLineParserRegExp (QString &pattern) const
 
bool parseMassSpectrumLine (QString &line, MassSpectrumLineData &ms_line_data, QRegularExpression &line_regexp) const
 
virtual void initialize () override
 
virtual bool accept (const QString &file_name) const override
 tells if the reader is able to handle this file must be implemented by private MS run reader, specific of one or more file format
 
QualifiedMassSpectrum qualifiedMassSpectrumFromBafAsciiMSDataFile (std::size_t spectrum_index, bool want_binary_data) const
 

Protected Attributes

QString m_fileName
 
std::size_t m_spectrumCount = 0
 
- Protected Attributes inherited from pappso::MsRunReader
MsRunIdCstSPtr mcsp_msRunId
 
MsRunReaderScanNumberMultiMapmpa_multiMapScanNumber = nullptr
 

Friends

class MsFileAccessor
 

Detailed Description

Definition at line 23 of file bafasciimsrunreader.h.

Constructor & Destructor Documentation

◆ BafAsciiMsRunReader()

pappso::BafAsciiMsRunReader::BafAsciiMsRunReader ( MsRunIdCstSPtr msrun_id_csp)

Definition at line 27 of file bafasciimsrunreader.cpp.

28 : pappso::MsRunReader(msrun_id_csp)
29{
30 // Run the initialization function that checks that the file exists!
31
32 initialize();
33}
virtual void initialize() override
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition msrunreader.h:63

References initialize().

◆ ~BafAsciiMsRunReader()

pappso::BafAsciiMsRunReader::~BafAsciiMsRunReader ( )
virtual

Definition at line 53 of file bafasciimsrunreader.cpp.

54{
55}

Member Function Documentation

◆ accept()

bool pappso::BafAsciiMsRunReader::accept ( const QString &  file_name) const
overrideprotectedvirtual

tells if the reader is able to handle this file must be implemented by private MS run reader, specific of one or more file format

Implements pappso::MsRunReader.

Definition at line 229 of file bafasciimsrunreader.cpp.

230{
231 qDebug();
232
233 // Here we just test all the lines of the file to check that they comply with
234 // the BafAscii format (ascii export from Baf file using the Bruker
235 // DataAnalysis/Compass software)..
236
237 // The format of the file, for MS1 data only is the following:
238 // <rt time in min>,+,ESI,ms1,-,profile,<m/z range start>-<m/z range
239 // end>,512704,<m/z> <int>,<m/z> <int>,.. One such line per retention time
240 // value.
241
242 QString line_regexp_pattern = craftLineParserRegExpPattern();
243 QRegularExpression line_regexp = craftLineParserRegExp(line_regexp_pattern);
244
245 if(!line_regexp.isValid())
246 {
247 qDebug() << "Failed to craft the regular expresssion";
248
249 return false;
250 }
251
252 QFile file(file_name);
253
254 if(!file.open(QFile::ReadOnly | QFile::Text))
255 {
256 qDebug() << "Failed to open file" << file_name;
257
258 return false;
259 }
260
261 MassSpectrumLineData ms_line_data;
262
263 while(!file.atEnd())
264 {
265 QString line = file.readLine().trimmed();
266
267 if(!parseMassSpectrumLine(line, ms_line_data, line_regexp))
268 {
269 qDebug() << "Failed to parse a line.";
270
271 file.close();
272 return false;
273 }
274
276 }
277
278 file.close();
279
280 if(m_spectrumCount >= 1)
281 {
282 qDebug() << "The file seems indeed to be BafAscii.";
283 return true;
284 }
285
286 qDebug() << "The file does not seem to be BafAscii.";
287 return false;
288}
QRegularExpression craftLineParserRegExp(QString &pattern) const
bool parseMassSpectrumLine(QString &line, MassSpectrumLineData &ms_line_data, QRegularExpression &line_regexp) const

References craftLineParserRegExp(), craftLineParserRegExpPattern(), line, m_spectrumCount, and parseMassSpectrumLine().

Referenced by initialize().

◆ acquireDevice()

bool pappso::BafAsciiMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 686 of file bafasciimsrunreader.cpp.

687{
688 return true;
689}

◆ craftLineParserRegExp()

QRegularExpression pappso::BafAsciiMsRunReader::craftLineParserRegExp ( QString &  pattern) const
protected

Definition at line 101 of file bafasciimsrunreader.cpp.

102{
103 QRegularExpression regexp = QRegularExpression(pattern);
104
105 if(!regexp.isValid())
106 {
107 qDebug() << "The regular expression is not valid:"
108 << regexp.errorString();
109 return QRegularExpression();
110 }
111
112 return QRegularExpression(pattern);
113}

Referenced by accept(), qualifiedMassSpectrumFromBafAsciiMSDataFile(), and readSpectrumCollectionByMsLevel().

◆ craftLineParserRegExpPattern()

QString pappso::BafAsciiMsRunReader::craftLineParserRegExpPattern ( ) const
protected

Definition at line 58 of file bafasciimsrunreader.cpp.

59{
60
61 // Construct the regular expression pattern, piecemeal...
62
63 // The retention time as the very first value in the line.
64 QString regexp_pattern = QString("^(%1)").arg(
66
67 // The ionization mode (positive or negative)
68 regexp_pattern += QString(",([+-])");
69
70 // The ion source type.
71 regexp_pattern += QString(",(ESI|MALDI)");
72
73 // The MS level (ms1 for full scan mass spectrum)
74 regexp_pattern += QString(",ms(\\d)");
75
76 // Do no know what this is for.
77 regexp_pattern += QString(",(-)");
78
79 // The type of peak (profile or centroid).
80 regexp_pattern += QString(",(profile|line)");
81
82 // The m/z range of the mass spectrum.
83 regexp_pattern +=
84 QString(",(%1-%2)")
87
88 // The count of peaks following this element in the remaining of the line.
89 regexp_pattern += QString(",(\\d+)");
90
91 // Finally the whole set of ,<mz><space><intensity> pairs to
92 // then end of the line.
93 regexp_pattern += QString("(.*$)");
94
95 // qDebug() << "The full regexp_pattern:" << regexp_pattern;
96
97 return regexp_pattern;
98}
static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
Definition utils.h:53

References pappso::Utils::unsignedDoubleNumberNoExponentialRegExp.

Referenced by accept(), qualifiedMassSpectrumFromBafAsciiMSDataFile(), and readSpectrumCollectionByMsLevel().

◆ initialize()

void pappso::BafAsciiMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 37 of file bafasciimsrunreader.cpp.

38{
39 // Use the accept function to parse the whole file, check its
40 // contents validity and also count the number of spectra (that is,
41 // of lines).
42 if(!accept(mcsp_msRunId->getFileName()))
43 {
45 QString("Failed to initialize reading of file %1 "
46 "in BafAsciiMsRunReader, for MS run %2:\n")
47 .arg(mcsp_msRunId->getFileName())
48 .arg(mcsp_msRunId.get()->toString())));
49 }
50}
virtual bool accept(const QString &file_name) const override
tells if the reader is able to handle this file must be implemented by private MS run reader,...
excetion to use when an item type is not recognized
MsRunIdCstSPtr mcsp_msRunId

References accept(), and pappso::MsRunReader::mcsp_msRunId.

Referenced by BafAsciiMsRunReader().

◆ massSpectrumCstSPtr()

pappso::MassSpectrumCstSPtr pappso::BafAsciiMsRunReader::massSpectrumCstSPtr ( std::size_t  spectrum_index)
overridevirtual

Implements pappso::MsRunReader.

Definition at line 299 of file bafasciimsrunreader.cpp.

300{
301 return qualifiedMassSpectrum(spectrum_index).getMassSpectrumCstSPtr();
302}
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.

References pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr(), and qualifiedMassSpectrum().

◆ massSpectrumSPtr()

pappso::MassSpectrumSPtr pappso::BafAsciiMsRunReader::massSpectrumSPtr ( std::size_t  spectrum_index)
overridevirtual

get a MassSpectrumSPtr class given its spectrum index

Implements pappso::MsRunReader.

Definition at line 292 of file bafasciimsrunreader.cpp.

293{
294 return qualifiedMassSpectrum(spectrum_index).getMassSpectrumSPtr();
295}
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.

References pappso::QualifiedMassSpectrum::getMassSpectrumSPtr(), and qualifiedMassSpectrum().

◆ newXicCoordSPtrFromQualifiedMassSpectrum()

XicCoordSPtr pappso::BafAsciiMsRunReader::newXicCoordSPtrFromQualifiedMassSpectrum ( const pappso::QualifiedMassSpectrum mass_spectrum,
pappso::PrecisionPtr  precision 
) const
overridevirtual

get a xic coordinate object from a given spectrum

Implements pappso::MsRunReader.

Definition at line 703 of file bafasciimsrunreader.cpp.

706{
707 throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
708 .arg(__FILE__)
709 .arg(__FUNCTION__)
710 .arg(__LINE__));
711}

◆ newXicCoordSPtrFromSpectrumIndex()

XicCoordSPtr pappso::BafAsciiMsRunReader::newXicCoordSPtrFromSpectrumIndex ( std::size_t  spectrum_index,
pappso::PrecisionPtr  precision 
) const
overridevirtual

get a xic coordinate object from a given spectrum index

Implements pappso::MsRunReader.

Definition at line 692 of file bafasciimsrunreader.cpp.

695{
696 throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
697 .arg(__FILE__)
698 .arg(__FUNCTION__)
699 .arg(__LINE__));
700}

◆ parseMassSpectrumLine()

bool pappso::BafAsciiMsRunReader::parseMassSpectrumLine ( QString &  line,
MassSpectrumLineData ms_line_data,
QRegularExpression &  line_regexp 
) const
protected

Definition at line 116 of file bafasciimsrunreader.cpp.

120{
121 // We get a line from the file, exactly as is and we have to
122 // parse it using regexp to extract all the data out of it,
123 // which are then set to ms_line_data.
124
125 line = line.trimmed();
126
127 // qDebug() << "Current brukerBafAscii format line " << line_count << ": "
128 // << line.left(30) << " ... " << line.right(30);
129
130 QRegularExpressionMatch regexp_match = line_regexp.match(line);
131 bool ok = false;
132
133 if(regexp_match.hasMatch())
134 {
135 // qDebug() << "The match succeeded.";
136
137 double retention_time = regexp_match.captured(1).toDouble(&ok);
138 if(!ok)
139 {
140 qDebug()
141 << "Failed to extract the retention time of the mass spectrum.";
142 return false;
143 }
144 ms_line_data.retentionTime = retention_time;
145
146
147 ms_line_data.ionizationMode = regexp_match.captured(2);
148 ms_line_data.ionSourceType = regexp_match.captured(3);
149
150 int ms_level = regexp_match.captured(4).toInt(&ok);
151 if(!ok)
152 {
153 qDebug() << "Failed to extract the MS level of the mass spectrum.";
154 return false;
155 }
156 ms_line_data.msLevel = ms_level;
157
158 QString dash = regexp_match.captured(5);
159 ms_line_data.dash = dash;
160
161 ms_line_data.peakShapeType = regexp_match.captured(6);
162
163 QString mz_range = regexp_match.captured(7);
164
165 double mz_range_start =
166 mz_range.left(mz_range.indexOf("-")).toDouble(&ok);
167 if(!ok)
168 {
169 qDebug() << "Failed to extract the start of the m/z range.";
170 return false;
171 }
172 double mz_range_end =
173 mz_range.right(mz_range.indexOf("-") + 1).toDouble(&ok);
174 if(!ok)
175 {
176 qDebug() << "Failed to extract the end of the m/z range.";
177 return false;
178 }
179 ms_line_data.mz_range =
180 std::pair<double, double>(mz_range_start, mz_range_end);
181
182 // qDebug() << qSetRealNumberPrecision(10)
183 // << "mz_range_start: " << mz_range_start
184 // << "mz_range_end: " << mz_range_end;
185
186 std::size_t peak_count = regexp_match.captured(8).toULongLong(&ok);
187 if(!ok)
188 {
189 qDebug() << "Failed to extract the number of peaks in the mass "
190 "spectrum.";
191 return false;
192 }
193 ms_line_data.peakCount = peak_count;
194
195 QString peaks = regexp_match.captured(9);
196 ms_line_data.peakList = peaks.split(",", Qt::SkipEmptyParts);
197
198 // qDebug() << "The number of peaks:" << ms_line_data.peakList.size();
199
200 // Sanity check:
201 if(static_cast<std::size_t>(ms_line_data.peakList.size()) !=
202 ms_line_data.peakCount)
203 {
204 qDebug() << "The number of peaks in the mass spectrum does not "
205 "match the advertised one.";
206 return false;
207 }
208
209 // qDebug() << "The retention time:" << retention_time
210 // << "the ionization mode: " << ionization_mode
211 // << "the source type: " << source_type
212 // << "MS level is:" << ms_level
213 // << "peak shape type: " << peak_shape_type
214 // << "m/z range: " << mz_range << "peak count: " <<
215 // peak_count
216 // << "and peaks: " << peaks.left(100) << " ... "
217 // << peaks.right(100) << "";
218 }
219 else
220 {
221 qDebug() << "The match failed.";
222 return false;
223 }
224
225 return true;
226}

References pappso::MassSpectrumLineData::dash, pappso::MassSpectrumLineData::ionizationMode, pappso::MassSpectrumLineData::ionSourceType, line, pappso::MassSpectrumLineData::msLevel, pappso::MassSpectrumLineData::mz_range, pappso::MassSpectrumLineData::peakCount, pappso::MassSpectrumLineData::peakList, pappso::MassSpectrumLineData::peakShapeType, and pappso::MassSpectrumLineData::retentionTime.

Referenced by accept(), qualifiedMassSpectrumFromBafAsciiMSDataFile(), and readSpectrumCollectionByMsLevel().

◆ qualifiedMassSpectrum()

QualifiedMassSpectrum pappso::BafAsciiMsRunReader::qualifiedMassSpectrum ( std::size_t  spectrum_index,
bool  want_binary_data = true 
) const
overridevirtual

get a QualifiedMassSpectrum class given its scan number

Implements pappso::MsRunReader.

Definition at line 459 of file bafasciimsrunreader.cpp.

461{
462 // qDebug();
463
464 QualifiedMassSpectrum qualified_mass_spectrum =
466 want_binary_data);
467
468 // qDebug() << "qualified mass spectrum has size:"
469 // << qualified_mass_spectrum.getMassSpectrumSPtr()->size();
470
471 return qualified_mass_spectrum;
472}
QualifiedMassSpectrum qualifiedMassSpectrumFromBafAsciiMSDataFile(std::size_t spectrum_index, bool want_binary_data) const

References qualifiedMassSpectrumFromBafAsciiMSDataFile().

Referenced by massSpectrumCstSPtr(), and massSpectrumSPtr().

◆ qualifiedMassSpectrumFromBafAsciiMSDataFile()

QualifiedMassSpectrum pappso::BafAsciiMsRunReader::qualifiedMassSpectrumFromBafAsciiMSDataFile ( std::size_t  spectrum_index,
bool  want_binary_data 
) const
protected

Definition at line 306 of file bafasciimsrunreader.cpp.

308{
309 // qDebug();
310
311 // Each line holds the data of one mass spectrum. There are other
312 // metadata at the beginning of the line.
313
314 QString file_name = mcsp_msRunId->getFileName();
315
316 QFile file(file_name);
317
318 if(!file.open(QFile::ReadOnly | QFile::Text))
319 {
320 throw(PappsoException(QString("%1-%2 Error reading file %3 in "
321 "BafAsciiMsRunReader, for MS run %4:\n")
322 .arg(__FILE__)
323 .arg(__LINE__)
324 .arg(mcsp_msRunId->getFileName())
325 .arg(mcsp_msRunId.get()->toString())));
326 }
327
328 // The format of the file, for MS1 data only is the following:
329 // <rt time in min>,+,ESI,ms1,-,profile,<m/z range start>-<m/z range
330 // end>,512704,<m/z> <int>,<m/z> <int>,.. One such line per retention time
331 // value.
332
333 QString line_regexp_pattern = craftLineParserRegExpPattern();
334 QRegularExpression line_regexp = craftLineParserRegExp(line_regexp_pattern);
335
336 if(!line_regexp.isValid())
337 {
338 throw(PappsoException(
339 QString("%1-%2 Failed to craft the regular expresssion while reading "
340 "file %3 in BafAsciiMsRunReader, for MS run %4:")
341 .arg(__FILE__)
342 .arg(__LINE__)
343 .arg(mcsp_msRunId->getFileName())
344 .arg(mcsp_msRunId.get()->toString())));
345 }
346
347 QualifiedMassSpectrum qualified_mass_spectrum;
348 MassSpectrumLineData ms_line_data;
349 std::size_t mass_spectrum_index = 0;
350
351 while(!file.atEnd())
352 {
353 if(mass_spectrum_index < spectrum_index)
354 continue;
355
356
357 QString line = file.readLine().trimmed();
358
359 if(!parseMassSpectrumLine(line, ms_line_data, line_regexp))
360 {
361 file.close();
362
363 throw(PappsoException(
364 QString("%1-%2 Failed to parse line while reading file %3 "
365 "in BafAsciiMsRunReader, for MS run %4:\n")
366 .arg(__FILE__)
367 .arg(__LINE__)
368 .arg(mcsp_msRunId->getFileName())
369 .arg(mcsp_msRunId.get()->toString())));
370 }
371
372 // At this point we have all the data inside the ms_line_data structure.
373 // If the user wants the binary data, that is, the mass spectrometric
374 // data, we need to prepare these.
375
376 MassSpectrumId mass_spectrum_id(mcsp_msRunId, mass_spectrum_index);
377
378 qualified_mass_spectrum.setMassSpectrumId(mass_spectrum_id);
379 qualified_mass_spectrum.setMsLevel(ms_line_data.msLevel);
380 qualified_mass_spectrum.setRtInSeconds(ms_line_data.retentionTime * 60);
381
382 // Should we create the peak list?
383
384 if(want_binary_data)
385 {
386 // qDebug() << "The binary data are wanted.";
387
388 MassSpectrum mass_spectrum;
389 bool ok = false;
390
391 for(int iter = 0; iter < ms_line_data.peakList.size(); ++iter)
392 {
393 QString pair_string = ms_line_data.peakList.at(iter);
394
395 // qDebug() << "The pair string:" << pair_string;
396
397 QStringList mz_and_intensity_list =
398 pair_string.split(" ", Qt::SkipEmptyParts);
399
400 double mz = mz_and_intensity_list.first().toDouble(&ok);
401 if(!ok)
402 {
403 file.close();
404
405 throw(PappsoException(
406 QString("%1-%2 Failed to parse line while reading file %3 "
407 "in BafAsciiMsRunReader, for MS run %4:\n")
408 .arg(__FILE__)
409 .arg(__LINE__)
410 .arg(mcsp_msRunId->getFileName())
411 .arg(mcsp_msRunId.get()->toString())));
412 }
413
414 // qDebug() << qSetRealNumberPrecision(10) << "m/z:" << mz;
415
416 double intensity = mz_and_intensity_list.last().toDouble(&ok);
417 if(!ok)
418 {
419 file.close();
420
421 throw(PappsoException(
422 QString("%1-%2 Failed to parse line while reading file %3 "
423 "in BafAsciiMsRunReader, for MS run %4:\n")
424 .arg(__FILE__)
425 .arg(__LINE__)
426 .arg(mcsp_msRunId->getFileName())
427 .arg(mcsp_msRunId.get()->toString())));
428 }
429
430 // qDebug() << qSetRealNumberPrecision(10)
431 // << "intensity:" << intensity;
432
433 // qDebug() << "Emplacing back with:" << mz << "-" << intensity;
434
435 mass_spectrum.emplace_back(mz, intensity);
436 }
437
438 MassSpectrumSPtr spectrum_sp = mass_spectrum.makeMassSpectrumSPtr();
439 qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
440 }
441 else
442 qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
443
444 // qDebug() << "qualified mass spectrum has size:"
445 // << qualified_mass_spectrum.getMassSpectrumSPtr()->size();
446
447 break;
448 }
449 // End of
450 // while(!file.atEnd())
451
452 file.close();
453
454 return qualified_mass_spectrum;
455}
std::shared_ptr< MassSpectrum > MassSpectrumSPtr

References craftLineParserRegExp(), craftLineParserRegExpPattern(), line, pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::MassSpectrumLineData::msLevel, pappso::mz, parseMassSpectrumLine(), pappso::MassSpectrumLineData::peakList, pappso::MassSpectrumLineData::retentionTime, pappso::QualifiedMassSpectrum::setMassSpectrumId(), pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), and pappso::QualifiedMassSpectrum::setRtInSeconds().

Referenced by qualifiedMassSpectrum().

◆ readSpectrumCollection()

void pappso::BafAsciiMsRunReader::readSpectrumCollection ( SpectrumCollectionHandlerInterface handler)
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler

Implements pappso::MsRunReader.

Definition at line 476 of file bafasciimsrunreader.cpp.

478{
480}
virtual void readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels

References readSpectrumCollectionByMsLevel().

Referenced by readSpectrumCollection2().

◆ readSpectrumCollection2()

void pappso::BafAsciiMsRunReader::readSpectrumCollection2 ( const MsRunReadConfig config,
SpectrumCollectionHandlerInterface handler 
)
overridevirtual

Implements pappso::MsRunReader.

Definition at line 666 of file bafasciimsrunreader.cpp.

669{
670 return readSpectrumCollection(handler);
671}
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler

References readSpectrumCollection().

◆ readSpectrumCollectionByMsLevel()

void pappso::BafAsciiMsRunReader::readSpectrumCollectionByMsLevel ( SpectrumCollectionHandlerInterface handler,
unsigned int  ms_level 
)
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels

Implements pappso::MsRunReader.

Definition at line 484 of file bafasciimsrunreader.cpp.

486{
487 qDebug();
488
489 // Each line holds the data of one mass spectrum. There are other
490 // metadata at the beginning of the line.
491
492 // Does the handler consuming the mass spectra read from file want these
493 // mass spectra to hold the binary data arrays (mz/i vectors)?
494
495 const bool want_binary_data = handler.needPeakList();
496
497 QString file_name = mcsp_msRunId->getFileName();
498
499 QFile file(file_name);
500
501 if(!file.open(QFile::ReadOnly | QFile::Text))
502 {
503 throw(PappsoException(QString("%1-%2 Error reading file %3 in "
504 "BafAsciiMsRunReader, for MS run %4:\n")
505 .arg(__FILE__)
506 .arg(__LINE__)
507 .arg(mcsp_msRunId->getFileName())
508 .arg(mcsp_msRunId.get()->toString())));
509 }
510
511 // The format of the file, for MS1 data only is the following:
512 // <rt time in min>,+,ESI,ms1,-,profile,<m/z range start>-<m/z range
513 // end>,512704,<m/z> <int>,<m/z> <int>,.. One such line per retention time
514 // value.
515
516 QString line_regexp_pattern = craftLineParserRegExpPattern();
517 QRegularExpression line_regexp = craftLineParserRegExp(line_regexp_pattern);
518
519 if(!line_regexp.isValid())
520 {
521 throw(PappsoException(
522 QString(
523 "%1-%2 Failed to craft the regular expresssion while reading file %3 "
524 "in BafAsciiMsRunReader, for MS run %4:\n")
525 .arg(__FILE__)
526 .arg(__LINE__)
527 .arg(mcsp_msRunId->getFileName())
528 .arg(mcsp_msRunId.get()->toString())));
529 }
530
531 MassSpectrumLineData ms_line_data;
532 std::size_t mass_spectrum_index = 0;
533
534 while(!file.atEnd())
535 {
536 // qDebug() << "Iterating at line index:" << mass_spectrum_index;
537
538 // If the user of this reader instance wants to stop reading the
539 // spectra, then break this loop.
540 if(handler.shouldStop())
541 {
542 qDebug() << "The operation was cancelled. Breaking the loop.";
543 break;
544 }
545
546 QString line = file.readLine().trimmed();
547
548 if(!parseMassSpectrumLine(line, ms_line_data, line_regexp))
549 {
550 file.close();
551
552 throw(PappsoException(
553 QString("%1-%2 Failed to parse line whilereading file %3 "
554 "in BafAsciiMsRunReader, for MS run %4:\n")
555 .arg(__FILE__)
556 .arg(__LINE__)
557 .arg(mcsp_msRunId->getFileName())
558 .arg(mcsp_msRunId.get()->toString())));
559 }
560
561 // qDebug() << "The size of the peaks string list:"
562 // << ms_line_data.peakList.size();
563
564 // At this point we have all the data inside the ms_line_data structure.
565 // If the user wants the binary data, that is, the mass spectrometric
566 // data, we need to prepare these.
567
568 MassSpectrumId mass_spectrum_id(mcsp_msRunId, mass_spectrum_index);
569
570 QualifiedMassSpectrum qualified_mass_spectrum(mass_spectrum_id);
571
572 qualified_mass_spectrum.setMsLevel(ms_line_data.msLevel);
573 qualified_mass_spectrum.setRtInSeconds(ms_line_data.retentionTime * 60);
574
575 // Should we create the peak list?
576
577 if(want_binary_data)
578 {
579 // qDebug() << "The binary data are wanted.";
580
581 MassSpectrum mass_spectrum;
582 bool ok = false;
583
584 for(int iter = 0; iter < ms_line_data.peakList.size(); ++iter)
585 {
586 QString pair_string = ms_line_data.peakList.at(iter);
587
588 // qDebug() << "The pair string:" << pair_string;
589
590 QStringList mz_and_intensity_list =
591 pair_string.split(" ", Qt::SkipEmptyParts);
592
593 double mz = mz_and_intensity_list.first().toDouble(&ok);
594 if(!ok)
595 {
596 file.close();
597
598 throw(PappsoException(
599 QString("%1-%2 Failed to parse line while reading file %3 "
600 "in BafAsciiMsRunReader, for MS run %4:\n")
601 .arg(__FILE__)
602 .arg(__LINE__)
603 .arg(mcsp_msRunId->getFileName())
604 .arg(mcsp_msRunId.get()->toString())));
605 }
606
607 // qDebug() << qSetRealNumberPrecision(10) << "m/z:" << mz;
608
609 double intensity = mz_and_intensity_list.last().toDouble(&ok);
610 if(!ok)
611 {
612 file.close();
613
614 throw(PappsoException(
615 QString("%1-%2 Failed to parse line while reading file %3 "
616 "in BafAsciiMsRunReader, for MS run %4:\n")
617 .arg(__FILE__)
618 .arg(__LINE__)
619 .arg(mcsp_msRunId->getFileName())
620 .arg(mcsp_msRunId.get()->toString())));
621 }
622
623 // qDebug() << qSetRealNumberPrecision(10)
624 // << "intensity:" << intensity;
625
626 // qDebug() << "Emplacing back with:" << mz << "-" << intensity;
627
628 mass_spectrum.emplace_back(mz, intensity);
629 }
630
631 MassSpectrumSPtr spectrum_sp = mass_spectrum.makeMassSpectrumSPtr();
632 qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
633 }
634 else
635 qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
636
637 // qDebug() << "qualified mass spectrum has size:"
638 // << qualified_mass_spectrum.getMassSpectrumSPtr()->size();
639
640 // The handler will receive the index of the mass spectrum in the
641 // current run via the mass spectrum id member datum.
642 // Only hand over the mass spectrum to the handler if the
643 // requested ms_level matches: if ms_level is 0, then any
644 // mass spectrum of any msLevel will be ok. If ms_level is not 0,
645 // then we only hand over the mass spectrum if its msLevel is
646 // exactly equal to ms_level.
647 if(ms_level == 0 || qualified_mass_spectrum.getMsLevel() == ms_level)
648 {
649 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
650 }
651
652 // This is and index of the spectrum in the file, not a count
653 // of the mass spectra actually handed over to the handler.
654 ++mass_spectrum_index;
655 }
656 // End of
657 // while(!file.atEnd())
658
659 file.close();
660
661 qDebug() << "Loading ended";
662 handler.loadingEnded();
663}

References craftLineParserRegExp(), craftLineParserRegExpPattern(), pappso::QualifiedMassSpectrum::getMsLevel(), line, pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::MassSpectrumLineData::msLevel, pappso::mz, pappso::SpectrumCollectionHandlerInterface::needPeakList(), parseMassSpectrumLine(), pappso::MassSpectrumLineData::peakList, pappso::MassSpectrumLineData::retentionTime, pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum(), pappso::QualifiedMassSpectrum::setRtInSeconds(), and pappso::SpectrumCollectionHandlerInterface::shouldStop().

Referenced by readSpectrumCollection().

◆ releaseDevice()

bool pappso::BafAsciiMsRunReader::releaseDevice ( )
overridevirtual

release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 680 of file bafasciimsrunreader.cpp.

681{
682 return true;
683}

◆ spectrumListSize()

std::size_t pappso::BafAsciiMsRunReader::spectrumListSize ( ) const
overridevirtual

get the totat number of spectrum conained in the MSrun data file

Implements pappso::MsRunReader.

Definition at line 674 of file bafasciimsrunreader.cpp.

675{
676 return m_spectrumCount;
677}

References m_spectrumCount.

Friends And Related Symbol Documentation

◆ MsFileAccessor

friend class MsFileAccessor
friend

Definition at line 25 of file bafasciimsrunreader.h.

Member Data Documentation

◆ m_fileName

QString pappso::BafAsciiMsRunReader::m_fileName
protected

Definition at line 67 of file bafasciimsrunreader.h.

◆ m_spectrumCount

std::size_t pappso::BafAsciiMsRunReader::m_spectrumCount = 0
mutableprotected

Definition at line 70 of file bafasciimsrunreader.h.

Referenced by accept(), and spectrumListSize().


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