diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 840bbd57bab9cfdc7f001be66be149214bc10144..e4de9a708af5615c451b544018d012f7264b4ef6 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 3f577aa1ee11919b184143839e705089e475f129..17723ee25e85fe2d3c773c46760c0f3a59caecd4 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 0000000000000000000000000000000000000000..d61bed55396e17af9829940c306d5c19ce7661fd --- /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 0000000000000000000000000000000000000000..81645e2964d3894b53e2d7a1eef7ab5cd4697d05 --- /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 a7b2cd5366578fe3c971b4f03d01dfd242610a63..c80ad03ccc3679b4368284fdef4e1973eeaec38f 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 };