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

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
 
raw_toperator>> (raw_t *o, node_t &p)
 binary deserialization of node_t
 

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:34
slate_t slate
Definition node.h:35
static const name_t null_lineage
Definition node.h:13
Here is the caller graph for this function:

◆ node_t() [2/3]

node_t::node_t ( const node_t & p)
delete

copy constructor

Here is the call graph for this function:

◆ node_t() [3/3]

node_t::node_t ( node_t && p)
delete

move constructor

Here is the call graph for this function:

◆ ~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:
Here is the caller 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 };

◆ 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 caller graph for this function:

◆ describe()

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

human-readable info

Definition at line 177 of file node.h.

177 {
178 std::string s = "node("
179 + std::to_string(uniq)
180 + "," + std::to_string(deme()) + ",";
181 if (lineage() != null_lineage) {
182 s += std::to_string(lineage());
183 }
184 s += ")" + pocket_t::describe();
185 s += ", t = " + std::to_string(slate) + "\n";
186 return s;
187 };
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:146
Here is the call graph for this function:
Here is the caller 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 };
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_t *b : *this) {
155 switch (b->color) {
156 case green: case black:
157 incr[b->deme()]++;
158 sat[b->deme()]++;
159 break;
160 default:
161 break;
162 }
163 }
164 if (holds_own()) {
165 sat[d]--;
166 etype[d] = -1;
167 } else if (holds(blue)) {
168 etype[d] = 1;
169 } else {
170 etype[d] = 2;
171 }
172 };
@ green
Definition ball.h:14
@ black
Definition ball.h:14
@ blue
Definition ball.h:14
name_t deme(void) const
view deme
Definition ball.h:86
color_t color
Definition ball.h:38
bool holds(ball_t *b) const
does this node hold the given ball?
Definition pocket.h:111
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_t *b : *this) {
134 switch (b->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 214 of file node.h.

214 {
215 std::string o1 = "", o2 = "", o3 = "";
216 int n = nchildren();
217 if (n > 0) {
218 o1 = "("; o3 = ")";
219 }
220 if (holds(blue)) {
221 o3 += "b_";
222 } else if (holds_own()) {
223 o3 += "m_";
224 } else {
225 o3 += "g_";
226 }
227 n = 0;
228 for (ball_t *b : *this) {
229 node_t *p = 0;
230 switch (b->color) {
231 case green:
232 p = b->child();
233 if (p != this) {
234 if (n++ > 0) o2 += ",";
235 o2 += p->newick(tnow,slate);
236 }
237 break;
238 case black:
239 if (n++ > 0) o2 += ",";
240 o2 += b->newick(tnow-slate);
241 break;
242 case blue:
243 break;
244 }
245 }
246 return o1 + o2 + o3
247 + std::to_string(deme())
248 + "_" + std::to_string(uniq)
249 + ":" + std::to_string(slate - tpar);
250 };
std::string newick(const slate_t &t) const
element of a newick representation
Definition ball.h:177
node_t * child(void) const
a child is the owner of a green ball
Definition ball.h:104
std::string newick(const slate_t &tnow, const slate_t &tpar) const
Newick format.
Definition node.h:214
node_t(name_t u=0, slate_t t=R_NaReal)
basic constructor for node class
Definition node.h:66
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

Here is the call graph for this function:

◆ operator=() [2/2]

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

move assignment operator

Here is the call graph for this function:

◆ 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 201 of file node.h.

201 {
202 SEXP O, On;
203 PROTECT(O = NEW_LIST(4));
204 PROTECT(On = NEW_CHARACTER(4));
205 set_list_elem(O,On,ScalarInteger(int(uniq)),"name",0);
206 set_list_elem(O,On,ScalarReal(double(slate)),"time",1);
207 set_list_elem(O,On,ScalarInteger(int(deme())),"deme",2);
208 set_list_elem(O,On,pocket_t::structure(),"pocket",3);
209 SET_NAMES(O,On);
210 UNPROTECT(2);
211 return O;
212 };
SEXP structure(void) const
R list description.
Definition pocket.h:157
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:
Here is the caller graph for this function:

◆ yaml()

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

machine-readable info

Definition at line 189 of file node.h.

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

Friends And Related Symbol 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 };

◆ 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: