/******************************************************************************* * Copyright (c) 2017 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/>. * * Contributors: * Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation ******************************************************************************/ #include "identificationgroup.h" #include "project.h" #include "../utils/groupstore.h" #include <pappsomspp/pappsoexception.h> IdentificationGroup::IdentificationGroup(Project * project) { _p_project = project; } IdentificationGroup::~IdentificationGroup() { auto it = _protein_match_list.begin(); while (it != _protein_match_list.end()) { delete (*it); it++; } } unsigned int IdentificationGroup::countDecoyProtein(ValidationState state) const { unsigned int i=0; for (auto & p_protein_match : _protein_match_list) { if (!p_protein_match->getProteinXtpSp().get()->isDecoy()) continue; if (state == ValidationState::grouped) { if (p_protein_match->isGrouped()) { i++; } } else if(state == ValidationState::valid) { if (p_protein_match->isValid()) { i++; } } else if (state == ValidationState::validAndChecked) { if (p_protein_match->isValidAndChecked()) { i++; } } } return i; } unsigned int IdentificationGroup::countProtein(ValidationState state) const { unsigned int i=0; if (state == ValidationState::grouped) { for (auto & p_protein_match : _protein_match_list) { if (p_protein_match->isGrouped()) { i++; } } } else if(state == ValidationState::valid) { for (auto & p_protein_match : _protein_match_list) { if (p_protein_match->isValid()) { i++; } } } else if (state == ValidationState::validAndChecked) { for (auto & p_protein_match : _protein_match_list) { if (p_protein_match->isValidAndChecked()) { i++; } } } return i; } void IdentificationGroup::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) { for (auto & p_protein_match : _protein_match_list) { p_protein_match->updateAutomaticFilters(automatic_filter_parameters); } if (_p_grp_experiment != nullptr) { } } ProteinMatch * IdentificationGroup::getProteinMatchInstance(const QString accession) { if (accession.isEmpty()) { throw pappso::PappsoException(QObject::tr("Error protein match not found : accession is empty")); } auto it_cache = _cache_accession_protein_match.find(accession); if (it_cache == _cache_accession_protein_match.end()) { //accession not found in cache ProteinMatch * p_protein_match = new ProteinMatch(); _cache_accession_protein_match.insert(std::pair<QString, ProteinMatch *>(accession, p_protein_match)); _protein_match_list.push_back(p_protein_match); return p_protein_match; } else { return it_cache->second; } return nullptr; } void IdentificationGroup::addProteinMatch(ProteinMatch * protein_match) { _protein_match_list.push_back(protein_match); } bool IdentificationGroup::contains (const MsRun * p_msrun) const { for (const MsRunSp & msrun: _ms_run_list) { if (msrun.get() == p_msrun) return true; } return false; } void IdentificationGroup::addMsRunSp(MsRunSp ms_run_sp) { auto it = std::find (_ms_run_list.begin() ,_ms_run_list.end(),ms_run_sp); if (it == _ms_run_list.end()) { _ms_run_list.push_back(ms_run_sp); } } const std::vector<MsRunSp> & IdentificationGroup::getMsRunSpList() const { return _ms_run_list; } std::vector<ProteinMatch *> & IdentificationGroup::getProteinMatchList() { return _protein_match_list; } size_t IdentificationGroup::countGrouped()const { size_t i=0; for (auto & p_protein_match : _protein_match_list) { if (p_protein_match->isGrouped()) { i++; } } return i; } size_t IdentificationGroup::countValidAndChecked()const { size_t i=0; for (auto & p_protein_match : _protein_match_list) { if (p_protein_match->isValidAndChecked()) { i++; } } return i; } size_t IdentificationGroup::countValid()const { size_t i=0; for (auto & p_protein_match : _protein_match_list) { if (p_protein_match->isValid()) { i++; } } return i; } std::size_t IdentificationGroup::countGroup()const { return _group_store.countGroup(); } std::size_t IdentificationGroup::countSubGroup()const { return _group_store.countSubGroup(); } void IdentificationGroup::startGrouping (const GroupingType & grouping_type) { qDebug() << "IdentificationGroup::startGrouping begin "; if (_p_grp_experiment != nullptr) { delete _p_grp_experiment; } _p_grp_experiment = GroupingExperiment::newInstance(grouping_type); for (auto & p_protein_match : _protein_match_list) { p_protein_match->setGroupingExperiment(_p_grp_experiment); } _p_grp_experiment->startGrouping(); _group_store.clear(); for (auto & p_protein_match : _protein_match_list) { p_protein_match->setGroupInstance(_group_store); } qDebug() << "IdentificationGroup::startGrouping end "; } const QString IdentificationGroup::getTabName() const { return _ms_run_list[0]->getFilename(); }