Skip to contents

An individual-based family tree stored in sample_family is transformed into a gene-based table with gather_segments(). Then, the ancestry of each gene/segment is randomly assigned in make_gene_genealogy(). Sampled segments and their ancestors can be annotated with annotate_sampled().

Usage

make_gene_genealogy(samples)

gather_segments(samples)

count_uncoalesced(genealogy)

annotate_sampled(genealogy)

Arguments

samples

A data.frame: sample_family or its transformation by gather_segments(). Using the latter will improve performance when the function is called many times, e.g., in make_snp().

genealogy

An output from make_gene_genealogy().

Value

An igraphlite object with genealogy subclass.

gather_segments() transforms an individual-based sample_family into a segment-based table.

count_uncoalesced() returns the count of uncoalesced roots of the genealogy.

annotate_sampled() adds the "sampled" edge attribute to the genealogy: TRUE if sampled, FALSE if upstream of samples, NA if unrelated.

See also

make_snp() for SNP generation using genealogy.

Examples

set.seed(666)
result = tekka("-y25 -l2 --sa 2,2 --sj 2,2")
samples = result$sample_family[[1L]]
segments = gather_segments(samples)
segments
#> # A tibble: 220 × 4
#>    id    birth_year capture_year parent_id
#>    <chr>      <int>        <int>     <int>
#>  1 5-1           25           25        71
#>  2 5-2           25           25        66
#>  3 6-1           25           25        75
#>  4 6-2           25           25        72
#>  5 13-1          25           25        15
#>  6 13-2          25           25        97
#>  7 14-1          25           25        15
#>  8 14-2          25           25       100
#>  9 1-1           24           24        43
#> 10 1-2           24           24        17
#> # ℹ 210 more rows

genealogy = make_gene_genealogy(segments)
genealogy
#> $V  tibble [222 × 1] (S3: tbl_df/tbl/data.frame)
#>  $ name: chr [1:222] "71-1" "5-1" "66-1" "5-2" ...
#> # A tibble: 220 × 4
#>    from  to    birth_year capture_year
#>    <chr> <chr>      <int>        <int>
#>  1 71-1  5-1           25           25
#>  2 66-1  5-2           25           25
#>  3 75-2  6-1           25           25
#>  4 72-2  6-2           25           25
#>  5 15-1  13-1          25           25
#>  6 97-1  13-2          25           25
#>  7 15-2  14-1          25           25
#>  8 100-1 14-2          25           25
#>  9 43-2  1-1           24           24
#> 10 17-1  1-2           24           24
#> # ℹ 210 more rows

count_uncoalesced(genealogy)
#> [1] 13

annotate_sampled(genealogy)
#> $V  tibble [222 × 1] (S3: tbl_df/tbl/data.frame)
#>  $ name: chr [1:222] "71-1" "5-1" "66-1" "5-2" ...
#> # A tibble: 220 × 5
#>    from  to    birth_year capture_year sampled
#>    <chr> <chr>      <int>        <int> <lgl>  
#>  1 71-1  5-1           25           25 TRUE   
#>  2 66-1  5-2           25           25 TRUE   
#>  3 75-2  6-1           25           25 TRUE   
#>  4 72-2  6-2           25           25 TRUE   
#>  5 15-1  13-1          25           25 TRUE   
#>  6 97-1  13-2          25           25 TRUE   
#>  7 15-2  14-1          25           25 TRUE   
#>  8 100-1 14-2          25           25 TRUE   
#>  9 43-2  1-1           24           24 TRUE   
#> 10 17-1  1-2           24           24 TRUE   
#> # ℹ 210 more rows