libpappsomspp
Library for mass spectrometry
pappso::MsRunXicExtractorDisk Class Reference

#include <msrunxicextractordisk.h>

Inheritance diagram for pappso::MsRunXicExtractorDisk:
pappso::MsRunXicExtractor pappso::MsRunXicExtractorInterface pappso::MsRunXicExtractorDiskBuffer

Public Member Functions

 MsRunXicExtractorDisk (MsRunReaderSPtr &msrun_reader)
 
 MsRunXicExtractorDisk (const MsRunXicExtractorDisk &other)
 
virtual ~MsRunXicExtractorDisk ()
 
virtual void extractXicCoordSPtrList (UiMonitorInterface &monitor, std::vector< XicCoordSPtr > &xic_coord_list) override
 extract a list of XIC given a list of xic coordinates to extract More...
 
- Public Member Functions inherited from pappso::MsRunXicExtractor
 MsRunXicExtractor (const MsRunXicExtractor &other)
 
virtual ~MsRunXicExtractor ()
 
- Public Member Functions inherited from pappso::MsRunXicExtractorInterface
void setXicExtractMethod (XicExtractMethod method)
 set the XIC extraction method More...
 
void setRetentionTimeAroundTarget (double range_in_seconds)
 set the retention time range in seconds around the target rt More...
 
const MsRunIdCstSPtrgetMsRunId () const
 
const MsRunReaderSPtrgetMsRunReaderSPtr () const
 get the msrunreader currently used for XIC extraction More...
 

Protected Member Functions

 MsRunXicExtractorDisk (MsRunReaderSPtr &msrun_reader, const QDir &temporary_dir)
 
void prepareExtractor ()
 
void serializeMsRun ()
 
virtual void storeSlices (std::map< unsigned int, MassSpectrum > &slice_vector, std::size_t ipos)
 store MassSpectrum slices (by daltons) for a given retention time More...
 
void appendSliceOnDisk (unsigned int slice_number, MassSpectrum &spectrum, std::size_t ipos)
 append a slice on disk (in a file) More...
 
std::vector< MsRunSliceSPtracquireSlices (const MzRange &mz_range)
 retrieve all the slices corresponding to a given mz_range More...
 
MsRunSliceSPtr unserializeSlice (unsigned int slice_number)
 get one slice from disk by her slice number (dalton) More...
 
virtual void endPwizRead ()
 
- Protected Member Functions inherited from pappso::MsRunXicExtractor
 MsRunXicExtractor (MsRunReaderSPtr &msrun_reader)
 
virtual void getXicFromPwizMSDataFile (std::vector< Xic * > &xic_list, const std::vector< MzRange > &mass_range_list, pappso::pappso_double rt_begin, pappso::pappso_double rt_end)
 
- Protected Member Functions inherited from pappso::MsRunXicExtractorInterface
 MsRunXicExtractorInterface (MsRunReaderSPtr &msrun_reader)
 constructor is private, use the MsRunXicExtractorFactory More...
 
 MsRunXicExtractorInterface (const MsRunXicExtractorInterface &other)
 
virtual ~MsRunXicExtractorInterface ()
 

Protected Attributes

QString m_temporaryDirectory
 
QTemporaryDir * mpa_temporaryDirectory = nullptr
 
std::vector< pappso::pappso_doublem_retentionTimeList
 
pappso::pappso_double m_maxMz = 0
 
pappso::pappso_double m_minMz = 5000
 
std::size_t m_rtSize = 0
 
std::deque< MsRunSliceSPtrm_msRunSliceListCache
 
QMutex m_mutex
 
- Protected Attributes inherited from pappso::MsRunXicExtractor
std::vector< MsRunXicExtractorPointsm_msrun_points
 
- Protected Attributes inherited from pappso::MsRunXicExtractorInterface
MsRunReaderSPtr msp_msrun_reader
 
XicExtractMethod m_xicExtractMethod = XicExtractMethod::max
 
double m_retentionTimeAroundTarget = std::numeric_limits<double>::max()
 

Private Member Functions

void extractOneXicCoord (XicCoord &xic_coord)
 

Private Attributes

friend MsRunXicExtractorFactory
 

Detailed Description

Definition at line 44 of file msrunxicextractordisk.h.

Constructor & Destructor Documentation

◆ MsRunXicExtractorDisk() [1/3]

pappso::MsRunXicExtractorDisk::MsRunXicExtractorDisk ( MsRunReaderSPtr msrun_reader)

