libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
msrunxicextractor.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/xicextractor/private/msrunxicextractorpwiz.cpp
3 * \date 07/05/2018
4 * \author Olivier Langella
5 * \brief simple proteowizard based XIC extractor
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 "msrunxicextractor.h"
32#include <QDebug>
33#include <QObject>
34
38
39namespace pappso
40{
41
42
44 : pappso::MsRunXicExtractorInterface(msrun_reader)
45{
46
48
49
51 config.setNeedPeakList(true);
52 config.setMsLevels({1});
53
54 msp_msrun_reader.get()->readSpectrumCollection2(config, get_msrun_points);
55
56 std::sort(
57 m_msrun_points.begin(),
58 m_msrun_points.end(),
59 [](const MsRunXicExtractorPoints &a, const MsRunXicExtractorPoints &b) { return a.rt < b.rt; });
60
61
62 if(m_msrun_points.size() == 0)
63 {
65 QObject::tr("error extracting XIC: no MS level 1 in data file"));
66 }
67}
71
72
78
79
80void
82 UiMonitorInterface &monitor,
83 std::vector<XicCoordSPtr>::iterator it_xic_coord_list_begin,
84 std::vector<XicCoordSPtr>::iterator it_xic_coord_list_end)
85{
86
87 // sort xic by mz:
88 std::sort(it_xic_coord_list_begin, it_xic_coord_list_end, [](XicCoordSPtr &a, XicCoordSPtr &b) {
89 return a.get()->rtTarget < b.get()->rtTarget;
90 });
91
92 for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
93 {
94 // XicCoord *p_xic_coord = sp_xic_coord.get();
95 extractOneXicCoord(*(it->get()));
96 monitor.count();
97 if(monitor.shouldIstop())
98 {
99 throw pappso::ExceptionInterrupted(QObject::tr("Xic extraction process interrupted"));
100 }
101 }
102}
103
104
105void
107{
108 FilterResampleKeepXRange keep_range(xic_coord.mzRange.lower(), xic_coord.mzRange.upper());
109 std::shared_ptr<Xic> msrunxic_sp = xic_coord.xicSptr;
110
111 double rt_begin = xic_coord.rtTarget - m_retentionTimeAroundTarget;
112 double rt_end = xic_coord.rtTarget + m_retentionTimeAroundTarget;
113
114
115 auto itpoints = m_msrun_points.begin();
116
117 // find startint retention time :
118 while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
119 {
120 itpoints++;
121 }
122 MassSpectrumSPtr spectrum;
123 DataPoint peak;
124 while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
125 {
126 spectrum = msp_msrun_reader.get()->massSpectrumSPtr(itpoints->spectrum_index);
127 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
128 // << spectrum->size(); spectrum->debugPrintValues();
129
130 qDebug() << " spectrum->size()=" << spectrum->size();
131 keep_range.filter(*(spectrum.get()));
132 qDebug() << " spectrum->size()=" << spectrum->size();
133
134 peak.x = itpoints->rt;
135
137 {
138 peak.y = 0;
139 if(spectrum->size() > 0)
140 {
141 peak.y = maxYDataPoint(spectrum->begin(), spectrum->end())->y;
142
143 qDebug() << " peak.y=" << peak.y << " 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}
155
156} // namespace pappso
Trace & filter(Trace &trace) const override
void setNeedPeakList(bool need_peak_list)
void setMsLevels(std::vector< std::size_t > ms_levels)
MsRunXicExtractorInterface(MsRunReaderSPtr &msrun_reader)
constructor is private, use the MsRunXicExtractorFactory
class to read retention time points of MsRun
MsRunXicExtractor(const MsRunXicExtractor &other)
void extractOneXicCoord(XicCoord &xic_coord)
std::vector< MsRunXicExtractorPoints > m_msrun_points
virtual void protectedExtractXicCoordSPtrList(UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end) override
pappso_double lower() const
Definition mzrange.h:71
pappso_double upper() const
Definition mzrange.h:77
virtual bool shouldIstop()=0
should the procces be stopped ? If true, then cancel process Use this function at strategic point of ...
virtual void count()=0
count steps report when a step is computed in an algorithm
@ max
maximum of intensities
Definition types.h:280
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition msrunreader.h:57
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:169
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:226
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44
pappso_double x
Definition datapoint.h:24
pappso_double y
Definition datapoint.h:25
coordinates of the XIC to extract and the resulting XIC after extraction
Definition xiccoord.h:68
XicSPtr xicSptr
extracted xic
Definition xiccoord.h:135
double rtTarget
the targeted retention time to extract around intended in seconds, and related to one msrun....
Definition xiccoord.h:131
MzRange mzRange
the mass to extract
Definition xiccoord.h:125