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 tranfromation bygather_segments()
. Using the latter will improve performance when the function is called many times, e.g., inmake_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("-y20 -l2 --sa 2,2 --sj 2,2")
samples = result$sample_family[[1L]]
segments = gather_segments(samples)
segments
#> # A tibble: 152 × 4
#> id birth_year capture_year parent_id
#> <chr> <int> <int> <int>
#> 1 7-1 20 20 55
#> 2 7-2 20 20 53
#> 3 8-1 20 20 58
#> 4 8-2 20 20 56
#> 5 15-1 20 20 73
#> 6 15-2 20 20 72
#> 7 16-1 20 20 14
#> 8 16-2 20 20 75
#> 9 3-1 19 19 38
#> 10 3-2 19 19 13
#> # ℹ 142 more rows
genealogy = make_gene_genealogy(segments)
genealogy
#> $V tibble [154 × 1] (S3: tbl_df/tbl/data.frame)
#> $ name: chr [1:154] "55-1" "7-1" "53-1" "7-2" ...
#> # A tibble: 152 × 4
#> from to birth_year capture_year
#> <chr> <chr> <int> <int>
#> 1 55-1 7-1 20 20
#> 2 53-1 7-2 20 20
#> 3 58-2 8-1 20 20
#> 4 56-2 8-2 20 20
#> 5 73-1 15-1 20 20
#> 6 72-1 15-2 20 20
#> 7 14-2 16-1 20 20
#> 8 75-1 16-2 20 20
#> 9 38-2 3-1 19 19
#> 10 13-1 3-2 19 19
#> # ℹ 142 more rows
count_uncoalesced(genealogy)
#> [1] 12
annotate_sampled(genealogy)
#> $V tibble [154 × 1] (S3: tbl_df/tbl/data.frame)
#> $ name: chr [1:154] "55-1" "7-1" "53-1" "7-2" ...
#> # A tibble: 152 × 5
#> from to birth_year capture_year sampled
#> <chr> <chr> <int> <int> <lgl>
#> 1 55-1 7-1 20 20 TRUE
#> 2 53-1 7-2 20 20 TRUE
#> 3 58-2 8-1 20 20 TRUE
#> 4 56-2 8-2 20 20 TRUE
#> 5 73-1 15-1 20 20 TRUE
#> 6 72-1 15-2 20 20 TRUE
#> 7 14-2 16-1 20 20 TRUE
#> 8 75-1 16-2 20 20 TRUE
#> 9 38-2 3-1 19 19 TRUE
#> 10 13-1 3-2 19 19 TRUE
#> # ℹ 142 more rows