◆ MsRunXicExtractorDisk() [2/3]

pappso::MsRunXicExtractorDisk::MsRunXicExtractorDisk ( const MsRunXicExtractorDisk other)

Definition at line 47 of file msrunxicextractordisk.cpp.

49 {
50 
51  m_temporaryDirectory = other.m_temporaryDirectory;
52  mpa_temporaryDirectory = new QTemporaryDir(
53  QString("%1/msrun_%2_")
55  .arg(msp_msrun_reader.get()->getMsRunId().get()->getXmlId()));
56 }

References m_temporaryDirectory, mpa_temporaryDirectory, and pappso::MsRunXicExtractorInterface::msp_msrun_reader.

◆ ~MsRunXicExtractorDisk()

pappso::MsRunXicExtractorDisk::~MsRunXicExtractorDisk ( )
virtual

Definition at line 58 of file msrunxicextractordisk.cpp.

59 {
60  if(mpa_temporaryDirectory != nullptr)
61  {
63  }
64 }

References mpa_temporaryDirectory.

◆ MsRunXicExtractorDisk() [3/3]

pappso::MsRunXicExtractorDisk::MsRunXicExtractorDisk ( MsRunReaderSPtr msrun_reader,
const QDir &  temporary_dir 
)
protected

Definition at line 39 of file msrunxicextractordisk.cpp.

41  : pappso::MsRunXicExtractor(msrun_reader)
42 {
43  mpa_temporaryDirectory = nullptr;
44  m_temporaryDirectory = temporary_dir.absolutePath();
45 }

References m_temporaryDirectory, and mpa_temporaryDirectory.

Member Function Documentation

◆ acquireSlices()

std::vector< MsRunSliceSPtr > pappso::MsRunXicExtractorDisk::acquireSlices ( const MzRange mz_range)
protected

retrieve all the slices corresponding to a given mz_range

Parameters
mz_rangedesired mz range

Definition at line 328 of file msrunxicextractordisk.cpp.

329 {
330  QMutexLocker lock(&m_mutex);
331  std::vector<MsRunSliceSPtr> slice_list;
332  for(unsigned int i = mz_range.lower(); i <= mz_range.upper(); i++)
333  {
334  auto it = std::find_if(m_msRunSliceListCache.begin(),
335  m_msRunSliceListCache.end(),
336  [i](const MsRunSliceSPtr &slice_sp) {
337  return slice_sp.get()->getSliceNumber() == i;
338  });
339  if(it != m_msRunSliceListCache.end())
340  {
341  slice_list.push_back(*it);
342  m_msRunSliceListCache.push_back(*it);
343  }
344  else
345  {
346  MsRunSliceSPtr slice_sp = unserializeSlice(i);
347  slice_list.push_back(slice_sp);
348  m_msRunSliceListCache.push_back(slice_sp);
349  }
350  }
351 
352  if(m_msRunSliceListCache.size() > 20)
353  {
354  m_msRunSliceListCache.pop_front();
355  }
356  return slice_list;
357 }
std::deque< MsRunSliceSPtr > m_msRunSliceListCache
MsRunSliceSPtr unserializeSlice(unsigned int slice_number)
get one slice from disk by her slice number (dalton)
std::shared_ptr< const MsRunSlice > MsRunSliceSPtr
Definition: msrunslice.h:39

References pappso::MzRange::lower(), m_msRunSliceListCache, m_mutex, unserializeSlice(), and pappso::MzRange::upper().

Referenced by extractOneXicCoord().

◆ appendSliceOnDisk()

void pappso::MsRunXicExtractorDisk::appendSliceOnDisk ( unsigned int  slice_number,
MassSpectrum spectrum,
std::size_t  ipos 
)
protected

append a slice on disk (in a file)

Parameters
slice_numberthe slice number == dalton integer
spectrumthe part of the mass spectrum (mz/intensity) in the range of the slice number
iposthe position in the retention time vector

Definition at line 253 of file msrunxicextractordisk.cpp.

256 {
257  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
258  QFile slice_file(
259  QString("%1/%2").arg(mpa_temporaryDirectory->path()).arg(slice_number));
260  bool new_file = false;
261  if(!slice_file.exists())
262  {
263  new_file = true;
264  }
265  if(!slice_file.open(QIODevice::WriteOnly | QIODevice::Append))
266  {
268  QObject::tr("unable to open file %1").arg(slice_file.fileName()));
269  }
270  QDataStream stream(&slice_file);
271 
272  if(new_file)
273  {
274  stream << (quint32)slice_number;
275  stream << (quint32)m_rtSize;
276  }
277 
278  stream << (quint32)ipos;
279  stream << spectrum;
280 
281  slice_file.flush();
282  slice_file.close();
283  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
284 }

References m_rtSize, and mpa_temporaryDirectory.

Referenced by storeSlices().

◆ endPwizRead()

void pappso::MsRunXicExtractorDisk::endPwizRead ( )
protectedvirtual

Reimplemented in pappso::MsRunXicExtractorDiskBuffer.

Definition at line 361 of file msrunxicextractordisk.cpp.

362 {
363  msp_msrun_reader.get()->releaseDevice();
364 }

References pappso::MsRunXicExtractorInterface::msp_msrun_reader.

Referenced by serializeMsRun().

◆ extractOneXicCoord()

void pappso::MsRunXicExtractorDisk::extractOneXicCoord ( XicCoord xic_coord)
private

Definition at line 116 of file msrunxicextractordisk.cpp.

117 {
118  std::shared_ptr<Xic> msrunxic_sp = xic_coord.xicSptr;
119 
120  double rt_begin = xic_coord.rtTarget - m_retentionTimeAroundTarget;
121  double rt_end = xic_coord.rtTarget + m_retentionTimeAroundTarget;
122 
123 
124  std::vector<MsRunSliceSPtr> slice_list;
125  slice_list = acquireSlices(xic_coord.mzRange);
126 
127  if(slice_list.size() == 0)
128  {
130  QObject::tr("Error getMsRunXicSp slice_list.size() == 0"));
131  }
132 
133  for(std::size_t i = 0; i < m_retentionTimeList.size(); i++)
134  {
135 
136  DataPoint xic_element;
137  xic_element.x = m_retentionTimeList[i];
138  xic_element.y = 0;
139  if((xic_element.x < rt_begin) || (xic_element.x > rt_end))
140  continue;
141 
142  for(auto &&msrun_slice : slice_list)
143  {
144  const MassSpectrum &spectrum = msrun_slice.get()->getSpectrum(i);
145  for(auto &&peak : spectrum)
146  {
147  if(xic_coord.mzRange.contains(peak.x))
148  {
150  {
151  xic_element.y += peak.y;
152  }
153  else
154  {
155  if(xic_element.y < peak.y)
156  {
157  xic_element.y = peak.y;
158  }
159  }
160  }
161  }
162  }
163  msrunxic_sp.get()->push_back(xic_element);
164  }
165 }
std::vector< MsRunSliceSPtr > acquireSlices(const MzRange &mz_range)
retrieve all the slices corresponding to a given mz_range
std::vector< pappso::pappso_double > m_retentionTimeList
@ sum
sum of intensities

References acquireSlices(), pappso::MzRange::contains(), pappso::MsRunXicExtractorInterface::m_retentionTimeAroundTarget, m_retentionTimeList, pappso::MsRunXicExtractorInterface::m_xicExtractMethod, pappso::XicCoord::mzRange, pappso::XicCoord::rtTarget, pappso::sum, pappso::DataPoint::x, pappso::XicCoord::xicSptr, and pappso::DataPoint::y.

Referenced by extractXicCoordSPtrList().

◆ extractXicCoordSPtrList()

void pappso::MsRunXicExtractorDisk::extractXicCoordSPtrList ( UiMonitorInterface monitor,
std::vector< XicCoordSPtr > &  xic_coord_list 
)
overridevirtual

extract a list of XIC given a list of xic coordinates to extract

XicCoord is a vessel containing the xic to fill and coordinates of this XIC in the MS run

Parameters
monitorprocess monitoring
xic_coord_listlist of xic coordinates to extract. The order of xic coordinates may change.

Reimplemented from pappso::MsRunXicExtractor.

Definition at line 95 of file msrunxicextractordisk.cpp.

97 {
98  monitor.setStatus(
99  QObject::tr("extracting %1 XICs").arg(xic_coord_list.size()));
100  monitor.setTotalSteps(xic_coord_list.size());
101  // sort xic by mz:
102  std::sort(xic_coord_list.begin(),
103  xic_coord_list.end(),
104  [](XicCoordSPtr &a, XicCoordSPtr &b) {
105  return a.get()->mzRange.getMz() < b.get()->mzRange.getMz();
106  });
107 
108  for(XicCoordSPtr &p_xic_coord : xic_coord_list)
109  {
110  extractOneXicCoord(*p_xic_coord.get());
111  monitor.count();
112  }
113 }
void extractOneXicCoord(XicCoord &xic_coord)
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:41

