phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
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
 
void reuniqify (name_t shift)
 shifts name to avoid overlap
 
 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 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
 
slate_t joining_branch_length (const std::unordered_map< name_t, bool > &) const
 
void cblv (std::vector< slate_t > &, std::vector< slate_t > &, std::unordered_map< name_t, bool > &, const std::unordered_map< name_t, std::vector< node_t * > > &, slate_t) const
 
void insert (ball_t *a)
 insert a ball into the pocket of a node
 
string_t yaml (string_t tab="") const
 human/machine-readable info
 
SEXP structure (void) const
 R list description.
 
string_t newick (const slate_t &tnow, const slate_t &tpar, bool showdeme, bool extended) const
 Newick-format output.
 
- 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_tfirst_ball (void) const
 retrieve the first ball
 
ball_tlast_ball (void) const
 retrieve the last ball
 
ball_tball (const color_t c) const
 retrieve the first ball of the specified color.
 
string_t yaml (string_t tab="") const
 human/machine-readable info
 
SEXP structure (void) const
 R list description.
 

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

68 {
69 uniq = u;
70 slate = t;
71 _green_ball = 0;
73 };
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 83 of file node.h.

83 {
84 clean();
85 };
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:44
size_t name_t
Definition internal.h:54
double slate_t
Definition internal.h:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cblv()

void node_t::cblv ( std::vector< slate_t > & x,
std::vector< slate_t > & y,
std::unordered_map< name_t, bool > & memo,
const std::unordered_map< name_t, std::vector< node_t * > > & children,
slate_t t0 ) const

Recursive in-order walk over the subtree rooted at node p.

  • at leaf node, push added branch length into x
  • at internal node, push height into y

Definition at line 43 of file cblv.cc.

51{
52 assert(!memo[uniq]);
53 const std::vector<node_t*>& ch = children.at(uniq);
54 if (ch.empty()) {
55 // leaf node: push joining branch length to x
56 x.push_back(joining_branch_length(memo));
57 memo[uniq] = true;
58 } else {
59 // first child: recurse
60 ch[0]->cblv(x, y, memo, children, t0);
61 // subsequent children:
62 for (size_t i = 1; i < ch.size(); i++) {
63 // push the height of current node into y
64 y.push_back(slate - t0);
65 memo[uniq] = true;
66 ch[i]->cblv(x, y, memo, children, t0);
67 }
68 }
69}
slate_t joining_branch_length(const std::unordered_map< name_t, bool > &) const
Definition cblv.cc:36
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 123 of file node.h.

123 {
124 return is_root() && size()==1;
125 };
bool is_root(void) const
Definition node.h:120
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 102 of file node.h.

102 {
103 return _green_ball->deme();
104 };

◆ deme() [2/2]

name_t node_t::deme ( void ) const
inline

view deme

Definition at line 98 of file node.h.

98 {
99 return _green_ball->deme();
100 };
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 94 of file node.h.

94 {
95 return _green_ball;
96 };

◆ green_ball() [2/2]

ball_t * node_t::green_ball ( void ) const
inline

pointer to my green ball

Definition at line 90 of file node.h.

90 {
91 return _green_ball;
92 };
Here is the caller graph for this function:

◆ insert()

void node_t::insert ( ball_t * a)
inline

insert a ball into the pocket of a node

Definition at line 167 of file node.h.

167 {
168 a->holder() = this;
169 pocket_t::insert(a);
170 };
node_t * holder(void) const
in whose pocket do I lie?
Definition ball.h:107
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 120 of file node.h.

120 {
121 return (_green_ball->holder() == this);
122 };
Here is the caller graph for this function:

◆ joining_branch_length()

slate_t node_t::joining_branch_length ( const std::unordered_map< name_t, bool > & memo) const

distance along the genealogy from given node back to the nearest already-visited ancestor.

Definition at line 35 of file cblv.cc.

37{
38 const node_t *p = parent();
39 while (!p->is_root() && !memo.at(p->uniq)) p = p->parent();
40 return slate - p->slate;
41}
node_t * parent(void) const
Definition node.h:117
node_t(name_t u=0, slate_t t=R_NaReal)
basic constructor for node class
Definition node.h:68
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 110 of file node.h.

110 {
111 return g->owner()->lineage();
112 };
node_t * owner(void) const
view owner of a green ball
Definition ball.h:92
name_t lineage(void) const
view lineage
Definition node.h:106
Here is the call graph for this function:

◆ lineage() [2/3]

name_t & node_t::lineage ( void )
inline

set lineage

Definition at line 114 of file node.h.

114 {
115 return _lineage;
116 };

◆ lineage() [3/3]

name_t node_t::lineage ( void ) const
inline

view lineage

Definition at line 106 of file node.h.

106 {
107 return _lineage;
108 };
Here is the caller graph for this function:

◆ lineage_incr()

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

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

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

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

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

Definition at line 13 of file lineages.cc.

15{
16 const name_t d = deme();
17 incr[d]--;
18 for (ball_t *b : *this) {
19 switch (b->color) {
20 case green: case black:
21 incr[b->deme()]++;
22 sat[b->deme()]++;
23 break;
24 default:
25 break;
26 }
27 }
28 if (is_root()) {
29 sat[d]--;
30 etype[d] = -1;
31 } else if (holds(blue)) {
32 etype[d] = 1;
33 } else {
34 etype[d] = 2;
35 }
36}
@ green
Definition ball.h:12
@ black
Definition ball.h:12
@ blue
Definition ball.h:12
name_t deme(void) const
view deme
Definition ball.h:84
color_t color
Definition ball.h:36
name_t deme(void) const
view deme
Definition node.h:98
bool holds(ball_t *b) const
does this node hold the given ball?
Definition pocket.h:101
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 130 of file node.h.

130 {
131 int n = 0;
132 for (ball_t *b : *this) {
133 switch (b->color) {
134 case green: case black:
135 n++;
136 break;
137 default:
138 break;
139 }
140 }
141 if (is_root()) n--;
142 return n;
143 };
#define n
Definition lbdp_pomp.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ newick()

string_t node_t::newick ( const slate_t & tnow,
const slate_t & tpar,
bool showdeme,
bool extended ) const

Newick-format output.

Newick format with phylopomp extension Deme and node-type information is returned in a metadata wrapper.

Definition at line 45 of file newick.cc.

48{
49 string_t o1 = "", o2 = "", o3 = "";
50 int n = nchildren();
51 if (n > 0) {
52 o1 = "("; o3 = ")";
53 }
54 if (extended) {
55 o3 += "[&&PhyloPOMP ";
56 if (holds(blue))
57 o3 += "type=sample";
58 else if (is_root())
59 o3 += "type=root";
60 else
61 o3 += "type=node";
62 if (showdeme && deme() != undeme)
63 o3 += " deme=" + std::to_string(deme());
64 o3 += "]";
65 }
66 n = 0;
67 for (ball_t *b : *this) {
68 node_t *p = 0;
69 switch (b->color) {
70 case green:
71 p = b->child();
72 if (p != this) {
73 if (n++ > 0) o2 += ",";
74 o2 += p->newick(tnow,slate,showdeme,extended);
75 }
76 break;
77 case black:
78 assert(extended);
79 if (n++ > 0) o2 += ",";
80 o2 += b->newick(tnow-slate,showdeme);
81 break;
82 case blue:
83 break;
84 }
85 }
86 return o1 + o2 + o3
87 + ":" + double2string(slate - tpar);
88}
static const name_t undeme
Definition ball.h:15
string_t newick(const slate_t &t, bool showdeme) const
Definition newick.cc:32
node_t * child(void) const
a child is the owner of a green ball
Definition ball.h:102
string_t newick(const slate_t &tnow, const slate_t &tpar, bool showdeme, bool extended) const
Newick-format output.
Definition newick.cc:46
int nchildren(void) const
number of descendants
Definition node.h:130
std::string double2string(double value)
Definition newick.cc:17
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 117 of file node.h.

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

◆ reuniqify()

void node_t::reuniqify ( name_t shift)

shifts name to avoid overlap

Definition at line 9 of file sum.cc.

11{
12 this->uniq += shift;
13 for (ball_t *b : *this) {
14 b->uniq += shift;
15 }
16}
name_t uniq
Definition ball.h:35
Here is the caller graph for this function:

◆ structure()

SEXP node_t::structure ( void ) const

R list description.

Definition at line 54 of file structure.cc.

56{
57 SEXP O, On;
58 PROTECT(O = NEW_LIST(4));
59 PROTECT(On = NEW_CHARACTER(4));
60 set_list_elem(O,On,ScalarInteger(int(uniq)),"name",0);
61 set_list_elem(O,On,ScalarReal(double(slate)),"time",1);
62 set_list_elem(O,On,ScalarInteger(int(deme())),"deme",2);
63 set_list_elem(O,On,pocket_t::structure(),"pocket",3);
64 SET_NAMES(O,On);
65 UNPROTECT(2);
66 return O;
67}
SEXP structure(void) const
R list description.
Definition structure.cc:41
static int set_list_elem(SEXP list, SEXP names, SEXP element, const char *name, int pos)
Definition internal.h:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ yaml()

string_t node_t::yaml ( string_t tab = "") const

human/machine-readable info

Definition at line 36 of file yaml.cc.

38{
39 string_t t = tab + " ";
40 string_t o = "name: " + std::to_string(uniq) + "\n"
41 + tab + "time: " + double2string(slate) + "\n"
42 + tab + "deme: " + std::to_string(deme()) + "\n";
43 if (lineage() != null_lineage) {
44 o += tab + "lineage: " + std::to_string(lineage()) + "\n";
45 }
46 o += tab + "pocket:\n" + pocket_t::yaml(tab);
47 return o;
48}
string_t yaml(string_t tab="") const
human/machine-readable info
Definition yaml.cc:25
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:72

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