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
 
virtual std::size_t spectrumStringIdentifier2SpectrumIndex (const QString &spectrum_identifier) override
 if possible, get the spectrum index given a string identifier throw a not found exception if spectrum identifier is not found
 
- 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
 
virtual const OboPsiModTerm getOboPsiModTermInstrumentModelName () const
 get OboPsiModTerm corresponding to the instrument model name child of : [Term] id: MS:1000031 name: instrument model def: "Instrument model name not including the vendor's name." [PSI:MS] relationship: part_of MS:1000463 ! instrument
 

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
class PMSPP_LIB_DECL MsRunReader
Definition msrunreader.h:56

References pappso::MsRunReader::MsRunReader(), and initialize().

Referenced by MsFileAccessor.

◆ ~BafAsciiMsRunReader()

pappso::BafAsciiMsRunReader::~BafAsciiMsRunReader ( )
virtual

Definition at line 52 of file bafasciimsrunreader.cpp.

53{
54}

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 220 of file bafasciimsrunreader.cpp.

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

664{
665 return true;
666}

Referenced by MsFileAccessor.

◆ craftLineParserRegExp()

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

Definition at line 99 of file bafasciimsrunreader.cpp.

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

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

◆ craftLineParserRegExpPattern()

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

Definition at line 57 of file bafasciimsrunreader.cpp.

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

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 {
44 throw(pappso::ExceptionNotRecognized(QString("Failed to initialize reading of file %1 "
45 "in BafAsciiMsRunReader, for MS run %2:\n")
46 .arg(mcsp_msRunId->getFileName())
47 .arg(mcsp_msRunId.get()->toString())));
48 }
49}
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,...
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 290 of file bafasciimsrunreader.cpp.

291{
292 return qualifiedMassSpectrum(spectrum_index).getMassSpectrumCstSPtr();
293}
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().

Referenced by MsFileAccessor.

◆ 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 283 of file bafasciimsrunreader.cpp.

284{
285 return qualifiedMassSpectrum(spectrum_index).getMassSpectrumSPtr();
286}
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.

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

Referenced by MsFileAccessor.

◆ 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 678 of file bafasciimsrunreader.cpp.

681{
682 throw ExceptionNotImplemented(
683 QObject::tr("Not implemented %1 %2 %3").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
684}

Referenced by MsFileAccessor.

◆ 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 669 of file bafasciimsrunreader.cpp.

672{
673 throw ExceptionNotImplemented(
674 QObject::tr("Not implemented %1 %2 %3").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
675}

Referenced by MsFileAccessor.

◆ parseMassSpectrumLine()

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

Definition at line 113 of file bafasciimsrunreader.cpp.

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

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 445 of file bafasciimsrunreader.cpp.

446{
447 // qDebug();
448
449 QualifiedMassSpectrum qualified_mass_spectrum =
450 qualifiedMassSpectrumFromBafAsciiMSDataFile(spectrum_index, want_binary_data);
451
452 // qDebug() << "qualified mass spectrum has size:"
453 // << qualified_mass_spectrum.getMassSpectrumSPtr()->size();
454
455 return qualified_mass_spectrum;
456}
QualifiedMassSpectrum qualifiedMassSpectrumFromBafAsciiMSDataFile(std::size_t spectrum_index, bool want_binary_data) const

References qualifiedMassSpectrumFromBafAsciiMSDataFile().

Referenced by massSpectrumCstSPtr(), massSpectrumSPtr(), and MsFileAccessor.

◆ qualifiedMassSpectrumFromBafAsciiMSDataFile()

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

Definition at line 297 of file bafasciimsrunreader.cpp.

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

References craftLineParserRegExp(), craftLineParserRegExpPattern(), line, pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::MassSpectrumLineData::msLevel, 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 460 of file bafasciimsrunreader.cpp.

461{
463}
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 MsFileAccessor, and readSpectrumCollection2().

◆ readSpectrumCollection2()

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

Implements pappso::MsRunReader.

Definition at line 644 of file bafasciimsrunreader.cpp.

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

References readSpectrumCollection().

Referenced by MsFileAccessor.

◆ 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 467 of file bafasciimsrunreader.cpp.

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

References craftLineParserRegExp(), craftLineParserRegExpPattern(), pappso::QualifiedMassSpectrum::getMsLevel(), line, pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::MassSpectrumLineData::msLevel, 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 MsFileAccessor, and 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 657 of file bafasciimsrunreader.cpp.

658{
659 return true;
660}

Referenced by MsFileAccessor.

◆ 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 651 of file bafasciimsrunreader.cpp.

652{
653 return m_spectrumCount;
654}

References m_spectrumCount.

Referenced by MsFileAccessor.

◆ spectrumStringIdentifier2SpectrumIndex()

std::size_t pappso::BafAsciiMsRunReader::spectrumStringIdentifier2SpectrumIndex ( const QString & spectrum_identifier)
overridevirtual

if possible, get the spectrum index given a string identifier throw a not found exception if spectrum identifier is not found

Parameters
spectrum_identifierstring identifier of a specific spectrum
Returns
the spectrum index

Implements pappso::MsRunReader.

Definition at line 687 of file bafasciimsrunreader.cpp.

689{
690 throw pappso::ExceptionNotImplemented(
691 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
692}

Referenced by MsFileAccessor.

Friends And Related Symbol Documentation

◆ MsFileAccessor

Member Data Documentation

◆ m_fileName

QString pappso::BafAsciiMsRunReader::m_fileName
protected

Definition at line 65 of file bafasciimsrunreader.h.

◆ m_spectrumCount

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

Definition at line 68 of file bafasciimsrunreader.h.

Referenced by accept(), and spectrumListSize().


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