Loading...
Searching...
No Matches
msrunxicextractor.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/xicextractor/private/msrunxicextractorpwiz.cpp
* \date 07/05/2018
* \author Olivier Langella
* \brief simple proteowizard based XIC extractor
*/
/*******************************************************************************
* Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of the PAPPSOms++ library.
*
* PAPPSOms++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAPPSOms++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
*implementation
******************************************************************************/
#include "msrunxicextractor.h"
#include <QDebug>
#include <QObject>
#include "pappsomspp/core/pappsoexception.h"
#include "pappsomspp/core/exception/exceptioninterrupted.h"
#include "pappsomspp/core/processing/filters/filterresample.h"
namespace pappso
{
MsRunXicExtractor::MsRunXicExtractor(MsRunReaderSPtr &msrun_reader)
: pappso::MsRunXicExtractorInterface(msrun_reader)
{
MsRunXicExtractorReadPoints get_msrun_points(m_msrun_points);
pappso::MsRunReadConfig config;
config.setNeedPeakList(true);
config.setMsLevels({1});
msp_msrun_reader.get()->readSpectrumCollection2(config, get_msrun_points);
std::sort(
m_msrun_points.begin(),
m_msrun_points.end(),
[](const MsRunXicExtractorPoints &a, const MsRunXicExtractorPoints &b) { return a.rt < b.rt; });
if(m_msrun_points.size() == 0)
{
throw pappso::PappsoException(
QObject::tr("error extracting XIC: no MS level 1 in data file"));
}
}
MsRunXicExtractor::~MsRunXicExtractor()
{
}
MsRunXicExtractor::MsRunXicExtractor(const MsRunXicExtractor &other)
: MsRunXicExtractorInterface(other)
{
m_msrun_points = other.m_msrun_points;
}
void
MsRunXicExtractor::protectedExtractXicCoordSPtrList(
UiMonitorInterface &monitor,
std::vector<XicCoordSPtr>::iterator it_xic_coord_list_begin,
std::vector<XicCoordSPtr>::iterator it_xic_coord_list_end)
{
// sort xic by mz:
std::sort(it_xic_coord_list_begin, it_xic_coord_list_end, [](XicCoordSPtr &a, XicCoordSPtr &b) {
return a.get()->rtTarget < b.get()->rtTarget;
});
for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
{
// XicCoord *p_xic_coord = sp_xic_coord.get();
extractOneXicCoord(*(it->get()));
monitor.count();
if(monitor.shouldIstop())
{
throw pappso::ExceptionInterrupted(QObject::tr("Xic extraction process interrupted"));
}
}
}
void
MsRunXicExtractor::extractOneXicCoord(XicCoord &xic_coord)
{
FilterResampleKeepXRange keep_range(xic_coord.mzRange.lower(), xic_coord.mzRange.upper());
std::shared_ptr<Xic> msrunxic_sp = xic_coord.xicSptr;
double rt_begin = xic_coord.rtTarget - m_retentionTimeAroundTarget;
double rt_end = xic_coord.rtTarget + m_retentionTimeAroundTarget;
auto itpoints = m_msrun_points.begin();
// find startint retention time :
while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
{
itpoints++;
}
MassSpectrumSPtr spectrum;
DataPoint peak;
while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
{
spectrum = msp_msrun_reader.get()->massSpectrumSPtr(itpoints->spectrum_index);
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
// << spectrum->size(); spectrum->debugPrintValues();
qDebug() << " spectrum->size()=" << spectrum->size();
keep_range.filter(*(spectrum.get()));
qDebug() << " spectrum->size()=" << spectrum->size();
peak.x = itpoints->rt;
if(m_xicExtractMethod == Enums::XicExtractMethod::max)
{
peak.y = 0;
if(spectrum->size() > 0)
{
peak.y = maxYDataPoint(spectrum->begin(), spectrum->end())->y;
qDebug() << " peak.y=" << peak.y << " spectrum->size()=" << spectrum->size();
}
}
else
{
peak.y = sumYTrace(spectrum->begin(), spectrum->end(), 0);
}
msrunxic_sp->push_back(peak);
itpoints++;
}
}
} // namespace pappso
pappso::ExceptionInterrupted
Definition exceptioninterrupted.h:36
pappso::FilterResampleKeepXRange
Definition filterresample.h:89
pappso::FilterResampleKeepXRange::filter
Trace & filter(Trace &trace) const override
Definition filterresample.cpp:159
pappso::MsRunReadConfig
Definition msrunreadconfig.h:62
pappso::MsRunReadConfig::setNeedPeakList
void setNeedPeakList(bool need_peak_list)
Definition msrunreadconfig.cpp:173
pappso::MsRunReadConfig::setMsLevels
void setMsLevels(std::vector< std::size_t > ms_levels)
Definition msrunreadconfig.cpp:89
pappso::MsRunXicExtractorInterface::m_retentionTimeAroundTarget
double m_retentionTimeAroundTarget
Definition msrunxicextractorinterface.h:120
pappso::MsRunXicExtractorInterface::m_xicExtractMethod
Enums::XicExtractMethod m_xicExtractMethod
Definition msrunxicextractorinterface.h:119
pappso::MsRunXicExtractorInterface::msp_msrun_reader
MsRunReaderSPtr msp_msrun_reader
Definition msrunxicextractorinterface.h:118
pappso::MsRunXicExtractorInterface::MsRunXicExtractorInterface
MsRunXicExtractorInterface(MsRunReaderSPtr &msrun_reader)
constructor is private, use the MsRunXicExtractorFactory
Definition msrunxicextractorinterface.cpp:40
pappso::MsRunXicExtractor::MsRunXicExtractorReadPoints
class to read retention time points of MsRun
Definition msrunxicextractor.h:68
pappso::MsRunXicExtractor::MsRunXicExtractor
MsRunXicExtractor(const MsRunXicExtractor &other)
Definition msrunxicextractor.cpp:73
pappso::MsRunXicExtractor::extractOneXicCoord
void extractOneXicCoord(XicCoord &xic_coord)
Definition msrunxicextractor.cpp:106
pappso::MsRunXicExtractor::m_msrun_points
std::vector< MsRunXicExtractorPoints > m_msrun_points
Definition msrunxicextractor.h:99
pappso::MsRunXicExtractor::~MsRunXicExtractor
virtual ~MsRunXicExtractor()
Definition msrunxicextractor.cpp:68
pappso::MsRunXicExtractor::protectedExtractXicCoordSPtrList
virtual void protectedExtractXicCoordSPtrList(UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end) override
Definition msrunxicextractor.cpp:81
pappso::MzRange::lower
pappso_double lower() const
Definition mzrange.h:71
pappso::MzRange::upper
pappso_double upper() const
Definition mzrange.h:77
pappso::PappsoException
Definition pappsoexception.h:41
pappso::UiMonitorInterface
Definition uimonitorinterface.h:50
pappso::UiMonitorInterface::shouldIstop
virtual bool shouldIstop()=0
should the procces be stopped ? If true, then cancel process Use this function at strategic point of ...
pappso::UiMonitorInterface::count
virtual void count()=0
count steps report when a step is computed in an algorithm
exceptioninterrupted.h
filterresample.h
msrunxicextractor.h
pappso::Enums::XicExtractMethod::max
@ max
maximum of intensities
Definition types.h:280
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::MsRunReaderSPtr
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition msrunreader.h:57
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:169
pappso::PeptideIonNter::a
@ a
Definition peptide.h:77
pappso::PeptideIonNter::b
@ b
Definition peptide.h:74
pappso::sumYTrace
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
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition massspectrum.h:53
pappso::XicCoordSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44
pappsoexception.h
pappso::DataPoint
Definition datapoint.h:22
pappso::DataPoint::x
pappso_double x
Definition datapoint.h:24
pappso::DataPoint::y
pappso_double y
Definition datapoint.h:25
pappso::MsRunXicExtractor::MsRunXicExtractorPoints
Definition msrunxicextractor.h:60
pappso::XicCoord
coordinates of the XIC to extract and the resulting XIC after extraction
Definition xiccoord.h:68
pappso::XicCoord::xicSptr
XicSPtr xicSptr
extracted xic
Definition xiccoord.h:135
pappso::XicCoord::rtTarget
double rtTarget
the targeted retention time to extract around intended in seconds, and related to one msrun....
Definition xiccoord.h:131
pappso::XicCoord::mzRange
MzRange mzRange
the mass to extract
Definition xiccoord.h:125