libpappsomspp
Library for mass spectrometry
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 More...
 
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 More...
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler More...
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum index More...
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum More...
 
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 More...
 
virtual std::size_t spectrumListSize () const override
 get the totat number of spectrum conained in the MSrun data file More...
 
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 More...
 
virtual bool acquireDevice () override
 acquire data back end device More...
 
- Public Member Functions inherited from pappso::MsRunReader
 MsRunReader (MsRunIdCstSPtr &ms_run_id)
 
 MsRunReader (const MsRunReader &other)
 
virtual ~MsRunReader ()
 
const MsRunIdCstSPtrgetMsRunId () const
 
virtual MassSpectrumSPtr massSpectrumSPtr (std::size_t spectrum_index)=0
 get a MassSpectrumSPtr class given its spectrum index More...
 
virtual MassSpectrumCstSPtr massSpectrumCstSPtr (std::size_t spectrum_index)=0
 
virtual QualifiedMassSpectrum qualifiedMassSpectrum (std::size_t spectrum_index, bool want_binary_data=true) const =0
 get a QualifiedMassSpectrum class given its scan number More...
 
virtual XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, PrecisionPtr precision) const =0
 get a xic coordinate object from a given spectrum index More...
 
virtual XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const QualifiedMassSpectrum &mass_spectrum, PrecisionPtr precision) const =0
 get a xic coordinate object from a given spectrum More...
 
virtual std::size_t spectrumListSize () const =0
 get the totat number of spectrum conained in the MSrun data file More...
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler)=0
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler More...
 
virtual void readSpectrumCollectionByMsLevel (SpectrumCollectionHandlerInterface &handler, unsigned int ms_level)=0
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels More...
 
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. More...
 
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 More...
 
virtual bool releaseDevice ()=0
 release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object More...
 
virtual bool acquireDevice ()=0
 acquire data back end device More...
 
virtual std::vector< double > getRetentionTimeLine ()
 retention timeline get retention times along the MSrun in seconds More...
 
virtual Trace getTicChromatogram ()
 get a TIC chromatogram More...
 
void setMonoThread (bool is_mono_thread)
 set only one is_mono_thread to true More...
 
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 More...
 
QualifiedMassSpectrum qualifiedMassSpectrumFromXyMSDataFile (MassSpectrumId mass_spectrum_id) const
 
virtual void initialize ()=0
 
virtual bool accept (const QString &file_name) const =0
 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 More...
 

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:183

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:53
static QRegularExpression endOfLineRegExp
Regular expression that tracks the end of line in text files.
Definition: utils.h:62

References pappso::Utils::endOfLineRegExp, 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 308 of file xymsrunreader.cpp.

309{
310 return true;
311}

◆ 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
Definition: msrunreader.h:298

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 326 of file xymsrunreader.cpp.

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

◆ 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 314 of file xymsrunreader.cpp.

318{
319 throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
320 .arg(__FILE__)
321 .arg(__FUNCTION__)
322 .arg(__LINE__));
323}

◆ 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 215 of file xymsrunreader.cpp.

217{
218 // qDebug();
219
220 // In reality there is only one mass spectrum in the file, so we do not use
221 // spectrum_index, but use 0 instead.
222
223 MassSpectrumId massSpectrumId(mcsp_msRunId, 0);
224
225 QualifiedMassSpectrum qualified_mass_spectrum =
227
228 // qDebug() << "qualified mass spectrum has size:"
229 //<< qualified_mass_spectrum.getMassSpectrumSPtr()->size();
230
231 // We also do not abide by the want_binary_data parameter because in this XY
232 // mass spec data file loading process we actually want the data.
233 if(!want_binary_data)
234 {
235 // qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
236 }
237
238 return qualified_mass_spectrum;
239}
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 DataPoint data_point(x, y);
197
198 mass_spectrum.emplace_back(x, y);
199 }
200 }
201
202 file.close();
203
204 MassSpectrumSPtr spectrum_sp = mass_spectrum.makeMassSpectrumSPtr();
205 qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
206
207 // qDebug() << "the qualified mass spectrum has size:"
208 //<< qualified_mass_spectrum.getMassSpectrumSPtr()->size();
209
210 return qualified_mass_spectrum;
211}
double pappso_double
A type definition for doubles.
Definition: types.h:49
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54

References pappso::Utils::endOfLineRegExp, 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 243 of file xymsrunreader.cpp.

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

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

◆ 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 268 of file xymsrunreader.cpp.

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

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 302 of file xymsrunreader.cpp.

303{
304 return true;
305}

◆ 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 296 of file xymsrunreader.cpp.

297{
298 return 1;
299}

Friends And Related Function 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 50 of file xymsrunreader.h.


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