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

#include <xymsrunreader.h>

Inheritance diagram for pappso::XyMsRunReader:
pappso::MsRunReader

Public Member Functions

 XyMsRunReader (MsRunIdCstSPtr &msrun_id_csp)
 
virtual ~XyMsRunReader ()
 
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

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 qualifiedMassSpectrumFromXyMSDataFile (MassSpectrumId mass_spectrum_id) const
 
- Protected Member Functions inherited from pappso::MsRunReader

Protected Attributes

QString m_fileName
 
- Protected Attributes inherited from pappso::MsRunReader
MsRunIdCstSPtr mcsp_msRunId
 
MsRunReaderScanNumberMultiMapmpa_multiMapScanNumber = nullptr
 

Friends

class MsFileAccessor
 

Detailed Description

Definition at line 10 of file xymsrunreader.h.

Constructor & Destructor Documentation

◆ XyMsRunReader()

pappso::XyMsRunReader::XyMsRunReader ( MsRunIdCstSPtr & msrun_id_csp)

Definition at line 26 of file xymsrunreader.cpp.

27 : pappso::MsRunReader(msrun_id_csp)
28{
29 // Run the initialization function that checks that the file exists!
30
31 initialize();
32}
virtual void initialize() override
class PMSPP_LIB_DECL MsRunReader
Definition msrunreader.h:55

References initialize().

◆ ~XyMsRunReader()

pappso::XyMsRunReader::~XyMsRunReader ( )
virtual

Definition at line 47 of file xymsrunreader.cpp.

48{
49}

Member Function Documentation

◆ accept()

bool pappso::XyMsRunReader::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 53 of file xymsrunreader.cpp.

54{
55
56 // Here we just test all the lines of the file to check that they comply with
57 // the xy format.
58
59 std::size_t line_count = 0;
60
61 QFile file(file_name);
62
63 if(!file.open(QFile::ReadOnly | QFile::Text))
64 {
65 qDebug() << __FILE__ << __LINE__ << "Failed to open file" << file_name;
66
67 return false;
68 }
69
70 QRegularExpressionMatch regExpMatch;
71
72 QString line;
73 bool file_reading_failed = false;
74
75 while(!file.atEnd())
76 {
77 line = file.readLine();
78 ++line_count;
79
80 if(line.startsWith('#') || line.isEmpty() ||
81 Utils::endOfLineRegExp.match(line).hasMatch())
82 continue;
83
84 // qDebug() << __FILE__ << __LINE__ << "Current xy format line:" << line;
85
86 if(Utils::xyMassDataFormatRegExp.match(line).hasMatch())
87 continue;
88 else
89 {
90 file_reading_failed = true;
91 break;
92 }
93 }
94
95 file.close();
96
97 if(!file_reading_failed && line_count >= 1)
98 return true;
99
100 return false;
101}
static QRegularExpression xyMassDataFormatRegExp
Definition utils.h:59
static QRegularExpression endOfLineRegExp
Regular expression that tracks the end of line in text files.
Definition utils.h:68

References pappso::Utils::endOfLineRegExp, line, and pappso::Utils::xyMassDataFormatRegExp.

◆ acquireDevice()

bool pappso::XyMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 318 of file xymsrunreader.cpp.

319{
320 return true;
321}

◆ initialize()

void pappso::XyMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 36 of file xymsrunreader.cpp.

37{
38 // qDebug();
39
40 if(!QFileInfo(mcsp_msRunId->getFileName()).exists())
41 throw ExceptionNotFound(QObject::tr("Xy MS file %1 not found\n")
42 .arg(mcsp_msRunId->getFileName()));
43 // qDebug();
44}
MsRunIdCstSPtr mcsp_msRunId

References pappso::MsRunReader::mcsp_msRunId.

Referenced by XyMsRunReader().

◆ massSpectrumCstSPtr()

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

Implements pappso::MsRunReader.

Definition at line 112 of file xymsrunreader.cpp.

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

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

◆ massSpectrumSPtr()

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

get a MassSpectrumSPtr class given its spectrum index

Implements pappso::MsRunReader.

Definition at line 105 of file xymsrunreader.cpp.

