23 #include <unordered_map>
26 #include <boost/function.hpp>
27 #include <boost/blank.hpp>
28 #include <boost/serialization/strong_typedef.hpp>
29 #include <boost/graph/adjacency_list.hpp>
30 #include <boost/graph/depth_first_search.hpp>
31 #include <boost/graph/filtered_graph.hpp>
32 #include <boost/graph/properties.hpp>
33 #include <boost/variant.hpp>
34 #include <boost/variant/detail/hash_variant.hpp>
35 #include <boost/variant/static_visitor.hpp>
39 struct ScoreToTgtDecLabelPairs;
64 #pragma clang diagnostic push
65 #pragma clang diagnostic ignored "-Wextra-semi"
89 #pragma clang diagnostic pop
94 typedef boost::variant<ProteinHit*, ProteinGroup, PeptideCluster, Peptide, RunIndex, Charge, PeptideHit*>
IDPointer;
95 typedef boost::variant<const ProteinHit*, const ProteinGroup*, const PeptideCluster*, const Peptide, const RunIndex, const Charge, const PeptideHit*>
IDPointerConst;
100 typedef boost::adjacency_list <boost::setS, boost::vecS, boost::undirectedS, IDPointer>
Graph;
102 typedef boost::adjacency_list <boost::setS, boost::vecS, boost::undirectedS, IDPointer>
GraphConst;
104 typedef boost::graph_traits<Graph>::vertex_descriptor
vertex_t;
105 typedef boost::graph_traits<Graph>::edge_descriptor
edge_t;
113 public boost::default_dfs_visitor
117 : gs(vgs), curr_v(0), next_v(0), m()
120 template <
typename Vertex,
typename Graph >
124 next_v = boost::add_vertex(tg[u], gs.back());
128 template <
typename Vertex,
typename Graph >
134 template <
typename Edge,
typename Graph >
137 if (m.find(e.m_target) == m.end())
139 next_v = boost::add_vertex(tg[e.m_target], gs.back());
140 m[e.m_target] = next_v;
144 next_v = m[e.m_target];
147 boost::add_edge(m[e.m_source], next_v, gs.back());
153 std::map<vertex_t, vertex_t>
m;
159 public boost::static_visitor<OpenMS::String>
190 return "rep" +
String(ri);
195 return "chg" +
String(chg);
202 template<
class CharT>
204 public boost::static_visitor<>
219 stream_ << prot->
getAccession() <<
": " << prot << std::endl;
224 stream_ <<
"PG" << std::endl;
229 stream_ <<
"PepClust" << std::endl;
234 stream_ << peptide << std::endl;
239 stream_ <<
"rep" << ri << std::endl;
244 stream_ <<
"chg" << chg << std::endl;
254 public boost::static_visitor<>
270 pg.
score = posterior;
285 public boost::static_visitor<double>
317 public boost::static_visitor<std::pair<double,bool>>
340 return {-1.0,
false};
349 bool best_psms_annotated,
350 const std::optional<const ExperimentalDesign>& ed = std::optional<const ExperimentalDesign>());
356 bool use_unassigned_ids,
357 bool best_psms_annotated,
358 const std::optional<const ExperimentalDesign>& ed = std::optional<const ExperimentalDesign>());
434 bool stop_at_first, std::vector<vertex_t>& result);
445 bool stop_at_first, std::vector<vertex_t>& result);
460 struct SequenceToReplicateChargeVariantHierarchy;
490 #ifdef INFERENCE_BENCH
492 std::vector<std::tuple<vertex_t, vertex_t, unsigned long, double>> sizes_and_times_{1};
510 Size nrPrefractionationGroups_ = 0;
537 bool best_psms_annotated =
false);
542 bool use_unassigned_ids,
543 bool best_psms_annotated =
false);
549 const std::unordered_map<std::string, ProteinHit*>& accession_map,
551 bool best_psms_annotated);
555 std::unordered_map<unsigned, unsigned>& indexToPrefractionationGroup,
557 std::unordered_map<std::string, ProteinHit*>& accession_map,
571 bool use_unassigned_ids,
583 template<
class NodeType>
586 Graph::adjacency_iterator adjIt, adjIt_end;
587 boost::tie(adjIt, adjIt_end) = boost::adjacent_vertices(start, graph);
588 for (;adjIt != adjIt_end; ++adjIt)
590 if (graph[*adjIt].type() ==
typeid(NodeType))
592 result.emplace_back(boost::get<NodeType>(graph[*adjIt]));
594 else if (graph[*adjIt].which() > graph[start].which())
596 getDownstreamNodes(*adjIt, graph, result);
601 template<
class NodeType>
604 Graph::adjacency_iterator adjIt, adjIt_end;
605 boost::tie(adjIt, adjIt_end) = boost::adjacent_vertices(start, graph);
606 for (;adjIt != adjIt_end; ++adjIt)
608 if (graph[*adjIt].type() ==
typeid(NodeType))
610 result.emplace_back(boost::get<NodeType>(graph[*adjIt]));
612 else if (graph[*adjIt].which() < graph[start].which())
614 getUpstreamNodes(*adjIt, graph, result);
String toString() const
returns the peptide as string with modifications embedded in brackets
String toUnmodifiedString() const
returns the peptide as string without any modifications or (e.g., "PEPTIDER")
A container for consensus elements.
Definition: ConsensusMap.h:68
String toString(bool full_precision=true) const
Conversion to String full_precision Controls number of fractional digits for all double types or list...
Representation of an experimental design in OpenMS. Instances can be loaded with the ExperimentalDesi...
Definition: ExperimentalDesign.h:109
Visits nodes in the boost graph (either ptrs to an ID Object or some lightweight surrogates) and depe...
Definition: IDBoostGraph.h:286
double operator()(PeptideHit *pep) const
Definition: IDBoostGraph.h:289
double operator()(ProteinHit *prot) const
Definition: IDBoostGraph.h:294
double operator()(T &) const
Definition: IDBoostGraph.h:306
double operator()(ProteinGroup &pg) const
Definition: IDBoostGraph.h:299
Visits nodes in the boost graph (either ptrs to an ID Object or some lightweight surrogates) and depe...
Definition: IDBoostGraph.h:318
std::pair< double, bool > operator()(T &) const
Definition: IDBoostGraph.h:338
std::pair< double, bool > operator()(ProteinGroup &pg) const
Definition: IDBoostGraph.h:331
std::pair< double, bool > operator()(PeptideHit *pep) const
Definition: IDBoostGraph.h:321
std::pair< double, bool > operator()(ProteinHit *prot) const
Definition: IDBoostGraph.h:326
Visits nodes in the boost graph (ptrs to an ID Object) and depending on their type creates a label e....
Definition: IDBoostGraph.h:160
OpenMS::String operator()(const Peptide &peptide) const
Definition: IDBoostGraph.h:183
OpenMS::String operator()(const Charge &chg) const
Definition: IDBoostGraph.h:193
OpenMS::String operator()(const PeptideHit *pep) const
Definition: IDBoostGraph.h:163
OpenMS::String operator()(const ProteinGroup &) const
Definition: IDBoostGraph.h:173
OpenMS::String operator()(const RunIndex &ri) const
Definition: IDBoostGraph.h:188
OpenMS::String operator()(const ProteinHit *prot) const
Definition: IDBoostGraph.h:168
OpenMS::String operator()(const PeptideCluster &) const
Definition: IDBoostGraph.h:178
Visits nodes in the boost graph (ptrs to an ID Object) and depending on their type prints the address...
Definition: IDBoostGraph.h:205
void operator()(const Charge &chg) const
Definition: IDBoostGraph.h:242
std::basic_ostream< CharT > stream_
Definition: IDBoostGraph.h:247
PrintAddressVisitor(std::basic_ostream< CharT > stream)
Definition: IDBoostGraph.h:208
void operator()(const PeptideCluster &) const
Definition: IDBoostGraph.h:227
void operator()(const RunIndex &ri) const
Definition: IDBoostGraph.h:237
void operator()(PeptideHit *pep) const
Definition: IDBoostGraph.h:212
void operator()(ProteinHit *prot) const
Definition: IDBoostGraph.h:217
void operator()(const Peptide &peptide) const
Definition: IDBoostGraph.h:232
void operator()(const ProteinGroup &) const
Definition: IDBoostGraph.h:222
Visits nodes in the boost graph (either ptrs to an ID Object or some lightweight surrogates) and depe...
Definition: IDBoostGraph.h:255
void operator()(T &, double) const
Definition: IDBoostGraph.h:275
void operator()(PeptideHit *pep, double posterior) const
Definition: IDBoostGraph.h:258
void operator()(ProteinGroup &pg, double posterior) const
Definition: IDBoostGraph.h:268
void operator()(ProteinHit *prot, double posterior) const
Definition: IDBoostGraph.h:263
A boost dfs visitor that copies connected components into a vector of graphs.
Definition: IDBoostGraph.h:114
std::map< vertex_t, vertex_t > m
A mapping from old node id to new node id to not duplicate existing ones in the new graph.
Definition: IDBoostGraph.h:153
void start_vertex(Vertex u, const Graph &tg)
Definition: IDBoostGraph.h:121
void examine_edge(Edge e, const Graph &tg)
Definition: IDBoostGraph.h:135
dfs_ccsplit_visitor(Graphs &vgs)
Definition: IDBoostGraph.h:116
vertex_t curr_v
Definition: IDBoostGraph.h:151
void discover_vertex(Vertex, const Graph &)
Definition: IDBoostGraph.h:129
Graphs & gs
Definition: IDBoostGraph.h:150
Creates and maintains a boost graph based on the OpenMS ID datastructures.
Definition: IDBoostGraph.h:58
void addPeptideIDWithAssociatedProteins_(PeptideIdentification &spectrum, std::unordered_map< IDPointer, vertex_t, boost::hash< IDPointer >> &vertex_map, const std::unordered_map< std::string, ProteinHit * > &accession_map, Size use_top_psms, bool best_psms_annotated)
Used during building.
const ProteinIdentification & getProteinIDs()
Returns the underlying protein identifications for viewing.
void buildGraph_(ProteinIdentification &proteins, PeptideIdentificationList &idedSpectra, Size use_top_psms, bool best_psms_annotated=false)
boost::graph_traits< Graph >::vertex_descriptor vertex_t
Definition: IDBoostGraph.h:104
BOOST_STRONG_TYPEDEF(boost::blank, PeptideCluster)
placeholder for peptides with the same parent proteins or protein groups
BOOST_STRONG_TYPEDEF(int, Charge)
in which charge state a PSM was observed
std::unordered_map< vertex_t, Size > pepHitVtx_to_run_
Definition: IDBoostGraph.h:504
boost::variant< const ProteinHit *, const ProteinGroup *, const PeptideCluster *, const Peptide, const RunIndex, const Charge, const PeptideHit * > IDPointerConst
Definition: IDBoostGraph.h:95
void addPeptideAndAssociatedProteinsWithRunInfo_(PeptideIdentification &spectrum, std::unordered_map< unsigned, unsigned > &indexToPrefractionationGroup, std::unordered_map< IDPointer, vertex_t, boost::hash< IDPointer >> &vertex_map, std::unordered_map< std::string, ProteinHit * > &accession_map, Size use_top_psms)
std::vector< Graph > Graphs
Definition: IDBoostGraph.h:101
double score
Definition: IDBoostGraph.h:76
IDBoostGraph(ProteinIdentification &proteins, ConsensusMap &cmap, Size use_top_psms, bool use_run_info, bool use_unassigned_ids, bool best_psms_annotated, const std::optional< const ExperimentalDesign > &ed=std::optional< const ExperimentalDesign >())
IDBoostGraph(ProteinIdentification &proteins, PeptideIdentificationList &idedSpectra, Size use_top_psms, bool use_run_info, bool best_psms_annotated, const std::optional< const ExperimentalDesign > &ed=std::optional< const ExperimentalDesign >())
Constructors.
void getDownstreamNodes(const vertex_t &start, const Graph &graph, std::vector< NodeType > &result)
Definition: IDBoostGraph.h:584
ProteinIdentification & protIDs_
Definition: IDBoostGraph.h:458
void getUpstreamNodes(const vertex_t &start, const Graph graph, std::vector< NodeType > &result)
Definition: IDBoostGraph.h:602
void computeConnectedComponents()
Splits the initialized graph into connected components and clears it.
void clusterIndistProteinsAndPeptides()
void getProteinGroupScoresAndHitchhikingTgtFraction(ScoreToTgtDecLabelPairs &scores_and_tgt_fraction)
int tgts
Definition: IDBoostGraph.h:75
Size getNrConnectedComponents()
Zero means the graph was not split yet.
void resolveGraphPeptideCentric_(Graph &fg, bool removeAssociationsInData)
see equivalent public method
void getUpstreamNodesNonRecursive(std::queue< vertex_t > &q, const Graph &graph, int lvl, bool stop_at_first, std::vector< vertex_t > &result)
Searches for all upstream nodes from a (set of) start nodes that are lower or equal than a given leve...
const Graph & getComponent(Size cc)
Returns a specific connected component of the graph as a graph itself.
void applyFunctorOnCCsST(const std::function< void(Graph &)> &functor)
Do sth on connected components single threaded (your functor object has to inherit from std::function...
Graph g
the initial boost Graph (will be cleared when split into CCs)
Definition: IDBoostGraph.h:460
void annotateIndistProteins_(const Graph &fg, bool addSingletons)
internal function to annotate the underlying ID structures based on the given Graph
void clusterIndistProteinsAndPeptidesAndExtendGraph()
std::set< IDBoostGraph::vertex_t > PeptideNodeSet
Definition: IDBoostGraph.h:108
std::set< IDBoostGraph::vertex_t > ProteinNodeSet
Definition: IDBoostGraph.h:107
void buildGraphWithRunInfo_(ProteinIdentification &proteins, ConsensusMap &cmap, Size use_top_psms, bool use_unassigned_ids, const ExperimentalDesign &ed)
boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, IDPointer > GraphConst
Definition: IDBoostGraph.h:102
void calculateAndAnnotateIndistProteins(bool addSingletons=true)
static void printGraph(std::ostream &out, const Graph &fg)
Prints a graph (component or if not split, the full graph) in graphviz (i.e. dot) format.
void calculateAndAnnotateIndistProteins_(const Graph &fg, bool addSingletons)
boost::graph_traits< Graph >::edge_descriptor edge_t
Definition: IDBoostGraph.h:105
void buildGraphWithRunInfo_(ProteinIdentification &proteins, PeptideIdentificationList &idedSpectra, Size use_top_psms, const ExperimentalDesign &ed)
BOOST_STRONG_TYPEDEF(String, Peptide)
an (currently unmodified) peptide sequence
void annotateIndistProteins(bool addSingletons=true)
BOOST_STRONG_TYPEDEF(Size, RunIndex)
in which run a PSM was observed
void resolveGraphPeptideCentric(bool removeAssociationsInData=true)
void getProteinGroupScoresAndTgtFraction(ScoreToTgtDecLabelPairs &scores_and_tgt_fraction)
void buildGraph_(ProteinIdentification &proteins, ConsensusMap &cmap, Size use_top_psms, bool use_unassigned_ids, bool best_psms_annotated=false)
void getProteinScores_(ScoreToTgtDecLabelPairs &scores_and_tgt)
boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, IDPointer > Graph
Definition: IDBoostGraph.h:100
void getDownstreamNodesNonRecursive(std::queue< vertex_t > &q, const Graph &graph, int lvl, bool stop_at_first, std::vector< vertex_t > &result)
Searches for all downstream nodes from a (set of) start nodes that are higher or equal than a given l...
boost::variant< ProteinHit *, ProteinGroup, PeptideCluster, Peptide, RunIndex, Charge, PeptideHit * > IDPointer
Definition: IDBoostGraph.h:94
void applyFunctorOnCCs(const std::function< unsigned long(Graph &, unsigned int)> &functor)
Do sth on connected components (your functor object has to inherit from std::function or be a lambda)
Graphs ccs_
the Graph split into connected components
Definition: IDBoostGraph.h:487
vertex_t addVertexWithLookup_(const IDPointer &ptr, std::unordered_map< IDPointer, vertex_t, boost::hash< IDPointer >> &vertex_map)
indistinguishable protein groups (size, nr targets, score)
Definition: IDBoostGraph.h:73
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition: PeptideHit.h:50
double getScore() const
returns the PSM score
const AASequence & getSequence() const
returns the peptide sequence
Int getCharge() const
returns the charge of the peptide
void setScore(double score)
sets the PSM score
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:63
Representation of a protein hit.
Definition: ProteinHit.h:34
double getScore() const
returns the score of the protein hit
void setScore(const double score)
sets the score of the protein hit
const String & getAccession() const
returns the accession of the protein
Representation of a protein identification run.
Definition: ProteinIdentification.h:51
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
bool operator==(const IDBoostGraph::ProteinGroup &lhs, const IDBoostGraph::ProteinGroup &rhs)
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition: IDScoreGetterSetter.h:32