libpappsomspp
Library for mass spectrometry
msrunreader.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/msrun/msrunreader.cpp
3  * \date 29/05/2018
4  * \author Olivier Langella
5  * \brief base interface to read MSrun files
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
10  *
11  * This file is part of the PAPPSOms++ library.
12  *
13  * PAPPSOms++ is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * PAPPSOms++ is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25  *
26  * Contributors:
27  * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
28  *implementation
29  ******************************************************************************/
30 
31 #include <QDebug>
32 
33 #include "msrunreader.h"
34 #include "../../pappsomspp/exception/exceptionnotfound.h"
35 
36 
38  qRegisterMetaType<pappso::MsRunReaderSPtr>("pappso::MsRunReaderSPtr");
39 
40 
41 namespace pappso
42 {
43 
44 
45 bool
47 {
48  return false;
49 }
50 void
52 {
53 }
54 void
56  [maybe_unused]] std::size_t size)
57 {
58 }
59 void
61 {
62  m_isReadAhead = is_read_ahead;
63 }
64 
65 bool
67 {
68  return m_isReadAhead;
69 }
70 
71 bool
73  unsigned int ms_level) const
74 {
75  if(needPeakList() == true)
76  {
77  if(ms_level < m_needPeakListByMsLevel.size())
78  {
79  return m_needPeakListByMsLevel[ms_level];
80  }
81  else
82  return true;
83  }
84  else
85  {
86  return false;
87  }
88 }
89 void
91  unsigned int ms_level, bool want_peak_list)
92 {
93  if(ms_level < m_needPeakListByMsLevel.size())
94  {
95  m_needPeakListByMsLevel[ms_level] = want_peak_list;
96  }
97 }
98 
99 bool
101 {
102  return false;
103 }
104 
105 
106 void
108 {
109  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
110  //<< "The data loading process ended.";
111 }
112 
113 
114 void
116  const QualifiedMassSpectrum &qspectrum)
117 {
118  unsigned int ms_level = qspectrum.getMsLevel();
119  if(ms_level == 0)
120  return;
121  if(ms_level > m_countMsLevelSpectrum.size())
122  {
123  m_countMsLevelSpectrum.resize(ms_level);
124  }
125  m_countMsLevelSpectrum[ms_level - 1]++;
126 }
127 
128 
129 unsigned long
130 MsRunSimpleStatistics::getMsLevelCount(unsigned int ms_level) const
131 {
132  if(ms_level == 0)
133  return 0;
134  if(ms_level > m_countMsLevelSpectrum.size())
135  return 0;
136  return (m_countMsLevelSpectrum[ms_level - 1]);
137 }
138 
139 
140 unsigned long
142 {
143  unsigned long total = 0;
144  for(unsigned long count : m_countMsLevelSpectrum)
145  {
146  total += count;
147  }
148  return total;
149 }
150 
151 
153 {
154  // qDebug();
155 }
156 
157 
159 {
160  // qDebug();
161 }
162 
163 
164 bool
166 {
167  return false;
168 }
169 
170 void
172  const QualifiedMassSpectrum &qspectrum)
173 {
174  qDebug() << " " << qspectrum.getMassSpectrumId().getNativeId();
175 
176  QStringList native_id_list =
177  qspectrum.getMassSpectrumId().getNativeId().split("=");
178  if(native_id_list.size() < 2)
179  {
180  return;
181  }
182  else
183  {
184  std::size_t scan_number = native_id_list.back().toULong();
185  m_mmap_scan2index.insert(std::pair<std::size_t, std::size_t>(
186  scan_number, qspectrum.getMassSpectrumId().getSpectrumIndex()));
187 
188  qDebug() << "scan number " << scan_number << "=>"
189  << qspectrum.getMassSpectrumId().getSpectrumIndex();
190  }
191 }
192 
193 std::size_t
195  std::size_t scan_number) const
196 {
197 
198  qDebug() << m_mmap_scan2index.size();
199 
200  auto it = m_mmap_scan2index.find(scan_number);
201 
202  if(it == m_mmap_scan2index.end())
203  {
204  throw ExceptionNotFound(
205  QObject::tr("scan number %1 not found").arg(scan_number));
206  }
207 
208  std::size_t index = it->second;
209 
210  it++;
211  if((it != m_mmap_scan2index.end()) && (it->first == scan_number))
212  {
213  throw PappsoException(
214  QObject::tr("scan number %1 found multiple times").arg(scan_number));
215  }
216  return index;
217 }
218 
219 
220 MsRunReader::MsRunReader(MsRunIdCstSPtr &ms_run_id) : mcsp_msRunId(ms_run_id)
221 {
222 }
223 
225  : mcsp_msRunId(other.mcsp_msRunId)
226 {
227  mpa_multiMapScanNumber = nullptr;
228 }
229 
230 
231 const MsRunIdCstSPtr &
233 {
234  return mcsp_msRunId;
235 }
236 
237 
239 {
240  if(mpa_multiMapScanNumber == nullptr)
241  delete mpa_multiMapScanNumber;
242 }
243 
244 
245 std::size_t
247 {
248  qDebug() << " " << mpa_multiMapScanNumber;
249 
250  if(mpa_multiMapScanNumber == nullptr)
251  {
254  }
255  try
256  {
258  scan_number);
259  }
260 
261  catch(ExceptionNotFound &error)
262  {
263  throw ExceptionNotFound(QObject::tr("error reading file %1 : %2")
264  .arg(mcsp_msRunId.get()->getFileName())
265  .arg(error.qwhat()));
266  }
267  catch(PappsoException &error)
268  {
269  throw PappsoException(QObject::tr("error reading file %1 : %2")
270  .arg(mcsp_msRunId.get()->getFileName())
271  .arg(error.qwhat()));
272  }
273 }
274 
275 
276 bool
278 {
279  return false;
280 }
281 
282 
283 } // namespace pappso
pappso::QualifiedMassSpectrum::getMsLevel
uint getMsLevel() const
Get the mass spectrum level.
Definition: qualifiedmassspectrum.cpp:232
pappso::MsRunReader
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:178
pappso::MsRunSimpleStatistics::getTotalCount
unsigned long getTotalCount() const
Definition: msrunreader.cpp:141
pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize
virtual void spectrumListHasSize(std::size_t size)
Definition: msrunreader.cpp:55
pappso::SpectrumCollectionHandlerInterface::isReadAhead
virtual bool isReadAhead() const
tells if we want to read ahead spectrum
Definition: msrunreader.cpp:66
msrunreader.h
base interface to read MSrun files
pappso::MsRunReader::scanNumber2SpectrumIndex
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 trans...
Definition: msrunreader.cpp:246
pappso
Definition: aa.cpp:38
pappso::MassSpectrumId::getNativeId
const QString & getNativeId() const
Definition: massspectrumid.cpp:117
pappso::MsRunReaderScanNumberMultiMap::getSpectrumIndexFromScanNumber
std::size_t getSpectrumIndexFromScanNumber(std::size_t scan_number) const
Definition: msrunreader.cpp:194
pappso::MsRunReader::mpa_multiMapScanNumber
MsRunReaderScanNumberMultiMap * mpa_multiMapScanNumber
Definition: msrunreader.h:229
pappso::MsRunIdCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition: msrunid.h:65
pappso::MsRunReaderScanNumberMultiMap::m_mmap_scan2index
std::multimap< std::size_t, std::size_t > m_mmap_scan2index
Definition: msrunreader.h:158
pappso::MsRunSimpleStatistics::loadingEnded
virtual void loadingEnded() override
Definition: msrunreader.cpp:107
pappso::MsRunReaderScanNumberMultiMap::MsRunReaderScanNumberMultiMap
MsRunReaderScanNumberMultiMap()
Definition: msrunreader.cpp:152
pappso::SpectrumCollectionHandlerInterface::shouldStop
virtual bool shouldStop()
Definition: msrunreader.cpp:46
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:228
pappso::MsRunSimpleStatistics::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
Definition: msrunreader.cpp:115
pappso::SpectrumCollectionHandlerInterface::loadingEnded
virtual void loadingEnded()
Definition: msrunreader.cpp:51
pappso::MsRunReaderScanNumberMultiMap::needPeakList
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
Definition: msrunreader.cpp:165
pappso::MsRunReader::getMsRunId
const MsRunIdCstSPtr & getMsRunId() const
Definition: msrunreader.cpp:232
pappso::MsRunReaderScanNumberMultiMap::~MsRunReaderScanNumberMultiMap
virtual ~MsRunReaderScanNumberMultiMap()
Definition: msrunreader.cpp:158
pappso::MsRunReader::readSpectrumCollection
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler)=0
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
pappso::MsRunReader::hasScanNumbers
virtual bool hasScanNumbers() const
tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided func...
Definition: msrunreader.cpp:277
pappso::QualifiedMassSpectrum
Class representing a fully specified mass spectrum.
Definition: qualifiedmassspectrum.h:85
msRunReaderSPtrMetaTypeId
int msRunReaderSPtrMetaTypeId
Definition: msrunreader.cpp:37
pappso::SpectrumCollectionHandlerInterface::setNeedMsLevelPeakList
virtual void setNeedMsLevelPeakList(unsigned int ms_level, bool want_peak_list) final
tells if we need the peak list given
Definition: msrunreader.cpp:90
pappso::SpectrumCollectionHandlerInterface::needPeakList
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
pappso::MassSpectrumId::getSpectrumIndex
std::size_t getSpectrumIndex() const
Definition: massspectrumid.cpp:131
pappso::SpectrumCollectionHandlerInterface::setReadAhead
virtual void setReadAhead(bool is_read_ahead) final
use threads to read a spectrum by batch of batch_size
Definition: msrunreader.cpp:60
pappso::SpectrumCollectionHandlerInterface::m_needPeakListByMsLevel
std::vector< bool > m_needPeakListByMsLevel
Definition: msrunreader.h:136
pappso::SpectrumCollectionHandlerInterface::needMsLevelPeakList
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:72
pappso::ExceptionNotFound
Definition: exceptionnotfound.h:52
pappso::QualifiedMassSpectrum::getMassSpectrumId
const MassSpectrumId & getMassSpectrumId() const
Get the MassSpectrumId.
Definition: qualifiedmassspectrum.cpp:146
pappso::MsRunReaderScanNumberMultiMap
provides a multimap to find quickly spectrum index from scan number
Definition: msrunreader.h:154
pappso::MsRunSimpleStatistics::m_countMsLevelSpectrum
std::vector< unsigned long > m_countMsLevelSpectrum
Definition: msrunreader.h:139
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition: pappsoexception.h:108
pappso::MsRunSimpleStatistics::getMsLevelCount
unsigned long getMsLevelCount(unsigned int ms_level) const
Definition: msrunreader.cpp:130
pappso::MsRunReader::MsRunReader
MsRunReader(MsRunIdCstSPtr &ms_run_id)
Definition: msrunreader.cpp:220
pappso::SpectrumCollectionHandlerInterface::m_isReadAhead
bool m_isReadAhead
Definition: msrunreader.h:135
pappso::MsRunReader::~MsRunReader
virtual ~MsRunReader()
Definition: msrunreader.cpp:238
pappso::MsRunReaderScanNumberMultiMap::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
Definition: msrunreader.cpp:171
pappso::MsRunSimpleStatistics::needPeakList
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
Definition: msrunreader.cpp:100
pappso::PappsoException
Definition: pappsoexception.h:62