This function computes admixture proprtions using a non-negative least squares on painting profiles obtained from the function PaintingProfile

PaintingNNLS(df_sum, target_pops, source_pops = NULL)

Arguments

df_sum

Output of PaintingProfile

target_pops

Vector of populations to be fitted

source_pops

(Optional) Vector of putative source populations. If not provided, all remaining populations are used.

Value

Returns a data frame with admixture proportions.

Examples

library(dplyr)
if (!requireNamespace("tidyr", quietly = TRUE)) {
  stop("This example needs 'tidyr'. Please install it.", call. = FALSE)
}
if (!requireNamespace("lsei", quietly = TRUE)) {
  stop("This example needs 'lsei'. Please install it.", call. = FALSE)
}

#This path stores files precomputed using Painting().
path      <- paste0(system.file("test/", package = "twigstats"),"/")
prefix    <- "test" #prefix of files under path

#compute the painting profiles with 100 bootstrap samples and a blocksize of 5cM (5000*0.001)
df <- PaintingProfile(c(paste0(path,prefix,"_painting.txt.gz")), paste0(path,prefix,"_idfile.txt.gz"), nboot = 100, blocksize = 5000)
#> 
[==================================================] 100%

#compute the NNLS to get admixture proportions
df <- PaintingNNLS(df, target_pops = c("PX"), source_pops = c("P2","P3"))

#Now you can summarize the bootstrap samples 
df %>% group_by(target, POP) %>% summarize(mean_ancestry = mean(ancestry), sd_ancestry = sd(ancestry)) -> df
#> `summarise()` has grouped output by 'target'. You can override using the
#> `.groups` argument.
print(df)
#> # A tibble: 2 × 4
#> # Groups:   target [1]
#>   target POP   mean_ancestry sd_ancestry
#>   <chr>  <chr>         <dbl>       <dbl>
#> 1 PX     P2            0.251      0.0181
#> 2 PX     P3            0.749      0.0181