diff --git a/src/grouping/ptm/ptmgroupingexperiment.cpp b/src/grouping/ptm/ptmgroupingexperiment.cpp index 3c1b5405a4db9ace4e50444416d77f82d3460eef..22cc58a4dc5c0260ca564a9aa27232a4da064025 100644 --- a/src/grouping/ptm/ptmgroupingexperiment.cpp +++ b/src/grouping/ptm/ptmgroupingexperiment.cpp @@ -75,8 +75,14 @@ PtmGroupingExperiment::~PtmGroupingExperiment() void PtmGroupingExperiment::numbering() { std::sort(_ptm_island_group_list.begin(), _ptm_island_group_list.end(),[](const PtmIslandGroupSp a, const PtmIslandGroupSp b) { - return a.get() < b.get(); + return *(a.get()) < *(b.get()); }); + + unsigned int number=0; + for (PtmIslandGroupSp ptm_island_group:_ptm_island_group_list) { + number ++; + ptm_island_group.get()->setGroupNumber(number); + } } void PtmGroupingExperiment::startGrouping() { //we have a list of ptm island subgroups to group : diff --git a/src/grouping/ptm/ptmisland.cpp b/src/grouping/ptm/ptmisland.cpp index 8bf6b8ff8aeb9959b76d6b31fb7fb3dd1b6e477d..2bb27540ef11fa6b716ba4b713956da44843443a 100644 --- a/src/grouping/ptm/ptmisland.cpp +++ b/src/grouping/ptm/ptmisland.cpp @@ -76,6 +76,10 @@ void PtmIsland::addPeptideMatch(const PeptideMatch* p_peptide_match) { } } +unsigned int PtmIsland::getProteinStartPosition() const { + return _protein_start; +} + bool PtmIsland::merge(PtmIslandSp ptm_island_sp) { if (std::none_of(_peptide_match_list.begin(), _peptide_match_list.end(), [ptm_island_sp](const PeptideMatch* element) { return ptm_island_sp.get()->containsPeptideMatch(element); diff --git a/src/grouping/ptm/ptmisland.h b/src/grouping/ptm/ptmisland.h index 713ab5bbd93b8ef6941df5173d18f045de62269a..619e6572a1d01dc7d2748fa619c9ec26e0a69853 100644 --- a/src/grouping/ptm/ptmisland.h +++ b/src/grouping/ptm/ptmisland.h @@ -56,6 +56,8 @@ public: bool containsPeptideMatch(const PeptideMatch* element) const; std::vector<std::size_t> getSampleScanSet() const; const ProteinMatch * getProteinMatch() const; + unsigned int getProteinStartPosition() const; + private: const ProteinMatch * _protein_match_p; std::vector<const PeptideMatch *> _peptide_match_list; diff --git a/src/grouping/ptm/ptmislandgroup.cpp b/src/grouping/ptm/ptmislandgroup.cpp index 599eb66e27c2510a772ebbeccabae98481469334..b4abe62f9c51aed727ffe831abb79b1e0ba1743b 100644 --- a/src/grouping/ptm/ptmislandgroup.cpp +++ b/src/grouping/ptm/ptmislandgroup.cpp @@ -44,6 +44,35 @@ PtmIslandGroup::~PtmIslandGroup() } +QString PtmIslandGroup::getFirstAccession() const { + if (_ptm_island_subgroup_list.size() == 0) return QString(); + QStringList accession_list; + for (PtmIslandSubgroupSp ptm_island_subgroup:_ptm_island_subgroup_list) { + for (PtmIslandSp ptm_island: ptm_island_subgroup.get()->getPtmIslandList()) { + accession_list << ptm_island.get()->getProteinMatch()->getProteinXtpSp().get()->getAccession(); + } + } + accession_list.sort(); + + return accession_list[0]; +} + +void PtmIslandGroup::setGroupNumber(unsigned int number) { + _group_number = number; + for (PtmIslandSubgroupSp ptm_island_subgroup:_ptm_island_subgroup_list) { + ptm_island_subgroup.get()->setPtmIslandGroup(this); + } + std::sort(_ptm_island_subgroup_list.begin(), _ptm_island_subgroup_list.end(), [](const PtmIslandSubgroupSp& a, const PtmIslandSubgroupSp& b) + { + return (a.get()->getFirstPtmIsland()->getProteinStartPosition() < b.get()->getFirstPtmIsland()->getProteinStartPosition()); + }); + + unsigned int sg_number=0; + for (PtmIslandSubgroupSp ptm_island_subgroup:_ptm_island_subgroup_list) { + sg_number ++; + ptm_island_subgroup.get()->setSubgroupNumber(sg_number); + } +} bool PtmIslandGroup::operator<(const PtmIslandGroup& other) const { if (_ptm_island_subgroup_list.size() == other._ptm_island_subgroup_list.size()) { if (maxCountSampleScan() == other.maxCountSampleScan()) { @@ -57,7 +86,13 @@ bool PtmIslandGroup::operator<(const PtmIslandGroup& other) const { return (_ptm_island_subgroup_list.size() < other._ptm_island_subgroup_list.size()); } } - +unsigned int PtmIslandGroup::maxCountSampleScan() const { + std::vector<PtmIslandSubgroupSp>::const_iterator it_result = std::max_element(_ptm_island_subgroup_list.begin(), _ptm_island_subgroup_list.end(), [](const PtmIslandSubgroupSp & a, const PtmIslandSubgroupSp & b) + { + return (a.get()->countSampleScan() < b.get()->countSampleScan()); + }); + return it_result->get()->countSampleScan(); +} bool PtmIslandGroup::mergePtmIslandSubgroupSp(PtmIslandSubgroupSp ptm_island_subgroup_sp) { diff --git a/src/grouping/ptm/ptmislandgroup.h b/src/grouping/ptm/ptmislandgroup.h index 1507afd7bbc102c9359e9ddb1f9f4c02092f3d67..18038220e5f610a00a68fbdeb4893d90af4028b6 100644 --- a/src/grouping/ptm/ptmislandgroup.h +++ b/src/grouping/ptm/ptmislandgroup.h @@ -46,9 +46,14 @@ public: PtmIslandGroup(PtmIslandSubgroupSp ptm_island_subgroup_sp); PtmIslandGroup(const PtmIslandGroup& other); ~PtmIslandGroup(); + bool operator<(const PtmIslandGroup& other) const; /** @brief merge with the given ptm island subgroup if at least one protein is shared * */ bool mergePtmIslandSubgroupSp(PtmIslandSubgroupSp ptm_island_subgroup_sp); + + unsigned int maxCountSampleScan() const; + QString getFirstAccession() const; + void setGroupNumber(unsigned int number); private : std::vector<PtmIslandSubgroupSp> _ptm_island_subgroup_list; diff --git a/src/grouping/ptm/ptmislandsubgroup.cpp b/src/grouping/ptm/ptmislandsubgroup.cpp index 423fa50e0a1913bfca405eade61b89f630dfb615..6a0d99e5f53e1605cfffcfee3a59ba8162952f83 100644 --- a/src/grouping/ptm/ptmislandsubgroup.cpp +++ b/src/grouping/ptm/ptmislandsubgroup.cpp @@ -46,17 +46,35 @@ PtmIslandSubgroup::~PtmIslandSubgroup() { } +const PtmIsland * PtmIslandSubgroup::getFirstPtmIsland() const { + return _ptm_island_list.begin()->get(); +} - +void PtmIslandSubgroup::setSubgroupNumber(unsigned int number) { + _subgroup_number = number; +} +void PtmIslandSubgroup::setPtmIslandGroup(PtmIslandGroup * p_ptm_island_group) { + _ptm_island_group_p = p_ptm_island_group; + std::sort(_ptm_island_list.begin(), _ptm_island_list.end(), [](const PtmIslandSp& a, const PtmIslandSp& b) + { + return (a.get()->getProteinMatch()->getProteinXtpSp().get()->getAccession() < b.get()->getProteinMatch()->getProteinXtpSp().get()->getAccession()); + }); +} +const std::vector< PtmIslandSp > & PtmIslandSubgroup::getPtmIslandList() const { + return _ptm_island_list; +} +unsigned int PtmIslandSubgroup::countSampleScan() const { + return _sample_scan_set.size(); +} bool PtmIslandSubgroup::containsProteinMatchFrom(PtmIslandSubgroup* ptm_island_subgroup_p) { - for (PtmIslandSp ptm_island_sp :_ptm_island_list) { - if (std::any_of(ptm_island_subgroup_p->_ptm_island_list.begin(), ptm_island_subgroup_p->_ptm_island_list.end(), [ptm_island_sp](PtmIslandSp element) { + for (PtmIslandSp ptm_island_sp :_ptm_island_list) { + if (std::any_of(ptm_island_subgroup_p->_ptm_island_list.begin(), ptm_island_subgroup_p->_ptm_island_list.end(), [ptm_island_sp](PtmIslandSp element) { return (element.get()->getProteinMatch() == ptm_island_sp.get()->getProteinMatch()); })) { return true; } - } - return false; + } + return false; } bool PtmIslandSubgroup::mergePtmIslandSp(PtmIslandSp ptm_island_sp) { diff --git a/src/grouping/ptm/ptmislandsubgroup.h b/src/grouping/ptm/ptmislandsubgroup.h index 862e71ae6d8a1f3b05370fa1fa1e63767fa3477f..4148fa31f83c5a55c8ec51a7888bab9b11f4bc6a 100644 --- a/src/grouping/ptm/ptmislandsubgroup.h +++ b/src/grouping/ptm/ptmislandsubgroup.h @@ -39,6 +39,7 @@ class PtmIslandSubgroup; */ typedef std::shared_ptr<PtmIslandSubgroup> PtmIslandSubgroupSp; +class PtmIslandGroup; class PtmIslandSubgroup { @@ -51,10 +52,21 @@ public: * */ bool mergePtmIslandSp(PtmIslandSp ptm_island_sp); bool containsProteinMatchFrom(PtmIslandSubgroup* ptm_island_subgroup_p); + + unsigned int countSampleScan() const; + + const std::vector< PtmIslandSp > & getPtmIslandList() const; + + void setPtmIslandGroup(PtmIslandGroup * p_ptm_island_group); + + const PtmIsland * getFirstPtmIsland() const; + void setSubgroupNumber(unsigned int number); private: std::vector< PtmIslandSp > _ptm_island_list; std::vector<std::size_t> _sample_scan_set; + PtmIslandGroup * _ptm_island_group_p = nullptr; + unsigned int _subgroup_number; };