libpappsomspp
Library for mass spectrometry
pappso::TimsMsRunReaderMs2Selected Class Reference

#include <timsmsrunreaderms2selected.h>

Inheritance diagram for pappso::TimsMsRunReaderMs2Selected:
pappso::TimsMsRunReaderMs2 pappso::MsRunReader

Public Member Functions

 TimsMsRunReaderMs2Selected (MsRunIdCstSPtr &msrun_id_csp)
 
virtual ~TimsMsRunReaderMs2Selected ()
 
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 hasScanNumbers () const override
 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...
 
void setMs2FilterCstSPtr (pappso::FilterInterfaceCstSPtr filter)
 
void setMs1FilterCstSPtr (pappso::FilterInterfaceCstSPtr filter)
 
- Public Member Functions inherited from pappso::TimsMsRunReaderMs2
 TimsMsRunReaderMs2 (MsRunIdCstSPtr &msrun_id_csp)
 
virtual ~TimsMsRunReaderMs2 ()
 
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...
 
void setMs2FilterCstSPtr (pappso::FilterInterfaceCstSPtr filter)
 
void setMs1FilterCstSPtr (pappso::FilterInterfaceCstSPtr filter)
 
void setMs2BuiltinCentroid (bool centroid)
 enable or disable simple centroid filter on raw tims data for MS2 More...
 
virtual std::vector< std::size_t > getPrecursorsIDFromMzRt (int charge, double mz_val, double rt_sec, double k0)
 Get all the precursors id which match the values. 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...
 
virtual TimsDataSp getTimsDataSPtr ()
 give an access to the underlying raw data pointer More...
 
virtual std::vector< double > getRetentionTimeLine () override
 retention timeline get retention times along the MSrun in seconds More...
 
virtual Trace getTicChromatogram () override
 get a TIC chromatogram 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...
 
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...
 

Private Attributes

TimsDatampa_timsData = nullptr
 

Friends

class MsFileAccessor
 

Additional Inherited Members

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

Detailed Description

Definition at line 41 of file timsmsrunreaderms2selected.h.

Constructor & Destructor Documentation

◆ TimsMsRunReaderMs2Selected()

TimsMsRunReaderMs2Selected::TimsMsRunReaderMs2Selected ( MsRunIdCstSPtr msrun_id_csp)
Todo:
write docs

Definition at line 37 of file timsmsrunreaderms2selected.cpp.

39  : TimsMsRunReaderMs2(msrun_id_csp)
40 {
41  initialize();
42 }
TimsMsRunReaderMs2(MsRunIdCstSPtr &msrun_id_csp)

References initialize().

◆ ~TimsMsRunReaderMs2Selected()

TimsMsRunReaderMs2Selected::~TimsMsRunReaderMs2Selected ( )
virtual

Definition at line 44 of file timsmsrunreaderms2selected.cpp.

45 {
46  if(mpa_timsData != nullptr)
47  {
48  delete mpa_timsData;
49  }
50 }

References mpa_timsData.

Member Function Documentation

◆ accept()

bool TimsMsRunReaderMs2Selected::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

Reimplemented from pappso::TimsMsRunReaderMs2.

Definition at line 91 of file timsmsrunreaderms2selected.cpp.

92 {
93  qDebug() << file_name;
94  return true;
95 }

◆ hasScanNumbers()

bool TimsMsRunReaderMs2Selected::hasScanNumbers ( ) const
overridevirtual

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

Reimplemented from pappso::TimsMsRunReaderMs2.

Definition at line 316 of file timsmsrunreaderms2selected.cpp.

317 {
318  return false;
319 }

◆ initialize()

void pappso::TimsMsRunReaderMs2Selected::initialize ( )
overrideprotectedvirtual

Reimplemented from pappso::TimsMsRunReaderMs2.

Definition at line 53 of file timsmsrunreaderms2selected.cpp.

54 {
55  mpa_timsData = new TimsData(mcsp_msRunId.get()->getFileName());
56 }
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:301

Referenced by TimsMsRunReaderMs2Selected().

