Genlight objects can contain millions of loci. Since it does not make much sense to calculate the index of association over that many loci, this function will scan windows across the loci positions and calculate the index of association.
win.ia( x, window = 100L, min.snps = 3L, threads = 1L, quiet = FALSE, name_window = TRUE, chromosome_buffer = TRUE )
x | a genlight or snpclone object. |
---|---|
window | an integer specifying the size of the window. |
min.snps | an integer specifying the minimum number of snps allowed per
window. If a window does not meet this criteria, the value will return as
|
threads | The maximum number of parallel threads to be used within this
function. Defaults to 1 thread, in which the function will run serially. A
value of 0 will attempt to use as many threads as there are available
cores/CPUs. In most cases this is ideal for speed. Note: this option is
passed to |
quiet | if |
name_window | if |
chromosome_buffer | DEPRECATED if |
A value of the standardized index of association for all windows in each chromosome.
this will calculate the standardized index of association from Agapow
and Burt, 2001. See ia()
for details.
genlight, snpclone, ia()
, samp.ia()
, bitwise.dist()
# with structured snps assuming 1e4 positions set.seed(999) x <- glSim(n.ind = 10, n.snp.nonstruc = 5e2, n.snp.struc = 5e2, ploidy = 2) position(x) <- sort(sample(1e4, 1e3)) res <- win.ia(x, window = 300L) # Calculate for windows of size 300 plot(res, type = "l")# \dontrun{ # unstructured snps set.seed(999) x <- glSim(n.ind = 10, n.snp.nonstruc = 1e3, ploidy = 2) position(x) <- sort(sample(1e4, 1e3)) res <- win.ia(x, window = 300L) # Calculate for windows of size 300 plot(res, type = "l")# Accounting for chromosome coordinates set.seed(999) x <- glSim(n.ind = 10, n.snp.nonstruc = 5e2, n.snp.struc = 5e2, ploidy = 2) position(x) <- as.vector(vapply(1:10, function(x) sort(sample(1e3, 100)), integer(100))) chromosome(x) <- rep(1:10, each = 100) res <- win.ia(x, window = 100L) plot(res, type = "l")#> #>#>#> #>#>#> #>#>#> #>library("tidyr")#> #>#>#> #>#>#> #>res_tidy <- res %>% data_frame(rd = ., chromosome = names(.)) %>% # create two column data frame separate(chromosome, into = c("chromosome", "position")) %>% # get the position info mutate(position = as.integer(position)) %>% # force position as integers mutate(chromosome = factor(chromosome, unique(chromosome))) # force order chromosomes#> Warning: `data_frame()` is deprecated, use `tibble()`. #> This warning is displayed once per session.res_tidy#> # A tibble: 100 x 3 #> rd chromosome position #> <dbl> <fct> <int> #> 1 -0.0582 1 100 #> 2 -0.111 1 200 #> 3 -0.111 1 300 #> 4 -0.111 1 400 #> 5 -0.131 1 500 #> 6 -0.111 1 600 #> 7 0.0319 1 700 #> 8 0.00976 1 800 #> 9 -0.0957 1 900 #> 10 0.196 1 1000 #> # … with 90 more rows# Plotting with ggplot2 library("ggplot2") ggplot(res_tidy, aes(x = position, y = rd, color = chromosome)) + geom_line() + facet_wrap(~chromosome, nrow = 1) + ylab(expression(bar(r)[d])) + xlab("terminal position of sliding window") + labs(caption = "window size: 100bp") + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) + theme(legend.position = "top")# }