Author: Joelle Barido-Sottani
Date: 2026-02-26

# Exporting sampled ancestor trees

#### Joelle Barido-Sottani

#### 2026-02-26

## Zero-edge format

Many phylogenetic inference software packages, such as BEAST2 and RevBayes, can handle trees containing fossil samples. In the zero-edge format, tip samples are represented normally in the tree, but sampled ancestors, i.e fossil samples which have sampled descendants, are represented as tips at the end of edges with length 0.

This format is included in `FossilSim` as the `SAtree` objects.

## Converting to SAtree

`SAtree` objects can be built from a `fossils` object and the associated tree. Tips (both extinct and extant) will be labelled with the species they were sampled from followed by an index: the oldest sample for a given species will get index 1 and all other samples will be ordered from oldest to youngest. The `SAtree` format also includes a field `complete` which indicates whether the tree should be considered as including all lineages of the process or only sampled lineages. Note that if the tree is complete, the youngest tip of a given extinct species represents the extinction event for this species and not a fossil sample.

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

    SAt = SAtree.from.fossils(tree = t, fossils = f)
    print(SAt$tree)

    ##
    ## Phylogenetic tree with 26 tips and 25 internal nodes.
    ##
    ## Tip labels:
    ##   t1_5, t6_2, t2_3, t3_2, t5_1, t4_3, ...
    ##
    ## Rooted; includes branch length(s).

    print(SAt$fossils)

    ##    sp edge       hmin       hmax          h tip.label
    ## 4   1    1 1.14922271 1.14922271 1.14922271      t1_1
    ## 3   1    1 0.97352619 0.97352619 0.97352619      t1_2
    ## 1   1    1 0.81919305 0.81919305 0.81919305      t1_3
    ## 2   1    1 0.81520886 0.81520886 0.81520886      t1_4
    ## 5   2    2 1.37432399 1.37432399 1.37432399      t6_1
    ## 7   3    3 0.40409207 0.40409207 0.40409207      t2_1
    ## 6   3    3 0.01287516 0.01287516 0.01287516      t2_2
    ## 8   4    4 0.53078016 0.53078016 0.53078016      t3_1
    ## 10  6    6 1.06802292 1.06802292 1.06802292      t4_1
    ## 9   6    6 1.02040098 1.02040098 1.02040098      t4_2
    ## ...
    ## Fossil record with 20 occurrences representing 9 species
    ## Fossil record not simulated using taxonomy: all speciation events are assumed to be symmetric

    print(SAt$tree$complete)

    ## [1] TRUE

## Other useful functions

Other functions are present in `FossilSim` to modify trees. `prune.fossils` will remove all intermediate fossil samples and keep only the first and last occurrences of any species.

    SAt_pruned = prune.fossils(tree = SAt$tree)
    plot(SAt_pruned)

`sampled.tree.from.combined` removes all unsampled lineages from the tree, and can optionally apply a sampling probability to extant samples, or keep only a specified list of extant samples.

    SAt_sampled = sampled.tree.from.combined(tree = SAt$tree)
    plot(SAt_sampled)

These two functions can be applied to any object of type `phylo`, but are designed to work on trees which include fossil samples.