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 (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)
 
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
 
 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
 
XicExtractMethod m_xicExtractMethod = 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]

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

328{
329 QMutexLocker lock(&m_mutex);
330 std::vector<MsRunSliceSPtr> slice_list;
331 for(unsigned int i = mz_range.lower(); i <= mz_range.upper(); i++)
332 {
333 auto it = std::find_if(m_msRunSliceListCache.begin(),
335 [i](const MsRunSliceSPtr &slice_sp) {
336 return slice_sp.get()->getSliceNumber() == i;
337 });
338 if(it != m_msRunSliceListCache.end())
339 {
340 slice_list.push_back(*it);
341 m_msRunSliceListCache.push_back(*it);
342 }
343 else
344 {
345 MsRunSliceSPtr slice_sp = unserializeSlice(i);
346 slice_list.push_back(slice_sp);
347 m_msRunSliceListCache.push_back(slice_sp);
348 }
349 }
350
351 if(m_msRunSliceListCache.size() > 20)
352 {
353 m_msRunSliceListCache.pop_front();
354 }
355 return slice_list;
356}
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 252 of file msrunxicextractordisk.cpp.

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

References m_rtSize, and mpa_temporaryDirectory.

Referenced by storeSlices().

◆ endPwizRead()

void pappso::MsRunXicExtractorDisk::endPwizRead ( )
protectedvirtual

Reimplemented in pappso::MsRunXicExtractorDiskBuffer.

Definition at line 360 of file msrunxicextractordisk.cpp.

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

References pappso::MsRunXicExtractorInterface::msp_msrun_reader.

Referenced by serializeMsRun().

◆ extractOneXicCoord()

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

Definition at line 115 of file msrunxicextractordisk.cpp.

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

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

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

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

◆ serializeMsRun()

void pappso::MsRunXicExtractorDisk::serializeMsRun ( )
protected

Definition at line 167 of file msrunxicextractordisk.cpp.

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

240{
241 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
242
243 for(auto &&spectrum_pair : spectrum_map)
244 {
245 appendSliceOnDisk(spectrum_pair.first, spectrum_pair.second, ipos);
246 }
247
248 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
249}
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 286 of file msrunxicextractordisk.cpp.

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

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: