libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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 ()
Public Member Functions inherited from pappso::MsRunXicExtractor
 MsRunXicExtractor (const MsRunXicExtractor &other)
virtual ~MsRunXicExtractor ()
Public Member Functions inherited from pappso::MsRunXicExtractorInterface
void setXicExtractMethod (Enums::XicExtractMethod method)
 set the XIC extraction method
void setRetentionTimeAroundTarget (double range_in_seconds)
 set the retention time range in seconds around the target rt
virtual void extractXicCoordSPtrList (UiMonitorInterface &monitor, std::vector< XicCoordSPtr > &xic_coord_list) final
 extract a list of XIC given a list of xic coordinates to extract
virtual void extractXicCoordSPtrListParallelized (UiMonitorInterface &monitor, std::vector< XicCoordSPtr > &xic_coord_list) final
 multithreaded XIC extraction
const MsRunIdCstSPtrgetMsRunId () const
const MsRunReaderSPtrgetMsRunReaderSPtr () const
 get the msrunreader currently used for XIC extraction
void setPostExtractionTraceFilterCstSPtr (pappso::FilterInterfaceCstSPtr &filter)
 filter interface to apply just after XIC extration on each trace

Protected Member Functions

 MsRunXicExtractorDisk (MsRunReaderSPtr &msrun_reader, const QDir &temporary_dir)
virtual void protectedExtractXicCoordSPtrList (UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end) override
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
void appendSliceOnDisk (unsigned int slice_number, MassSpectrum &spectrum, std::size_t ipos)
 append a slice on disk (in a file)
std::vector< MsRunSliceSPtracquireSlices (const MzRange &mz_range)
 retrieve all the slices corresponding to a given mz_range
MsRunSliceSPtr unserializeSlice (unsigned int slice_number)
 get one slice from disk by her slice number (dalton)
virtual void endPwizRead ()
Protected Member Functions inherited from pappso::MsRunXicExtractor
 MsRunXicExtractor (MsRunReaderSPtr &msrun_reader)
Protected Member Functions inherited from pappso::MsRunXicExtractorInterface
 MsRunXicExtractorInterface (MsRunReaderSPtr &msrun_reader)
 constructor is private, use the MsRunXicExtractorFactory
 MsRunXicExtractorInterface (const MsRunXicExtractorInterface &other)
virtual ~MsRunXicExtractorInterface ()
virtual void postExtractionProcess (UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end)
 possible post extraction process, eventually trace filters

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
Enums::XicExtractMethod m_xicExtractMethod = Enums::XicExtractMethod::max
double m_retentionTimeAroundTarget = std::numeric_limits<double>::max()
pappso::FilterInterfaceCstSPtr mcsp_postExtractionTraceFilter = nullptr

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]

◆ MsRunXicExtractorDisk() [2/3]

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

Definition at line 47 of file msrunxicextractordisk.cpp.

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

References pappso::MsRunXicExtractor::MsRunXicExtractor(), MsRunXicExtractorDisk(), 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 pappso::MsRunXicExtractor::MsRunXicExtractor(), 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 315 of file msrunxicextractordisk.cpp.

316{
317 QMutexLocker lock(&m_mutex);
318 std::vector<MsRunSliceSPtr> slice_list;
319 for(unsigned int i = mz_range.lower(); i <= mz_range.upper(); i++)
320 {
321 auto it = std::find_if(
322 m_msRunSliceListCache.begin(),
324 [i](const MsRunSliceSPtr &slice_sp) { return slice_sp.get()->getSliceNumber() == i; });
325 if(it != m_msRunSliceListCache.end())
326 {
327 slice_list.push_back(*it);
328 m_msRunSliceListCache.push_back(*it);
329 }
330 else
331 {
332 MsRunSliceSPtr slice_sp = unserializeSlice(i);
333 slice_list.push_back(slice_sp);
334 m_msRunSliceListCache.push_back(slice_sp);
335 }
336 }
337
338 if(m_msRunSliceListCache.size() > 20)
339 {
340 m_msRunSliceListCache.pop_front();
341 }
342 return slice_list;
343}
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:40

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 246 of file msrunxicextractordisk.cpp.

249{
250 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
251 QFile slice_file(QString("%1/%2").arg(mpa_temporaryDirectory->path()).arg(slice_number));
252 bool new_file = false;
253 if(!slice_file.exists())
254 {
255 new_file = true;
256 }
257 if(!slice_file.open(QIODevice::WriteOnly | QIODevice::Append))
258 {
259 throw pappso::PappsoException(
260 QObject::tr("unable to open file %1").arg(slice_file.fileName()));
261 }
262 QDataStream stream(&slice_file);
263
264 if(new_file)
265 {
266 stream << (quint32)slice_number;
267 stream << (quint32)m_rtSize;
268 }
269
270 stream << (quint32)ipos;
271 stream << spectrum;
272
273 slice_file.flush();
274 slice_file.close();
275 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
276}

References m_rtSize, and mpa_temporaryDirectory.

Referenced by storeSlices().

◆ endPwizRead()

void pappso::MsRunXicExtractorDisk::endPwizRead ( )
protectedvirtual

Reimplemented in pappso::MsRunXicExtractorDiskBuffer.

Definition at line 347 of file msrunxicextractordisk.cpp.

348{
349 msp_msrun_reader.get()->releaseDevice();
350}

References pappso::MsRunXicExtractorInterface::msp_msrun_reader.

Referenced by serializeMsRun().

