Converting from and to paleotree format

Compatibility with paleotree

Objects produced by FossilSim contain all the information required by the paleotree format and vice-versa, thus these two packages are fully compatible.

Converting from paleotree is done using the paleotree.record.to.fossils function, which returns a list of the corresponding phylo, taxonomy and fossils objects.

record = paleotree::simFossilRecord(p = 0.1, q = 0.1, r = 0.1, nruns = 1, nTotalTaxa = c(30,40),
                                    nExtant = 0, nSamp = c(5,25))

converted_record = paleotree.record.to.fossils(record = record)
converted_record
## $tree
## 
## Phylogenetic tree with 31 tips and 30 internal nodes.
## 
## Tip labels:
##   t1, t3, t7, t11, t9, t13, ...
## Node labels:
##   32, 33, 34, 35, 36, 37, ...
## 
## Rooted; includes branch length(s).
## 
## $fossils
##    sp edge     hmin     hmax
## 1   1   32 971.9145 971.9145
## 2   1   32 973.3466 973.3466
## 3   1   32 987.4003 987.4003
## 4   1   32 989.7576 989.7576
## 5   2   32 966.6233 966.6233
## 6  28   32 949.1969 949.1969
## 7  28   32 964.0159 964.0159
## 8  28   32 970.8105 970.8105
## 9  27   32 971.4643 971.4643
## 10 27   32 971.6289 971.6289
## ...
## Fossil record with 29 occurrences representing 15 species
## Fossils record simulated from or assigned to an existing taxonomy 
## 
## $taxonomy
##    sp edge parent       start        end mode cryptic cryptic.id
## 1   1    1     NA   58.075735 971.853629    r   FALSE          1
## 2   1   33     NA   59.608890  58.075735    r   FALSE          1
## 3   1   32     NA 1000.000000  59.608890    r   FALSE          1
## 4  31   31      1   59.608890 987.170861    b   FALSE         31
## 5   2    2      1   39.943035 965.564845    b   FALSE          2
## 6   2   37      1   41.797001  39.943035    b   FALSE          2
## 7   2   36      1   43.031361  41.797001    b   FALSE          2
## 8   2   35      1   43.580711  43.031361    b   FALSE          2
## 9   2   34      1   58.075735  43.580711    b   FALSE          2
## 10  2   33      1   59.608890  58.075735    b   FALSE          2
## 11  2   32      1  988.707069  59.608890    b   FALSE          2
## 12 28   28      2   25.932899 941.711849    b   FALSE         28
## 13 28   61      2   29.730503  25.932899    b   FALSE         28
## 14 28   60      2   43.580711  29.730503    b   FALSE         28
## 15 28   34      2   58.075735  43.580711    b   FALSE         28
## 16 28   33      2   59.608890  58.075735    b   FALSE         28
## 17 28   32      2  974.212045  59.608890    b   FALSE         28
## 18 27   27      2   43.031361 961.213641    b   FALSE         27
## 19 27   35      2   43.580711  43.031361    b   FALSE         27
## 20 27   34      2   58.075735  43.580711    b   FALSE         27
## 21 27   33      2   59.608890  58.075735    b   FALSE         27
## 22 27   32      2  973.662695  59.608890    b   FALSE         27
## 23 26   26      2   41.797001 968.729698    b   FALSE         26
## 24  3    3      2   31.707225 952.607144    b   FALSE          3
## 25  3   40      2   36.885853  31.707225    b   FALSE          3
## 26  3   39      2   38.450125  36.885853    b   FALSE          3
## 27  3   38      2   39.943035  38.450125    b   FALSE          3
## 28  3   37      2   41.797001  39.943035    b   FALSE          3
## 29  3   36      2   43.031361  41.797001    b   FALSE          3
## 30  3   35      2   43.580711  43.031361    b   FALSE          3
## 31  3   34      2   58.075735  43.580711    b   FALSE          3
## 32  3   33      2   59.608890  58.075735    b   FALSE          3
## 33  3   32      2  970.574368  59.608890    b   FALSE          3
## 34 17   17      3    9.834472 940.462046    b   FALSE         17
## 35 17   53      3   31.813778   9.834472    b   FALSE         17
## 36 17   52      3   38.450125  31.813778    b   FALSE         17
## 37 17   38      3   39.943035  38.450125    b   FALSE         17
## 38 17   37      3   41.797001  39.943035    b   FALSE         17
## 39 17   36      3   43.031361  41.797001    b   FALSE         17
## 40 17   35      3   43.580711  43.031361    b   FALSE         17
## 41 17   34      3   58.075735  43.580711    b   FALSE         17
## 42 17   33      3   59.608890  58.075735    b   FALSE         17
## 43 17   32      3  969.081459  59.608890    b   FALSE         17
## 44  5    5      3   29.364906 959.271553    b   FALSE          5
## 45  5   41      3   36.885853  29.364906    b   FALSE          5
## 46  5   39      3   38.450125  36.885853    b   FALSE          5
## 47  5   38      3   39.943035  38.450125    b   FALSE          5
## 48  5   37      3   41.797001  39.943035    b   FALSE          5
## 49  5   36      3   43.031361  41.797001    b   FALSE          5
## 50  5   35      3   43.580711  43.031361    b   FALSE          5
## ...
## Taxonomy representing 31 species across 61 edges.

If the paleotree record is fully extinct, i.e contains no extant samples, the age of the record will be encoded in the field origin.time of the tree.

converted_record$tree$origin.time
## [1] 1000

Similarly, converting from the FossilSim objects to paleotree format is done using the fossils.to.paleotree.record function, which requires a fossils object and either a phylo or taxonomy object. If no taxonomy is provided, all speciation events in the tree will be assumed to be symmetric (bifurcating).

t = ape::rtree(6)
f = sim.fossils.poisson(rate = 2, tree = t)

converted_record = fossils.to.paleotree.record(fossils = f, tree = t)
converted_record
## $t8
## $t8$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##   1.0000000          NA   1.3951422   0.9213295   0.0000000   1.0000000 
## 
## $t8$sampling.times
## numeric(0)
## 
## 
## $t6
## $t6$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##   2.0000000   1.0000000   0.9213295   0.5870906   0.0000000   2.0000000 
## 
## $t6$sampling.times
## numeric(0)
## 
## 
## $t5
## $t5$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##   3.0000000   1.0000000   0.9213295   0.4150379   0.0000000   3.0000000 
## 
## $t5$sampling.times
## numeric(0)
## 
## 
## $t9
## $t9$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##    4.000000          NA    1.395142    1.052488    0.000000    4.000000 
## 
## $t9$sampling.times
## [1] 1.169976 1.062755
## 
## 
## $t4
## $t4$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##   5.0000000   4.0000000   1.0524875   0.3692032   0.0000000   5.0000000 
## 
## $t4$sampling.times
## [1] 0.9279696 0.4424305
## 
## 
## $t10
## $t10$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##    6.000000    4.000000    1.052488    1.040256    0.000000    6.000000 
## 
## $t10$sampling.times
## numeric(0)
## 
## 
## $t3
## $t3$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##   7.0000000   6.0000000   1.0402556   0.4318103   0.0000000   7.0000000 
## 
## $t3$sampling.times
## [1] 0.6594577
## 
## 
## $t11
## $t11$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##   8.0000000   6.0000000   1.0402556   0.6050447   0.0000000   8.0000000 
## 
## $t11$sampling.times
## [1] 0.9238745
## 
## 
## $t1
## $t1$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##   9.0000000   8.0000000   0.6050447   0.3302180   0.0000000   9.0000000 
## 
## $t1$sampling.times
## numeric(0)
## 
## 
## $t2
## $t2$taxa.data
##    taxon.id ancestor.id   orig.time    ext.time still.alive  looks.like 
##  10.0000000   8.0000000   0.6050447   0.0000000   1.0000000  10.0000000 
## 
## $t2$sampling.times
## [1] 0.4005886 0.3860503 0.0000000
## 
## 
## attr(,"class")
## [1] "fossilRecordSimulation"