libpappsomspp
Library for mass spectrometry
pappso::MsRunXicExtractor Class Reference

#include <msrunxicextractor.h>

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

Classes

struct  MsRunXicExtractorPoints
 
class  MsRunXicExtractorReadPoints
 class to read retention time points of MsRun More...
 

Public Member Functions

 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...
 
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 More...
 
virtual void extractXicCoordSPtrListParallelized (UiMonitorInterface &monitor, std::vector< XicCoordSPtr > &xic_coord_list) final
 multithreaded XIC extraction More...
 
const MsRunIdCstSPtrgetMsRunId () const
 
const MsRunReaderSPtrgetMsRunReaderSPtr () const
 get the msrunreader currently used for XIC extraction More...
 
void setPostExtractionTraceFilterCstSPtr (pappso::FilterInterfaceCstSPtr &filter)
 filter interface to apply just after XIC extration on each trace More...
 

Protected Member Functions

 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)
 
virtual void protectedExtractXicCoordSPtrList (UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end) override
 
- Protected Member Functions inherited from pappso::MsRunXicExtractorInterface
 MsRunXicExtractorInterface (MsRunReaderSPtr &msrun_reader)
 constructor is private, use the MsRunXicExtractorFactory More...
 
 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 More...
 

Protected Attributes

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 41 of file msrunxicextractor.h.

Constructor & Destructor Documentation

◆ MsRunXicExtractor() [1/2]

pappso::MsRunXicExtractor::MsRunXicExtractor ( const MsRunXicExtractor other)

Definition at line 67 of file msrunxicextractor.cpp.

69 {
70  m_msrun_points = other.m_msrun_points;
71 }
MsRunXicExtractorInterface(MsRunReaderSPtr &msrun_reader)
constructor is private, use the MsRunXicExtractorFactory
std::vector< MsRunXicExtractorPoints > m_msrun_points

References m_msrun_points.

◆ ~MsRunXicExtractor()

pappso::MsRunXicExtractor::~MsRunXicExtractor ( )
virtual

Definition at line 62 of file msrunxicextractor.cpp.

63 {
64 }

◆ MsRunXicExtractor() [2/2]

pappso::MsRunXicExtractor::MsRunXicExtractor ( MsRunReaderSPtr msrun_reader)
protected

Definition at line 43 of file msrunxicextractor.cpp.

45 {
46 
47  MsRunXicExtractorReadPoints get_msrun_points(m_msrun_points);
48  msp_msrun_reader.get()->readSpectrumCollection(get_msrun_points);
49 
50  std::sort(m_msrun_points.begin(),
51  m_msrun_points.end(),
52  [](const MsRunXicExtractorPoints &a,
53  const MsRunXicExtractorPoints &b) { return a.rt < b.rt; });
54 
55 
56  if(m_msrun_points.size() == 0)
57  {
59  QObject::tr("error extracting XIC: no MS level 1 in data file"));
60  }
61 }

References pappso::a, pappso::b, m_msrun_points, and pappso::MsRunXicExtractorInterface::msp_msrun_reader.

Member Function Documentation

◆ extractOneXicCoord()

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

Definition at line 103 of file msrunxicextractor.cpp.

104 {
105  FilterResampleKeepXRange keep_range(xic_coord.mzRange.lower(),
106  xic_coord.mzRange.upper());
107  std::shared_ptr<Xic> msrunxic_sp = xic_coord.xicSptr;
108 
109  double rt_begin = xic_coord.rtTarget - m_retentionTimeAroundTarget;
110  double rt_end = xic_coord.rtTarget + m_retentionTimeAroundTarget;
111 
112 
113  auto itpoints = m_msrun_points.begin();
114 
115  // find startint retention time :
116  while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
117  {
118  itpoints++;
119  }
120  MassSpectrumSPtr spectrum;
121  DataPoint peak;
122  while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
123  {
124  spectrum =
125  msp_msrun_reader.get()->massSpectrumSPtr(itpoints->spectrum_index);
126  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
127  // << spectrum->size(); spectrum->debugPrintValues();
128 
129  qDebug() << " spectrum->size()=" << spectrum->size();
130  keep_range.filter(*(spectrum.get()));
131  qDebug() << " spectrum->size()=" << spectrum->size();
132 
133  peak.x = itpoints->rt;
134 
136  {
137  peak.y = 0;
138  if(spectrum->size() > 0)
139  {
140  peak.y = maxYDataPoint(spectrum->begin(), spectrum->end())->y;
141 
142  qDebug() << " peak.y=" << peak.y
143  << " spectrum->size()=" << spectrum->size();
144  }
145  }
146  else
147  {
148  peak.y = sumYTrace(spectrum->begin(), spectrum->end(), 0);
149  }
150  msrunxic_sp->push_back(peak);
151 
152  itpoints++;
153  }
154 }
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:180
double sumYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double init)
calculate the sum of y value of a trace
Definition: trace.cpp:244
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54
@ max
maximum of intensities

