From bd1467f79e641cf3c28141c58b1ced634792e29b Mon Sep 17 00:00:00 2001 From: Olivier Langella <olivier.langella@u-psud.fr> Date: Thu, 12 Jul 2018 21:47:48 +0200 Subject: [PATCH] compute TIC on spectrum ms levels --- src/CMakeLists.txt | 1 + src/core/msrun.cpp | 9 ++- src/utils/msrunstatisticshandler.cpp | 92 ++++++++++++++++++++++++++++ src/utils/msrunstatisticshandler.h | 48 +++++++++++++++ src/utils/types.h | 3 + 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/utils/msrunstatisticshandler.cpp create mode 100644 src/utils/msrunstatisticshandler.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 840bbd57b..e4de9a708 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -152,6 +152,7 @@ SET(CPP_FILES utils/fastafilestore.cpp utils/identificationdatasourcestore.cpp utils/groupstore.cpp + utils/msrunstatisticshandler.cpp utils/msrunstore.cpp utils/peptideevidencestore.cpp utils/peptidestore.cpp diff --git a/src/core/msrun.cpp b/src/core/msrun.cpp index 3f577aa1e..17723ee25 100644 --- a/src/core/msrun.cpp +++ b/src/core/msrun.cpp @@ -38,6 +38,7 @@ #include <pappsomspp/msrun/msrunreaderfactory.h> #include <pappsomspp/exception/exceptionnotfound.h> #include <pappsomspp/xicextractor/msrunxicextractorfactory.h> +#include "../utils/msrunstatisticshandler.h" MsRun::MsRun(const QString &location) : pappso::MsRunId(location) { @@ -144,7 +145,7 @@ MsRun::checkMsRunStatistics() { try { - pappso::MsRunSimpleStatistics stats; + MsRunStatisticsHandler stats; _msrun_reader_sp.get()->readSpectrumCollection(stats); setMsRunStatistics(MsRunStatistics::total_spectra, @@ -155,6 +156,12 @@ MsRun::checkMsRunStatistics() (unsigned int)stats.getMsLevelCount(2)); setMsRunStatistics(MsRunStatistics::total_spectra_ms3, (unsigned int)stats.getMsLevelCount(3)); + setMsRunStatistics(MsRunStatistics::tic_spectra_ms1, + (unsigned int)stats.getMsLevelTic(1)); + setMsRunStatistics(MsRunStatistics::tic_spectra_ms2, + (unsigned int)stats.getMsLevelTic(2)); + setMsRunStatistics(MsRunStatistics::tic_spectra_ms3, + (unsigned int)stats.getMsLevelTic(3)); } catch(pappso::ExceptionNotFound &error) { diff --git a/src/utils/msrunstatisticshandler.cpp b/src/utils/msrunstatisticshandler.cpp new file mode 100644 index 000000000..d61bed553 --- /dev/null +++ b/src/utils/msrunstatisticshandler.cpp @@ -0,0 +1,92 @@ +/** + * \file utils/msrunstatisticshandler.cpp + * \date 12/08/2018 + * \author Olivier Langella + * \brief handler on MZ data file to read all spectrums and make basic + * statistics + */ + + +/******************************************************************************* + * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>. + * + * This file is part of XTPcpp. + * + * XTPcpp 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. + * + * XTPcpp 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 XTPcpp. If not, see <http://www.gnu.org/licenses/>. + ******************************************************************************/ + +#include "msrunstatisticshandler.h" +#include <pappsomspp/msrun/msrunreader.h> + + +bool +MsRunStatisticsHandler::needPeakList() const +{ + return true; +} +void +MsRunStatisticsHandler::setQualifiedSpectrum( + const pappso::QualifiedSpectrum &qspectrum) +{ + unsigned int ms_level = qspectrum.getMsLevel(); + if(ms_level == 0) + return; + if(ms_level > _count_ms_level_spectrum.size()) + { + _count_ms_level_spectrum.resize(ms_level); + _tic_ms_level_spectrum.resize(ms_level); + } + _count_ms_level_spectrum[ms_level - 1]++; + + pappso::SpectrumSp spectrum_sp = qspectrum.getOriginalSpectrumSp(); + if(spectrum_sp != nullptr) + { + for(auto &&peak : *(spectrum_sp.get())) + { + + _tic_ms_level_spectrum[ms_level - 1] += peak.intensity; + } + } +} + +unsigned long +MsRunStatisticsHandler::getMsLevelCount(unsigned int ms_level) const +{ + if(ms_level == 0) + return 0; + if(ms_level > _count_ms_level_spectrum.size()) + return 0; + return (_count_ms_level_spectrum[ms_level - 1]); +} + +pappso::pappso_double +MsRunStatisticsHandler::getMsLevelTic(unsigned int ms_level) const +{ + if(ms_level == 0) + return 0; + if(ms_level > _tic_ms_level_spectrum.size()) + return 0; + return (_tic_ms_level_spectrum[ms_level - 1]); +} + +unsigned long +MsRunStatisticsHandler::getTotalCount() const +{ + unsigned long total = 0; + for(unsigned long count : _count_ms_level_spectrum) + { + total += count; + } + return total; +} diff --git a/src/utils/msrunstatisticshandler.h b/src/utils/msrunstatisticshandler.h new file mode 100644 index 000000000..81645e296 --- /dev/null +++ b/src/utils/msrunstatisticshandler.h @@ -0,0 +1,48 @@ +/** + * \file utils/msrunstatisticshandler.h + * \date 12/08/2018 + * \author Olivier Langella + * \brief handler on MZ data file to read all spectrums and make basic statistics + */ + + +/******************************************************************************* +* Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>. +* +* This file is part of XTPcpp. +* +* XTPcpp 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. +* +* XTPcpp 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 XTPcpp. If not, see <http://www.gnu.org/licenses/>. +******************************************************************************/ + +#pragma once + +#include <pappsomspp/msrun/msrunreader.h> + + +class MsRunStatisticsHandler : public pappso::SpectrumCollectionHandlerInterface +{ +public: + virtual void setQualifiedSpectrum (const pappso::QualifiedSpectrum & qspectrum) override; + virtual bool needPeakList () const override ; + + unsigned long getMsLevelCount(unsigned int ms_level) const; + pappso::pappso_double getMsLevelTic(unsigned int ms_level) const; + + + unsigned long getTotalCount() const; + +private: + std::vector<unsigned long> _count_ms_level_spectrum; + std::vector<pappso::pappso_double> _tic_ms_level_spectrum; +}; diff --git a/src/utils/types.h b/src/utils/types.h index a7b2cd536..c80ad03cc 100644 --- a/src/utils/types.h +++ b/src/utils/types.h @@ -124,6 +124,9 @@ enum class MsRunStatistics : std::int8_t total_spectra_ms1 = 2, ///< total number of MS1 spectra total_spectra_ms2 = 3, ///< total number of MS2 spectra total_spectra_ms3 = 4, ///< total number of MS3 spectra + tic_spectra_ms1 = 5, ///< total ion current in MS1 spectra + tic_spectra_ms2 = 6, ///< total ion current in MS2 spectra + tic_spectra_ms3 = 7, ///< total ion current in MS3 spectra }; -- GitLab