◆ massSpectrumCstSPtr()

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

Reimplemented from pappso::TimsMsRunReaderMs2.

Definition at line 108 of file timsmsrunreaderms2selected.cpp.

109 {
110  QualifiedMassSpectrum mass_spectrum =
111  qualifiedMassSpectrum(spectrum_index, true);
112  return mass_spectrum.getMassSpectrumSPtr();
113 }
Class representing a fully specified mass spectrum.
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
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::getMassSpectrumSPtr(), and qualifiedMassSpectrum().

◆ massSpectrumSPtr()

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

get a MassSpectrumSPtr class given its spectrum index

Reimplemented from pappso::TimsMsRunReaderMs2.

Definition at line 99 of file timsmsrunreaderms2selected.cpp.

100 {
101  QualifiedMassSpectrum mass_spectrum =
102  qualifiedMassSpectrum(spectrum_index, true);
103  return mass_spectrum.getMassSpectrumSPtr();
104 }

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

◆ qualifiedMassSpectrum()

QualifiedMassSpectrum TimsMsRunReaderMs2Selected::qualifiedMassSpectrum ( std::size_t  spectrum_index,
bool  want_binary_data = true 
) const
overridevirtual

get a QualifiedMassSpectrum class given its scan number

Reimplemented from pappso::TimsMsRunReaderMs2.

Definition at line 117 of file timsmsrunreaderms2selected.cpp.

119 {
120 
121  std::size_t precursor_index = (spectrum_index / 2) + 1;
122 
123  TimsData::SpectrumDescr spectrum_descr =
125 
126  if(spectrum_index % 2 == 0)
127  {
128  qDebug();
129  // this is an MS1 spectrum
130  QualifiedMassSpectrum mass_spectrum_ms1;
132  getMsRunId(), mass_spectrum_ms1, spectrum_descr, want_binary_data);
133  qDebug(); // << mass_spectrum_ms1.toString();
134 
135  // qDebug() << mass_spectrum_ms1.getMassSpectrumSPtr().get()->toString();
136  return mass_spectrum_ms1;
137  }
138  else
139  {
140  qDebug();
141  QualifiedMassSpectrum mass_spectrum_ms2;
142  if(spectrum_descr.ms2_index != spectrum_index)
143  {
144  qDebug();
145  throw PappsoException(
146  QObject::tr(
147  "ERROR in %1 %2 %3 spectrum_descr.ms2_index != spectrum_index")
148  .arg(__FILE__)
149  .arg(__FUNCTION__)
150  .arg(__LINE__));
151  }
153  getMsRunId(), mass_spectrum_ms2, spectrum_descr, want_binary_data);
154  qDebug(); // << mass_spectrum_ms2.toString();
155 
156  // qDebug() << mass_spectrum_ms2.getMassSpectrumSPtr().get()->toString();
157  return mass_spectrum_ms2;
158  }
159 }
const MsRunIdCstSPtr & getMsRunId() const
void getQualifiedMs1MassSpectrumByPrecursorId(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, const SpectrumDescr &spectrum_descr, bool want_binary_data)
Definition: timsdata.cpp:972
SpectrumDescr getSpectrumDescrWithPrecursorId(std::size_t precursor_id)
get an intermediate structure describing a spectrum
Definition: timsdata.cpp:1897
void getQualifiedMs2MassSpectrumByPrecursorId(const MsRunIdCstSPtr &msrun_id, QualifiedMassSpectrum &mass_spectrum, const SpectrumDescr &spectrum_descr, bool want_binary_data)
Definition: timsdata.cpp:1416

References pappso::MsRunReader::getMsRunId(), pappso::TimsData::getQualifiedMs1MassSpectrumByPrecursorId(), pappso::TimsData::getQualifiedMs2MassSpectrumByPrecursorId(), pappso::TimsData::getSpectrumDescrWithPrecursorId(), mpa_timsData, and pappso::TimsData::SpectrumDescr::ms2_index.

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

◆ readSpectrumCollection()

void TimsMsRunReaderMs2Selected::readSpectrumCollection ( SpectrumCollectionHandlerInterface handler)
overridevirtual

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

