pappsomspp
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 {
57 }
58 void
60 {
61  m_isReadAhead = is_read_ahead;
62 }
63 
64 bool
66 {
67  return m_isReadAhead;
68 }
69 
70 bool
72  unsigned int ms_level) const
73 {
74  if(needPeakList() == true)
75  {
76  if(ms_level < m_needPeakListByMsLevel.size())
77  {
78  return m_needPeakListByMsLevel[ms_level];
79  }
80  else
81  return true;
82  }
83  else
84  {
85  return false;
86  }
87 }
88 void
90  unsigned int ms_level, bool want_peak_list)
91 {
92  if(ms_level < m_needPeakListByMsLevel.size())
93  {
94  m_needPeakListByMsLevel[ms_level] = want_peak_list;
95  }
96 }
97 
98 bool
100 {
101  return false;
102 }
103 
104 
105 void
107 {
108  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
109  << "The data loading process ended.";
110 }
111 
112 
113 void
115  const QualifiedMassSpectrum &qspectrum)
116 {
117  unsigned int ms_level = qspectrum.getMsLevel();
118  if(ms_level == 0)
119  return;
120  if(ms_level > m_countMsLevelSpectrum.size())
121  {
122  m_countMsLevelSpectrum.resize(ms_level);
123  }
124  m_countMsLevelSpectrum[ms_level - 1]++;
125 }
126 
127 
128 unsigned long
129 MsRunSimpleStatistics::getMsLevelCount(unsigned int ms_level) const
130 {
131  if(ms_level == 0)
132  return 0;
133  if(ms_level > m_countMsLevelSpectrum.size())
134  return 0;
135  return (m_countMsLevelSpectrum[ms_level - 1]);
136 }
137 
138 
139 unsigned long
141 {
142  unsigned long total = 0;
143  for(unsigned long count : m_countMsLevelSpectrum)
144  {
145  total += count;
146  }
147  return total;
148 }
149 
150 
152 {
153  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
154 }
156 {
157  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
158 }
159 bool
161 {
162  return false;
163 }
164 
165 void
167  const QualifiedMassSpectrum &qspectrum)
168 {
169  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
170  << " " << qspectrum.getMassSpectrumId().getNativeId();
171  QStringList native_id_list =
172  qspectrum.getMassSpectrumId().getNativeId().split("=");
173  if(native_id_list.size() < 2)
174  {
175  return;
176  }
177  else
178  {
179  std::size_t scan_number = native_id_list.back().toULong();
180  m_mmap_scan2index.insert(std::pair<std::size_t, std::size_t>(
181  scan_number, qspectrum.getMassSpectrumId().getSpectrumIndex()));
182  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
183  << " " << scan_number << "=>"
184  << qspectrum.getMassSpectrumId().getSpectrumIndex();
185  }
186 }
187 
188 std::size_t
190  std::size_t scan_number) const
191 {
192 
193  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
194  << " " << m_mmap_scan2index.size();
195  auto it = m_mmap_scan2index.find(scan_number);
196  if(it == m_mmap_scan2index.end())
197  {
198  throw ExceptionNotFound(
199  QObject::tr("scan number %1 not found").arg(scan_number));
200  }
201  std::size_t index = it->second;
202  it++;
203  if((it != m_mmap_scan2index.end()) && (it->first == scan_number))
204  {
205  throw PappsoException(
206  QObject::tr("scan number %1 found multiple times").arg(scan_number));
207  }
208  return index;
209 }
210 
211 
212 MsRunReader::MsRunReader(MsRunIdCstSPtr &ms_run_id) : mcsp_msRunId(ms_run_id)
213 {
214 }
215 
217  : mcsp_msRunId(other.mcsp_msRunId)
218 {
219  mpa_multiMapScanNumber = nullptr;
220 }
221 
222 
225 {
226  return mcsp_msRunId;
227 }
228 
229 
231 {
232  if(mpa_multiMapScanNumber == nullptr)
233  delete mpa_multiMapScanNumber;
234 }
235 
236 
237 std::size_t
238 MsRunReader::scanNumber2SpectrumIndex(std::size_t scan_number)
239 {
240  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
241  << " " << mpa_multiMapScanNumber;
242  if(mpa_multiMapScanNumber == nullptr)
243  {
246  }
247  try
248  {
250  scan_number);
251  }
252 
253  catch(ExceptionNotFound &error)
254  {
255  throw ExceptionNotFound(QObject::tr("error reading file %1 : %2")
256  .arg(mcsp_msRunId.get()->getFileName())
257  .arg(error.qwhat()));
258  }
259  catch(PappsoException &error)
260  {
261  throw PappsoException(QObject::tr("error reading file %1 : %2")
262  .arg(mcsp_msRunId.get()->getFileName())
263  .arg(error.qwhat()));
264  }
265 }
266 
267 
268 bool
270 {
271  return false;
272 }
273 
274 
275 } // namespace pappso
pappso::QualifiedMassSpectrum::getMsLevel
uint getMsLevel() const
Get the mass spectrum level.
Definition: qualifiedmassspectrum.cpp:210
pappso::MsRunReader
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition: msrunreader.h:174
pappso::MsRunSimpleStatistics::getTotalCount
unsigned long getTotalCount() const
Definition: msrunreader.cpp:139
pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize
virtual void spectrumListHasSize(std::size_t size)
Definition: msrunreader.cpp:54
pappso::SpectrumCollectionHandlerInterface::isReadAhead
virtual bool isReadAhead() const
tells if we want to read ahead spectrum
Definition: msrunreader.cpp:64
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:237
pappso
Definition: aa.cpp:38
pappso::MassSpectrumId::getNativeId
const QString & getNativeId() const
Definition: massspectrumid.cpp:116
pappso::MsRunReaderScanNumberMultiMap::getSpectrumIndexFromScanNumber
std::size_t getSpectrumIndexFromScanNumber(std::size_t scan_number) const
Definition: msrunreader.cpp:188
pappso::MsRunReader::mpa_multiMapScanNumber
MsRunReaderScanNumberMultiMap * mpa_multiMapScanNumber
Definition: msrunreader.h:225
pappso::MsRunIdCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition: msrunid.h:63
pappso::MsRunReaderScanNumberMultiMap::m_mmap_scan2index
std::multimap< std::size_t, std::size_t > m_mmap_scan2index
Definition: msrunreader.h:154
pappso::MsRunSimpleStatistics::loadingEnded
virtual void loadingEnded() override
Definition: msrunreader.cpp:105
pappso::MsRunReaderScanNumberMultiMap::MsRunReaderScanNumberMultiMap
MsRunReaderScanNumberMultiMap()
Definition: msrunreader.cpp:150
pappso::SpectrumCollectionHandlerInterface::shouldStop
virtual bool shouldStop()
Definition: msrunreader.cpp:45
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition: msrunreader.h:224
pappso::MsRunSimpleStatistics::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
Definition: msrunreader.cpp:113
pappso::SpectrumCollectionHandlerInterface::loadingEnded
virtual void loadingEnded()
Definition: msrunreader.cpp:50
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:159
pappso::MsRunReader::getMsRunId
const MsRunIdCstSPtr & getMsRunId() const
Definition: msrunreader.cpp:223
pappso::MsRunReaderScanNumberMultiMap::~MsRunReaderScanNumberMultiMap
virtual ~MsRunReaderScanNumberMultiMap()
Definition: msrunreader.cpp:154
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:268
pappso::QualifiedMassSpectrum
Class representing a fully specified mass spectrum.
Definition: qualifiedmassspectrum.h:83
msRunReaderSPtrMetaTypeId
int msRunReaderSPtrMetaTypeId
Definition: msrunreader.cpp:36
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:88
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:130
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:58
pappso::SpectrumCollectionHandlerInterface::m_needPeakListByMsLevel
std::vector< bool > m_needPeakListByMsLevel
Definition: msrunreader.h:133
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:70
pappso::ExceptionNotFound
Definition: exceptionnotfound.h:50
pappso::QualifiedMassSpectrum::getMassSpectrumId
const MassSpectrumId & getMassSpectrumId() const
Get the MassSpectrumId.
Definition: qualifiedmassspectrum.cpp:124
pappso::MsRunReaderScanNumberMultiMap
provides a multimap to find quickly spectrum index from scan number
Definition: msrunreader.h:151
pappso::MsRunSimpleStatistics::m_countMsLevelSpectrum
std::vector< unsigned long > m_countMsLevelSpectrum
Definition: msrunreader.h:136
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition: pappsoexception.h:105
pappso::MsRunSimpleStatistics::getMsLevelCount
unsigned long getMsLevelCount(unsigned int ms_level) const
Definition: msrunreader.cpp:128
pappso::MsRunReader::MsRunReader
MsRunReader(MsRunIdCstSPtr &ms_run_id)
Definition: msrunreader.cpp:211
pappso::SpectrumCollectionHandlerInterface::m_isReadAhead
bool m_isReadAhead
Definition: msrunreader.h:132
pappso::MsRunReader::~MsRunReader
virtual ~MsRunReader()
Definition: msrunreader.cpp:229
pappso::MsRunReaderScanNumberMultiMap::setQualifiedMassSpectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
Definition: msrunreader.cpp:165
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:98
pappso::PappsoException
Definition: pappsoexception.h:60