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

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
 

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

References initialize().

◆ ~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() ||
80  Utils::endOfLineRegExp.match(line).hasMatch())
81  continue;
82 
83  // qDebug() << __FILE__ << __LINE__ << "Current xy format line:" << line;
84 
85  if(Utils::xyMassDataFormatRegExp.match(line).hasMatch())
86  continue;
87  else
88  {
89  file_reading_failed = true;
90  break;
91  }
92  }
93 
94  file.close();
95 
96  if(!file_reading_failed && line_count >= 1)
97  return true;
98 
99  return false;
100 }

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

280 {
281  return true;
282 }

◆ 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(QObject::tr("Xy MS file %1 not found\n")
41  .arg(mcsp_msRunId->getFileName()));
42  // qDebug();
43 }

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

112 {
113  return qualifiedMassSpectrum(spectrum_index).getMassSpectrumCstSPtr();
114 }

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

105 {
106  return qualifiedMassSpectrum(spectrum_index).getMassSpectrumSPtr();
107 }

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

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

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

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

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

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

Referenced by qualifiedMassSpectrum(), and readSpectrumCollection().

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

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

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

274 {
275  return true;
276 }

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

268 {
269  return 1;
270 }

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 38 of file xymsrunreader.h.


The documentation for this class was generated from the following files:
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::QualifiedMassSpectrum::getMassSpectrumSPtr
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
Definition: qualifiedmassspectrum.cpp:133
pappso::XyMsRunReader::initialize
virtual void initialize() override
Definition: xymsrunreader.cpp:35
pappso::Utils::endOfLineRegExp
static QRegularExpression endOfLineRegExp
Regular expression that tracks the end of line in text files.
Definition: utils.h:62
pappso::PeptideIonCter::y
@ y
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:220
pappso::XyMsRunReader::qualifiedMassSpectrumFromXyMSDataFile
QualifiedMassSpectrum qualifiedMassSpectrumFromXyMSDataFile(MassSpectrumId mass_spectrum_id) const
Definition: xymsrunreader.cpp:118
pappso::XyMsRunReader::qualifiedMassSpectrum
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
Definition: xymsrunreader.cpp:214
pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.
Definition: qualifiedmassspectrum.cpp:141
pappso::MsRunReader
class PMSPP_LIB_DECL MsRunReader
Definition: msrunreader.h:150
pappso::Utils::xyMassDataFormatRegExp
static QRegularExpression xyMassDataFormatRegExp
Definition: utils.h:53
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54