106{
107 return qualifiedMassSpectrum(spectrum_index).getMassSpectrumSPtr();
108}
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.

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

◆ newXicCoordSPtrFromQualifiedMassSpectrum()

XicCoordSPtr pappso::XyMsRunReader::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 336 of file xymsrunreader.cpp.

339{
340 throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
341 .arg(__FILE__)
342 .arg(__FUNCTION__)
343 .arg(__LINE__));
344}

◆ newXicCoordSPtrFromSpectrumIndex()

XicCoordSPtr pappso::XyMsRunReader::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 324 of file xymsrunreader.cpp.

328{
329 throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
330 .arg(__FILE__)
331 .arg(__FUNCTION__)
332 .arg(__LINE__));
333}

◆ qualifiedMassSpectrum()

QualifiedMassSpectrum pappso::XyMsRunReader::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 217 of file xymsrunreader.cpp.

219{
220 // qDebug();
221
222 // In reality there is only one mass spectrum in the file, so we do not use
223 // spectrum_index, but use 0 instead.
224
225 MassSpectrumId massSpectrumId(mcsp_msRunId, 0);
226
227 QualifiedMassSpectrum qualified_mass_spectrum =
229
230 // qDebug() << "qualified mass spectrum has size:"
231 //<< qualified_mass_spectrum.getMassSpectrumSPtr()->size();
232
233 // We also do not abide by the want_binary_data parameter because in this XY
234 // mass spec data file loading process we actually want the data.
235 if(!want_binary_data)
236 {
237 // qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
238 }
239
240 return qualified_mass_spectrum;
241}
QualifiedMassSpectrum qualifiedMassSpectrumFromXyMSDataFile(MassSpectrumId mass_spectrum_id) const

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

Referenced by massSpectrumCstSPtr(), and massSpectrumSPtr().

◆ qualifiedMassSpectrumFromXyMSDataFile()

QualifiedMassSpectrum pappso::XyMsRunReader::qualifiedMassSpectrumFromXyMSDataFile ( MassSpectrumId mass_spectrum_id) const
protected

Definition at line 119 of file xymsrunreader.cpp.

121{
122 // qDebug();
123
124 // This is a file that contains a single spectrum. Just iterate in the various
125 // lines and convert them to DataPoint objects that are fed to the mass
126 // spectrum.
127
128 QualifiedMassSpectrum qualified_mass_spectrum(mass_spectrum_id);
129
130 // Set manually data that are necessary for the correct use of this mass
131 // spectrum in the MS data set tree node.
132 qualified_mass_spectrum.setMsLevel(1);
133 qualified_mass_spectrum.setRtInSeconds(0);
134
135 MassSpectrum mass_spectrum;
136
137 QFile file(mcsp_msRunId->getFileName());
138
139 if(!file.exists())
140 {
141 // qDebug() << "File" << mcsp_msRunId->getFileName() << "does not exist.";
142
143 return qualified_mass_spectrum;
144 }
145
146 if(!file.open(QFile::ReadOnly | QFile::Text))
147 {
148 // qDebug() << "Failed to open file" << mcsp_msRunId->getFileName();
149
150 return qualified_mass_spectrum;
151 }
152
153 QRegularExpressionMatch regExpMatch;
154
155 QString line;
156
157 while(!file.atEnd())
158 {
159 line = file.readLine();
160
161 if(line.startsWith('#') || line.isEmpty() ||
162 Utils::endOfLineRegExp.match(line).hasMatch())
163 continue;
164
165 if(Utils::xyMassDataFormatRegExp.match(line).hasMatch())
166 {
167 pappso_double x = -1;
168 pappso_double y = -1;
169
170 QRegularExpressionMatch regExpMatch =
172
173 if(!regExpMatch.hasMatch())
174 throw ExceptionNotPossible(
175 QObject::tr("Failed to create data point with line %1.\n")
176 .arg(line));
177
178 bool ok = false;
179
180 x = regExpMatch.captured(1).toDouble(&ok);
181
182 if(!ok)
183 throw ExceptionNotPossible(
184 QObject::tr("Failed to create data point with line %1.\n")
185 .arg(line));
186
187 // Note that group 2 is the separator group.
188
189 y = regExpMatch.captured(3).toDouble(&ok);
190
191 if(!ok)
192 throw ExceptionNotPossible(
193 QObject::tr("Failed to create data point with line %1.\n")
194 .arg(line));
195
196 // FIXME: what is this data point for if we use emplace_back
197 // right below ?
198 DataPoint data_point(x, y);
199
200 mass_spectrum.emplace_back(x, y);
201 }
202 }
203
204 file.close();
205
206 MassSpectrumSPtr spectrum_sp = mass_spectrum.makeMassSpectrumSPtr();
207 qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
208
209 // qDebug() << "the qualified mass spectrum has size:"
210 //<< qualified_mass_spectrum.getMassSpectrumSPtr()->size();
211
212 return qualified_mass_spectrum;
213}
double pappso_double
A type definition for doubles.
Definition types.h:50
std::shared_ptr< MassSpectrum > MassSpectrumSPtr

