Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
predicates.hpp
Go to the documentation of this file.
1 
2 
7 #ifndef PREDICATES_HPP
8 #define PREDICATES_HPP
9 
10 namespace scaffold{ namespace predicates {
11 
13  template<typename Element>
14  struct Predicate
15  {
16  const bool invert;
17 
19  Predicate(const bool _invert = false):
20  invert(_invert) {}
21 
23  virtual bool operator()(const Element& e) const = 0;
24  };
25 
26 
28  template<typename Element>
29  struct TruePredicate: public Predicate<Element>
30  {
33 
34  bool operator()(const Element& e) const
35  {
36  return !invert;
37  }
38  };
39 
41 
42  template<typename Element, typename Container = unordered_set<Element> >
43  struct ContainedPredicate: public Predicate<Element>
44  {
47 
48  const Container& container;
49 
51 
54  ContainedPredicate(const Container& _container, const bool _invert = false):
55  Predicate<Element>(_invert), container(_container) {}
56 
57  bool operator()(const Element& e) const
58  {
59  return (invert != contains(container, e));
60  }
61  };
62 
64 
65  template<typename Graph>
66  struct MatchingPredicate: public Predicate<Edge<Graph> >
67  {
68  using Element = Edge<Graph>;
71 
72  const Graph& g;
73 
75 
76  MatchingPredicate(const Graph& _g, const bool _invert = false):
77  Predicate<Element>(_invert), g(_g) {}
78 
79  bool operator()(const Element& e) const
80  {
81  return (invert != g[e].is_matching_edge());
82  }
83 
84  };
85 
86 
88 
91  template<typename Graph, typename Container = unordered_set<Vertex<Graph> > >
92  struct TargetContainedPredicate: public Predicate<Edge<Graph> >
93  {
94  using Element = Edge<Graph>;
97 
98  const Container& container;
99  const Graph& g;
100  const bool matching_OK;
101 
103 
104  TargetContainedPredicate(const Container& _container, const Graph& _g, const bool _invert = false, const bool _matching_OK = true):
105  Predicate<Element>(_invert), container(_container), g(_g), matching_OK(_matching_OK) {}
106 
107  bool operator()(const Element& e) const
108  {
109  if(!matching_OK && g[e].is_matching_edge()) return false;
110  return (invert != contains(container, boost::target(e, g)));
111  }
112  };
113 
114 
115 }}// namespace
116 
117 #endif
an edge predicate that is true iff the given edge has its target (not) in a given set ...
Definition: predicates.hpp:92
an edge predicate that is true iff the given edge is (not) a matching edge
Definition: predicates.hpp:66
TargetContainedPredicate(const Container &_container, const Graph &_g, const bool _invert=false, const bool _matching_OK=true)
constructor
Definition: predicates.hpp:104
virtual bool operator()(const Element &e) const =0
all predicates must implement operator()
const Container & container
container reference
Definition: predicates.hpp:48
const Container & container
reference to the container
Definition: predicates.hpp:98
a predicate that is true iff the given element is (not) contained in a given container ...
Definition: predicates.hpp:43
const bool invert
indicate whether the predicate should be inverted
Definition: predicates.hpp:16
Definition: read_adj_list.hpp:22
prototype predicate
Definition: predicates.hpp:14
ContainedPredicate(const Container &_container, const bool _invert=false)
constructor
Definition: predicates.hpp:54
a predicate that always evaluates to true
Definition: predicates.hpp:29
MatchingPredicate(const Graph &_g, const bool _invert=false)
constructer
Definition: predicates.hpp:76
bool operator()(const Element &e) const
all predicates must implement operator()
Definition: predicates.hpp:34
bool operator()(const Element &e) const
all predicates must implement operator()
Definition: predicates.hpp:57
Predicate(const bool _invert=false)
constructor
Definition: predicates.hpp:19
const Graph & g
reference to the graph for which containment should be checked
Definition: predicates.hpp:72
bool contains(const Set &s, const Element &el)
a more readable containment check
Definition: utils.hpp:171
const Graph & g
reference to the graph
Definition: predicates.hpp:99
const bool matching_OK
indicate whether matching edges should be treated like any other edge (true) or always evaluate to fa...
Definition: predicates.hpp:100