References pappso::a, pappso::b, pappso::UiMonitorInterface::count(), extractOneXicCoord(), pappso::UiMonitorInterface::setStatus(), and pappso::UiMonitorInterface::setTotalSteps().

◆ prepareExtractor()

void pappso::MsRunXicExtractorDisk::prepareExtractor ( )
protected

Definition at line 67 of file msrunxicextractordisk.cpp.

68 {
69  qDebug();
70  try
71  {
73  // msp_msrun_reader = nullptr;
74  }
75  catch(pappso::PappsoException &errora)
76  {
77  qDebug();
79  QObject::tr("Error reading file (%1) : %2")
80  .arg(msp_msrun_reader.get()->getMsRunId().get()->toString())
81  .arg(errora.qwhat()));
82  }
83  catch(std::exception &error)
84  {
85  qDebug();
87  QObject::tr("Error reading file (%1) using : %2")
88  .arg(msp_msrun_reader.get()->getMsRunId().get()->toString())
89  .arg(error.what()));
90  }
91 }
virtual const QString & qwhat() const

References pappso::MsRunXicExtractorInterface::msp_msrun_reader, pappso::PappsoException::qwhat(), and serializeMsRun().

◆ serializeMsRun()

void pappso::MsRunXicExtractorDisk::serializeMsRun ( )
protected

Definition at line 168 of file msrunxicextractordisk.cpp.

169 {
170  qDebug();
171  m_minMz = 5000;
172  m_maxMz = 0;
173 
174  unsigned int slice_number;
175  std::map<unsigned int, MassSpectrum> spectrum_map;
176 
177  /*
178  const pwiz::msdata::SpectrumList *p_spectrum_list =
179  p_msdatafile->run.spectrumListPtr.get();
180 
181  std::size_t spectrum_list_size = p_spectrum_list->size();
182  pwiz::msdata::SpectrumPtr pwiz_spectrum;
183  */
184 
185  m_rtSize = m_msrun_points.size();
186 
187 
188  MassSpectrumCstSPtr spectrum;
189  for(auto &&msrun_point : m_msrun_points)
190  {
191 
192  spectrum_map.clear();
193 
194  m_retentionTimeList.push_back(msrun_point.rt);
195 
196  spectrum =
197  msp_msrun_reader.get()->massSpectrumCstSPtr(msrun_point.spectrum_index);
198 
199  const MassSpectrum *p_spectrum = spectrum.get();
200  if(p_spectrum->size() > 0)
201  {
202  if(p_spectrum->begin()->x < m_minMz)
203  {
204  m_minMz = p_spectrum->begin()->x;
205  }
206  // iterate through the m/z-intensity pairs
207 
208  if(p_spectrum->back().x > m_maxMz)
209  {
210  m_maxMz = p_spectrum->back().x;
211  }
212 
213  for(auto &peak : *p_spectrum)
214  {
215 
216  slice_number = peak.x;
217 
218  std::pair<std::map<unsigned int, MassSpectrum>::iterator, bool>
219  ret = spectrum_map.insert(std::pair<unsigned int, MassSpectrum>(
220  slice_number, MassSpectrum()));
221 
222  ret.first->second.push_back(peak);
223  // auto ret = spectrum_map.insert(std::pair<unsigned int,
224  // MassSpectrum>(slice_number,MassSpectrum()));
225  // ret.first->second.push_back(peak);
226  }
227 
228  // slices are ready for this retention time
229  storeSlices(spectrum_map, m_retentionTimeList.size() - 1);
230  }
231  }
232 
233  endPwizRead();
234  qDebug();
235 }
virtual void storeSlices(std::map< unsigned int, MassSpectrum > &slice_vector, std::size_t ipos)
store MassSpectrum slices (by daltons) for a given retention time
std::vector< MsRunXicExtractorPoints > m_msrun_points
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55

References endPwizRead(), m_maxMz, m_minMz, pappso::MsRunXicExtractor::m_msrun_points, m_retentionTimeList, m_rtSize, pappso::MsRunXicExtractorInterface::msp_msrun_reader, and storeSlices().

Referenced by prepareExtractor().

◆ storeSlices()