References pappso::Utils::endOfLineRegExp, line, pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::QualifiedMassSpectrum::setRtInSeconds(), pappso::x, pappso::Utils::xyMassDataFormatRegExp, and pappso::y.

Referenced by qualifiedMassSpectrum(), readSpectrumCollection(), and readSpectrumCollectionByMsLevel().

◆ readSpectrumCollection()

void pappso::XyMsRunReader::readSpectrumCollection ( SpectrumCollectionHandlerInterface & handler)
overridevirtual

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

Implements pappso::MsRunReader.

Definition at line 245 of file xymsrunreader.cpp.

247{
248 // qDebug();
249
250 // In reality there is only one mass spectrum in the file.
251
252 MassSpectrumId massSpectrumId(mcsp_msRunId, 0 /* spectrum index*/);
253
254 QualifiedMassSpectrum qualified_mass_spectrum =
256
257 // qDebug() << "qualified mass spectrum has size:"
258 //<< qualified_mass_spectrum.getMassSpectrumSPtr()->size();
259
260 // The handler will receive the index of the mass spectrum in the
261 // current run via the mass spectrum id member datum.
262 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
263
264 // qDebug() << "Loading ended";
265 handler.loadingEnded();
266}

References pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::MsRunReader::mcsp_msRunId, qualifiedMassSpectrumFromXyMSDataFile(), and pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum().

Referenced by readSpectrumCollection2().

◆ readSpectrumCollection2()

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

Implements pappso::MsRunReader.

Definition at line 298 of file xymsrunreader.cpp.

301{
302 return readSpectrumCollection(handler);
303}
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::XyMsRunReader::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 270 of file xymsrunreader.cpp.

272{
273 // qDebug();
274
275 // In reality there is only one mass spectrum in the file.
276
277 MassSpectrumId massSpectrumId(mcsp_msRunId, 0 /* spectrum index*/);
278
279 QualifiedMassSpectrum qualified_mass_spectrum =
281
282 // qDebug() << "qualified mass spectrum has size:"
283 //<< qualified_mass_spectrum.getMassSpectrumSPtr()->size();
284
285 // The handler will receive the index of the mass spectrum in the
286 // current run via the mass spectrum id member datum.
287
288 if(qualified_mass_spectrum.getMsLevel() == ms_level)
289 {
290 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
291 }
292
293 // qDebug() << "Loading ended";
294 handler.loadingEnded();
295}

References pappso::QualifiedMassSpectrum::getMsLevel(), pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::MsRunReader::mcsp_msRunId, qualifiedMassSpectrumFromXyMSDataFile(), and pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum().

◆ releaseDevice()

bool pappso::XyMsRunReader::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 312 of file xymsrunreader.cpp.

313{
314 return true;
315}

◆ spectrumListSize()

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

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

Implements pappso::MsRunReader.

Definition at line 306 of file xymsrunreader.cpp.

307{
308 return 1;
309}

Friends And Related Symbol Documentation

◆ MsFileAccessor

friend class MsFileAccessor
friend

Definition at line 12 of file xymsrunreader.h.

Member Data Documentation

◆ m_fileName

QString pappso::XyMsRunReader::m_fileName
protected

Definition at line 54 of file xymsrunreader.h.


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