1 /*
  2  * =====================================================================================
  3  *
  4  *       Filename:  nodes.h
  5  *
  6  *    Description:  description of phylogentic nodes as per 
  7  *    Fitch and Sannkoff as describd by Felenstein
  8  *
  9  *        Version:  1.0
 10  *       Created: Nov  4 21:15:49 EDT 2016
 11  *       Revision:  none
 12  *       Compiler:  gcc
 13  *
 14  *         Author:  Ruben Safir,
 15  *        Company:  LIU Thesis 
 16  *
 17  * =====================================================================================
 18  */
 19 #ifndef NODES_H
 20 #define NODES_H
 21 #include<iostream>
 22 #include<string>
 23 #include<vector>
 24 namespace tree {
 25 
 26 
 27 /* ==============================================================================
 28  * Class NODE - 
 29  * Description - This is a node in the tree that must undergo parsimony evaluation
 30  * ================================================================================
 31  */
 32 template<class unk>
 33 class NODE{
 34    public:
 35    ¦  //=========================LIFECYCLE=========================================
 36    ¦  /* Constructor */
 37       NODE( std::string xt, unk x , NODE<unk> *xcl= 0, NODE<unk> *xcr = 0, NODE<unk> *xp = 0 );
 38    ¦  ~NODE();
 39    ¦
 40    ¦  /* ====================  ACCESSORS     ======================================= */
 41 //no need for inline when you are defineing functions within the class definition
 42       std::string trait()const{
 43          return _trait;
 44       }
 45       unk states()const{
 46    ¦  ¦  return _states;
 47    ¦  };
 48       NODE<unk> * cl()const{
 49    ¦  ¦  return _cl;
 50    ¦  };
 51       NODE<unk> * cr()const{
 52    ¦  ¦  return _cr;
 53    ¦  };
 54       NODE<unk> * p()const{
 55    ¦  ¦  return _p;
 56    ¦  };
 57       void states(unk &x){
 58    ¦  ¦  _states = x;
 59    ¦  }
 60       void trait(std::string xt){
 61          ¦_trait = xt; //With genetics this is a A C G T although it is just a label
 62       ¦}
 63       void cl(NODE<unk> *xcl){ //This is the left child node in the tree
 64    ¦  ¦  _cl = xcl;
 65    ¦  }
 66       void cr(NODE<unk> *xcr){//This is the right node child node in the tree
 67    ¦  ¦  _cr = xcr;
 68    ¦  }
 69       void p(NODE<unk> *xp){//This is the parant node in the tree
 70    ¦  ¦  _p = xp;
 71    ¦  }
 72    ¦  /* ====================  MUTATORS      ======================================= */
 73    ¦
 74    ¦  /* ====================  OPERATORS     ======================================= */
 75    ¦
 76    protected:
 77    ¦  /* ====================  DATA MEMBERS  ======================================= */
 78    ¦
 79    ¦
 80    private:
 81    ¦  /* ====================  DATA MEMBERS  ======================================= */
 82       ¦std::string _trait;
 83       ¦unk _states;
 84       ¦NODE<unk> * _cl, * _cr, * _p;
 85 
 86 
 87 }; /* -----  end of template class NODE  ----- */
 88 
 89 template<class unk>
 90 NODE<unk>::NODE( std::string xt, unk x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp  ){
 91    states(x);
 92    trait(xt);
 93    cl(xcl);
 94    cr(xcr);
 95    p(xp);
 96    std::cout << trait() << " node " << "has the following states => " << states() << std::endl;
 97 }
 98 
 99 template<class unk>
100    tree::NODE<unk>::~NODE<unk>(){
101 }
102 
103 /*
104  * =====================================================================================
105  *        Class:  State
106  *  Description:  This describes a possible individual state or charactoristic 
107  * =====================================================================================
108  */
109 template<class cost>
110 class state
111 {
112    public:
113       /* ====================  LIFECYCLE     ======================================= */
114       ¦  ¦  ¦  ¦  ¦  ¦  ¦  ¦/* constructor */
115       //r is the minimum cost of a single state when compared to the child nodes
116       explicit state<cost>(std::string const xa, cost xr)
117       :_nam{xa}, _r{xr}
118       {
119          std::cout << "Building a state pair" << std::endl;
120          std::cout << "nam => " << nam()  << "\tcost=> " << r() << std::endl;
121       };
122 
123 
124       /* ====================  ACCESSORS     ======================================= */
125       std::string nam(){return _nam;};
126       cost r(){return _r;};
127       void r(cost b ){_r = b;};
128       /* ====================  MUTATORS      ======================================= */
129 
130       /* ====================  OPERATORS     ======================================= */
131 
132       /* ====================  DATA MEMBERS  ======================================= */
133    protected:
134 
135    private:
136       std::string _nam;
137       cost _r;
138 
139 }; /* -----  end of class State  ----- */
140 
141 /*
142  * =====================================================================================
143  *        Class:  Pstates
144  *  Description:  vector of all possible states
145  * =====================================================================================
146  */
147 template<class cost>
148 class Pstates
149 {
150    public:
151 
152       /* ====================  LIFECYCLE     ======================================= */
153       /* constructor      */
154       Pstates (std::vector< state<cost>  > x)
155          : _vstate{x}
156       {
157             for( auto& y : _vstate)
158                std::cout << y << std::endl;
159       };
160       ~Pstates (){};                            /* destructor       */
161 
162       /* ====================  ACCESSORS     ======================================= */
163       const std::vector< state<cost> >& vstate(){
164          return _vstate;
165       }
166       void vstate(std::vector< state<cost> > in ){
167          _vstate = in;
168       }
169 
170       /* ====================  MUTATORS      ======================================= */
171 
172       /* ====================  OPERATORS     ======================================= */
173 
174       const Pstates& operator = ( const Pstates &other ); /* assignment operator */
175 
176       template<class outcost>
177       friend std::ostream& operator << ( std::ostream &output, state<outcost>  &p ) ;
178 
179 
180 
181       /* ====================  DATA MEMBERS  ======================================= */
182    protected:
183 
184    private:
185       std::vector< state <cost> > _vstate;
186 
187 }; /* -----  end of class Pstates  ----- */
188 
189 /* Overload ostream function */
190 template <class outcost>
191 std::ostream& operator << ( std::ostream &output, state<outcost> &p )
192       {
193          output << "nam => " << p.nam()  << "\tcost=> " << p.r() << std::endl;
194    ¦  ¦  return output;
195    ¦  }
196 /*
197 
198    
199    template<class unk>
200 inline unk NODE<unk>::value(){ if(this != NULL) return _value; else return NULL; };
201 
202 template<class unk>
203 inline void NODE<unk>::value(unk val){
204    _value = val;
205 };
206 
207 */
208 
209 
210 /*
211 template<class unk>
212 class LIST{
213    public:
214       LIST<unk>() : _at_front(0), _at_end(0), _size(0) {}
215       inline int size();
216       inline void insert(NODE<unk> *, unk);
217       inline void insert(unk);
218       inline void front(unk);
219       inline void up_size();
220       inline void down_size();
221       void display(ostream &os = cout);
222       void remove_front();
223       void remove_all();
224       void remove_item(unk);
225       void remove_item(NODE<unk> *);
226       NODE<unk> * find(unk);
227       NODE<unk> * find_all(unk, NODE<unk> * last = NULL );
228 
229       ~LIST<unk>();
230 
231    private:
232       NODE<unk> *_at_front;
233       NODE<unk> *_at_end;
234       int _size;
235       LIST<unk>(const LIST<unk>&);
236       LIST<unk>& operator=( const LIST<unk>&);
237 };
238 */
239 
240 /*
241 template<class unk>
242 void LIST<unk>::display(ostream &os){
243    NODE<unk> * tmp = _at_front;
244 
245    if (tmp == 0){
246       os << "No List" << endl;
247       return;
248    }
249 
250 
251    //unk i =0;
252    while(tmp != _at_end){
253       //cout << "Entering While Loop: "<< ++i << endl;
254       os << tmp->value() << ":";
255       tmp = tmp->next();
256    }
257 
258    os << tmp->value() << endl;
259 
260 }
261 */
262 }        /*---End of Namespace TREE---*/
263 #endif