libsequence  1.9.5
SimTypes.hpp
Go to the documentation of this file.
1 #ifndef __SEQUENCE_COALESCENT_SIM_TYPES_HPP__
2 #define __SEQUENCE_COALESCENT_SIM_TYPES_HPP__
3 
4 #include <vector>
5 #include <list>
6 #include <iosfwd>
7 #include <cassert>
8 #include <memory>
9 
80 namespace Sequence
81 {
82  namespace coalsim {
83  struct segment
84  {
85  int beg,end,desc;
86  segment();
87  explicit segment(const int & b,
88  const int & e,
89  const int & d);
90  };
91 
92  struct chromosome
93  {
106  typedef segment * iterator;
107  typedef const segment * const_iterator;
111  int pop;
115  unsigned nsegs;
116  chromosome();
117  chromosome(const chromosome & ch);
118  chromosome( const std::vector<segment> & initial_segs,
119  const int & population = 0 );
120  ~chromosome();
121  chromosome & operator=(const chromosome & ch);
122  void swap_with( chromosome & ch );
123  void assign_allocated_segs( segment * newsegs,
124  const unsigned & new_nsegs );
125  int first() const
129  {
130  assert(nsegs>0);
131  return segs->beg;
132  }
133 
134  int last() const
138  {
139  assert(nsegs>0);
140  return (segs+nsegs-1)->end;
141  }
142  int links() const;
143  iterator begin();
144  iterator end();
145  const_iterator begin() const;
146  const_iterator end() const;
147  };
148 
149  std::ostream & operator<<(std::ostream & s,const chromosome & c);
150 
151  struct node
152  {
156  double time;
161  int abv;
162  node(const double & t = 0.,
163  const int & a = -1 );
164  };
165 
166  struct marginal
167  {
171  int beg;
176  const int nsam;
184  int nnodes;
188  std::vector<node> tree;
189  typedef std::vector<node>::iterator iterator;
190  typedef std::vector<node>::const_iterator const_iterator;
191  typedef std::vector<node>::size_type size_type;
192  typedef std::vector<node>::reference reference;
193  typedef std::vector<node>::const_reference const_reference;
194  iterator begin();
195  iterator end();
196  const_iterator begin() const;
197  const_iterator end() const;
198  reference operator[](const std::vector<node>::size_type &i);
199  const_reference operator[](const std::vector<node>::size_type &i) const;
200  marginal(const int & b, const int & ns,const int & nn,
201  const std::vector<node> & tree);
202  bool operator<(const marginal & rhs) const;
203  };
204 
217  typedef std::list<marginal> arg;
218  std::ostream & operator<<(std::ostream & s, const marginal & m);
219 
222  {
223  private:
224  std::unique_ptr<newick_stream_marginal_tree_impl> impl;
225  public:
228  newick_stream_marginal_tree( arg::const_iterator m );
229  newick_stream_marginal_tree( arg::iterator m );
231  std::vector<node> get_tree() const;
232  std::ostream & print( std::ostream & o ) const;
233  std::istream & read( std::istream & i );
234  };
235  std::ostream & operator<<(std::ostream & o, const newick_stream_marginal_tree & n);
236  std::istream & operator>>(std::istream & i, newick_stream_marginal_tree & n);
237  }
238 }
239 #endif
std::list< marginal > arg
Ancestral Recombination Graph.
Definition: SimTypes.hpp:217
A point on a marginal tree at which a coalescent event occurs.
Definition: SimTypes.hpp:151
Class that provides a typecast-on-output of a marginal tree to a newick tree Example use: ...
Definition: SimTypes.hpp:221
std::ostream & operator<<(std::ostream &s, const chromosome &c)
output operator for chromosome types in coalescent simulation Outputs the segments contained by the c...
The namespace in which this library resides.
segment()
default constructor initializes all members to 0
std::istream & operator>>(std::istream &i, newick_stream_marginal_tree &n)
std::vector< node > tree
Definition: SimTypes.hpp:188
A chromosome is a container of segments.
Definition: SimTypes.hpp:92
A portion of a recombining chromosome.
Definition: SimTypes.hpp:83
The genealogy of a portion of a chromosome on which no recombination has occurred.
Definition: SimTypes.hpp:166