References pappso::FilterResampleKeepXRange::filter(), pappso::MzRange::lower(), m_msrun_points, pappso::MsRunXicExtractorInterface::m_retentionTimeAroundTarget, pappso::MsRunXicExtractorInterface::m_xicExtractMethod, pappso::max, pappso::maxYDataPoint(), pappso::MsRunXicExtractorInterface::msp_msrun_reader, pappso::XicCoord::mzRange, pappso::XicCoord::rtTarget, pappso::sumYTrace(), pappso::MzRange::upper(), pappso::DataPoint::x, pappso::XicCoord::xicSptr, and pappso::DataPoint::y.

Referenced by protectedExtractXicCoordSPtrList().

◆ getXicFromPwizMSDataFile()

void pappso::MsRunXicExtractor::getXicFromPwizMSDataFile ( std::vector< Xic * > &  xic_list,
const std::vector< MzRange > &  mass_range_list,
pappso::pappso_double  rt_begin,
pappso::pappso_double  rt_end 
)
protectedvirtual

Definition at line 157 of file msrunxicextractor.cpp.

162 {
163  qDebug();
164 
165  std::vector<DataPoint> peak_for_mass;
166  for(const MzRange &mass_range : mass_range_list)
167  {
168  peak_for_mass.push_back(DataPoint());
169  qDebug() << " mass_range=" << mass_range.getMz();
170  }
171 
172 
173  qDebug();
174 
175  auto itpoints = m_msrun_points.begin();
176 
177  while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
178  {
179  itpoints++;
180  }
181 
182  MassSpectrumCstSPtr spectrum;
183  while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
184  {
185  spectrum =
186  msp_msrun_reader.get()->massSpectrumCstSPtr(itpoints->spectrum_index);
187 
188  for(DataPoint &peak : peak_for_mass)
189  {
190  peak.x = itpoints->rt;
191  peak.y = 0;
192  }
193 
194 
195  // iterate through the m/z-intensity pairs
196  for(auto &&spectrum_point : *(spectrum.get()))
197  {
198  // qDebug() << "getXicFromPwizMSDataFile it->mz " << it->mz <<
199  // " it->intensity" << it->intensity;
200  for(std::size_t i = 0; i < mass_range_list.size(); i++)
201  {
202  if(mass_range_list[i].contains(spectrum_point.x))
203  {
205  {
206  if(peak_for_mass[i].y < spectrum_point.y)
207  {
208  peak_for_mass[i].y = spectrum_point.y;
209  }
210  }
211  else
212  {
213  peak_for_mass[i].y += spectrum_point.y;
214  }
215  }
216  }
217  }
218 
219  for(std::size_t i = 0; i < mass_range_list.size(); i++)
220  {
221  // qDebug() << "getXicFromPwizMSDataFile push_back " <<
222  // peak_for_mass[i].rt;
223  xic_list[i]->push_back(peak_for_mass[i]);
224  }
225 
226  itpoints++;
227  }
228 
229 
230  qDebug();
231 } // namespace pappso
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55

References m_msrun_points, pappso::MsRunXicExtractorInterface::m_xicExtractMethod, pappso::max, pappso::MsRunXicExtractorInterface::msp_msrun_reader, and pappso::y.

◆ protectedExtractXicCoordSPtrList()

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

Implements pappso::MsRunXicExtractorInterface.

Reimplemented in pappso::MsRunXicExtractorDisk.

Definition at line 75 of file msrunxicextractor.cpp.

79 {
80 
81  // sort xic by mz:
82  std::sort(it_xic_coord_list_begin,
83  it_xic_coord_list_end,
84  [](XicCoordSPtr &a, XicCoordSPtr &b) {
85  return a.get()->rtTarget < b.get()->rtTarget;
86  });
87 
88  for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
89  {
90  // XicCoord *p_xic_coord = sp_xic_coord.get();
91  extractOneXicCoord(*(it->get()));
92  monitor.count();
93  if(monitor.shouldIstop())
94  {
96  QObject::tr("Xic extraction process interrupted"));
97  }
98  }
99 }
void extractOneXicCoord(XicCoord &xic_coord)
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:41

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

Member Data Documentation

◆ m_msrun_points

std::vector<MsRunXicExtractorPoints> pappso::MsRunXicExtractor::m_msrun_points
protected

◆ MsRunXicExtractorFactory

friend pappso::MsRunXicExtractor::MsRunXicExtractorFactory
private

Definition at line 43 of file msrunxicextractor.h.


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