Newer
Older
/*******************************************************************************

Langella Olivier
committed
* 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
******************************************************************************/

Langella Olivier
committed
IdentificationGroup::IdentificationGroup(Project *project)

Langella Olivier
committed
_p_project = project;
}
IdentificationGroup::~IdentificationGroup()
{

Langella Olivier
committed
auto it = _protein_match_list.begin();
while(it != _protein_match_list.end())
{
delete(*it);
it++;

Langella Olivier
committed
const PtmGroupingExperiment *
IdentificationGroup::getPtmGroupingExperiment() const
{
return _p_grp_ptm_experiment;

Langella Olivier
committed
const GroupStore &
IdentificationGroup::getGroupStore() const
{
return _group_store;

Langella Olivier
committed
pappso::pappso_double
IdentificationGroup::computeProtoNsafSum(const MsRun *p_msrun_id) const
{
pappso::pappso_double nsaf_sum = 0;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getValidationState() >= ValidationState::grouped)
{
nsaf_sum += p_protein_match->getProtoNsaf(p_msrun_id);

Langella Olivier
committed
return nsaf_sum;

Langella Olivier
committed
unsigned int
IdentificationGroup::countPeptideMass(ValidationState state) const
{

Langella Olivier
committed
std::vector<pappso::GrpPeptide *> count_peptide_mass;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getValidationState() >= state)
{
p_protein_match->countPeptideMass(count_peptide_mass, state);

Langella Olivier
committed
std::sort(count_peptide_mass.begin(), count_peptide_mass.end());
auto last = std::unique(count_peptide_mass.begin(), count_peptide_mass.end());
return std::distance(count_peptide_mass.begin(), last);

Langella Olivier
committed
unsigned int
IdentificationGroup::countPeptideMassSample(ValidationState state) const
{

Langella Olivier
committed
std::vector<std::size_t> count_peptide_mass_sample;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getValidationState() >= state)
{
p_protein_match->countPeptideMassSample(count_peptide_mass_sample,
state);

Langella Olivier
committed
std::sort(count_peptide_mass_sample.begin(), count_peptide_mass_sample.end());
auto last = std::unique(count_peptide_mass_sample.begin(),
count_peptide_mass_sample.end());
return std::distance(count_peptide_mass_sample.begin(), last);

Langella Olivier
committed
unsigned int
IdentificationGroup::countDecoyPeptideMassSample(ValidationState state) const
{
std::vector<std::size_t> count_peptide_mass_sample;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getProteinXtpSp().get()->isDecoy())
{
if(p_protein_match->getValidationState() >= state)
{
p_protein_match->countPeptideMassSample(count_peptide_mass_sample,
state);

Langella Olivier
committed
std::sort(count_peptide_mass_sample.begin(), count_peptide_mass_sample.end());
auto last = std::unique(count_peptide_mass_sample.begin(),
count_peptide_mass_sample.end());
return std::distance(count_peptide_mass_sample.begin(), last);

Langella Olivier
committed
unsigned int
IdentificationGroup::countDecoyProteinMatch(ValidationState state) const
{
return std::count_if(
_protein_match_list.begin(),
_protein_match_list.end(),
[state](const ProteinMatch *p_protein_match) {
if((p_protein_match->getProteinXtpSp().get()->isDecoy()) &&
(p_protein_match->getValidationState() >= state))
{
return true;

Langella Olivier
committed
else
{
return false;

Langella Olivier
committed
unsigned int
IdentificationGroup::countPeptideEvidence(ValidationState state) const
{
std::set<const PeptideEvidence *> peptide_evidence_set;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getValidationState() >= state)
{
p_protein_match->collectPeptideEvidences(peptide_evidence_set, state);

Langella Olivier
committed
return peptide_evidence_set.size();

Langella Olivier
committed
unsigned int
IdentificationGroup::countDecoyPeptideEvidence(ValidationState state) const
{
std::set<const PeptideEvidence *> peptide_evidence_set;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getValidationState() >= state)
{
if(p_protein_match->getProteinXtpSp().get()->isDecoy())
{
p_protein_match->collectPeptideEvidences(peptide_evidence_set,
state);
}
}
}

Langella Olivier
committed
return peptide_evidence_set.size();

Langella Olivier
committed
unsigned int
IdentificationGroup::countPeptideMatch(ValidationState state) const
{
unsigned int i = 0;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getValidationState() >= state)
{
i += p_protein_match->countPeptideMatch(state);

Langella Olivier
committed
return i;

Langella Olivier
committed
unsigned int
IdentificationGroup::countDecoyPeptideMatch(ValidationState state) const
{
unsigned int i = 0;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getValidationState() >= state)
{
if(p_protein_match->getProteinXtpSp().get()->isDecoy())
{
i += p_protein_match->countPeptideMatch(state);
}
}
}

Langella Olivier
committed
return i;

Langella Olivier
committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
unsigned int
IdentificationGroup::countProteinMatch(ValidationState state) const
{
return std::count_if(_protein_match_list.begin(),
_protein_match_list.end(),
[state](const ProteinMatch *p_protein_match) {
if(p_protein_match->getValidationState() >= state)
{
return true;
}
else
{
return false;
}
});
}
void
IdentificationGroup::updateAutomaticFilters(
const AutomaticFilterParameters &automatic_filter_parameters)
{
qDebug() << "IdentificationGroup::updateAutomaticFilters begin";
for(IdentificationDataSource *p_identification_source_list : _id_source_list)
{
p_identification_source_list->getPeptideEvidenceStore()
.updateAutomaticFilters(automatic_filter_parameters);

Langella Olivier
committed
qDebug()
<< "IdentificationGroup::updateAutomaticFilters begin p_protein_match";
for(auto &p_protein_match : _protein_match_list)
{
p_protein_match->updateAutomaticFilters(automatic_filter_parameters);

Langella Olivier
committed
if(_p_grp_experiment != nullptr)
{
}
qDebug() << "IdentificationGroup::updateAutomaticFilters end";

Langella Olivier
committed
ProteinMatch *
IdentificationGroup::getProteinMatchInstance(const QString accession)
{
if(accession.isEmpty())
{
throw pappso::PappsoException(
QObject::tr("Error protein match not found : accession is empty"));

Langella Olivier
committed
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;

Langella Olivier
committed
else
{
return it_cache->second;

Langella Olivier
committed
return nullptr;

Langella Olivier
committed
void
IdentificationGroup::addProteinMatch(ProteinMatch *protein_match)
{
_protein_match_list.push_back(protein_match);

Langella Olivier
committed
bool
IdentificationGroup::contains(const MsRun *p_msrun) const
{
for(const MsRunSp &msrun : _ms_run_list)
{
if(msrun.get() == p_msrun)
return true;

Langella Olivier
committed
return false;

Langella Olivier
committed
bool
IdentificationGroup::containSample(const QString &sample) const
{
for(const MsRunSp &msrun : _ms_run_list)
{
if(msrun.get()->getSampleName() == sample)
return true;

Langella Olivier
committed
return false;

Langella Olivier
committed
void
IdentificationGroup::addIdentificationDataSourceP(
IdentificationDataSource *p_identification_source)
{
addMsRunSp(p_identification_source->getMsRunSp());
auto it = std::find(
_id_source_list.begin(), _id_source_list.end(), p_identification_source);
if(it == _id_source_list.end())
{
_id_source_list.push_back(p_identification_source);

Langella Olivier
committed
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);

Langella Olivier
committed
const std::vector<MsRunSp> &
IdentificationGroup::getMsRunSpList() const
{
return _ms_run_list;

Langella Olivier
committed
const std::vector<IdentificationDataSource *> &
IdentificationGroup::getIdentificationDataSourceList() const
{
return _id_source_list;

Langella Olivier
committed
const std::vector<ProteinMatch *> &
IdentificationGroup::getProteinMatchList() const
{
return _protein_match_list;

Langella Olivier
committed
std::vector<ProteinMatch *> &
IdentificationGroup::getProteinMatchList()
{
return _protein_match_list;

Langella Olivier
committed
std::size_t
IdentificationGroup::countGroup() const
{
return _group_store.countGroup();

Langella Olivier
committed
std::size_t
IdentificationGroup::countSubGroup() const
{
return _group_store.countSubGroup();

Langella Olivier
committed
void
IdentificationGroup::collectMhDelta(
std::vector<pappso::pappso_double> &delta_list,
pappso::PrecisionUnit unit,
ValidationState state) const
{
std::set<const PeptideEvidence *> peptide_evidence_list;
for(auto &p_protein_match : _protein_match_list)
{
if(p_protein_match->getValidationState() >= state)
{
if(!p_protein_match->getProteinXtpSp().get()->isDecoy())
{
// p_protein_match->collectMhDelta(already_counted, delta_list,
// unit, state);
p_protein_match->collectPeptideEvidences(peptide_evidence_list,
state);

Langella Olivier
committed
for(const PeptideEvidence *p_peptide_evidence : peptide_evidence_list)
{
if(unit == pappso::PrecisionUnit::ppm)
{
delta_list.push_back(p_peptide_evidence->getPpmDeltaMass());

Langella Olivier
committed
else
{
delta_list.push_back(p_peptide_evidence->getDeltaMass());

Langella Olivier
committed
void
IdentificationGroup::startGrouping(const GroupingType &grouping_type,
WorkMonitorInterface *p_work_monitor)
{
qDebug() << "IdentificationGroup::startGrouping begin ";
if(_p_grp_experiment != nullptr)
{
delete _p_grp_experiment;

Langella Olivier
committed
_p_grp_experiment =
GroupingExperiment::newInstance(grouping_type, p_work_monitor);
for(ProteinMatch *p_protein_match : _protein_match_list)
{
p_protein_match->setGroupingExperiment(_p_grp_experiment);

Langella Olivier
committed
_p_grp_experiment->startGrouping();
_group_store.clear();
for(ProteinMatch *p_protein_match : _protein_match_list)
{
p_protein_match->setGroupInstance(_group_store);

Langella Olivier
committed
if(_p_grp_ptm_experiment != nullptr)
{
delete _p_grp_ptm_experiment;
_p_grp_ptm_experiment = nullptr;

Langella Olivier
committed
qDebug() << "IdentificationGroup::startGrouping end ";

Langella Olivier
committed
void
IdentificationGroup::startPtmGrouping()
{
qDebug() << "IdentificationGroup::startPtmGrouping begin ";
if(_p_grp_ptm_experiment != nullptr)
{
delete _p_grp_ptm_experiment;
_p_grp_ptm_experiment = nullptr;

Langella Olivier
committed
_p_grp_ptm_experiment = new PtmGroupingExperiment();
_p_grp_ptm_experiment->setValidationState(ValidationState::grouped);
for(ProteinMatch *p_protein_match : _protein_match_list)
{
_p_grp_ptm_experiment->addProteinMatch(p_protein_match);

Langella Olivier
committed
_p_grp_ptm_experiment->startGrouping();

Langella Olivier
committed
qDebug() << "IdentificationGroup::startPtmGrouping end ";

Langella Olivier
committed
const QString
IdentificationGroup::getTabName() const
{
return _ms_run_list[0]->getSampleName();

Langella Olivier
committed
pappso::pappso_double
IdentificationGroup::getPeptideMassFdr(ValidationState state) const
{
// ValidationState state = ValidationState::valid;
pappso::pappso_double total_peptide = countPeptideMassSample(state);
pappso::pappso_double false_peptide = countDecoyPeptideMassSample(state);

Langella Olivier
committed
return (false_peptide / total_peptide);

Langella Olivier
committed
pappso::pappso_double
IdentificationGroup::getProteinFdr(ValidationState state) const
{
// ValidationState state = ValidationState::valid;
pappso::pappso_double total_prot = countProteinMatch(state);
pappso::pappso_double false_prot = countDecoyProteinMatch(state);

Langella Olivier
committed
return (false_prot / total_prot);

Langella Olivier
committed
void
IdentificationGroup::getSameXicPeptideEvidenceList(
std::vector<const PeptideEvidence *> &peptide_evidence_list,
const MsRun *p_msrun,
const PeptideXtp *p_peptide,
unsigned int charge) const
{
if(!contains(p_msrun))
return;
for(const IdentificationDataSource *p_identification_source : _id_source_list)
{
if(p_msrun == p_identification_source->getMsRunSp().get())
{
p_identification_source->getPeptideEvidenceStore()
.getSameXicPeptideEvidenceList(
peptide_evidence_list, p_msrun, p_peptide, charge);