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 "../../pappsoexception.h"
#include "../../exception/exceptioninterrupted.h"
#include "../../processing/filters/filterresample.h"
namespace pappso
{
MsRunXicExtractor::MsRunXicExtractor(MsRunReaderSPtr &msrun_reader)
: pappso::MsRunXicExtractorInterface(msrun_reader)
{
MsRunXicExtractorReadPoints get_msrun_points(m_msrun_points);
msp_msrun_reader.get()->readSpectrumCollection(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 == 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++;
}
}
void
MsRunXicExtractor::getXicFromPwizMSDataFile(
std::vector<Xic *> &xic_list,
const std::vector<MzRange> &mass_range_list,
pappso::pappso_double rt_begin,
pappso::pappso_double rt_end)
{
qDebug();
std::vector<DataPoint> peak_for_mass;
for(const MzRange &mass_range : mass_range_list)
{
peak_for_mass.push_back(DataPoint());
qDebug() << " mass_range=" << mass_range.getMz();
}
qDebug();
auto itpoints = m_msrun_points.begin();
while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
{
itpoints++;
}
MassSpectrumCstSPtr spectrum;
while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
{
spectrum =
msp_msrun_reader.get()->massSpectrumCstSPtr(itpoints->spectrum_index);
for(DataPoint &peak : peak_for_mass)
{
peak.x = itpoints->rt;
peak.y = 0;
}
// iterate through the m/z-intensity pairs
for(auto &&spectrum_point : *(spectrum.get()))
{
// qDebug() << "getXicFromPwizMSDataFile it->mz " << it->mz <<
// " it->intensity" << it->intensity;
for(std::size_t i = 0; i < mass_range_list.size(); i++)
{
if(mass_range_list[i].contains(spectrum_point.x))
{
if(m_xicExtractMethod == XicExtractMethod::max)
{
if(peak_for_mass[i].y < spectrum_point.y)
{
peak_for_mass[i].y = spectrum_point.y;
}
}
else
{
peak_for_mass[i].y += spectrum_point.y;
}
}
}
}
for(std::size_t i = 0; i < mass_range_list.size(); i++)
{
// qDebug() << "getXicFromPwizMSDataFile push_back " <<
// peak_for_mass[i].rt;
xic_list[i]->push_back(peak_for_mass[i]);
}
itpoints++;
}
qDebug();
} // namespace pappso
} // namespace pappso
pappso::ExceptionInterrupted
Definition exceptioninterrupted.h:36
pappso::FilterResampleKeepXRange
Definition filterresample.h:87
pappso::FilterResampleKeepXRange::filter
Trace & filter(Trace &trace) const override
Definition filterresample.cpp:168
pappso::MsRunXicExtractorInterface
Definition msrunxicextractorinterface.h:49
pappso::MsRunXicExtractorInterface::m_retentionTimeAroundTarget
double m_retentionTimeAroundTarget
Definition msrunxicextractorinterface.h:128
pappso::MsRunXicExtractorInterface::msp_msrun_reader
MsRunReaderSPtr msp_msrun_reader
Definition msrunxicextractorinterface.h:126
pappso::MsRunXicExtractorInterface::m_xicExtractMethod
XicExtractMethod m_xicExtractMethod
Definition msrunxicextractorinterface.h:127
pappso::MsRunXicExtractor::MsRunXicExtractorReadPoints
class to read retention time points of MsRun
Definition msrunxicextractor.h:74
pappso::MsRunXicExtractor
Definition msrunxicextractor.h:42
pappso::MsRunXicExtractor::getXicFromPwizMSDataFile
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)
Definition msrunxicextractor.cpp:157
pappso::MsRunXicExtractor::MsRunXicExtractor
MsRunXicExtractor(const MsRunXicExtractor &other)
Definition msrunxicextractor.cpp:67
pappso::MsRunXicExtractor::extractOneXicCoord
void extractOneXicCoord(XicCoord &xic_coord)
Definition msrunxicextractor.cpp:103
pappso::MsRunXicExtractor::m_msrun_points
std::vector< MsRunXicExtractorPoints > m_msrun_points
Definition msrunxicextractor.h:106
pappso::MsRunXicExtractor::~MsRunXicExtractor
virtual ~MsRunXicExtractor()
Definition msrunxicextractor.cpp:62
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:75
pappso::MzRange
Definition mzrange.h:46
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:42
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
msrunxicextractor.h
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:56
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:180
pappso::PeptideIonNter::a
@ a
pappso::PeptideIonNter::b
@ b
pappso::PeptideIonCter::y
@ y
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition types.h:50
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition massspectrum.h:57
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:244
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition massspectrum.h:56
pappso::XicExtractMethod::max
@ max
maximum of intensities
pappso::XicCoordSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:43
pappso::DataPoint
Definition datapoint.h:22
pappso::DataPoint::x
pappso_double x
Definition datapoint.h:23
pappso::DataPoint::y
pappso_double y
Definition datapoint.h:24
pappso::MsRunXicExtractor::MsRunXicExtractorPoints
Definition msrunxicextractor.h:66
pappso::XicCoord
coordinates of the XIC to extract and the resulting XIC after extraction
Definition xiccoord.h:67
pappso::XicCoord::xicSptr
XicSPtr xicSptr
extracted xic
Definition xiccoord.h:130
pappso::XicCoord::rtTarget
double rtTarget
the targeted retention time to extract around intended in seconds, and related to one msrun....
Definition xiccoord.h:126
pappso::XicCoord::mzRange
MzRange mzRange
the mass to extract
Definition xiccoord.h:120