OpenMS
Loading...
Searching...
No Matches
IDFilter.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Mathias Walzer $
6// $Authors: Nico Pfeifer, Mathias Walzer, Hendrik Weisser $
7// --------------------------------------------------------------------------
8
9#pragma once
10
24#include <OpenMS/config.h>
25#include <algorithm>
26#include <climits>
27#include <functional>
28#include <map>
29#include <set>
30#include <unordered_set>
31#include <vector>
32
33namespace OpenMS
34{
35 template<typename T>
37 std::is_same_v<T, PeptideIdentification> || std::is_same_v<T, ProteinIdentification>;
38
39 template<typename T>
41 std::is_same_v<T, FeatureMap> || std::is_same_v<T, ConsensusMap>;
42
44 template<typename T>
46 !std::is_same_v<T, std::vector<PeptideIdentification>> &&
47 !std::is_same_v<T, std::vector<ProteinIdentification>> &&
48 !std::is_same_v<T, PeptideIdentificationList>;
49
70 class OPENMS_DLLAPI IDFilter
71 {
72 public:
74 IDFilter() = default;
75
77 virtual ~IDFilter() = default;
78
80 typedef std::map<Int, PeptideHit*> ChargeToPepHitP;
81 typedef std::unordered_map<std::string, ChargeToPepHitP> SequenceToChargeToPepHitP;
82 typedef std::map<std::string, SequenceToChargeToPepHitP> RunToSequenceToChargeToPepHitP;
83
90
92 template<class HitType>
93 struct HasGoodScore {
94 typedef HitType argument_type; // for use as a predicate
95
96 double score;
98
99 HasGoodScore(double score_, bool higher_score_better_) : score(score_), higher_score_better(higher_score_better_)
100 {
101 }
102
103 bool operator()(const HitType& hit) const
104 {
105 if (higher_score_better)
106 {
107 return hit.getScore() >= score;
108 }
109 return hit.getScore() <= score;
110 }
111 };
112
118 template<class HitType>
120 typedef HitType argument_type; // for use as a predicate
121
122 std::string key;
124
125 HasMetaValue(const std::string& key_, const DataValue& value_) : key(key_), value(value_)
126 {
127 }
128
129 bool operator()(const HitType& hit) const
130 {
131 DataValue found = hit.getMetaValue(key);
132 if (found.isEmpty())
133 return false; // meta value "key" not set
134 if (value.isEmpty())
135 return true; // "key" is set, value doesn't matter
136 return found == value;
137 }
138 };
139
141 template<class HitType>
143 typedef HitType argument_type; // for use as a predicate
144
145 std::string key;
146 double value;
147
148 HasMaxMetaValue(const std::string& key_, const double& value_) : key(key_), value(value_)
149 {
150 }
151
152 bool operator()(const HitType& hit) const
153 {
154 DataValue found = hit.getMetaValue(key);
155 if (found.isEmpty())
156 return false; // meta value "key" not set
157 return double(found) <= value;
158 }
159 };
160
168 template<class HitType>
170 {
171 typedef HitType argument_type; // for use as a predicate
172
173 std::string key;
174 double value;
175
182 HasMinMetaValue(const std::string& key_, const double& value_) :
183 key(key_),
184 value(value_)
185 {
186 }
187
194 bool operator()(const HitType& hit) const
195 {
196 DataValue found = hit.getMetaValue(key);
197 if (found.isEmpty())
198 {
199 return false; // meta value "key" not set
200 }
201 return static_cast<double>(found) >= value;
202 }
203 };
204
206
221 template<class HitType>
223 {
224 typedef HitType argument_type; // for use as a predicate
225
226 struct HasMetaValue<HitType> target_decoy, is_decoy;
227
234 target_decoy("target_decoy", "decoy"),
235 is_decoy("isDecoy", "true")
236 {
237 }
238
247 bool operator()(const HitType& hit) const
248 {
249 // @TODO: this could be done slightly more efficiently by returning
250 // false if the "target_decoy" meta value is "target" or "target+decoy",
251 // without checking for an "isDecoy" meta value in that case
252 return target_decoy(hit) || is_decoy(hit);
253 }
254 };
255
264 template<class HitType, class SetType>
266 typedef HitType argument_type; // for use as a predicate
267
268 const SetType& accessions;
269
270 explicit HasMatchingAccessionImpl(const SetType& accessions_) : accessions(accessions_)
271 {
272 }
273
274 bool operator()(const PeptideHit& hit) const
275 {
276 for (const auto& acc : hit.extractProteinAccessionsSet())
277 {
278 if (accessions.contains(acc))
279 return true;
280 }
281 return false;
282 }
283
284 bool operator()(const ProteinHit& hit) const
285 {
286 return accessions.contains(hit.getAccession());
287 }
288
289 bool operator()(const PeptideEvidence& evidence) const
290 {
291 return accessions.contains(evidence.getProteinAccession());
292 }
293 };
294
296 template<class HitType>
298
300 template<class HitType>
302
308 template<class HitType, class Entry>
310 typedef HitType argument_type; // for use as a predicate
311 typedef std::map<std::string, Entry*> ItemMap; // Store pointers to avoid copying data
313
314 GetMatchingItems(std::vector<Entry>& records)
315 {
316 for (typename std::vector<Entry>::iterator rec_it = records.begin(); rec_it != records.end(); ++rec_it)
317 {
318 items[getKey(*rec_it)] = &(*rec_it);
319 }
320 }
321
323 {
324 }
325
326 const std::string& getKey(const FASTAFile::FASTAEntry& entry) const
327 {
328 return entry.identifier;
329 }
330
331 bool exists(const HitType& hit) const
332 {
333 return items.contains(getHitKey(hit));
334 }
335
336 const std::string& getHitKey(const PeptideEvidence& p) const
337 {
338 return p.getProteinAccession();
339 }
340
341 const Entry& getValue(const PeptideEvidence& evidence) const
342 {
343 if (!exists(evidence))
344 {
345 throw Exception::InvalidParameter(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Accession: '" + getHitKey(evidence) + "'. peptide evidence accession not in data");
346 }
347 return *(items.find(getHitKey(evidence))->second);
348 }
349 };
350
352
353
360
362 struct HasMinPeptideLength;
363
365 struct HasMinCharge;
366
368 struct HasLowMZError;
369
375 struct HasMatchingModification;
376
382 struct HasMatchingSequence;
383
385 struct HasNoEvidence;
386
387
394 {
395 private:
399
400 public:
402 PeptideDigestionFilter(EnzymaticDigestion& digestion, Int min, Int max) : digestion_(digestion), min_cleavages_(min), max_cleavages_(max)
403 {
404 }
405
406 static inline Int disabledValue()
407 {
408 return -1;
409 }
410
413 bool operator()(PeptideHit& p) const
414 {
415 const auto& fun = [&](const Int missed_cleavages) {
416 bool max_filter = max_cleavages_ != disabledValue() ? missed_cleavages > max_cleavages_ : false;
417 bool min_filter = min_cleavages_ != disabledValue() ? missed_cleavages < min_cleavages_ : false;
418 return max_filter || min_filter;
419 };
420 return digestion_.filterByMissedCleavages(p.getSequence().toUnmodifiedString(), fun);
421 }
422
423 void filterPeptideSequences(std::vector<PeptideHit>& hits)
424 {
425 hits.erase(std::remove_if(hits.begin(), hits.end(), (*this)), hits.end());
426 }
427 };
428
429
437
438 // Build an accession index to avoid the linear search cost
443
444 DigestionFilter(std::vector<FASTAFile::FASTAEntry>& entries, ProteaseDigestion& digestion, bool ignore_missed_cleavages, bool methionine_cleavage) :
445 accession_resolver_(entries), digestion_(digestion), ignore_missed_cleavages_(ignore_missed_cleavages), methionine_cleavage_(methionine_cleavage)
446 {
447 }
448
449 bool operator()(const PeptideEvidence& evidence) const
450 {
451 if (!evidence.hasValidLimits())
452 {
453 OPENMS_LOG_WARN << "Invalid limits! Peptide '" << evidence.getProteinAccession() << "' not filtered" << std::endl;
454 return true;
455 }
456
457 if (accession_resolver_.exists(evidence))
458 {
459 return digestion_.isValidProduct(AASequence::fromString(accession_resolver_.getValue(evidence).sequence), evidence.getStart(), evidence.getEnd() - evidence.getStart() + 1, // end is inclusive
460 ignore_missed_cleavages_, methionine_cleavage_);
461 }
462 else
463 {
464 if (evidence.getProteinAccession().empty())
465 {
466 OPENMS_LOG_WARN << "Peptide accession not available! Skipping Evidence." << std::endl;
467 }
468 else
469 {
470 OPENMS_LOG_WARN << "Peptide accession '" << evidence.getProteinAccession() << "' not found in fasta file!" << std::endl;
471 }
472 return true;
473 }
474 }
475
477 {
478 IDFilter::FilterPeptideEvidences<IDFilter::DigestionFilter>(*this, peptides);
479 }
480 };
481
483
484
487
489 template<class IdentificationType>
490 struct HasNoHits {
491 typedef IdentificationType argument_type; // for use as a predicate
492
493 bool operator()(const IdentificationType& id) const
494 {
495 return id.getHits().empty();
496 }
497 };
498
500
501
504
506 struct HasRTInRange;
507
509 struct HasMZInRange;
510
512
513
520
522 template<class Container, class Predicate>
523 static void removeMatchingItems(Container& items, const Predicate& pred)
524 {
525 items.erase(std::remove_if(items.begin(), items.end(), pred), items.end());
526 }
527
529 template<class Container, class Predicate>
530 static void keepMatchingItems(Container& items, const Predicate& pred)
531 {
532 items.erase(std::remove_if(items.begin(), items.end(), std::not_fn(pred)), items.end());
533 }
534
536 template<class Container, class Predicate>
537 static void moveMatchingItems(Container& items, const Predicate& pred, Container& target)
538 {
539 auto part = std::partition(items.begin(), items.end(), std::not_fn(pred));
540 std::move(part, items.end(), std::back_inserter(target));
541 items.erase(part, items.end());
542 }
543
545 template<class IDContainer, class Predicate>
546 static void removeMatchingItemsUnroll(IDContainer& items, const Predicate& pred)
547 {
548 for (auto& item : items)
549 {
550 removeMatchingItems(item.getHits(), pred);
551 }
552 }
553
555 template<class IDContainer, class Predicate>
556 static void keepMatchingItemsUnroll(IDContainer& items, const Predicate& pred)
557 {
558 for (auto& item : items)
559 {
560 keepMatchingItems(item.getHits(), pred);
561 }
562 }
563
564 template<class MapType, class Predicate>
565 static void keepMatchingPeptideHits(MapType& prot_and_pep_ids, Predicate& pred)
566 {
567 for (auto& feat : prot_and_pep_ids)
568 {
569 keepMatchingItemsUnroll(feat.getPeptideIdentifications(), pred);
570 }
571 keepMatchingItemsUnroll(prot_and_pep_ids.getUnassignedPeptideIdentifications(), pred);
572 }
573
574 template<class MapType, class Predicate>
575 static void removeMatchingPeptideHits(MapType& prot_and_pep_ids, Predicate& pred)
576 {
577 for (auto& feat : prot_and_pep_ids)
578 {
579 removeMatchingItemsUnroll(feat.getPeptideIdentifications(), pred);
580 }
581 removeMatchingItemsUnroll(prot_and_pep_ids.getUnassignedPeptideIdentifications(), pred);
582 }
583
584 template<IsFeatureOrConsensusMap MapType, class Predicate>
585 static void removeMatchingPeptideIdentifications(MapType& prot_and_pep_ids, Predicate& pred)
586 {
587 for (auto& feat : prot_and_pep_ids)
588 {
589 removeMatchingItems(feat.getPeptideIdentifications(), pred);
590 }
591 removeMatchingItems(prot_and_pep_ids.getUnassignedPeptideIdentifications(), pred);
592 }
593
594 // Specialization for PeptideIdentificationList
595 template<class Predicate>
597 {
598 removeMatchingItems(pep_ids, pred);
599 }
600
602
603
606
608 template<class IdentificationType>
609 static Size countHits(const std::vector<IdentificationType>& ids)
610 {
611 Size counter = 0;
612 for (typename std::vector<IdentificationType>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it)
613 {
614 counter += id_it->getHits().size();
615 }
616 return counter;
617 }
618
621 {
622 Size counter = 0;
623 for (const auto& id : ids)
624 {
625 counter += id.getHits().size();
626 }
627 return counter;
628 }
629
631 static void filterHitsByRank(PeptideIdentificationList& ids, Size min_rank, Size max_rank)
632 {
633 std::vector<PeptideIdentification>& vec = ids.getData();
634 filterHitsByRank(vec, min_rank, max_rank);
635 }
636
638 static void removeHitsMatchingProteins(PeptideIdentificationList& ids, const std::set<std::string>& accessions)
639 {
640 std::vector<PeptideIdentification>& vec = ids.getData();
641 removeHitsMatchingProteins(vec, accessions);
642 }
643
645 static void keepHitsMatchingProteins(PeptideIdentificationList& ids, const std::set<std::string>& accessions)
646 {
647 std::vector<PeptideIdentification>& vec = ids.getData();
648 keepHitsMatchingProteins(vec, accessions);
649 }
650
652 static bool getBestHit(PeptideIdentificationList& ids, bool assume_sorted, PeptideHit& best_hit)
653 {
654 std::vector<PeptideIdentification>& vec = ids.getData();
655 return getBestHit(vec, assume_sorted, best_hit);
656 }
657
660 {
661 std::vector<PeptideIdentification>& vec = ids.getData();
662 removeEmptyIdentifications(vec);
663 }
664
678 template<class IdentificationType>
679 static bool getBestHit(const std::vector<IdentificationType>& identifications, bool assume_sorted, typename IdentificationType::HitType& best_hit)
680 {
681 if (identifications.empty())
682 return false;
683
684 typename std::vector<IdentificationType>::const_iterator best_id_it = identifications.end();
685 typename std::vector<typename IdentificationType::HitType>::const_iterator best_hit_it;
686
687 for (typename std::vector<IdentificationType>::const_iterator id_it = identifications.begin(); id_it != identifications.end(); ++id_it)
688 {
689 if (id_it->getHits().empty())
690 continue;
691
692 if (best_id_it == identifications.end()) // no previous "best" hit
693 {
694 best_id_it = id_it;
695 best_hit_it = id_it->getHits().begin();
696 }
697 else if (best_id_it->getScoreType() != id_it->getScoreType())
698 {
699 throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Can't compare scores of different types", best_id_it->getScoreType() + "/" + id_it->getScoreType());
700 }
701
702 bool higher_better = best_id_it->isHigherScoreBetter();
703 for (typename std::vector<typename IdentificationType::HitType>::const_iterator hit_it = id_it->getHits().begin(); hit_it != id_it->getHits().end(); ++hit_it)
704 {
705 if ((higher_better && (hit_it->getScore() > best_hit_it->getScore())) || (!higher_better && (hit_it->getScore() < best_hit_it->getScore())))
706 {
707 best_hit_it = hit_it;
708 }
709 if (assume_sorted)
710 break; // only consider the first hit
711 }
712 }
713
714 if (best_id_it == identifications.end())
715 {
716 return false; // no hits in any IDs
717 }
718
719 best_hit = *best_hit_it;
720 return true;
721 }
722
730 static void extractPeptideSequences(const PeptideIdentificationList& peptides, std::set<std::string>& sequences, bool ignore_mods = false);
731
737 static std::map<std::string, std::vector<ProteinHit>> extractUnassignedProteins(ConsensusMap& cmap);
738
744 template<class EvidenceFilter>
745 static void FilterPeptideEvidences(EvidenceFilter& filter, PeptideIdentificationList& peptides)
746 {
747 for (PeptideIdentificationList::iterator pep_it = peptides.begin(); pep_it != peptides.end(); ++pep_it)
748 {
749 for (std::vector<PeptideHit>::iterator hit_it = pep_it->getHits().begin(); hit_it != pep_it->getHits().end(); ++hit_it)
750 {
751 std::vector<PeptideEvidence> evidences;
752 remove_copy_if(hit_it->getPeptideEvidences().begin(), hit_it->getPeptideEvidences().end(), back_inserter(evidences), std::not_fn(filter));
753 hit_it->setPeptideEvidences(evidences);
754 }
755 }
756 }
757
759
760
765 static void removeUnreferencedProteins(ConsensusMap& cmap, bool include_unassigned);
766
768 static void removeUnreferencedProteins(std::vector<ProteinIdentification>& proteins, const PeptideIdentificationList& peptides);
771
787 static void removeDanglingProteinReferences(PeptideIdentificationList& peptides, const std::vector<ProteinIdentification>& proteins, bool remove_peptides_without_reference = false);
788
803 static void removeDanglingProteinReferences(ConsensusMap& cmap, bool remove_peptides_without_reference = false);
804
819 static void removeDanglingProteinReferences(ConsensusMap& cmap, const ProteinIdentification& ref_run, bool remove_peptides_without_reference = false);
820
829 static bool updateProteinGroups(std::vector<ProteinIdentification::ProteinGroup>& groups, const std::vector<ProteinHit>& hits);
830
837 static void removeUngroupedProteins(const std::vector<ProteinIdentification::ProteinGroup>& groups, std::vector<ProteinHit>& hits);
839
840
843
845 template<IsPeptideOrProteinIdentification IdentificationType>
846 static void removeEmptyIdentifications(std::vector<IdentificationType>& ids)
847 {
848 struct HasNoHits<IdentificationType> empty_filter;
849 removeMatchingItems(ids, empty_filter);
850 }
851
857 template<class IdentificationType>
858 static void filterHitsByScore(std::vector<IdentificationType>& ids, double threshold_score)
859 {
860 for (typename std::vector<IdentificationType>::iterator id_it = ids.begin(); id_it != ids.end(); ++id_it)
861 {
862 struct HasGoodScore<typename IdentificationType::HitType> score_filter(threshold_score, id_it->isHigherScoreBetter());
863 keepMatchingItems(id_it->getHits(), score_filter);
864 }
865 }
866
880 template<class IdentificationType>
881 static void filterHitsByScore(std::vector<IdentificationType>& ids, double threshold_score, IDScoreSwitcherAlgorithm::ScoreType score_type)
882 {
884 bool any_id_missing_score_type = false;
885 for (IdentificationType& id : ids)
886 {
887 if (switcher.isScoreType(id.getScoreType(), score_type))
888 {
889 struct HasGoodScore<typename IdentificationType::HitType> score_filter(threshold_score, id.isHigherScoreBetter());
890 keepMatchingItems(id.getHits(), score_filter);
891 }
892 else
893 {
894 // If one assumes they are all the same in the vector, this could be done in the beginning.
895 auto result = switcher.findScoreType<IdentificationType>(id, score_type);
896 if (!result.score_name.empty())
897 {
898 std::string metaval = result.score_name;
899 if (switcher.isScoreTypeHigherBetter(score_type))
900 {
901 struct HasMinMetaValue<typename IdentificationType::HitType> score_filter(metaval, threshold_score);
902 keepMatchingItems(id.getHits(), score_filter);
903 }
904 else
905 {
906 struct HasMaxMetaValue<typename IdentificationType::HitType> score_filter(metaval, threshold_score);
907 keepMatchingItems(id.getHits(), score_filter);
908 }
909 }
910 else
911 {
912 // Remove all hits when the requested score type is absent, as documented above.
913 id.getHits().clear();
914 any_id_missing_score_type = true;
915 }
916 }
917 }
918 if (any_id_missing_score_type)
919 {
920 OPENMS_LOG_WARN << "Warning: At least one identification did not contain the given score_type; all hits of those identifications were removed." << std::endl;
921 }
922 }
923
930 static void filterGroupsByScore(std::vector<ProteinIdentification::ProteinGroup>& grps, double threshold_score, bool higher_better);
931
937 template<class IdentificationType>
938 static void filterHitsByScore(IdentificationType& id, double threshold_score)
939 {
940 struct HasGoodScore<typename IdentificationType::HitType> score_filter(threshold_score, id.isHigherScoreBetter());
941 keepMatchingItems(id.getHits(), score_filter);
942 }
943
949 template<class IdentificationType>
950 static void keepNBestHits(std::vector<IdentificationType>& ids, Size n)
951 {
952 for (typename std::vector<IdentificationType>::iterator id_it = ids.begin(); id_it != ids.end(); ++id_it)
953 {
954 id_it->sort();
955 if (n < id_it->getHits().size())
956 id_it->getHits().resize(n);
957 }
958 }
959
969 {
970 std::vector<PeptideIdentification>& vec = pep_ids.getData();
971 keepNBestHits(vec, n);
972 }
973
988 template<class IdentificationType>
989 static void filterHitsByRank(std::vector<IdentificationType>& ids, Size min_rank, Size max_rank)
990 {
991 for (auto& id : ids)
992 {
993 auto& hits = id.getHits();
994 if (hits.empty()) continue;
995
996 id.sort(); // Ensure hits are properly sorted
997
998 // ignore max_rank?
999 if (max_rank < min_rank) max_rank = hits.size();
1000
1001 Size rank = 1;
1002 double last_score = hits.front().getScore();
1003
1004 // Remove hits not within [min_rank, max_rank], while computing rank on the fly
1005 hits.erase(
1006 std::remove_if(hits.begin(), hits.end(),
1007 [&](const auto& hit) {
1008 if (hit.getScore() != last_score)
1009 {
1010 ++rank;
1011 last_score = hit.getScore();
1012 }
1013 return rank < min_rank || rank > max_rank;
1014 }),
1015 hits.end()
1016 );
1017 }
1018 }
1019
1027 template<class IdentificationType>
1028 static void removeDecoyHits(std::vector<IdentificationType>& ids)
1029 {
1030 struct HasDecoyAnnotation<typename IdentificationType::HitType> decoy_filter;
1031 for (typename std::vector<IdentificationType>::iterator id_it = ids.begin(); id_it != ids.end(); ++id_it)
1032 {
1033 removeMatchingItems(id_it->getHits(), decoy_filter);
1034 }
1035 }
1036
1044 template<class IdentificationType>
1045 static void removeHitsMatchingProteins(std::vector<IdentificationType>& ids, const std::set<std::string> accessions)
1046 {
1048 for (auto& id_it : ids)
1049 {
1050 removeMatchingItems(id_it.getHits(), acc_filter);
1051 }
1052 }
1053
1061 template<IsPeptideOrProteinIdentification IdentificationType>
1062 static void keepHitsMatchingProteins(IdentificationType& id, const std::set<std::string>& accessions)
1063 {
1065 keepMatchingItems(id.getHits(), acc_filter);
1066 }
1067
1075 template<class IdentificationType>
1076 static void keepHitsMatchingProteins(std::vector<IdentificationType>& ids, const std::set<std::string>& accessions)
1077 {
1078 for (auto& id_it : ids) keepHitsMatchingProteins(id_it, accessions);
1079 }
1080
1082
1083
1086
1093 static void keepBestPeptideHits(PeptideIdentificationList& peptides, bool strict = false);
1094
1103 static void filterPeptidesByLength(PeptideIdentificationList& peptides, Size min_length, Size max_length = UINT_MAX);
1104
1113 static void filterPeptidesByCharge(PeptideIdentificationList& peptides, Int min_charge, Int max_charge);
1114
1116 static void filterPeptidesByRT(PeptideIdentificationList& peptides, double min_rt, double max_rt);
1117
1119 static void filterPeptidesByMZ(PeptideIdentificationList& peptides, double min_mz, double max_mz);
1120
1132 static void filterPeptidesByMZError(PeptideIdentificationList& peptides, double mass_error, bool unit_ppm);
1133
1134
1141 template<class Filter>
1142 static void filterPeptideEvidences(Filter& filter, PeptideIdentificationList& peptides);
1143
1155 static void filterPeptidesByRTPredictPValue(PeptideIdentificationList& peptides, const std::string& metavalue_key, double threshold = 0.05);
1156
1158 static void removePeptidesWithMatchingModifications(PeptideIdentificationList& peptides, const std::set<std::string>& modifications);
1159
1160 static void removePeptidesWithMatchingRegEx(PeptideIdentificationList& peptides, const std::string& regex);
1161
1163 static void keepPeptidesWithMatchingModifications(PeptideIdentificationList& peptides, const std::set<std::string>& modifications);
1164
1172 static void removePeptidesWithMatchingSequences(PeptideIdentificationList& peptides, const PeptideIdentificationList& bad_peptides, bool ignore_mods = false);
1173
1181 static void keepPeptidesWithMatchingSequences(PeptideIdentificationList& peptides, const PeptideIdentificationList& good_peptides, bool ignore_mods = false);
1182
1185
1192 static void removeDuplicatePeptideHits(PeptideIdentificationList& peptides, bool seq_only = false);
1193
1195
1196
1199
1201 static void filterHitsByScore(AnnotatedMSRun& annotated_data,
1202 double peptide_threshold_score,
1203 double protein_threshold_score)
1204 {
1205 // filter protein hits:
1206 filterHitsByScore(annotated_data.getProteinIdentifications(),
1207 protein_threshold_score);
1208 // don't remove empty protein IDs - they contain search meta data and may
1209 // be referenced by peptide IDs (via run ID)
1210
1211 // filter peptide hits:
1212 for (PeptideIdentification& peptide_id : annotated_data.getPeptideIdentifications())
1213 {
1214 filterHitsByScore(peptide_id, peptide_threshold_score);
1215 }
1216 removeDanglingProteinReferences(annotated_data.getPeptideIdentifications(), annotated_data.getProteinIdentifications());
1217 }
1218
1220 static void keepNBestHits(AnnotatedMSRun& annotated_data, Size n)
1221 {
1222 // don't filter the protein hits by "N best" here - filter the peptides
1223 // and update the protein hits!
1224 PeptideIdentificationList all_peptides; // IDs from all spectra
1225 // filter peptide hits:
1226 for (PeptideIdentification& peptide_id : annotated_data.getPeptideIdentifications())
1227 {
1228 // Create a temporary vector with a single PeptideIdentification
1229 PeptideIdentificationList temp_vec = {peptide_id};
1230 keepNBestHits(temp_vec, n);
1231 // Copy back the filtered hits
1232 if (!temp_vec.empty())
1233 {
1234 peptide_id = temp_vec[0];
1235 }
1236 else
1237 {
1238 peptide_id.getHits().clear();
1239 }
1240
1241 // Since we're working with individual PeptideIdentifications, we don't need to remove empty ones
1242 // but we still need to update protein references
1243 temp_vec = {peptide_id};
1244 removeDanglingProteinReferences(temp_vec, annotated_data.getProteinIdentifications());
1245 all_peptides.push_back(peptide_id);
1246 }
1247 // update protein hits:
1248 removeUnreferencedProteins(annotated_data.getProteinIdentifications(), all_peptides);
1249 }
1250
1254
1256 template<class MapType>
1257 static void keepNBestPeptideHits(MapType& map, Size n)
1258 {
1259 // The rank predicate needs annotated ranks, not sure if they are always updated. Use the following instead,
1260 // which sorts Hits first.
1261 for (auto& feat : map)
1262 {
1263 keepNBestHits(feat.getPeptideIdentifications(), n);
1264 }
1265 keepNBestHits(map.getUnassignedPeptideIdentifications(), n);
1266 }
1267
1268 template<IsNotIdentificationVector MapType>
1269 static void removeEmptyIdentifications(MapType& prot_and_pep_ids)
1270 {
1271 const auto pred = HasNoHits<PeptideIdentification>();
1272 removeMatchingPeptideIdentifications(prot_and_pep_ids, pred);
1273 }
1274
1276 static void keepBestPerPeptide(PeptideIdentificationList& pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
1277 {
1278 annotateBestPerPeptide(pep_ids, ignore_mods, ignore_charges, nr_best_spectrum);
1279 HasMetaValue<PeptideHit> best_per_peptide {"best_per_peptide", 1};
1280 keepMatchingItemsUnroll(pep_ids, best_per_peptide);
1281 }
1282
1283 static void keepBestPerPeptidePerRun(std::vector<ProteinIdentification>& prot_ids, PeptideIdentificationList& pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
1284 {
1285 annotateBestPerPeptidePerRun(prot_ids, pep_ids, ignore_mods, ignore_charges, nr_best_spectrum);
1286 HasMetaValue<PeptideHit> best_per_peptide {"best_per_peptide", 1};
1287 keepMatchingItemsUnroll(pep_ids, best_per_peptide);
1288 }
1289
1290 // TODO allow skipping unassigned?
1291 template<class MapType>
1292 static void annotateBestPerPeptidePerRun(MapType& prot_and_pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
1293 {
1294 const auto& prot_ids = prot_and_pep_ids.getProteinIdentifications();
1295
1296 RunToSequenceToChargeToPepHitP best_peps_per_run;
1297 for (const auto& idrun : prot_ids)
1298 {
1299 best_peps_per_run[idrun.getIdentifier()] = SequenceToChargeToPepHitP();
1300 }
1301
1302 for (auto& feat : prot_and_pep_ids)
1303 {
1304 annotateBestPerPeptidePerRunWithData(best_peps_per_run, feat.getPeptideIdentifications(), ignore_mods, ignore_charges, nr_best_spectrum);
1305 }
1306
1307 annotateBestPerPeptidePerRunWithData(best_peps_per_run, prot_and_pep_ids.getUnassignedPeptideIdentifications(), ignore_mods, ignore_charges, nr_best_spectrum);
1308 }
1309
1310 template<class MapType>
1311 static void keepBestPerPeptidePerRun(MapType& prot_and_pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
1312 {
1313 annotateBestPerPeptidePerRun(prot_and_pep_ids, ignore_mods, ignore_charges, nr_best_spectrum);
1314 HasMetaValue<PeptideHit> best_per_peptide {"best_per_peptide", 1};
1315 keepMatchingPeptideHits(prot_and_pep_ids, best_per_peptide);
1316 }
1317
1320 static void annotateBestPerPeptidePerRun(const std::vector<ProteinIdentification>& prot_ids, PeptideIdentificationList& pep_ids, bool ignore_mods, bool ignore_charges,
1321 Size nr_best_spectrum)
1322 {
1323 RunToSequenceToChargeToPepHitP best_peps_per_run;
1324 for (const auto& id : prot_ids)
1325 {
1326 best_peps_per_run[id.getIdentifier()] = SequenceToChargeToPepHitP();
1327 }
1328 annotateBestPerPeptidePerRunWithData(best_peps_per_run, pep_ids, ignore_mods, ignore_charges, nr_best_spectrum);
1329 }
1330
1334 static void annotateBestPerPeptidePerRunWithData(RunToSequenceToChargeToPepHitP& best_peps_per_run, PeptideIdentificationList& pep_ids, bool ignore_mods, bool ignore_charges,
1335 Size nr_best_spectrum)
1336 {
1337 for (auto& pep : pep_ids)
1338 {
1339 SequenceToChargeToPepHitP& best_pep = best_peps_per_run[pep.getIdentifier()];
1340 annotateBestPerPeptideWithData(best_pep, pep, ignore_mods, ignore_charges, nr_best_spectrum);
1341 }
1342 }
1343
1347 static void annotateBestPerPeptide(PeptideIdentificationList& pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
1348 {
1350 for (auto& pep : pep_ids)
1351 {
1352 annotateBestPerPeptideWithData(best_pep, pep, ignore_mods, ignore_charges, nr_best_spectrum);
1353 }
1354 }
1355
1360 static void annotateBestPerPeptideWithData(SequenceToChargeToPepHitP& best_pep, PeptideIdentification& pep, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
1361 {
1362 bool higher_score_better = pep.isHigherScoreBetter();
1363 // make sure that first = best hit
1364 pep.sort();
1365
1366 auto pepIt = pep.getHits().begin();
1367 auto pepItEnd = nr_best_spectrum == 0 || pep.getHits().size() <= nr_best_spectrum ? pep.getHits().end() : pep.getHits().begin() + nr_best_spectrum;
1368 for (; pepIt != pepItEnd; ++pepIt)
1369 {
1370 PeptideHit& hit = *pepIt;
1371
1372 std::string lookup_seq;
1373 if (ignore_mods)
1374 {
1375 lookup_seq = hit.getSequence().toUnmodifiedString();
1376 }
1377 else
1378 {
1379 lookup_seq = hit.getSequence().toString();
1380 }
1381
1382 int lookup_charge = 0;
1383 if (!ignore_charges)
1384 {
1385 lookup_charge = hit.getCharge();
1386 }
1387
1388 // try to insert
1389 auto it_inserted = best_pep.emplace(std::move(lookup_seq), ChargeToPepHitP());
1390 auto it_inserted_chg = it_inserted.first->second.emplace(lookup_charge, &hit);
1391
1392 PeptideHit*& p = it_inserted_chg.first->second; // now this gets either the old one if already present, or this
1393 if (!it_inserted_chg.second) // was already present -> possibly update
1394 {
1395 if ((higher_score_better && (hit.getScore() > p->getScore())) || (!higher_score_better && (hit.getScore() < p->getScore())))
1396 {
1397 p->setMetaValue("best_per_peptide", 0);
1398 hit.setMetaValue("best_per_peptide", 1);
1399 p = &hit;
1400 }
1401 else // note that this was def. not the best
1402 {
1403 // TODO if it is only about filtering, we can omit writing this metavalue (absence = false)
1404 hit.setMetaValue("best_per_peptide", 0);
1405 }
1406 }
1407 else // newly inserted -> first for that sequence (and optionally charge)
1408 {
1409 hit.setMetaValue("best_per_peptide", 1);
1410 }
1411 }
1412 }
1413
1416 AnnotatedMSRun& experiment,
1417 const std::vector<FASTAFile::FASTAEntry>& proteins)
1418 {
1419 std::set<std::string> accessions;
1420 for (auto it = proteins.begin(); it != proteins.end(); ++it)
1421 {
1422 accessions.insert(it->identifier);
1423 }
1424
1425 // filter protein hits:
1426 keepHitsMatchingProteins(experiment.getProteinIdentifications(), accessions);
1427
1428 // filter peptide hits:
1429 // std::pair<OpenMS::MSSpectrum&, OpenMS::PeptideIdentification&>
1430 for (auto [spectrum, peptide_id] : experiment)
1431 {
1432 if (spectrum.getMSLevel() == 2)
1433 {
1434 keepHitsMatchingProteins(peptide_id, accessions);
1435 }
1436 }
1437 removeEmptyIdentifications(experiment.getPeptideIdentifications());
1438 }
1439
1441
1442
1445
1456
1474
1480 static void removeDecoys(IdentificationData& id_data);
1482
1483 // Specific overloads for PeptideIdentificationList to ensure correct template resolution
1485 {
1486 removeDecoyHits(ids.getData());
1487 }
1488
1489 static void filterHitsByScore(PeptideIdentificationList& ids, double threshold_score)
1490 {
1491 filterHitsByScore(ids.getData(), threshold_score);
1492 }
1493
1494 static void removeUnreferencedProteins(std::vector<ProteinIdentification>& proteins, PeptideIdentificationList& ids)
1495 {
1496 removeUnreferencedProteins(proteins, ids.getData());
1497 }
1498 };
1499
1500} // namespace OpenMS
#define OPENMS_LOG_WARN
Macro for warnings.
Definition LogStream.h:691
std::string toString() const
returns the peptide as string with modifications embedded in brackets
std::string toUnmodifiedString() const
returns the peptide as string without any modifications or (e.g., "PEPTIDER")
Class for storing MS run data with peptide and protein identifications.
Definition AnnotatedMSRun.h:38
PeptideIdentificationList & getPeptideIdentifications()
Get all peptide identifications for all spectra.
std::vector< ProteinIdentification > & getProteinIdentifications()
Get the protein identification.
Definition AnnotatedMSRun.h:85
A container for consensus elements.
Definition ConsensusMap.h:67
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition DataValue.h:33
bool isEmpty() const
Test if the value is empty.
Class for the enzymatic digestion of sequences.
Definition EnzymaticDigestion.h:39
bool filterByMissedCleavages(const std::string &sequence, const std::function< bool(const Int)> &filter) const
Filter based on the number of missed cleavages.
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition Exception.h:317
Invalid value exception.
Definition Exception.h:306
const VecMember & getData() const
read-only access to the underlying data
Definition ExposedVector.h:328
void clear() noexcept
Clear all elements.
Definition ExposedVector.h:200
typename VecMember::iterator iterator
Definition ExposedVector.h:68
bool empty() const noexcept
Definition ExposedVector.h:140
iterator begin() noexcept
Definition ExposedVector.h:104
void push_back(const VectorElement &f)
Definition ExposedVector.h:168
iterator end() noexcept
Definition ExposedVector.h:108
Filter Peptide Hit by its digestion product.
Definition IDFilter.h:394
Int max_cleavages_
Definition IDFilter.h:398
EnzymaticDigestion & digestion_
Definition IDFilter.h:396
PeptideHit argument_type
Definition IDFilter.h:401
Int min_cleavages_
Definition IDFilter.h:397
bool operator()(PeptideHit &p) const
Definition IDFilter.h:413
void filterPeptideSequences(std::vector< PeptideHit > &hits)
Definition IDFilter.h:423
PeptideDigestionFilter(EnzymaticDigestion &digestion, Int min, Int max)
Definition IDFilter.h:402
static Int disabledValue()
Definition IDFilter.h:406
Collection of functions for filtering peptide and protein identifications.
Definition IDFilter.h:71
static void filterHitsByScore(std::vector< IdentificationType > &ids, double threshold_score)
Filters peptide or protein identifications according to the score of the hits.
Definition IDFilter.h:858
static void removeUnreferencedProteins(std::vector< ProteinIdentification > &proteins, const PeptideIdentificationList &peptides)
Removes protein hits from proteins that are not referenced by a peptide in peptides.
static void removeDanglingProteinReferences(ConsensusMap &cmap, const ProteinIdentification &ref_run, bool remove_peptides_without_reference=false)
Removes dangling protein references from peptide hits using a reference protein run.
static void moveMatchingItems(Container &items, const Predicate &pred, Container &target)
Move items that satisfy a condition to a container (e.g. vector)
Definition IDFilter.h:537
static void keepBestPerPeptide(PeptideIdentificationList &pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
Filters PeptideHits from PeptideIdentification by keeping only the best peptide hits for every peptid...
Definition IDFilter.h:1276
static void keepPeptidesWithMatchingModifications(PeptideIdentificationList &peptides, const std::set< std::string > &modifications)
Keeps only peptide hits that have at least one of the given modifications.
static void keepBestMatchPerObservation(IdentificationData &id_data, IdentificationData::ScoreTypeRef score_ref)
Filter IdentificationData to keep only the best match (e.g. PSM) for each observation (e....
static void annotateBestPerPeptidePerRun(MapType &prot_and_pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
Definition IDFilter.h:1292
static void annotateBestPerPeptidePerRunWithData(RunToSequenceToChargeToPepHitP &best_peps_per_run, PeptideIdentificationList &pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
Definition IDFilter.h:1334
static void annotateBestPerPeptidePerRun(const std::vector< ProteinIdentification > &prot_ids, PeptideIdentificationList &pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
Definition IDFilter.h:1320
std::map< std::string, SequenceToChargeToPepHitP > RunToSequenceToChargeToPepHitP
Definition IDFilter.h:82
static void keepMatchingPeptideHits(MapType &prot_and_pep_ids, Predicate &pred)
Definition IDFilter.h:565
static void removeEmptyIdentifications(MapType &prot_and_pep_ids)
Definition IDFilter.h:1269
static void removeMatchingItems(Container &items, const Predicate &pred)
Remove items that satisfy a condition from a container (e.g. vector)
Definition IDFilter.h:523
std::unordered_map< std::string, ChargeToPepHitP > SequenceToChargeToPepHitP
Definition IDFilter.h:81
static void filterPeptidesByMZError(PeptideIdentificationList &peptides, double mass_error, bool unit_ppm)
Filter peptide identifications according to mass deviation.
static void removeDecoyHits(PeptideIdentificationList &ids)
Definition IDFilter.h:1484
static void removeEmptyIdentifications(std::vector< IdentificationType > &ids)
Removes peptide or protein identifications that have no hits in them.
Definition IDFilter.h:846
static void removeEmptyIdentifications(PeptideIdentificationList &ids)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition IDFilter.h:659
static void keepHitsMatchingProteins(PeptideIdentificationList &ids, const std::set< std::string > &accessions)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition IDFilter.h:645
static void keepNBestHits(AnnotatedMSRun &annotated_data, Size n)
Filters AnnotatedMSRun by keeping the N best peptide hits for every spectrum.
Definition IDFilter.h:1220
IDFilter()=default
Constructor.
static void keepMatchingItemsUnroll(IDContainer &items, const Predicate &pred)
Keep Hit items that satisfy a condition in one of our ID containers (e.g. vector of Peptide or Protei...
Definition IDFilter.h:556
static void removeDanglingProteinReferences(ConsensusMap &cmap, bool remove_peptides_without_reference=false)
Removes dangling protein references from peptide hits in a ConsensusMap.
static void removeDecoys(IdentificationData &id_data)
Filter IdentificationData to remove parent sequences annotated as decoys.
static void removeDecoyHits(std::vector< IdentificationType > &ids)
Removes hits annotated as decoys from peptide or protein identifications.
Definition IDFilter.h:1028
static void removeHitsMatchingProteins(PeptideIdentificationList &ids, const std::set< std::string > &accessions)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition IDFilter.h:638
virtual ~IDFilter()=default
Destructor.
static void keepMatchingItems(Container &items, const Predicate &pred)
Keep items that satisfy a condition in a container (e.g. vector), removing all others.
Definition IDFilter.h:530
static void annotateBestPerPeptideWithData(SequenceToChargeToPepHitP &best_pep, PeptideIdentification &pep, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
Definition IDFilter.h:1360
static void filterObservationMatchesByScore(IdentificationData &id_data, IdentificationData::ScoreTypeRef score_ref, double cutoff)
Filter observation matches (e.g. PSMs) in IdentificationData by score.
static void keepHitsMatchingProteins(AnnotatedMSRun &experiment, const std::vector< FASTAFile::FASTAEntry > &proteins)
Filters AnnotatedMSRun according to the given proteins.
Definition IDFilter.h:1415
static void removeMatchingPeptideHits(MapType &prot_and_pep_ids, Predicate &pred)
Definition IDFilter.h:575
static void annotateBestPerPeptide(PeptideIdentificationList &pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
Definition IDFilter.h:1347
static void filterHitsByRank(PeptideIdentificationList &ids, Size min_rank, Size max_rank)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition IDFilter.h:631
static bool updateProteinGroups(std::vector< ProteinIdentification::ProteinGroup > &groups, const std::vector< ProteinHit > &hits)
Update protein groups after protein hits were filtered.
static void keepBestPeptideHits(PeptideIdentificationList &peptides, bool strict=false)
Filters peptide identifications keeping only the single best-scoring hit per ID.
static Size countHits(const PeptideIdentificationList &ids)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition IDFilter.h:620
static void removeHitsMatchingProteins(std::vector< IdentificationType > &ids, const std::set< std::string > accessions)
Filters peptide or protein identifications according to the given proteins (negative).
Definition IDFilter.h:1045
static void keepHitsMatchingProteins(IdentificationType &id, const std::set< std::string > &accessions)
Filters peptide or protein identifications according to the given proteins (positive).
Definition IDFilter.h:1062
static void filterHitsByRank(std::vector< IdentificationType > &ids, Size min_rank, Size max_rank)
Filters peptide or protein identifications according to the ranking of the hits.
Definition IDFilter.h:989
static void keepUniquePeptidesPerProtein(PeptideIdentificationList &peptides)
Removes all peptides that are not annotated as unique for a protein (by PeptideIndexer)
static void keepNBestPeptideHits(MapType &map, Size n)
Filters a Consensus/FeatureMap by keeping the N best peptide hits for every spectrum.
Definition IDFilter.h:1257
static bool getBestHit(PeptideIdentificationList &ids, bool assume_sorted, PeptideHit &best_hit)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition IDFilter.h:652
static void filterGroupsByScore(std::vector< ProteinIdentification::ProteinGroup > &grps, double threshold_score, bool higher_better)
Filters protein groups according to the score of the groups.
static void filterPeptidesByLength(PeptideIdentificationList &peptides, Size min_length, Size max_length=UINT_MAX)
Filters peptide identifications according to peptide sequence length.
static void filterPeptideEvidences(Filter &filter, PeptideIdentificationList &peptides)
Digest a collection of proteins and filter PeptideEvidences based on specificity PeptideEvidences of ...
static void removeMatchingItemsUnroll(IDContainer &items, const Predicate &pred)
Remove Hit items that satisfy a condition in one of our ID containers (e.g. vector of Peptide or Prot...
Definition IDFilter.h:546
static void keepNBestHits(PeptideIdentificationList &pep_ids, Size n)
Filters peptide identifications according to the ranking of the hits.
Definition IDFilter.h:968
static void keepHitsMatchingProteins(std::vector< IdentificationType > &ids, const std::set< std::string > &accessions)
Filters peptide or protein identifications according to the given proteins (positive).
Definition IDFilter.h:1076
static void filterHitsByScore(PeptideIdentificationList &ids, double threshold_score)
Definition IDFilter.h:1489
static void removeMatchingPeptideIdentifications(MapType &prot_and_pep_ids, Predicate &pred)
Definition IDFilter.h:585
static void filterHitsByScore(AnnotatedMSRun &annotated_data, double peptide_threshold_score, double protein_threshold_score)
Filters AnnotatedMSRun according to score thresholds.
Definition IDFilter.h:1201
static void FilterPeptideEvidences(EvidenceFilter &filter, PeptideIdentificationList &peptides)
remove peptide evidences based on a filter
Definition IDFilter.h:745
static void removePeptidesWithMatchingModifications(PeptideIdentificationList &peptides, const std::set< std::string > &modifications)
Removes all peptide hits that have at least one of the given modifications.
static Size countHits(const std::vector< IdentificationType > &ids)
Returns the total number of peptide/protein hits in a vector of peptide/protein identifications.
Definition IDFilter.h:609
static void removeUnreferencedProteins(std::vector< ProteinIdentification > &proteins, PeptideIdentificationList &ids)
Definition IDFilter.h:1494
static void removeDanglingProteinReferences(PeptideIdentificationList &peptides, const std::vector< ProteinIdentification > &proteins, bool remove_peptides_without_reference=false)
Removes dangling protein references from peptide hits.
static bool getBestHit(const std::vector< IdentificationType > &identifications, bool assume_sorted, typename IdentificationType::HitType &best_hit)
Finds the best-scoring hit in a vector of peptide or protein identifications.
Definition IDFilter.h:679
static void removePeptidesWithMatchingSequences(PeptideIdentificationList &peptides, const PeptideIdentificationList &bad_peptides, bool ignore_mods=false)
Removes all peptide hits with a sequence that matches one in bad_peptides.
static void filterHitsByScore(IdentificationType &id, double threshold_score)
Filters peptide or protein identifications according to the score of the hits.
Definition IDFilter.h:938
static void keepBestPerPeptidePerRun(MapType &prot_and_pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
Definition IDFilter.h:1311
static void keepBestPerPeptidePerRun(std::vector< ProteinIdentification > &prot_ids, PeptideIdentificationList &pep_ids, bool ignore_mods, bool ignore_charges, Size nr_best_spectrum)
Definition IDFilter.h:1283
static void removePeptidesWithMatchingRegEx(PeptideIdentificationList &peptides, const std::string &regex)
static void keepNBestSpectra(PeptideIdentificationList &peptides, Size n)
static void removeUngroupedProteins(const std::vector< ProteinIdentification::ProteinGroup > &groups, std::vector< ProteinHit > &hits)
Update protein hits after protein groups were filtered.
static void extractPeptideSequences(const PeptideIdentificationList &peptides, std::set< std::string > &sequences, bool ignore_mods=false)
Extracts all unique peptide sequences from a list of peptide IDs.
static void filterPeptidesByRT(PeptideIdentificationList &peptides, double min_rt, double max_rt)
Filters peptide identifications by precursor RT, keeping only IDs in the given range.
static void filterPeptidesByCharge(PeptideIdentificationList &peptides, Int min_charge, Int max_charge)
Filters peptide identifications according to charge state.
static void removeMatchingPeptideIdentifications(PeptideIdentificationList &pep_ids, Predicate &pred)
Definition IDFilter.h:596
static void filterPeptidesByMZ(PeptideIdentificationList &peptides, double min_mz, double max_mz)
Filters peptide identifications by precursor m/z, keeping only IDs in the given range.
static void removeDuplicatePeptideHits(PeptideIdentificationList &peptides, bool seq_only=false)
Removes duplicate peptide hits from each peptide identification, keeping only unique hits (per ID).
static void filterPeptidesByRTPredictPValue(PeptideIdentificationList &peptides, const std::string &metavalue_key, double threshold=0.05)
Filters peptide identifications according to p-values from RTPredict.
static void keepPeptidesWithMatchingSequences(PeptideIdentificationList &peptides, const PeptideIdentificationList &good_peptides, bool ignore_mods=false)
Removes all peptide hits with a sequence that does not match one in good_peptides.
static void removeUnreferencedProteins(ConsensusMap &cmap, bool include_unassigned)
static void removeUnreferencedProteins(ProteinIdentification &proteins, const PeptideIdentificationList &peptides)
Removes protein hits from proteins that are not referenced by a peptide in peptides.
static std::map< std::string, std::vector< ProteinHit > > extractUnassignedProteins(ConsensusMap &cmap)
Extracts all proteins not matched by PSMs in features.
std::map< Int, PeptideHit * > ChargeToPepHitP
Typedefs.
Definition IDFilter.h:80
This class is used to switch identification scores within identification or consensus feature maps.
Definition IDScoreSwitcherAlgorithm.h:43
bool isScoreType(const std::string &score_name, const ScoreType &type) const
Checks if the given score name corresponds to a specific score type.
Definition IDScoreSwitcherAlgorithm.h:65
bool isScoreTypeHigherBetter(ScoreType score_type)
Determines whether a higher score type is better given a ScoreType enum.
Definition IDScoreSwitcherAlgorithm.h:93
ScoreSearchResult findScoreType(const IdentificationType &id, ScoreType score_type) const
Searches for a general score type (e.g. PEP, QVAL) in an identification data structure.
Definition IDScoreSwitcherAlgorithm.h:130
Definition IdentificationData.h:87
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
void setMetaValue(const std::string &name, const DataValue &value)
Sets the DataValue corresponding to a name.
Representation of a peptide evidence.
Definition PeptideEvidence.h:28
Int getStart() const
get the position in the protein (starting at 0 for the N-terminus). If not available UNKNOWN_POSITION...
bool hasValidLimits() const
start and end numbers in evidence represent actual numeric indices
const std::string & getProteinAccession() const
get the protein accession the peptide matches to. If not available the empty string is returned.
Int getEnd() const
get the position of the last AA of the peptide in protein coordinates (starting at 0 for the N-termin...
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition PeptideHit.h:52
double getScore() const
returns the PSM score
const AASequence & getSequence() const
returns the peptide sequence
Int getCharge() const
returns the charge of the peptide
std::set< std::string > extractProteinAccessionsSet() const
extracts the set of non-empty protein accessions from peptide evidences
Container for peptide identifications from multiple spectra.
Definition PeptideIdentificationList.h:66
Represents the set of candidates (SpectrumMatches) identified for a single precursor spectrum.
Definition PeptideIdentification.h:66
void sort()
Sorts the hits by score.
const std::vector< PeptideHit > & getHits() const
returns the peptide hits as const
bool isHigherScoreBetter() const
returns the peptide score orientation
Class for the enzymatic digestion of proteins represented as AASequence or String.
Definition ProteaseDigestion.h:32
bool isValidProduct(const std::string &protein, int pep_pos, int pep_length, bool ignore_missed_cleavages=true, bool allow_nterm_protein_cleavage=false, bool allow_random_asp_pro_cleavage=false) const
Variant of EnzymaticDigestion::isValidProduct() with support for n-term protein cleavage and random D...
Representation of a protein hit.
Definition ProteinHit.h:34
const std::string & getAccession() const
returns the accession of the protein
Representation of a protein identification run.
Definition ProteinIdentification.h:55
if none is found
Definition common-cmake-parameters.doxygen:88
Definition IDFilter.h:40
Concept to exclude std::vector of identification types (used to disambiguate template overloads)
Definition IDFilter.h:45
int Int
Signed integer type.
Definition Types.h:72
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
FASTA entry type (identifier, description and sequence) The first std::string corresponds to the iden...
Definition FASTAFile.h:46
std::string identifier
Definition FASTAFile.h:47
Is peptide evidence digestion product of some protein.
Definition IDFilter.h:435
DigestionFilter(std::vector< FASTAFile::FASTAEntry > &entries, ProteaseDigestion &digestion, bool ignore_missed_cleavages, bool methionine_cleavage)
Definition IDFilter.h:444
GetMatchingItems< PeptideEvidence, FASTAFile::FASTAEntry > accession_resolver_
Definition IDFilter.h:439
void filterPeptideEvidences(PeptideIdentificationList &peptides)
Definition IDFilter.h:476
bool operator()(const PeptideEvidence &evidence) const
Definition IDFilter.h:449
bool ignore_missed_cleavages_
Definition IDFilter.h:441
PeptideEvidence argument_type
Definition IDFilter.h:436
ProteaseDigestion & digestion_
Definition IDFilter.h:440
bool methionine_cleavage_
Definition IDFilter.h:442
Builds a map index of data that have a std::string index to find matches and return the objects.
Definition IDFilter.h:309
GetMatchingItems()
Definition IDFilter.h:322
ItemMap items
Definition IDFilter.h:312
std::map< std::string, Entry * > ItemMap
Definition IDFilter.h:311
HitType argument_type
Definition IDFilter.h:310
bool exists(const HitType &hit) const
Definition IDFilter.h:331
GetMatchingItems(std::vector< Entry > &records)
Definition IDFilter.h:314
const std::string & getHitKey(const PeptideEvidence &p) const
Definition IDFilter.h:336
const Entry & getValue(const PeptideEvidence &evidence) const
Definition IDFilter.h:341
const std::string & getKey(const FASTAFile::FASTAEntry &entry) const
Definition IDFilter.h:326
Is this a decoy hit?
Definition IDFilter.h:223
bool operator()(const HitType &hit) const
Operator to check if a HitType object has decoy annotation.
Definition IDFilter.h:247
HitType argument_type
Definition IDFilter.h:224
HasDecoyAnnotation()
Default constructor.
Definition IDFilter.h:233
Is the score of this hit at least as good as the given value?
Definition IDFilter.h:93
bool operator()(const HitType &hit) const
Definition IDFilter.h:103
double score
Definition IDFilter.h:96
HitType argument_type
Definition IDFilter.h:94
HasGoodScore(double score_, bool higher_score_better_)
Definition IDFilter.h:99
bool higher_score_better
Definition IDFilter.h:97
Given a list of protein accessions, do any occur in the annotation(s) of this hit?
Definition IDFilter.h:265
HasMatchingAccessionImpl(const SetType &accessions_)
Definition IDFilter.h:270
const SetType & accessions
Definition IDFilter.h:268
HitType argument_type
Definition IDFilter.h:266
bool operator()(const PeptideHit &hit) const
Definition IDFilter.h:274
bool operator()(const PeptideEvidence &evidence) const
Definition IDFilter.h:289
bool operator()(const ProteinHit &hit) const
Definition IDFilter.h:284
Does a meta value of this hit have at most the given value?
Definition IDFilter.h:142
bool operator()(const HitType &hit) const
Definition IDFilter.h:152
HitType argument_type
Definition IDFilter.h:143
HasMaxMetaValue(const std::string &key_, const double &value_)
Definition IDFilter.h:148
std::string key
Definition IDFilter.h:145
double value
Definition IDFilter.h:146
Is a meta value with given key and value set on this hit?
Definition IDFilter.h:119
bool operator()(const HitType &hit) const
Definition IDFilter.h:129
DataValue value
Definition IDFilter.h:123
HitType argument_type
Definition IDFilter.h:120
HasMetaValue(const std::string &key_, const DataValue &value_)
Definition IDFilter.h:125
std::string key
Definition IDFilter.h:122
Predicate to check if a HitType object has a minimum meta value.
Definition IDFilter.h:170
HasMinMetaValue(const std::string &key_, const double &value_)
Constructor for HasMinMetaValue.
Definition IDFilter.h:182
bool operator()(const HitType &hit) const
Operator() function to check if a HitType object has a minimum meta value.
Definition IDFilter.h:194
HitType argument_type
Definition IDFilter.h:171
std::string key
Definition IDFilter.h:173
double value
Definition IDFilter.h:174
Is the list of hits of this peptide/protein ID empty?
Definition IDFilter.h:490
bool operator()(const IdentificationType &id) const
Definition IDFilter.h:493
IdentificationType argument_type
Definition IDFilter.h:491
Wrapper that adds operator< to iterators, so they can be used as (part of) keys in maps/sets or multi...
Definition MetaData.h:20