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 ()
 
virtual void extractXicCoordSPtrList (UiMonitorInterface &monitor, std::vector< XicCoordSPtr > &xic_coord_list) override
 extract a list of XIC given a list of xic coordinates to extract More...
 
- 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...
 
const MsRunIdCstSPtrgetMsRunId () const
 
const MsRunReaderSPtrgetMsRunReaderSPtr () const
 get the msrunreader currently used for XIC extraction 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)
 
- Protected Member Functions inherited from pappso::MsRunXicExtractorInterface
 MsRunXicExtractorInterface (MsRunReaderSPtr &msrun_reader)
 constructor is private, use the MsRunXicExtractorFactory More...
 
 MsRunXicExtractorInterface (const MsRunXicExtractorInterface &other)
 
virtual ~MsRunXicExtractorInterface ()
 

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()
 

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 65 of file msrunxicextractor.cpp.

67 {
68  m_msrun_points = other.m_msrun_points;
69 }
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 60 of file msrunxicextractor.cpp.

61 {
62 }

◆ MsRunXicExtractor() [2/2]

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

Definition at line 41 of file msrunxicextractor.cpp.

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

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 102 of file msrunxicextractor.cpp.

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

◆ extractXicCoordSPtrList()

void pappso::MsRunXicExtractor::extractXicCoordSPtrList ( UiMonitorInterface monitor,
std::vector< XicCoordSPtr > &  xic_coord_list 
)
overridevirtual

extract a list of XIC given a list of xic coordinates to extract

XicCoord is a vessel containing the xic to fill and coordinates of this XIC in the MS run

Parameters
monitorprocess monitoring
xic_coord_listlist of xic coordinates to extract. The order of xic coordinates may change.

Implements pappso::MsRunXicExtractorInterface.

Reimplemented in pappso::MsRunXicExtractorDisk.

Definition at line 73 of file msrunxicextractor.cpp.

75 {
76 
77  monitor.setStatus(
78  QObject::tr("extracting %1 XICs").arg(xic_coord_list.size()));
79  monitor.setTotalSteps(xic_coord_list.size());
80  // sort xic by mz:
81  std::sort(xic_coord_list.begin(),
82  xic_coord_list.end(),
83  [](XicCoordSPtr &a, XicCoordSPtr &b) {
84  return a.get()->rtTarget < b.get()->rtTarget;
85  });
86 
87  for(XicCoordSPtr &sp_xic_coord : xic_coord_list)
88  {
89  // XicCoord *p_xic_coord = sp_xic_coord.get();
90  extractOneXicCoord(*(sp_xic_coord.get()));
91  monitor.count();
92  if(monitor.shouldIstop())
93  {
95  QObject::tr("Xic extraction process interrupted"));
96  }
97  }
98 }
void extractOneXicCoord(XicCoord &xic_coord)
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:41

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

◆ 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 156 of file msrunxicextractor.cpp.

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

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: