phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parse.cc
Go to the documentation of this file.
1 #include "genealogy.h"
2 #include "generics.h"
3 #include "internal.h"
4 
7 
8 extern "C" {
9 
10  SEXP parse_newick (SEXP X, SEXP T0, SEXP Tf) {
11  PROTECT(X = AS_CHARACTER(X));
12  PROTECT(T0 = AS_NUMERIC(T0));
13  PROTECT(Tf = AS_NUMERIC(Tf));
14  double t0 = *REAL(T0);
15  double tf = *REAL(Tf);
16  // parse the Newick representation into a genealogy:
17  std::string x = CHAR(STRING_ELT(X,0));
18  genealogy_t G(t0);
19  G.parse(x,t0);
20  if (!ISNA(tf)) {
21  if (G.time() > tf) {
22  G.curtail(tf);
23  } else {
24  G.time() = tf;
25  }
26  }
27  G.trace_lineages();
28  UNPROTECT(3);
29  return serial(G);
30  }
31 
32 }
Encodes a genealogy.
Definition: genealogy.h:22
genealogy_t & parse(const std::string &s, slate_t t0, node_t *p=0)
Parse a Newick string and create the indicated genealogy.
Definition: genealogy.h:694
slate_t & time(void)
view/set current time.
Definition: genealogy.h:150
void curtail(slate_t tnew)
Definition: genealogy.h:496
void trace_lineages(void)
Definition: nodeseq.h:244
SEXP serial(const TYPE &X)
binary serialization
Definition: generics.h:28
SEXP parse_newick(SEXP X, SEXP T0, SEXP Tf)
Definition: parse.cc:10