Skip to content

Commit 73baf9f

Browse files
committed
streamline curtail
1 parent 48631f8 commit 73baf9f

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: phylopomp
22
Type: Package
33
Title: Phylodynamic Inference for POMP Models
4-
Version: 0.14.9.0
4+
Version: 0.14.9.1
55
Date: 2024-12-02
66
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="[email protected]",comment=c(ORCID="0000-0001-6159-3207")),
77
person(given=c("Qianying"),family="Lin",role=c("aut"),comment=c(ORCID="0000-0001-8620-9910"))

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## To-do List
22

3-
- curtail from the left also
4-
- LBDP and SIRS into new format
3+
- ~~~curtail from the left also~~~
4+
- ~~~LBDP and SIRS into new format~~~
55
- use integer time?
66
7-
- trap Newick errors in `parse_newick`
87
- runtime yaml parser
8+
- trap Newick errors in `parse_newick`
99
- segmented virus simulator

src/genealogy.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class genealogy_t : public nodeseq_t {
7777
//! binary serialization
7878
friend raw_t* operator>> (const genealogy_t& G, raw_t* o) {
7979
name_t A[3]; A[0] = magic; A[1] = G._unique; A[2] = name_t(G._ndeme);
80-
slate_t B[2]; B[0] = G._t0; B[1] = G._time;
80+
slate_t B[2]; B[0] = G.timezero(); B[1] = G.time();
8181
memcpy(o,A,sizeof(A)); o += sizeof(A);
8282
memcpy(o,B,sizeof(B)); o += sizeof(B);
8383
return reinterpret_cast<const nodeseq_t&>(G) >> o;
@@ -93,7 +93,7 @@ class genealogy_t : public nodeseq_t {
9393
err("in %s (%s line %d) corrupted genealogy serialization.",
9494
__func__,__FILE__,__LINE__);
9595
G._unique = A[1]; G._ndeme = size_t(A[2]);
96-
G._t0 = B[0]; G._time = B[1];
96+
G.timezero() = B[0]; G.time() = B[1];
9797
return o >> reinterpret_cast<nodeseq_t&>(G);
9898
};
9999

@@ -154,6 +154,10 @@ class genealogy_t : public nodeseq_t {
154154
slate_t time (void) const {
155155
return _time;
156156
};
157+
//! view/set zero time.
158+
slate_t& timezero (void) {
159+
return _t0;
160+
};
157161
//! get zero time.
158162
slate_t timezero (void) const {
159163
return _t0;
@@ -523,7 +527,7 @@ class genealogy_t : public nodeseq_t {
523527
if (!empty()) p = back();
524528
}
525529
}
526-
if (tnew < time()) _time = tnew;
530+
time() = tnew;
527531
if (!empty() && troot > timezero()) {
528532
node_t *p = front();
529533
node_t *q;
@@ -563,7 +567,7 @@ class genealogy_t : public nodeseq_t {
563567
}
564568
sort();
565569
}
566-
if (troot > timezero()) _t0 = troot;
570+
if (troot > timezero()) timezero() = troot;
567571
};
568572
//! merge two genealogies:
569573
//! 1. the node-sequences are merged;

src/parse.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ extern "C" {
1818
genealogy_t G(t0);
1919
G.parse(x,t0);
2020
if (!ISNA(tf)) {
21-
if (G.time() > tf) {
22-
G.curtail(tf,t0);
23-
} else {
24-
G.time() = tf;
25-
}
21+
G.curtail(tf,t0);
2622
}
2723
G.trace_lineages();
2824
UNPROTECT(3);

tests/parse.Rout.save

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Error : in 'scan_tree': premature end of Newick string.
136136
+ r"{((o_9_1:1.000000,b_3_2:0.500000,o_1_3:1.000000)m_0_0:0.000000);}" |>
137137
+ parse_newick()
138138
+ )
139-
Error : in 'scan_label' (genealogy.h line 607): invalid Newick label: expected one of 'b','g','m', or 'o', got ';'.
139+
Error : in 'scan_label' (genealogy.h line 611): invalid Newick label: expected one of 'b','g','m', or 'o', got ';'.
140140
>
141141
> try(
142142
+ r"{(o_9_1:1.000000,b_3_2:0.500000,o_1_3:1.000000)m_0_0:0.000000);}" |>
@@ -167,13 +167,13 @@ Error : in 'parse': invalid Newick string.
167167
+ r"{(o_9_1:1.000000)_g_1_3:1.000000)m_0_0:0.000000;}" |>
168168
+ parse_newick()
169169
+ )
170-
Error : in 'scan_label' (genealogy.h line 607): invalid Newick label: expected one of 'b','g','m', or 'o', got '_'.
170+
Error : in 'scan_label' (genealogy.h line 611): invalid Newick label: expected one of 'b','g','m', or 'o', got '_'.
171171
>
172172
> try(
173173
+ r"{(o_9_1:1.000000)z_1_3:1.000000)m_0_0:0.000000;}" |>
174174
+ parse_newick()
175175
+ )
176-
Error : in 'scan_label' (genealogy.h line 607): invalid Newick label: expected one of 'b','g','m', or 'o', got 'z'.
176+
Error : in 'scan_label' (genealogy.h line 611): invalid Newick label: expected one of 'b','g','m', or 'o', got 'z'.
177177
>
178178
> r"{((,o_9_1:1.000000,)g_1_3:1.000000)m_0_0:0.000000;}" |>
179179
+ parse_newick() |>
@@ -212,7 +212,7 @@ Error : in 'parse': invalid Newick string: unbalanced parentheses.
212212
+ r"{((((o_9_1:1.000000)g_1_3:1.000000)m_0_0:0.000000)g_3:22)()))));}" |>
213213
+ parse_newick()
214214
+ )
215-
Error : in 'scan_label' (genealogy.h line 607): invalid Newick label: expected one of 'b','g','m', or 'o', got '('.
215+
Error : in 'scan_label' (genealogy.h line 611): invalid Newick label: expected one of 'b','g','m', or 'o', got '('.
216216
>
217217
> try(
218218
+ r"{(o_9_1:1.000000,b_1_3)m_0_0:0.000000;}" |>
@@ -258,7 +258,7 @@ $newick
258258
+ r"{(o_a9_1:1.000000,b_0_0:3)m_0_0:0.000000,b_____2:17;}" |>
259259
+ parse_newick()
260260
+ )
261-
Error : in 'scan_label' (genealogy.h line 624): invalid Newick format: deme should be indicated with an integer.
261+
Error : in 'scan_label' (genealogy.h line 628): invalid Newick format: deme should be indicated with an integer.
262262
>
263263
> try(
264264
+ r"{(o_9_1:1.000000,b_0_0:3)m_0_0(:0.500000,b_____2:17;}" |>
@@ -270,7 +270,7 @@ Error : in 'scan_label': invalid Newick format: missing or invalid branch length
270270
+ r"{(o_9_1:1.000000,b_0_0:3)m_)0_0:0.500000,b_____2:17;}" |>
271271
+ parse_newick()
272272
+ )
273-
Error : in 'scan_label' (genealogy.h line 614): invalid Newick format.
273+
Error : in 'scan_label' (genealogy.h line 618): invalid Newick format.
274274
>
275275
> try(
276276
+ r"{(o_9_1:1.000000,b_0_0:3)m_0_0:(0.000000,b_____2:17;}" |>
@@ -321,7 +321,7 @@ $newick
321321
+ r"{(o_9_1:1.000000,b_0_0:3))m_0_0:0.000000,b_____2:17;}" |>
322322
+ parse_newick()
323323
+ )
324-
Error : in 'scan_label' (genealogy.h line 607): invalid Newick label: expected one of 'b','g','m', or 'o', got ')'.
324+
Error : in 'scan_label' (genealogy.h line 611): invalid Newick label: expected one of 'b','g','m', or 'o', got ')'.
325325
>
326326
> try(
327327
+ r"{(o_9_1:1.000000,b_0_0:3)m_0_0:0.000000,b_____2:17))));}" |>
@@ -359,7 +359,7 @@ Error : in 'scan_label': invalid Newick format: missing or invalid branch length
359359
+ parse_newick() |>
360360
+ newick(prune=FALSE,obscure=FALSE)
361361
+ )
362-
Error : in 'scan_label' (genealogy.h line 593): invalid Newick format: empty label.
362+
Error : in 'scan_label' (genealogy.h line 597): invalid Newick format: empty label.
363363
>
364364
> dev.off()
365365
null device

0 commit comments

Comments
 (0)