35 #ifndef OPENMS_FILTERING_ID_IDFILTER_H
36 #define OPENMS_FILTERING_ID_IDFILTER_H
38 #include <OpenMS/config.h>
89 template <
class HitType>
98 score(score), higher_score_better(higher_score_better)
103 if (higher_score_better)
105 return hit.getScore() >= score;
107 return hit.getScore() <= score;
116 template <
class HitType>
128 throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"The cut-off value for rank filtering must not be zero!");
134 Size hit_rank = hit.getRank();
139 return hit_rank <= rank;
148 template <
class HitType>
157 key(key), value(value)
163 if (found.
isEmpty())
return false;
164 if (value.
isEmpty())
return true;
165 return found == value;
170 template <
class HitType>
179 key(key), value(value)
185 if (found.
isEmpty())
return false;
186 return double(found) <= value;
191 template <
class HitType>
199 target_decoy(
"target_decoy",
"decoy"), is_decoy(
"isDecoy",
"true")
207 return target_decoy(hit) || is_decoy(hit);
216 template <
class HitType>
224 accessions(accessions)
230 for (std::set<String>::iterator it = present_accessions.begin();
231 it != present_accessions.end(); ++it)
233 if (accessions.count(*it) > 0)
return true;
260 struct HasMinPeptideLength;
266 struct HasLowMZError;
273 struct HasMatchingModification;
280 struct HasMatchingSequence;
283 struct HasNoEvidence;
292 template <
class IdentificationType>
299 return id.getHits().empty();
326 template <
class Container,
class Predicate>
329 items.erase(std::remove_if(items.begin(), items.end(), pred),
334 template <
class Container,
class Predicate>
337 items.erase(std::remove_if(items.begin(), items.end(), std::not1(pred)),
348 template <
class IdentificationType>
352 for (
typename std::vector<IdentificationType>::const_iterator id_it =
353 ids.begin(); id_it != ids.end(); ++id_it)
355 counter += id_it->getHits().size();
372 template <
class IdentificationType>
374 const std::vector<IdentificationType>& identifications,
375 bool assume_sorted,
typename IdentificationType::HitType& best_hit)
377 if (identifications.empty())
return false;
379 typename std::vector<IdentificationType>::const_iterator best_id_it =
380 identifications.end();
381 typename std::vector<typename IdentificationType::HitType>::const_iterator
384 for (
typename std::vector<IdentificationType>::const_iterator id_it =
385 identifications.begin(); id_it != identifications.end(); ++id_it)
387 if (id_it->getHits().empty())
continue;
389 if (best_id_it == identifications.end())
392 best_hit_it = id_it->getHits().begin();
394 else if (best_id_it->getScoreType() != id_it->getScoreType())
396 throw Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"Can't compare scores of different types", best_id_it->getScoreType() +
"/" + id_it->getScoreType());
399 bool higher_better = best_id_it->isHigherScoreBetter();
400 for (
typename std::vector<typename IdentificationType::HitType>::
401 const_iterator hit_it = id_it->getHits().begin(); hit_it !=
402 id_it->getHits().end(); ++hit_it)
404 if ((higher_better && (hit_it->getScore() >
405 best_hit_it->getScore())) ||
406 (!higher_better && (hit_it->getScore() <
407 best_hit_it->getScore())))
409 best_hit_it = hit_it;
411 if (assume_sorted)
break;
415 if (best_id_it == identifications.end())
420 best_hit = *best_hit_it;
431 static void extractPeptideSequences(
432 const std::vector<PeptideIdentification>& peptides,
433 std::set<String>& sequences,
bool ignore_mods =
false);
442 template <
class IdentificationType>
445 for (
typename std::vector<IdentificationType>::iterator it = ids.begin();
446 it != ids.end(); ++it)
453 static void removeUnreferencedProteins(
454 std::vector<ProteinIdentification>& proteins,
455 const std::vector<PeptideIdentification>& peptides);
464 static void updateProteinReferences(
465 std::vector<PeptideIdentification>& peptides,
466 const std::vector<ProteinIdentification>& proteins,
467 bool remove_peptides_without_reference =
false);
477 static bool updateProteinGroups(
478 std::vector<ProteinIdentification::ProteinGroup>& groups,
479 const std::vector<ProteinHit>& hits);
488 template <
class IdentificationType>
491 struct HasNoHits<IdentificationType> empty_filter;
492 removeMatchingItems(ids, empty_filter);
500 template <
class IdentificationType>
502 double threshold_score)
504 for (
typename std::vector<IdentificationType>::iterator id_it =
505 ids.begin(); id_it != ids.end(); ++id_it)
507 struct HasGoodScore<typename IdentificationType::HitType> score_filter(
508 threshold_score, id_it->isHigherScoreBetter());
509 keepMatchingItems(id_it->getHits(), score_filter);
518 template <class IdentificationType>
519 static void filterHitsBySignificance(std::vector<IdentificationType>& ids,
520 double threshold_fraction = 1.0)
522 for (
typename std::vector<IdentificationType>::iterator id_it =
523 ids.begin(); id_it != ids.end(); ++id_it)
525 double threshold_score = (threshold_fraction *
526 id_it->getSignificanceThreshold());
527 struct HasGoodScore<typename IdentificationType::HitType> score_filter(
528 threshold_score, id_it->isHigherScoreBetter());
529 keepMatchingItems(id_it->getHits(), score_filter);
538 template <class IdentificationType>
539 static void keepNBestHits(std::vector<IdentificationType>& ids, Size n)
541 for (
typename std::vector<IdentificationType>::iterator id_it =
542 ids.begin(); id_it != ids.end(); ++id_it)
545 if (n < id_it->getHits().size()) id_it->getHits().resize(n);
563 template <
class IdentificationType>
570 struct HasMaxRank<typename IdentificationType::HitType>
571 rank_filter(min_rank - 1);
572 for (typename std::vector<IdentificationType>::iterator id_it =
573 ids.begin(); id_it != ids.end(); ++id_it)
575 removeMatchingItems(id_it->getHits(), rank_filter);
578 if (max_rank >= min_rank)
580 struct HasMaxRank<typename IdentificationType::HitType>
581 rank_filter(max_rank);
582 for (typename std::vector<IdentificationType>::iterator id_it =
583 ids.begin(); id_it != ids.end(); ++id_it)
585 keepMatchingItems(id_it->getHits(), rank_filter);
597 template <
class IdentificationType>
602 for (typename std::vector<IdentificationType>::iterator id_it =
603 ids.begin(); id_it != ids.end(); ++id_it)
605 removeMatchingItems(id_it->getHits(), decoy_filter);
616 template <
class IdentificationType>
618 const std::set<String> accessions)
621 acc_filter(accessions);
622 for (typename std::vector<IdentificationType>::iterator id_it =
623 ids.begin(); id_it != ids.end(); ++id_it)
625 removeMatchingItems(id_it->getHits(), acc_filter);
636 template <
class IdentificationType>
638 const std::set<String> accessions)
641 acc_filter(accessions);
642 for (typename std::vector<IdentificationType>::iterator id_it =
643 ids.begin(); id_it != ids.end(); ++id_it)
645 keepMatchingItems(id_it->getHits(), acc_filter);
661 static void keepBestPeptideHits(
662 std::vector<PeptideIdentification>& peptides,
bool strict =
false);
672 static void filterPeptidesByLength(
673 std::vector<PeptideIdentification>& peptides,
Size min_length,
674 Size max_length = UINT_MAX);
684 static void filterPeptidesByCharge(
685 std::vector<PeptideIdentification>& peptides,
Int min_charge,
689 static void filterPeptidesByRT(std::vector<PeptideIdentification>& peptides,
690 double min_rt,
double max_rt);
693 static void filterPeptidesByMZ(std::vector<PeptideIdentification>& peptides,
694 double min_mz,
double max_mz);
707 static void filterPeptidesByMZError(
708 std::vector<PeptideIdentification>& peptides,
double mass_error,
722 static void filterPeptidesByRTPredictPValue(
723 std::vector<PeptideIdentification>& peptides,
724 const String& metavalue_key,
double threshold = 0.05);
727 static void removePeptidesWithMatchingModifications(
728 std::vector<PeptideIdentification>& peptides,
729 const std::set<String>& modifications);
732 static void keepPeptidesWithMatchingModifications(
733 std::vector<PeptideIdentification>& peptides,
734 const std::set<String>& modifications);
743 static void removePeptidesWithMatchingSequences(
744 std::vector<PeptideIdentification>& peptides,
745 const std::vector<PeptideIdentification>& bad_peptides,
746 bool ignore_mods =
false);
755 static void keepPeptidesWithMatchingSequences(
756 std::vector<PeptideIdentification>& peptides,
757 const std::vector<PeptideIdentification>& good_peptides,
758 bool ignore_mods =
false);
761 static void keepUniquePeptidesPerProtein(std::vector<PeptideIdentification>&
769 static void removeDuplicatePeptideHits(std::vector<PeptideIdentification>&
779 template <
class PeakT>
781 double peptide_threshold_score,
782 double protein_threshold_score)
786 protein_threshold_score);
792 exp_it != experiment.
end(); ++exp_it)
794 filterHitsByScore(exp_it->getPeptideIdentifications(),
795 peptide_threshold_score);
796 removeEmptyIdentifications(exp_it->getPeptideIdentifications());
797 updateProteinReferences(exp_it->getPeptideIdentifications(),
804 template <
class PeakT>
806 double peptide_threshold_fraction,
807 double protein_threshold_fraction)
811 protein_threshold_fraction);
817 exp_it != experiment.
end(); ++exp_it)
819 filterHitsBySignificance(exp_it->getPeptideIdentifications(),
820 peptide_threshold_fraction);
821 removeEmptyIdentifications(exp_it->getPeptideIdentifications());
822 updateProteinReferences(exp_it->getPeptideIdentifications(),
829 template <
class PeakT>
834 std::vector<PeptideIdentification> all_peptides;
838 exp_it != experiment.
end(); ++exp_it)
840 std::vector<PeptideIdentification>& peptides =
841 exp_it->getPeptideIdentifications();
842 keepNBestHits(peptides, n);
843 removeEmptyIdentifications(peptides);
844 updateProteinReferences(peptides,
846 all_peptides.insert(all_peptides.end(), peptides.begin(),
855 template <
class PeakT>
858 const std::vector<FASTAFile::FASTAEntry>& proteins)
860 std::set<String> accessions;
861 for (std::vector<FASTAFile::FASTAEntry>::const_iterator it =
862 proteins.begin(); it != proteins.end(); ++it)
864 accessions.insert(it->identifier);
874 exp_it != experiment.
end(); ++exp_it)
876 if (exp_it->getMSLevel() == 2)
878 keepHitsMatchingProteins(exp_it->getPeptideIdentifications(),
880 removeEmptyIdentifications(exp_it->getPeptideIdentifications());
881 updateHitRanks(exp_it->getPeptideIdentifications());
892 #endif // OPENMS_FILTERING_ID_IDFILTER_H
Is the rank of this hit below or at the given cut-off?
Definition: IDFilter.h:117
A more convenient string class.
Definition: String.h:57
static void removeHitsMatchingProteins(std::vector< IdentificationType > &ids, const std::set< String > accessions)
Filters peptide or protein identifications according to the given proteins (negative).
Definition: IDFilter.h:617
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:349
static void keepHitsMatchingProteins(MSExperiment< PeakT > &experiment, const std::vector< FASTAFile::FASTAEntry > &proteins)
Filters an MS/MS experiment according to the given proteins.
Definition: IDFilter.h:856
static void filterHitsBySignificance(MSExperiment< PeakT > &experiment, double peptide_threshold_fraction, double protein_threshold_fraction)
Filters an MS/MS experiment according to fractions of the significance thresholds.
Definition: IDFilter.h:805
std::vector< SpectrumType >::iterator Iterator
Mutable iterator.
Definition: MSExperiment.h:103
const std::vector< ProteinIdentification > & getProteinIdentifications() const
returns a const reference to the protein ProteinIdentification vector
HasMatchingAccession(const std::set< String > &accessions)
Definition: IDFilter.h:223
double score
Definition: IDFilter.h:94
Is this a decoy hit?
Definition: IDFilter.h:192
Is the list of hits of this peptide/protein ID empty?
Definition: IDFilter.h:293
const String & getProteinAccession() const
get the protein accession the peptide matches to. If not available the empty string is returned...
bool operator()(const IdentificationType &id) const
Definition: IDFilter.h:297
Iterator begin()
Definition: MSExperiment.h:149
bool operator()(const ProteinHit &hit) const
Definition: IDFilter.h:238
const std::set< String > & accessions
Definition: IDFilter.h:221
static void keepHitsMatchingProteins(std::vector< IdentificationType > &ids, const std::set< String > accessions)
Filters peptide or protein identifications according to the given proteins (positive).
Definition: IDFilter.h:637
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
static void removeDecoyHits(std::vector< IdentificationType > &ids)
Removes hits annotated as decoys from peptide or protein identifications.
Definition: IDFilter.h:598
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:501
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
Iterator end()
Definition: MSExperiment.h:159
static void updateHitRanks(std::vector< IdentificationType > &ids)
Updates the hit ranks on all peptide or protein IDs.
Definition: IDFilter.h:443
HasMaxRank(Size rank)
Definition: IDFilter.h:123
A method or algorithm argument contains illegal values.
Definition: Exception.h:634
Size rank
Definition: IDFilter.h:121
static void removeMatchingItems(Container &items, const Predicate &pred)
Remove items that satisfy a condition from a container (e.g. vector)
Definition: IDFilter.h:327
bool operator()(const PeptideHit &hit) const
Definition: IDFilter.h:227
Representation of a peptide hit.
Definition: PeptideHit.h:55
HasGoodScore(double score, bool higher_score_better)
Definition: IDFilter.h:97
IdentificationType argument_type
Definition: IDFilter.h:295
HasDecoyAnnotation()
Definition: IDFilter.h:198
Is the score of this hit at least as good as the given value?
Definition: IDFilter.h:90
Representation of a peptide evidence.
Definition: PeptideEvidence.h:51
Given a list of protein accessions, do any occur in the annotation(s) of this hit?
Definition: IDFilter.h:217
HitType argument_type
Definition: IDFilter.h:194
HitType argument_type
Definition: IDFilter.h:92
bool operator()(const HitType &hit) const
Definition: IDFilter.h:202
bool isEmpty() const
test if the value is empty
Definition: DataValue.h:360
Representation of a protein hit.
Definition: ProteinHit.h:54
Invalid value exception.
Definition: Exception.h:336
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:71
static void keepNBestHits(MSExperiment< PeakT > &experiment, Size n)
Filters an MS/MS experiment by keeping the N best peptide hits for every spectrum.
Definition: IDFilter.h:830
static void removeEmptyIdentifications(std::vector< IdentificationType > &ids)
Removes peptide or protein identifications that have no hits in them.
Definition: IDFilter.h:489
std::set< String > extractProteinAccessions() const
extracts the set of non-empty protein accessions from peptide evidences
bool operator()(const PeptideEvidence &evidence) const
Definition: IDFilter.h:243
bool higher_score_better
Definition: IDFilter.h:95
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:564
bool operator()(const HitType &hit) const
Definition: IDFilter.h:101
HitType argument_type
Definition: IDFilter.h:219
HitType argument_type
Definition: IDFilter.h:119
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:373
Collection of functions for filtering peptide and protein identifications.
Definition: IDFilter.h:70
bool operator()(const HitType &hit) const
Definition: IDFilter.h:132
int Int
Signed integer type.
Definition: Types.h:103
static void filterHitsByScore(MSExperiment< PeakT > &experiment, double peptide_threshold_score, double protein_threshold_score)
Filters an MS/MS experiment according to score thresholds.
Definition: IDFilter.h:780
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:335
const String & getAccession() const
returns the accession of the protein