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

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 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.

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

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

Referenced by MsFileAccessor.

◆ ~XyMsRunReader()

pappso::XyMsRunReader::~XyMsRunReader ( )
virtual

Definition at line 46 of file xymsrunreader.cpp.

47{
48}

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

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

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

309{
310 return true;
311}

Referenced by MsFileAccessor.

◆ initialize()

void pappso::XyMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 35 of file xymsrunreader.cpp.

36{
37 // qDebug();
38
39 if(!QFileInfo(mcsp_msRunId->getFileName()).exists())
40 throw ExceptionNotFound(
41 QObject::tr("Xy MS file %1 not found\n").arg(mcsp_msRunId->getFileName()));
42 // qDebug();
43}
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 110 of file xymsrunreader.cpp.

111{
112 return qualifiedMassSpectrum(spectrum_index).getMassSpectrumCstSPtr();
113}
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().

Referenced by MsFileAccessor.

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

104{
105 return qualifiedMassSpectrum(spectrum_index).getMassSpectrumSPtr();
106}
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.

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

Referenced by MsFileAccessor.

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

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

Referenced by MsFileAccessor.

◆ 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.

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

Referenced by MsFileAccessor.

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

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

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

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

◆ qualifiedMassSpectrumFromXyMSDataFile()

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

Definition at line 117 of file xymsrunreader.cpp.

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

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

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

Referenced by MsFileAccessor, and readSpectrumCollection2().

◆ readSpectrumCollection2()

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

Implements pappso::MsRunReader.

Definition at line 289 of file xymsrunreader.cpp.

291{
292 return readSpectrumCollection(handler);
293}
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::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 261 of file xymsrunreader.cpp.

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

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

Referenced by MsFileAccessor.

◆ 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}

Referenced by MsFileAccessor.

◆ 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}

Referenced by MsFileAccessor.

◆ spectrumStringIdentifier2SpectrumIndex()

std::size_t pappso::XyMsRunReader::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 333 of file xymsrunreader.cpp.

335{
336 throw pappso::ExceptionNotImplemented(
337 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
338}

Referenced by MsFileAccessor.

Friends And Related Symbol Documentation

◆ MsFileAccessor

Member Data Documentation

◆ m_fileName

QString pappso::XyMsRunReader::m_fileName
protected

Definition at line 52 of file xymsrunreader.h.


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