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

44 {
45 }

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

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

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

◆ initialize()

void pappso::XyMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 35 of file xymsrunreader.cpp.

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

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

109 {
110  return qualifiedMassSpectrum(spectrum_index).getMassSpectrumCstSPtr();
111 }

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

102 {
103  return qualifiedMassSpectrum(spectrum_index).getMassSpectrumSPtr();
104 }

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

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

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

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

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(), 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 233 of file xymsrunreader.cpp.

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

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

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

259 {
260  return 1;
261 }

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 33 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:67
pappso::QualifiedMassSpectrum::getMassSpectrumSPtr
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
Definition: qualifiedmassspectrum.cpp:140
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:81
pappso::PeptideIonCter::y
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:224
pappso::PeptideIonCter::x
pappso::XyMsRunReader::qualifiedMassSpectrumFromXyMSDataFile
QualifiedMassSpectrum qualifiedMassSpectrumFromXyMSDataFile(MassSpectrumId mass_spectrum_id) const
Definition: xymsrunreader.cpp:115
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:205
pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.
Definition: qualifiedmassspectrum.cpp:148
pappso::MsRunReader
class PMSPP_LIB_DECL MsRunReader
Definition: msrunreader.h:167
pappso::Utils::xyMassDataFormatRegExp
static QRegularExpression xyMassDataFormatRegExp
Definition: utils.h:72
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:73