| OpenMS 2.5.0

IDMergerAlgorithm.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2020.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Julianus Pfeuffer $
32 // $Authors: Julianus Pfeuffer $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
38 #include <OpenMS/CONCEPT/Exception.h>
39 #include <OpenMS/CONCEPT/ProgressLogger.h>
40 #include <OpenMS/KERNEL/ConsensusMap.h>
41 #include <OpenMS/METADATA/ExperimentalDesign.h>
42
43 #include <unordered_set>
44
45 namespace OpenMS
46 {
47
48 //TODO add params for checking consistency (i.e. how strict to check)
49 //TODO add another subclass that does score-aware merging? (i.e. only keep best per peptide[sequence])
50
61 class OPENMS_DLLAPI IDMergerAlgorithm:
62 public DefaultParamHandler,
63 public ProgressLogger
64 {
65 public:
66 explicit IDMergerAlgorithm (const String& runIdentifier = "merged");
67
70 void insertRuns(std::vector<ProteinIdentification>&& prots,
71 std::vector<PeptideIdentification>&& peps);
72 void insertRuns(const std::vector<ProteinIdentification>& prots,
73 const std::vector<PeptideIdentification>& peps);
74
75 //TODO add methods to just insert prots or just peps. Especially makes sense if you do re-indexing anyway,
76 // then you do not need the proteins. But then we need origin information. Either externally in form of a
77 // String or StringList (like the one from ProteinID.getPrimaryMSRunPath). Or by having the file annotated
78 // at the PeptideID (with getBasename maybe?)
79 // Current solution would be to clear the ProteinIdentification if you do not need the proteins and add all the
80 // necessary information about origin(s) to this ProteinIdentification.
81
83 void returnResultsAndClear(ProteinIdentification& prots,
84 std::vector<PeptideIdentification>& peps);
85
86 private:
87
89 String getNewIdentifier_() const;
90
92 static void copySearchParams_(const ProteinIdentification& from, ProteinIdentification& to);
93
99 bool checkOldRunConsistency_(
100 const std::vector<ProteinIdentification>& protRuns,
101 const String& experiment_type) const;
102
109 bool checkOldRunConsistency_(
110 const std::vector<ProteinIdentification>& protRuns,
111 const ProteinIdentification& ref,
112 const String& experiment_type) const;
113
116 void insertProteinIDs_(
117 std::vector<ProteinIdentification>&& old_protRuns
118 );
119
123 void updateAndMovePepIDs_(
124 std::vector<PeptideIdentification>&& pepIDs,
125 const std::map<String, Size>& runID_to_runIdx,
126 const std::vector<StringList>& originFiles,
127 bool annotate_origin
128 );
129
130
131 void movePepIDsAndRefProteinsToResultFaster_(
132 std::vector<PeptideIdentification>&& pepIDs,
133 std::vector<ProteinIdentification>&& old_protRuns
134 );
135
137 ProteinIdentification prot_result_;
138
140 std::vector<PeptideIdentification> pep_result_;
141
142 static size_t accessionHash_(const ProteinHit& p){
143 return std::hash<String>()(p.getAccession());
144 }
145 static bool accessionEqual_(const ProteinHit& p1, const ProteinHit& p2){
146 return p1.getAccession() == p2.getAccession();
147 }
148 using hash_type = std::size_t (*)(const ProteinHit&);
149 using equal_type = bool (*)(const ProteinHit&, const ProteinHit&);
150 std::unordered_set<ProteinHit, hash_type, equal_type> collected_protein_hits_;
151
153 bool filled_ = false;
154
156 std::map<String, Size> file_origin_to_idx_;
157
159 String id_;
160 };
161 } // namespace OpenMS
OpenMS::IDMergerAlgorithm::file_origin_to_idx_
std::map< String, Size > file_origin_to_idx_
to keep track of the mzML origins of spectra
Definition: IDMergerAlgorithm.h:156
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
OpenMS::ProteinHit::getAccession
const String & getAccession() const
returns the accession of the protein
Exception.h
OpenMS::ProteinHit
Representation of a protein hit.
Definition: ProteinHit.h:57
OpenMS::IDMergerAlgorithm::prot_result_
ProteinIdentification prot_result_
the resulting new Protein IDs
Definition: IDMergerAlgorithm.h:137
OpenMS::IDMergerAlgorithm::equal_type
bool(*)(const ProteinHit &, const ProteinHit &) equal_type
Definition: IDMergerAlgorithm.h:149
ExperimentalDesign.h
OpenMS::ProteinIdentification
Representation of a protein identification run.
Definition: ProteinIdentification.h:71
ConsensusMap.h
ProgressLogger.h
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
DefaultParamHandler.h
OpenMS::IDMergerAlgorithm::id_
String id_
the new identifier string
Definition: IDMergerAlgorithm.h:159
OpenMS::IDMergerAlgorithm::accessionHash_
static size_t accessionHash_(const ProteinHit &p)
Definition: IDMergerAlgorithm.h:142
OpenMS::IDMergerAlgorithm
Creates a new Protein ID run into which other runs can be inserted. Creates union of protein hits but...
Definition: IDMergerAlgorithm.h:61
OpenMS::IDMergerAlgorithm::pep_result_
std::vector< PeptideIdentification > pep_result_
the resulting new Peptide IDs
Definition: IDMergerAlgorithm.h:140
OpenMS::IDMergerAlgorithm::collected_protein_hits_
std::unordered_set< ProteinHit, hash_type, equal_type > collected_protein_hits_
Definition: IDMergerAlgorithm.h:150
OpenMS::IDMergerAlgorithm::accessionEqual_
static bool accessionEqual_(const ProteinHit &p1, const ProteinHit &p2)
Definition: IDMergerAlgorithm.h:145
OpenMS::IDMergerAlgorithm::hash_type
std::size_t(*)(const ProteinHit &) hash_type
Definition: IDMergerAlgorithm.h:148