phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
getinfo.cc
Go to the documentation of this file.
1// Get information about a genealogy
2
3#include "genealogy.h"
4#include "generics.h"
5#include "internal.h"
6
7static size_t matchargs (const char *prov, const char **set, size_t n) {
8 size_t i;
9 for (i = 0; i < n; i++) {
10 if (strcmp(prov,set[i]) == 0) break;
11 }
12 return i;
13}
14
15extern "C" {
16
19 SEXP getInfo (SEXP args) {
20 const char *argname[] = {
21 "object","prune","obscure","extended",
22 "t0","time","nsample","nroot","ndeme",
23 "structure","yaml","newick",
24 "lineages","gendat","genealogy","cblv"};
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 < narg) {
42 flag[j] = *LOGICAL(AS_LOGICAL(arg));
43 if (j > 3 && flag[j]) nout++;
44 } else {
45 err("unrecognized argument '%s' in '%s'.",name,__func__);
46 }
47 args = CDR(args);
48 }
49
50 if (!flag[0]) err("no genealogy furnished to '%s'",__func__);
51 genealogy_t A = object;
52
53 // prune and/or obscure if requested
54 const bool *f = flag+1;
55 if (*(f++)) A.prune();
56 if (*(f++)) A.obscure();
58 bool extended = false;
59 if (*(f++)) {
60 extended = true;
61 } else {
62 A.insert_zlb();
63 }
64
65 SEXP out, outnames;
66 PROTECT(out = NEW_LIST(nout));
67 PROTECT(outnames = NEW_CHARACTER(nout));
68 k = 0;
69 if (*(f++)) { // t0
70 k = set_list_elem(out,outnames,timezero(A),"t0",k);
71 }
72 if (*(f++)) { // time
73 k = set_list_elem(out,outnames,time(A),"time",k);
74 }
75 if (*(f++)) { // nsample
76 k = set_list_elem(out,outnames,nsample(A),"nsample",k);
77 }
78 if (*(f++)) { // nroot
79 k = set_list_elem(out,outnames,nroot(A),"nroot",k);
80 }
81 if (*(f++)) { // ndeme
82 k = set_list_elem(out,outnames,ndeme(A),"ndeme",k);
83 }
84 if (*(f++)) { // structure
85 k = set_list_elem(out,outnames,structure(A),"structure",k);
86 }
87 if (*(f++)) { // yaml
88 k = set_list_elem(out,outnames,yaml(A),"yaml",k);
89 }
90 if (*(f++)) { // newick
91 k = set_list_elem(out,outnames,newick(A,extended),"newick",k);
92 }
93 if (*(f++)) { // lineages
94 k = set_list_elem(out,outnames,lineage_count(A),"lineages",k);
95 }
96 if (*(f++)) { // gendat
97 k = set_list_elem(out,outnames,gendat(A),"gendat",k);
98 }
99 if (*(f++)) { // genealogy
100 SEXP S;
101 PROTECT(S = serial(A));
102 SET_ATTR(S,install("class"),mkString("gpgen"));
103 k = set_list_elem(out,outnames,S,"genealogy",k);
104 UNPROTECT(1);
105 }
106 if (*(f++)) { // cblv
107 k = set_list_elem(out,outnames,cblv(A),"cblv",k);
108 }
109 SET_NAMES(out,outnames);
110 UNPROTECT(2);
111 return out;
112 }
113}
SEXP cblv(genealogy_t &A)
Definition cblv.cc:151
Encodes a genealogy.
Definition genealogy.h:20
genealogy_t & prune(void)
prune the tree (drop all black balls)
Definition genealogy.h:311
genealogy_t & obscure(void)
erase all deme information
Definition genealogy.h:322
genealogy_t & insert_zlb(void)
insert zero-length branches for samples where needed
Definition genealogy.h:359
void trace_lineages(void)
Definition nodeseq.h:309
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 serial(const TYPE &X)
binary serialization
Definition generics.h:33
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
SEXP getInfo(SEXP args)
Definition getinfo.cc:19
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
#define n
Definition lbdp_pomp.c:9
#define S
Definition seirs_pomp.c:38