◆ extractOneXicCoord()

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

Definition at line 111 of file msrunxicextractordisk.cpp.

112{
113 std::shared_ptr<Xic> msrunxic_sp = xic_coord.xicSptr;
114
115 double rt_begin = xic_coord.rtTarget - m_retentionTimeAroundTarget;
116 double rt_end = xic_coord.rtTarget + m_retentionTimeAroundTarget;
117
118
119 std::vector<MsRunSliceSPtr> slice_list;
120 slice_list = acquireSlices(xic_coord.mzRange);
121
122 if(slice_list.size() == 0)
123 {
124 throw pappso::PappsoException(QObject::tr("Error getMsRunXicSp slice_list.size() == 0"));
125 }
126
127 for(std::size_t i = 0; i < m_retentionTimeList.size(); i++)
128 {
129
130 DataPoint xic_element;
131 xic_element.x = m_retentionTimeList[i];
132 xic_element.y = 0;
133 if((xic_element.x < rt_begin) || (xic_element.x > rt_end))
134 continue;
135
136 for(auto &&msrun_slice : slice_list)
137 {
138 const MassSpectrum &spectrum = msrun_slice.get()->getSpectrum(i);
139 for(auto &&peak : spectrum)
140 {
141 if(xic_coord.mzRange.contains(peak.x))
142 {
144 {
145 xic_element.y += peak.y;
146 }
147 else
148 {
149 if(xic_element.y < peak.y)
150 {
151 xic_element.y = peak.y;
152 }
153 }
154 }
155 }
156 }
157 msrunxic_sp.get()->push_back(xic_element);
158 }
159}
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
Definition types.h:279

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

Referenced by protectedExtractXicCoordSPtrList().

◆ 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();
78 throw pappso::PappsoException(QObject::tr("Error reading file (%1) : %2")
79 .arg(msp_msrun_reader.get()->getMsRunId().get()->toString())
80 .arg(errora.qwhat()));
81 }
82 catch(std::exception &error)
83 {
84 qDebug();
85 throw pappso::PappsoException(QObject::tr("Error reading file (%1) using : %2")
86 .arg(msp_msrun_reader.get()->getMsRunId().get()->toString())
87 .arg(error.what()));
88 }
89}
virtual const QString & qwhat() const

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

◆ protectedExtractXicCoordSPtrList()

void pappso::MsRunXicExtractorDisk::protectedExtractXicCoordSPtrList ( UiMonitorInterface & monitor,
std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin,
std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end )
overrideprotectedvirtual

Reimplemented from pappso::MsRunXicExtractor.

Definition at line 93 of file msrunxicextractordisk.cpp.

97{
98 // sort xic by mz:
99 std::sort(it_xic_coord_list_begin, it_xic_coord_list_end, [](XicCoordSPtr &a, XicCoordSPtr &b) {
100 return a.get()->mzRange.getMz() < b.get()->mzRange.getMz();
101 });
102
103 for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
104 {
105 extractOneXicCoord(*(it->get()));
106 monitor.count();
107 }
108}
void extractOneXicCoord(XicCoord &xic_coord)
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44

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

◆ serializeMsRun()

void pappso::MsRunXicExtractorDisk::serializeMsRun ( )
protected

Definition at line 162 of file msrunxicextractordisk.cpp.

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

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 232 of file msrunxicextractordisk.cpp.

234{
235 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
236
237 for(auto &&spectrum_pair : spectrum_map)
238 {
239 appendSliceOnDisk(spectrum_pair.first, spectrum_pair.second, ipos);
240 }
241
242 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
243}
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 279 of file msrunxicextractordisk.cpp.

280{
281 qDebug();
282 try
283 {
284 std::shared_ptr<MsRunSlice> msrun_slice_sp = std::make_shared<MsRunSlice>(MsRunSlice());
285
286 QFile slice_file(QString("%1/%2").arg(mpa_temporaryDirectory->path()).arg(slice_number));
287 if(!slice_file.exists())
288 {
289 msrun_slice_sp.get()->setSize(m_rtSize);
290 msrun_slice_sp.get()->setSliceNumber(slice_number);
291 return msrun_slice_sp;
292 }
293 if(!slice_file.open(QIODevice::ReadOnly))
294 {
295 throw pappso::PappsoException(
296 QObject::tr("unable to open file %1 in readonly").arg(slice_file.fileName()));
297 }
298 QDataStream stream(&slice_file);
299
300 stream >> *(msrun_slice_sp.get());
301
302 slice_file.close();
303
304 return msrun_slice_sp;
305 }
306 catch(pappso::PappsoException &error)
307 {
308 throw pappso::PappsoException(
309 QObject::tr("error unserializing slice %1:\n%2").arg(slice_number).arg(error.qwhat()));
310 }
311 qDebug();
312}

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 103 of file msrunxicextractordisk.h.

Referenced by serializeMsRun().

◆ m_minMz

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

Definition at line 104 of file msrunxicextractordisk.h.

Referenced by serializeMsRun().

◆ m_msRunSliceListCache

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

Definition at line 108 of file msrunxicextractordisk.h.

Referenced by acquireSlices().

◆ m_mutex

QMutex pappso::MsRunXicExtractorDisk::m_mutex
protected

Definition at line 110 of file msrunxicextractordisk.h.

Referenced by acquireSlices().

◆ m_retentionTimeList

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

Definition at line 101 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 99 of file msrunxicextractordisk.h.

Referenced by MsRunXicExtractorDisk(), and 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: