phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
node_t Class Reference

Encodes a genealogical node. More...

#include <node.h>

Inheritance diagram for node_t:
Collaboration diagram for node_t:

Public Member Functions

size_t bytesize (void) const
 size of binary serialization More...
 
 node_t (name_t u=0, slate_t t=R_NaReal)
 basic constructor for node class More...
 
 node_t (const node_t &p)=delete
 copy constructor More...
 
 node_t (node_t &&p)=delete
 move constructor More...
 
node_toperator= (const node_t &p)=delete
 copy assignment operator More...
 
node_toperator= (node_t &&p)=delete
 move assignment operator More...
 
 ~node_t (void)
 destructor More...
 
ball_tgreen_ball (void) const
 pointer to my green ball More...
 
ball_t *& green_ball (void)
 set green ball More...
 
name_t deme (void) const
 view deme More...
 
name_tdeme (void)
 set deme More...
 
name_t lineage (void) const
 view lineage More...
 
name_t lineage (const ball_t *g) const
 view lineage associated with a green ball More...
 
name_tlineage (void)
 set lineage More...
 
node_tparent (void) const
 
bool holds_own (void) const
 
bool is_root (void) const
 
bool dead_root (void) const
 
int nchildren (void) const
 number of descendants More...
 
void lineage_incr (int *incr, int *sat, int *etype) const
 
std::string describe (void) const
 human-readable info More...
 
std::string yaml (std::string tab="") const
 machine-readable info More...
 
SEXP structure (void) const
 R list description. More...
 
std::string newick (const slate_t &tnow, const slate_t &tpar) const
 Newick format. More...
 
- Public Member Functions inherited from pocket_t
size_t bytesize (void) const
 size of binary serialization More...
 
void repair_owners (const std::unordered_map< name_t, node_t * > &node_name, std::unordered_map< name_t, ball_t * > *ball_name)
 
 ~pocket_t (void)
 destructor More...
 
bool holds (ball_t *b) const
 does this node hold the given ball? More...
 
bool holds (color_t c) const
 does this node hold a ball of this color? More...
 
ball_tlast_ball (void) const
 retrieve the last ball More...
 
ball_tball (const color_t c) const
 retrieve the first ball of the specified color. More...
 
ball_tother (const ball_t *b) const
 return a pointer to another ball More...
 
std::string describe (void) const
 human-readable info More...
 
SEXP structure (void) const
 R list description. More...
 
std::string yaml (std::string tab="") const
 human/machine-readable info More...
 

Data Fields

name_t uniq
 
slate_t slate
 

Private Member Functions

void clean (void)
 

Private Attributes

ball_t_green_ball
 
name_t _lineage
 

Friends

raw_toperator>> (const node_t &p, raw_t *o)
 binary serialization of node_t More...
 
raw_toperator>> (raw_t *o, node_t &p)
 binary deserialization of node_t More...
 

Additional Inherited Members

- Protected Member Functions inherited from pocket_t
void repair_holder (node_t *p)
 

Detailed Description

Encodes a genealogical node.

Each node has:

  • a unique name (uniq)
  • a pocket containting two or more balls
  • a "slate" with the time
  • a lineage
  • a pointer to its own green ball

Definition at line 23 of file node.h.

Constructor & Destructor Documentation

◆ node_t() [1/3]

node_t::node_t ( name_t  u = 0,
slate_t  t = R_NaReal 
)
inline

basic constructor for node class

Definition at line 66 of file node.h.

66  {
67  uniq = u;
68  slate = t;
69  _green_ball = 0;
71  };
name_t _lineage
Definition: node.h:28
ball_t * _green_ball
Definition: node.h:27
name_t uniq
Definition: node.h:30
slate_t slate
Definition: node.h:35
static const name_t null_lineage
Definition: node.h:13

◆ node_t() [2/3]

node_t::node_t ( const node_t p)
delete

copy constructor

◆ node_t() [3/3]

node_t::node_t ( node_t &&  p)
delete

move constructor

◆ ~node_t()

node_t::~node_t ( void  )
inline

destructor

Definition at line 81 of file node.h.

81  {
82  clean();
83  };
void clean(void)
Definition: node.h:30
Here is the call graph for this function:

Member Function Documentation

◆ bytesize()

size_t node_t::bytesize ( void  ) const
inline

size of binary serialization

Definition at line 40 of file node.h.

40  {
41  return 2*sizeof(name_t) + sizeof(slate_t)
43  };
size_t bytesize(void) const
size of binary serialization
Definition: pocket.h:46
size_t name_t
Definition: internal.h:45
double slate_t
Definition: internal.h:44
Here is the call graph for this function:

◆ clean()

void node_t::clean ( void  )
inlineprivate

Definition at line 30 of file node.h.

30 { };
Here is the caller graph for this function:

◆ dead_root()

bool node_t::dead_root ( void  ) const
inline

Definition at line 124 of file node.h.

124  {
125  return holds_own() && size()==1;
126  };
bool holds_own(void) const
Definition: node.h:118
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deme() [1/2]

name_t& node_t::deme ( void  )
inline

set deme

Definition at line 100 of file node.h.

100  {
101  return _green_ball->deme();
102  };
name_t deme(void) const
view deme
Definition: ball.h:86
Here is the call graph for this function:

◆ deme() [2/2]

name_t node_t::deme ( void  ) const
inline

view deme

Definition at line 96 of file node.h.

96  {
97  return _green_ball->deme();
98  };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ describe()

std::string node_t::describe ( void  ) const
inline

human-readable info

Definition at line 178 of file node.h.

178  {
179  std::string s = "node("
180  + std::to_string(uniq)
181  + "," + std::to_string(deme()) + ",";
182  if (lineage() != null_lineage) {
183  s += std::to_string(lineage());
184  }
185  s += ")" + pocket_t::describe();
186  s += ", t = " + std::to_string(slate) + "\n";
187  return s;
188  };
name_t lineage(void) const
view lineage
Definition: node.h:104
name_t deme(void) const
view deme
Definition: node.h:96
std::string describe(void) const
human-readable info
Definition: pocket.h:147
Here is the call graph for this function:

◆ green_ball() [1/2]

ball_t*& node_t::green_ball ( void  )
inline

set green ball

Definition at line 92 of file node.h.

92  {
93  return _green_ball;
94  };

◆ green_ball() [2/2]

ball_t* node_t::green_ball ( void  ) const
inline

pointer to my green ball

Definition at line 88 of file node.h.

88  {
89  return _green_ball;
90  };
Here is the caller graph for this function:

◆ holds_own()

bool node_t::holds_own ( void  ) const
inline

Definition at line 118 of file node.h.

118  {
119  return (_green_ball->holder() == this);
120  };
node_t * holder(void) const
in whose pocket do I lie?
Definition: ball.h:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_root()

bool node_t::is_root ( void  ) const
inline

Definition at line 121 of file node.h.

121  {
122  return holds_own();
123  };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lineage() [1/3]

name_t node_t::lineage ( const ball_t g) const
inline

view lineage associated with a green ball

Definition at line 108 of file node.h.

108  {
109  return g->owner()->lineage();
110  };
node_t * owner(void) const
view owner of a green ball
Definition: ball.h:94
Here is the call graph for this function:

◆ lineage() [2/3]

name_t& node_t::lineage ( void  )
inline

set lineage

Definition at line 112 of file node.h.

112  {
113  return _lineage;
114  };

◆ lineage() [3/3]

name_t node_t::lineage ( void  ) const
inline

view lineage

Definition at line 104 of file node.h.

104  {
105  return _lineage;
106  };
Here is the caller graph for this function:

◆ lineage_incr()

void node_t::lineage_incr ( int *  incr,
int *  sat,
int *  etype 
) const
inline

lineage count, saturation, and event-type types are:

  • 0 = non-event
  • -1 = root
  • 1 = sample
  • 2 = non-sample node

Definition at line 151 of file node.h.

151  {
152  const name_t d = deme();
153  incr[d]--;
154  for (ball_it i = cbegin(); i != cend(); i++) {
155  ball_t *b = *i;
156  switch (b->color) {
157  case green: case black:
158  incr[b->deme()]++;
159  sat[b->deme()]++;
160  break;
161  default:
162  break;
163  }
164  }
165  if (holds_own()) {
166  sat[d]--;
167  etype[d] = -1;
168  } else if (holds(blue)) {
169  etype[d] = 1;
170  } else {
171  etype[d] = 2;
172  }
173  };
@ green
Definition: ball.h:14
@ black
Definition: ball.h:14
@ blue
Definition: ball.h:14
Balls function as pointers.
Definition: ball.h:29
color_t color
Definition: ball.h:38
bool holds(ball_t *b) const
does this node hold the given ball?
Definition: pocket.h:112
std::set< ball_t *, ball_order >::const_iterator ball_it
Definition: pocket.h:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nchildren()

int node_t::nchildren ( void  ) const
inline

number of descendants

Definition at line 131 of file node.h.

131  {
132  int n = 0;
133  for (ball_it i = begin(); i != end(); i++) {
134  switch ((*i)->color) {
135  case green: case black:
136  n++;
137  break;
138  default:
139  break;
140  }
141  }
142  if (holds_own()) n--;
143  return n;
144  };
#define n
Definition: lbdp_pomp.c:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ newick()

std::string node_t::newick ( const slate_t tnow,
const slate_t tpar 
) const
inline

Newick format.

Definition at line 215 of file node.h.

215  {
216  std::string o1 = "", o2 = "", o3 = "";
217  int n = nchildren();
218  if (n > 0) {
219  o1 = "("; o3 = ")";
220  }
221  if (holds(blue)) {
222  o3 += "b_";
223  } else if (holds_own()) {
224  o3 += "m_";
225  } else {
226  o3 += "g_";
227  }
228  n = 0;
229  for (ball_it i = begin(); i != end(); i++) {
230  ball_t *b = *i;
231  node_t *p = 0;
232  switch (b->color) {
233  case green:
234  p = b->child();
235  if (p != this) {
236  if (n++ > 0) o2 += ",";
237  o2 += p->newick(tnow,slate);
238  }
239  break;
240  case black:
241  if (n++ > 0) o2 += ",";
242  o2 += b->newick(tnow-slate);
243  break;
244  case blue:
245  break;
246  }
247  }
248  return o1 + o2 + o3
249  + std::to_string(deme())
250  + "_" + std::to_string(uniq)
251  + ":" + std::to_string(slate - tpar);
252  };
node_t * child(void) const
a child is the owner of a green ball
Definition: ball.h:104
std::string newick(const slate_t &t) const
element of a newick representation
Definition: ball.h:177
Encodes a genealogical node.
Definition: node.h:23
std::string newick(const slate_t &tnow, const slate_t &tpar) const
Newick format.
Definition: node.h:215
int nchildren(void) const
number of descendants
Definition: node.h:131
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

node_t& node_t::operator= ( const node_t p)
delete

copy assignment operator

◆ operator=() [2/2]

node_t& node_t::operator= ( node_t &&  p)
delete

move assignment operator

◆ parent()

node_t* node_t::parent ( void  ) const
inline

Definition at line 115 of file node.h.

115  {
116  return _green_ball->holder();
117  };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ structure()

SEXP node_t::structure ( void  ) const
inline

R list description.

Definition at line 202 of file node.h.

202  {
203  SEXP O, On;
204  PROTECT(O = NEW_LIST(4));
205  PROTECT(On = NEW_CHARACTER(4));
206  set_list_elem(O,On,ScalarInteger(int(uniq)),"name",0);
207  set_list_elem(O,On,ScalarReal(double(slate)),"time",1);
208  set_list_elem(O,On,ScalarInteger(int(deme())),"deme",2);
209  set_list_elem(O,On,pocket_t::structure(),"pocket",3);
210  SET_NAMES(O,On);
211  UNPROTECT(2);
212  return O;
213  };
SEXP structure(void) const
R list description.
Definition: pocket.h:158
static int set_list_elem(SEXP list, SEXP names, SEXP element, const char *name, int pos)
Definition: internal.h:67
Here is the call graph for this function:

◆ yaml()

std::string node_t::yaml ( std::string  tab = "") const
inline

machine-readable info

Definition at line 190 of file node.h.

190  {
191  std::string t = tab + " ";
192  std::string o = "name: " + std::to_string(uniq) + "\n"
193  + tab + "time: " + std::to_string(slate) + "\n"
194  + tab + "deme: " + std::to_string(deme()) + "\n";
195  if (lineage() != null_lineage) {
196  o += tab + "lineage: " + std::to_string(lineage()) + "\n";
197  }
198  o += tab + "pocket:\n" + pocket_t::yaml(tab);
199  return o;
200  };
std::string yaml(std::string tab="") const
human/machine-readable info
Definition: pocket.h:169
Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator>> [1/2]

raw_t* operator>> ( const node_t p,
raw_t o 
)
friend

binary serialization of node_t

Definition at line 45 of file node.h.

45  {
46  name_t buf[2] = {p.uniq, p._lineage};
47  memcpy(o,buf,sizeof(buf)); o += sizeof(buf);
48  memcpy(o,&p.slate,sizeof(slate_t)); o += sizeof(slate_t);
49  return reinterpret_cast<const pocket_t&>(p) >> o;
50  };
A pocket is a set of balls.
Definition: pocket.h:32

◆ operator>> [2/2]

raw_t* operator>> ( raw_t o,
node_t p 
)
friend

binary deserialization of node_t

Definition at line 52 of file node.h.

52  {
53  p.clean();
54  name_t buf[2];
55  memcpy(buf,o,sizeof(buf)); o += sizeof(buf);
56  memcpy(&p.slate,o,sizeof(slate_t)); o += sizeof(slate_t);
57  p.uniq = buf[0]; p._lineage = buf[1];
58  o = (o >> reinterpret_cast<pocket_t&>(p));
59  p.repair_holder(&p);
60  return o;
61  };
void repair_holder(node_t *p)
Definition: pocket.h:74

Field Documentation

◆ _green_ball

ball_t* node_t::_green_ball
private

Definition at line 27 of file node.h.

◆ _lineage

name_t node_t::_lineage
private

Definition at line 28 of file node.h.

◆ slate

slate_t node_t::slate

Definition at line 35 of file node.h.

◆ uniq

name_t node_t::uniq

Definition at line 34 of file node.h.


The documentation for this class was generated from the following file: