00001 #ifndef __SEQUENCE_COALESCENT_SIM_TYPES_HPP__
00002 #define __SEQUENCE_COALESCENT_SIM_TYPES_HPP__
00003
00004 #include <vector>
00005 #include <list>
00006 #include <iosfwd>
00007 #include <cassert>
00008
00079 namespace Sequence
00080 {
00081 struct segment
00082 {
00083 int beg,end,desc;
00084 segment();
00085 explicit segment(const int & b,
00086 const int & e,
00087 const int & d);
00088 };
00089
00090 struct chromosome
00091 {
00103 segment * segs;
00104 typedef segment * iterator;
00105 typedef const segment * const_iterator;
00109 int pop;
00113 unsigned nsegs;
00114 chromosome();
00115 chromosome(const chromosome & ch);
00116 chromosome( const std::vector<segment> & initial_segs,
00117 const int & population = 0 );
00118 ~chromosome();
00119 chromosome & operator=(const chromosome & ch);
00120 void swap_with( chromosome & ch );
00121 void assign_allocated_segs( segment * newsegs,
00122 const int & new_nsegs );
00123 int first() const
00127 {
00128 assert(nsegs>0);
00129 return segs->beg;
00130 }
00131
00132 int last() const
00136 {
00137 assert(nsegs>0);
00138 return (segs+nsegs-1)->end;
00139 }
00140 int links() const;
00141 iterator begin();
00142 iterator end();
00143 const_iterator begin() const;
00144 const_iterator end() const;
00145 };
00146
00147 std::ostream & operator<<(std::ostream & s,const chromosome & c);
00148
00149 struct node
00150 {
00154 double time;
00159 int abv;
00160 node(const double & t = 0.,
00161 const int & a = -1 );
00162 };
00163
00164 struct marginal
00165 {
00169 int beg;
00174 mutable int nsam;
00182 int nnodes;
00186 std::vector<node> tree;
00187 typedef std::vector<node>::iterator iterator;
00188 typedef std::vector<node>::const_iterator const_iterator;
00189 typedef std::vector<node>::size_type size_type;
00190 typedef std::vector<node>::reference reference;
00191 typedef std::vector<node>::const_reference const_reference;
00192 iterator begin();
00193 iterator end();
00194 const_iterator begin() const;
00195 const_iterator end() const;
00196 reference operator[](const std::vector<node>::size_type &i);
00197 const_reference operator[](const std::vector<node>::size_type &i) const;
00198 marginal(const int & b, const int & ns,const int & nn,
00199 const std::vector<node> & tree);
00200 bool operator<(const marginal & rhs) const;
00201 };
00202
00215 typedef std::list<marginal> arg;
00216 std::ostream & operator<<(std::ostream & s, const marginal & m);
00217
00218 class newick_stream_marginal_tree_impl;
00219 class newick_stream_marginal_tree
00220 {
00221 private:
00222 newick_stream_marginal_tree_impl * impl;
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 public:
00233 newick_stream_marginal_tree( const marginal & m );
00234 newick_stream_marginal_tree( const marginal * m );
00235 newick_stream_marginal_tree( arg::const_iterator m );
00236 newick_stream_marginal_tree( arg::iterator m );
00237 ~newick_stream_marginal_tree( );
00238 std::vector<node> get_tree() const;
00239 std::ostream & print( std::ostream & o ) const;
00240 std::istream & read( std::istream & i );
00241 };
00242 std::ostream & operator<<(std::ostream & o, const newick_stream_marginal_tree & n);
00243 std::istream & operator>>(std::istream & i, newick_stream_marginal_tree & n);
00244 }
00245 #endif