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 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
 
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.
 
ball_tother (const ball_t *b) const
 return a pointer to another ball
 
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 21 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:26
ball_t * _green_ball
Definition node.h:25
name_t uniq
Definition node.h:32
slate_t slate
Definition node.h:33
static const name_t null_lineage
Definition node.h:11
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:28
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 38 of file node.h.

38 {
39 return 2*sizeof(name_t) + sizeof(slate_t)
41 };
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:

◆ clean()

void node_t::clean ( void )
inlineprivate

Definition at line 28 of file node.h.

28{ };
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:

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

◆ insert()

void node_t::insert ( ball_t * a)
inline

insert a ball into the pocket of a node

Definition at line 156 of file node.h.

156 {
157 a->holder() = this;
158 pocket_t::insert(a);
159 };
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 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:92
name_t lineage(void) const
view lineage
Definition node.h:104
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

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 (holds_own()) {
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:96
bool holds(ball_t *b) const
does this node hold the given ball?
Definition pocket.h:109
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: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 30 of file newick.cc.

33{
34 string_t o1 = "", o2 = "", o3 = "";
35 int n = nchildren();
36 if (n > 0) {
37 o1 = "("; o3 = ")";
38 }
39 if (extended) {
40 o3 += "[&&PhyloPOMP ";
41 if (holds(blue))
42 o3 += "type=sample";
43 else if (holds_own())
44 o3 += "type=root";
45 else
46 o3 += "type=node";
47 if (showdeme)
48 o3 += " deme=" + std::to_string(deme());
49 o3 += "]";
50 }
51 n = 0;
52 for (ball_t *b : *this) {
53 node_t *p = 0;
54 switch (b->color) {
55 case green:
56 p = b->child();
57 if (p != this) {
58 if (n++ > 0) o2 += ",";
59 o2 += p->newick(tnow,slate,showdeme,extended);
60 }
61 break;
62 case black:
63 assert(extended);
64 if (n++ > 0) o2 += ",";
65 o2 += b->newick(tnow-slate,showdeme);
66 break;
67 case blue:
68 break;
69 }
70 }
71 return o1 + o2 + o3
72 + std::to_string(uniq)
73 + ":" + std::to_string(slate - tpar);
74}
string_t newick(const slate_t &t, bool showdeme) const
Definition newick.cc:15
node_t * child(void) const
a child is the owner of a green ball
Definition ball.h:102
node_t(name_t u=0, slate_t t=R_NaReal)
basic constructor for node class
Definition node.h:66
string_t newick(const slate_t &tnow, const slate_t &tpar, bool showdeme, bool extended) const
Newick-format output.
Definition newick.cc:31
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:

◆ 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: " + std::to_string(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 43 of file node.h.

43 {
44 name_t buf[2] = {p.uniq, p._lineage};
45 memcpy(o,buf,sizeof(buf)); o += sizeof(buf);
46 memcpy(o,&p.slate,sizeof(slate_t)); o += sizeof(slate_t);
47 return reinterpret_cast<const pocket_t&>(p) >> o;
48 };

◆ operator>> [2/2]

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

binary deserialization of node_t

Definition at line 50 of file node.h.

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

Field Documentation

◆ _green_ball

ball_t* node_t::_green_ball
private

Definition at line 25 of file node.h.

◆ _lineage

name_t node_t::_lineage
private

Definition at line 26 of file node.h.

◆ slate

slate_t node_t::slate

Definition at line 33 of file node.h.

◆ uniq

name_t node_t::uniq

Definition at line 32 of file node.h.


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