phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
init.c File Reference
#include "init.h"
#include "decls.h"
#include "pomplink.h"
Include dependency graph for init.c:

Go to the source code of this file.

Functions

SEXP parse_newick (SEXP, SEXP, SEXP)
 
SEXP newick (SEXP, SEXP)
 tree in newick format
 
SEXP getInfo (SEXP)
 
SEXP genealSum (SEXP)
 combine genealogies
 
SEXP curtail (SEXP, SEXP, SEXP)
 curtail the given genealogy
 
SEXP yaml (SEXP)
 extract a YAML description
 
SEXP gendat (SEXP, SEXP)
 data-frame format
 
SEXP geneal (SEXP)
 extract the bare genealogy
 
 DECLARATIONS (LBDP)
 
 DECLARATIONS (Moran)
 
 DECLARATIONS (S2I2R2)
 
 DECLARATIONS (SEIR)
 
 DECLARATIONS (SI2R)
 
 DECLARATIONS (SIIR)
 
 DECLARATIONS (SIR)
 
 DECLARATIONS (Strains)
 
 DECLARATIONS (TwoSpecies)
 
 DECLARATIONS (TwoUndead)
 
void R_init_phylopomp (DllInfo *info)
 

Variables

get_userdata_t * get_userdata
 
get_userdata_double_t * get_userdata_double
 
get_userdata_int_t * get_userdata_int
 
static const R_CallMethodDef callMethods []
 
static const R_CallMethodDef extMethods []
 

Function Documentation

◆ curtail()

SEXP curtail ( SEXP State,
SEXP Time,
SEXP Troot )

curtail the given genealogy

Definition at line 88 of file curtail.cc.

88 {
89 genealogy_t A = State;
90 double t, t0;
91 t = *REAL(AS_NUMERIC(Time));
92 t0 = *REAL(AS_NUMERIC(Troot));
93 if (ISNA(t)) t = A.time();
94 if (ISNA(t0)) t0 = A.timezero();
95 A.curtail(t,t0);
96 SEXP out;
97 PROTECT(out = serial(A));
98 SET_ATTR(out,install("class"),mkString("gpgen"));
99 UNPROTECT(1);
100 return out;
101 }
Encodes a genealogy.
Definition genealogy.h:19
slate_t & timezero(void)
view/set zero time.
Definition genealogy.h:153
slate_t & time(void)
view/set current time.
Definition genealogy.h:145
void curtail(slate_t tnew, slate_t troot)
Definition curtail.cc:11
SEXP serial(const TYPE &X)
binary serialization
Definition generics.h:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DECLARATIONS() [1/10]

DECLARATIONS ( LBDP )

◆ DECLARATIONS() [2/10]

DECLARATIONS ( Moran )

◆ DECLARATIONS() [3/10]

DECLARATIONS ( S2I2R2 )

◆ DECLARATIONS() [4/10]

DECLARATIONS ( SEIR )

◆ DECLARATIONS() [5/10]

DECLARATIONS ( SI2R )

◆ DECLARATIONS() [6/10]

DECLARATIONS ( SIIR )

◆ DECLARATIONS() [7/10]

DECLARATIONS ( SIR )

◆ DECLARATIONS() [8/10]

DECLARATIONS ( Strains )

◆ DECLARATIONS() [9/10]

DECLARATIONS ( TwoSpecies )

◆ DECLARATIONS() [10/10]

DECLARATIONS ( TwoUndead )

◆ gendat()

SEXP gendat ( SEXP State,
SEXP Obscure )

data-frame format

Definition at line 104 of file gendat.cc.

104 {
105 genealogy_t A = State;
106 A.prune();
107 if (*LOGICAL(Obscure)) A.obscure();
108 A.trace_lineages();
109 return A.gendat();
110 }
genealogy_t & prune(void)
prune the tree (drop all black balls)
Definition genealogy.h:310
void gendat(double *tout, int *anc, int *lin, int *sat, int *type, int *deme, int *index, int *child) const
genealogy information in list format
Definition gendat.cc:9
genealogy_t & obscure(void)
erase all deme information
Definition genealogy.h:321
void trace_lineages(void)
Definition nodeseq.h:253
Here is the call graph for this function:
Here is the caller graph for this function:

◆ geneal()

SEXP geneal ( SEXP State)

extract the bare genealogy

Definition at line 12 of file geneal.cc.

12 {
13 SEXP S;
14 PROTECT(S = serial(genealogy_t(State)));
15 SET_ATTR(S,install("class"),mkString("gpgen"));
16 UNPROTECT(1);
17 return S;
18 }
#define S
Definition seirs_pomp.c:37
Here is the call graph for this function:

◆ genealSum()

SEXP genealSum ( SEXP args)

combine genealogies

Definition at line 50 of file sum.cc.

50 {
51 args = CDR(args);
52 genealogy_t A(R_NegInf); // a "null" genealogy on [-inf,inf]
53 A.time() = R_PosInf;
54 while (args != R_NilValue) {
55 A += CAR(args);
56 args = CDR(args);
57 }
58 SEXP S;
59 PROTECT(S = serial(A));
60 SET_ATTR(S,install("class"),mkString("gpgen"));
61 UNPROTECT(1);
62 return S;
63 }
Here is the call graph for this function:

◆ getInfo()

SEXP getInfo ( SEXP args)

extract requested information prune and/or obscure if requested

Definition at line 19 of file getinfo.cc.

19 {
20 const char *argname[] = {
21 "object","prune","obscure","extended",
22 "t0","time","nsample","nroot","ndeme",
23 "structure","yaml","newick",
24 "lineages","gendat","genealogy"};
25 const int narg = sizeof(argname)/sizeof(const char *);
26 bool flag[narg];
27 SEXP object = R_NilValue;
28 size_t nout = 0;
29 int k;
30
31 for (k = 0; k < narg; k++) flag[k] = false;
32 args = CDR(args);
33
34 while (args != R_NilValue) {
35 const char *name = isNull(TAG(args)) ? "" : CHAR(PRINTNAME(TAG(args)));
36 SEXP arg = CAR(args);
37 size_t j = matchargs(name,argname,narg);
38 if (j == 0) {
39 object = arg;
40 flag[0] = true;
41 } else if (j < 4) {
42 flag[j] = *LOGICAL(AS_LOGICAL(arg));
43 } else if (j < narg) {
44 flag[j] = *LOGICAL(AS_LOGICAL(arg));
45 if (flag[j]) nout++;
46 } else {
47 err("unrecognized argument '%s' in '%s'.",name,__func__);
48 }
49 args = CDR(args);
50 }
51
52 if (!flag[0]) err("no genealogy furnished to '%s'",__func__);
53 genealogy_t A = object;
54
55 // prune and/or obscure if requested
56 const bool *f = flag+1;
57 if (*(f++)) A.prune();
58 if (*(f++)) A.obscure();
60 bool extended = false;
61 if (*(f++)) {
62 extended = true;
63 } else {
64 A.insert_zlb();
65 }
66
67 SEXP out, outnames;
68 PROTECT(out = NEW_LIST(nout));
69 PROTECT(outnames = NEW_CHARACTER(nout));
70 k = 0;
71 if (*(f++)) { // t0
72 k = set_list_elem(out,outnames,timezero(A),"t0",k);
73 }
74 if (*(f++)) { // time
75 k = set_list_elem(out,outnames,time(A),"time",k);
76 }
77 if (*(f++)) { // nsample
78 k = set_list_elem(out,outnames,nsample(A),"nsample",k);
79 }
80 if (*(f++)) { // nroot
81 k = set_list_elem(out,outnames,nroot(A),"nroot",k);
82 }
83 if (*(f++)) { // ndeme
84 k = set_list_elem(out,outnames,ndeme(A),"ndeme",k);
85 }
86 if (*(f++)) { // structure
87 k = set_list_elem(out,outnames,structure(A),"structure",k);
88 }
89 if (*(f++)) { // yaml
90 k = set_list_elem(out,outnames,yaml(A),"yaml",k);
91 }
92 if (*(f++)) { // newick
93 k = set_list_elem(out,outnames,newick(A,extended),"newick",k);
94 }
95 if (*(f++)) { // lineages
96 k = set_list_elem(out,outnames,lineage_count(A),"lineages",k);
97 }
98 if (*(f++)) { // gendat
99 k = set_list_elem(out,outnames,gendat(A),"gendat",k);
100 }
101 if (*(f++)) { // genealogy
102 SEXP S;
103 PROTECT(S = serial(A));
104 SET_ATTR(S,install("class"),mkString("gpgen"));
105 k = set_list_elem(out,outnames,S,"genealogy",k);
106 UNPROTECT(1);
107 }
108 SET_NAMES(out,outnames);
109 UNPROTECT(2);
110 return out;
111 }
void insert_zlb(void)
insert zero-length branches for samples where needed
Definition genealogy.h:358
SEXP gendat(SEXP State, SEXP Obscure)
data-frame format
Definition gendat.cc:104
SEXP ndeme(TYPE &X)
Definition generics.h:7
SEXP nroot(TYPE &X)
Definition generics.h:17
SEXP timezero(TYPE &X)
Definition generics.h:22
SEXP time(TYPE &X)
Definition generics.h:27
SEXP structure(const TYPE &X)
structure in R list format
Definition generics.h:49
SEXP yaml(const TYPE &X)
human/machine readable output
Definition generics.h:43
SEXP lineage_count(const TYPE &G)
number of lineages through time
Definition generics.h:61
SEXP nsample(TYPE &X)
Definition generics.h:12
SEXP newick(const TYPE &X, bool extended)
tree in newick format
Definition generics.h:55
static size_t matchargs(const char *prov, const char **set, size_t n)
Definition getinfo.cc:7
static int set_list_elem(SEXP list, SEXP names, SEXP element, const char *name, int pos)
Definition internal.h:76
#define err(...)
Definition internal.h:18
Here is the call graph for this function:

◆ newick()

SEXP newick ( SEXP State,
SEXP Extended )

tree in newick format

Definition at line 102 of file newick.cc.

102 {
103 PROTECT(Extended = AS_LOGICAL(Extended));
104 bool extended = *LOGICAL(Extended);
105 genealogy_t A(State);
106 UNPROTECT(1);
107 return mkString(A.newick(extended).c_str());
108 }
Here is the call graph for this function:

◆ parse_newick()

SEXP parse_newick ( SEXP X,
SEXP T0,
SEXP Tf )

A parser for Newick code. Returns a genealogy in the phylopomp format.

Definition at line 236 of file parse.cc.

236 {
237 PROTECT(X = AS_CHARACTER(X));
238 PROTECT(T0 = AS_NUMERIC(T0));
239 PROTECT(Tf = AS_NUMERIC(Tf));
240 double t0 = *REAL(T0);
241 double tf = *REAL(Tf);
242 // parse the Newick representation into a genealogy:
243 string_t x = CHAR(STRING_ELT(X,0));
244 genealogy_t G(t0);
245 G.parse(x);
246 if (!ISNA(tf)) {
247 G.curtail(tf,t0);
248 }
249 G.trace_lineages();
250 UNPROTECT(3);
251 return serial(G);
252 }
Here is the call graph for this function:

◆ R_init_phylopomp()

void R_init_phylopomp ( DllInfo * info)

Definition at line 58 of file init.c.

58 {
59 // Register routines
60 R_registerRoutines(info,NULL,callMethods,NULL,extMethods);
61 R_useDynamicSymbols(info,TRUE);
62 // R_useDynamicSymbols(info,FALSE);
63 // R_forceSymbols(info,TRUE);
64 get_userdata = (get_userdata_t*) R_GetCCallable("pomp","get_userdata");
65 get_userdata_double = (get_userdata_double_t*) R_GetCCallable("pomp","get_userdata_double");
66 get_userdata_int = (get_userdata_int_t*) R_GetCCallable("pomp","get_userdata_int");
67}
static const R_CallMethodDef extMethods[]
Definition init.c:52
get_userdata_int_t * get_userdata_int
Definition init.c:7
static const R_CallMethodDef callMethods[]
Definition init.c:32
get_userdata_t * get_userdata
Definition init.c:5
get_userdata_double_t * get_userdata_double
Definition init.c:6

◆ yaml()

SEXP yaml ( SEXP State)

extract a YAML description

Definition at line 78 of file yaml.cc.

78 {
79 genealogy_t A = State;
80 return mkString(A.yaml().c_str());
81 }
string_t yaml(string_t tab="") const
human/machine-readable info
Definition yaml.cc:64
Here is the call graph for this function:

Variable Documentation

◆ callMethods

const R_CallMethodDef callMethods[]
static
Initial value:
= {
METHODS(LBDP),
METHODS(Moran),
METHODS(S2I2R2),
METHODS(SEIR),
METHODS(SI2R),
METHODS(SIIR),
METHODS(SIR),
METHODS(Strains),
METHODS(TwoSpecies),
METHODS(TwoUndead),
{"parse_newick", (DL_FUNC) &parse_newick, 3},
{"newick", (DL_FUNC) &newick, 2},
{"curtail", (DL_FUNC) &curtail, 3},
{"yaml", (DL_FUNC) &yaml, 1},
{"gendat", (DL_FUNC) &gendat, 2},
{"geneal", (DL_FUNC) &geneal, 1},
{NULL, NULL, 0}
}
SEXP curtail(SEXP State, SEXP Time, SEXP Troot)
curtail the given genealogy
Definition curtail.cc:88
SEXP geneal(SEXP State)
extract the bare genealogy
Definition geneal.cc:12
SEXP parse_newick(SEXP, SEXP, SEXP)
Definition parse.cc:236
#define METHODS(X)
Definition init.h:13

Definition at line 32 of file init.c.

32 {
33 METHODS(LBDP),
34 METHODS(Moran),
35 METHODS(S2I2R2),
36 METHODS(SEIR),
37 METHODS(SI2R),
38 METHODS(SIIR),
39 METHODS(SIR),
40 METHODS(Strains),
41 METHODS(TwoSpecies),
42 METHODS(TwoUndead),
43 {"parse_newick", (DL_FUNC) &parse_newick, 3},
44 {"newick", (DL_FUNC) &newick, 2},
45 {"curtail", (DL_FUNC) &curtail, 3},
46 {"yaml", (DL_FUNC) &yaml, 1},
47 {"gendat", (DL_FUNC) &gendat, 2},
48 {"geneal", (DL_FUNC) &geneal, 1},
49 {NULL, NULL, 0}
50};

◆ extMethods

const R_CallMethodDef extMethods[]
static
Initial value:
= {
{"getInfo", (DL_FUNC) &getInfo, -1},
{"genealSum", (DL_FUNC) &genealSum, -1},
{NULL, NULL, 0}
}
SEXP getInfo(SEXP args)
Definition getinfo.cc:19
SEXP genealSum(SEXP)
combine genealogies
Definition sum.cc:50

Definition at line 52 of file init.c.

52 {
53 {"getInfo", (DL_FUNC) &getInfo, -1},
54 {"genealSum", (DL_FUNC) &genealSum, -1},
55 {NULL, NULL, 0}
56};

◆ get_userdata

get_userdata_t* get_userdata

Definition at line 5 of file init.c.

◆ get_userdata_double

get_userdata_double_t* get_userdata_double

Definition at line 6 of file init.c.

◆ get_userdata_int

get_userdata_int_t* get_userdata_int

Definition at line 7 of file init.c.