adegenet icon indicating copy to clipboard operation
adegenet copied to clipboard

snpposi.plot for genlight

Open thibautjombart opened this issue 9 years ago • 0 comments

Add procedure, and add an option to plot SNPs by chromosome. Relates to this post:


Hi there,

basically the workflow should be 1) split data by chromosome and 2) lapply over the result to generate the plot. 1) should be implemented by seploc, and I have just posted a feature request for this: https://github.com/thibautjombart/adegenet/issues/84 and for the whole thing.

Meanwhile, there is a simple work around if you have i) SNP positions and ii) chromosome info. Split the first with the second, and apply snpposi.plot to the resulting list; or tapply directly. Here's an example with a simulated dataset:

## load package
library(adegenet)

## simulate data: 10 indiv, 1,000 SNPs from 10,000 nucleotide positions; first 600 SNPs are chr1, the other are chr2
x=glSim(10, 1000)
position(x) <- sort(sample(1:1e4, 1000))
chromosome(x) <- rep(1:2, c(600,400))

## split positions by chromosome and apply snpposi.plot to the bits
allPlots <- tapply(position(x), chromosome(x), snpposi.plot, genome.size=1e4)
allPlots[[1]] # chr 1
allPlots[[2]] # chr 2

Note that if you want the positions to be relative to the chromosomes, then you have to subtract manually the starting positions, e.g.

temp <- split(position(x), chromosome(x))
temp[[2]] <- temp[[2]] - 5504 # assuming chr 2 starts at position 5504
allPlots.scaled <- lapply(1:2, function(i) snpposi.plot(temp[[i]], genome.size=max(temp[[i]])))

Cheers Thibaut

thibautjombart avatar Aug 17 '15 16:08 thibautjombart