Reimplemented from pappso::TimsMsRunReaderMs2.

Definition at line 163 of file timsmsrunreaderms2selected.cpp.

165 {
166  const bool want_binary_data = handler.needPeakList();
167  // const bool want_binary_data = false;
168 
169  // We'll need it to perform the looping in the spectrum list.
170  std::size_t spectrum_list_size = spectrumListSize();
171 
172  // qDebug() << "The spectrum list has size:" << spectrum_list_size;
173 
174  // Inform the handler of the spectrum list so that it can handle feedback to
175  // the user.
176  handler.spectrumListHasSize(spectrum_list_size);
177 
178  std::vector<size_t> selected_precursor{63905,
179  73549,
180  105675,
181  130439,
182  177297,
183  177369,
184  177483,
185  190453,
186  196967,
187  246691,
188  271215,
189  289423,
190  310669};
191  // QFile temp_output("/data/temp.txt");
192  // temp_output.open(QIODevice::WriteOnly | QIODevice::Text);
193  // QTextStream out(&temp_output);
194 
195  // Iterate in the full list of spectra.
196  bool readAhead = handler.isReadAhead();
197 
198  if(readAhead)
199  {
200 
201  std::size_t process_list_size = 300;
202 
203  struct tmp_item
204  {
205  QualifiedMassSpectrum qualified_mass_spectrum;
206  std::size_t iter;
207  bool want_binary_data;
208  };
209 
210  for(std::size_t i = 0; i < spectrum_list_size; i += process_list_size)
211  {
212  // QTextStream out(&temp_output);
213  qDebug();
214  // If the user of this reader instance wants to stop reading the
215  // spectra, then break this loop.
216  if(handler.shouldStop())
217  {
218  qDebug() << "The operation was cancelled. Breaking the loop.";
219  break;
220  }
221  std::vector<tmp_item> item_list;
222  for(std::size_t iter = 0;
223  (iter < process_list_size) && ((iter + i) < spectrum_list_size);
224  iter++)
225  {
226  if(std::find(selected_precursor.begin(),
227  selected_precursor.end(),
228  iter + i) != selected_precursor.end())
229  {
230  bool get_data = want_binary_data;
231  if((iter + i) % 2 == 0)
232  { // MS1
233  get_data = handler.needMsLevelPeakList(1);
234  }
235  else
236  {
237  get_data = handler.needMsLevelPeakList(2);
238  }
239 
240  item_list.push_back(
241  {QualifiedMassSpectrum(), iter + i, get_data});
242  }
243  }
244  qDebug() << item_list.size();
245  // Use QtConcurrentBlocking::mapped to apply the scale function to all
246  // the images in the list.
247  QtConcurrent::blockingMap(
248  item_list.begin(), item_list.end(), [this](tmp_item &one_item) {
249  qDebug() << one_item.iter;
250  one_item.qualified_mass_spectrum =
251  qualifiedMassSpectrum(one_item.iter, one_item.want_binary_data);
252 
253  // qDebug() << one_item.qualified_mass_spectrum.size() << " " <<
254  // one_item.qualified_mass_spectrum.getMassSpectrumSPtr().get()->toString();
255  });
256 
257  qDebug() << item_list.size();
258  for(auto &item : item_list)
259  {
260  // qDebug() <<
261  // item.qualified_mass_spectrum.getMassSpectrumSPtr()
262  // .get()
263  // ->toString();
264  handler.setQualifiedMassSpectrum(item.qualified_mass_spectrum);
265  qDebug();
266  }
267  }
268  }
269  else
270  {
271  for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
272  {
273  qDebug();
274  // If the user of this reader instance wants to stop reading the
275  // spectra, then break this loop.
276  if(handler.shouldStop())
277  {
278  qDebug() << "The operation was cancelled. Breaking the loop.";
279  break;
280  }
281  bool get_data = want_binary_data;
282  if(iter % 2 == 0)
283  { // MS1
284  if(!handler.needMsLevelPeakList(1))
285  {
286  get_data = false;
287  }
288  }
289  QualifiedMassSpectrum qualified_mass_spectrum =
290  qualifiedMassSpectrum(iter, get_data);
291  handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
292  qDebug();
293  }
294  }
295  // End of
296  // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
297 
298  // Now let the loading handler know that the loading of the data has
299  // ended. The handler might need this "signal" to perform additional tasks
300  // or to cleanup cruft.
301 
302  // qDebug() << "Loading ended";
303  // temp_output.close();
304  handler.loadingEnded();
305 }
virtual bool isReadAhead() const
tells if we want to read ahead spectrum
Definition: msrunreader.cpp:64
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
virtual bool needMsLevelPeakList(unsigned int ms_level) const final
tells if we need the peak list (if we want the binary data) for each spectrum, given an MS level
Definition: msrunreader.cpp:70
virtual void spectrumListHasSize(std::size_t size)
Definition: msrunreader.cpp:53
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
virtual std::size_t spectrumListSize() const override
get the totat number of spectrum conained in the MSrun data file

References pappso::SpectrumCollectionHandlerInterface::isReadAhead(), pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::SpectrumCollectionHandlerInterface::needMsLevelPeakList(), pappso::SpectrumCollectionHandlerInterface::needPeakList(), qualifiedMassSpectrum(), pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum(), pappso::SpectrumCollectionHandlerInterface::shouldStop(), pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize(), and spectrumListSize().

◆ setMs1FilterCstSPtr()

void TimsMsRunReaderMs2Selected::setMs1FilterCstSPtr ( pappso::FilterInterfaceCstSPtr  filter)

Definition at line 75 of file timsmsrunreaderms2selected.cpp.

77 {
78  if(mpa_timsData != nullptr)
79  {
81  }
82  else
83  {
84  throw PappsoException(
85  QObject::tr("ERROR in TimsMsRunReaderMs2Selected::setMs1FilterCstSPtr "
86  "mpa_timsData is null"));
87  }
88 }
void setMs1FilterCstSPtr(pappso::FilterInterfaceCstSPtr &filter)
filter interface to apply just after raw MS1 specturm extraction the filter can be a list of filters ...
Definition: timsdata.cpp:1176

References mpa_timsData, and pappso::TimsData::setMs1FilterCstSPtr().

◆ setMs2FilterCstSPtr()

void TimsMsRunReaderMs2Selected::setMs2FilterCstSPtr ( pappso::FilterInterfaceCstSPtr  filter)

Definition at line 59 of file timsmsrunreaderms2selected.cpp.

61 {
62  if(mpa_timsData != nullptr)
63  {
65  }
66  else
67  {
68  throw PappsoException(
69  QObject::tr("ERROR in TimsMsRunReaderMs2Selected::setMs2FilterCstSPtr "
70  "mpa_timsData is null"));
71  }
72 }
void setMs2FilterCstSPtr(pappso::FilterInterfaceCstSPtr &filter)
filter interface to apply just after raw MS2 specturm extraction the filter can be a list of filters ...
Definition: timsdata.cpp:1171

References mpa_timsData, and pappso::TimsData::setMs2FilterCstSPtr().

◆ spectrumListSize()

std::size_t TimsMsRunReaderMs2Selected::spectrumListSize ( ) const
overridevirtual

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

Reimplemented from pappso::TimsMsRunReaderMs2.

Definition at line 309 of file timsmsrunreaderms2selected.cpp.

310 {
312 }
std::size_t getTotalNumberOfPrecursors() const
get the number of precursors analyzes by PASEF
Definition: timsdata.cpp:638

References pappso::TimsData::getTotalNumberOfPrecursors(), and mpa_timsData.

Referenced by readSpectrumCollection().

Friends And Related Function Documentation

◆ MsFileAccessor

friend class MsFileAccessor
friend

Definition at line 43 of file timsmsrunreaderms2selected.h.

Member Data Documentation

◆ mpa_timsData

TimsData* pappso::TimsMsRunReaderMs2Selected::mpa_timsData = nullptr
private

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