void pappso::MsRunXicExtractorDisk::storeSlices ( std::map< unsigned int, MassSpectrum > &  slice_vector,
std::size_t  ipos 
)
protectedvirtual

store MassSpectrum slices (by daltons) for a given retention time

Parameters
slice_vectormass spectrum chunks (by daltons)
iposthe position in the retention time vector

Reimplemented in pappso::MsRunXicExtractorDiskBuffer.

Definition at line 239 of file msrunxicextractordisk.cpp.

241 {
242  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
243 
244  for(auto &&spectrum_pair : spectrum_map)
245  {
246  appendSliceOnDisk(spectrum_pair.first, spectrum_pair.second, ipos);
247  }
248 
249  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
250 }
void appendSliceOnDisk(unsigned int slice_number, MassSpectrum &spectrum, std::size_t ipos)
append a slice on disk (in a file)

References appendSliceOnDisk().

Referenced by serializeMsRun().

◆ unserializeSlice()

MsRunSliceSPtr pappso::MsRunXicExtractorDisk::unserializeSlice ( unsigned int  slice_number)
protected

get one slice from disk by her slice number (dalton)

Parameters
slice_numberthe slice number == dalton integer

Definition at line 287 of file msrunxicextractordisk.cpp.

288 {
289  qDebug();
290  try
291  {
292  std::shared_ptr<MsRunSlice> msrun_slice_sp =
293  std::make_shared<MsRunSlice>(MsRunSlice());
294 
295  QFile slice_file(
296  QString("%1/%2").arg(mpa_temporaryDirectory->path()).arg(slice_number));
297  if(!slice_file.exists())
298  {
299  msrun_slice_sp.get()->setSize(m_rtSize);
300  msrun_slice_sp.get()->setSliceNumber(slice_number);
301  return msrun_slice_sp;
302  }
303  if(!slice_file.open(QIODevice::ReadOnly))
304  {
306  QObject::tr("unable to open file %1 in readonly")
307  .arg(slice_file.fileName()));
308  }
309  QDataStream stream(&slice_file);
310 
311  stream >> *(msrun_slice_sp.get());
312 
313  slice_file.close();
314 
315  return msrun_slice_sp;
316  }
317  catch(pappso::PappsoException &error)
318  {
320  QObject::tr("error unserializing slice %1:\n%2")
321  .arg(slice_number)
322  .arg(error.qwhat()));
323  }
324  qDebug();
325 }

References m_rtSize, mpa_temporaryDirectory, and pappso::PappsoException::qwhat().

Referenced by acquireSlices().

Member Data Documentation

◆ m_maxMz

pappso::pappso_double pappso::MsRunXicExtractorDisk::m_maxMz = 0
protected

Definition at line 102 of file msrunxicextractordisk.h.

Referenced by serializeMsRun().

◆ m_minMz

pappso::pappso_double pappso::MsRunXicExtractorDisk::m_minMz = 5000
protected

Definition at line 103 of file msrunxicextractordisk.h.

Referenced by serializeMsRun().

◆ m_msRunSliceListCache

std::deque<MsRunSliceSPtr> pappso::MsRunXicExtractorDisk::m_msRunSliceListCache
protected

Definition at line 107 of file msrunxicextractordisk.h.

Referenced by acquireSlices().

◆ m_mutex

QMutex pappso::MsRunXicExtractorDisk::m_mutex
protected

Definition at line 109 of file msrunxicextractordisk.h.

Referenced by acquireSlices().

◆ m_retentionTimeList

std::vector<pappso::pappso_double> pappso::MsRunXicExtractorDisk::m_retentionTimeList
protected

Definition at line 100 of file msrunxicextractordisk.h.

Referenced by extractOneXicCoord(), and serializeMsRun().

◆ m_rtSize

std::size_t pappso::MsRunXicExtractorDisk::m_rtSize = 0
protected

◆ m_temporaryDirectory

QString pappso::MsRunXicExtractorDisk::m_temporaryDirectory
protected

Definition at line 98 of file msrunxicextractordisk.h.

Referenced by MsRunXicExtractorDisk().

◆ mpa_temporaryDirectory

QTemporaryDir* pappso::MsRunXicExtractorDisk::mpa_temporaryDirectory = nullptr
protected

◆ MsRunXicExtractorFactory

friend pappso::MsRunXicExtractorDisk::MsRunXicExtractorFactory
private

Definition at line 46 of file msrunxicextractordisk.h.


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