[adegenet-forum] snpposi.plot with multiple chromosomes
hvh22 at cam.ac.uk
Tue Aug 25 17:20:54 CEST 2015
thanks a lot for your reply. I have got a data frame 'snps' which is
metadata about the snps (positions, chromosome number, and other info I
used to calculate genome position since I started off with positions
relative to chromosomes). Its structure is as follows:
'data.frame': 23774 obs. of 6 variables:
$ chrnumbers : Factor w/ 19 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1
1 1 ...
$ scaffold : Factor w/ 10 levels "scaffold_1","scaffold_2",..: 1 1 1
1 1 1 1 1 1 1 ...
$ position : int 82542 88128 88139 88175 90818 90857 91131 91147
91250 91807 ...
$ length : int 42145699 42145699 42145699 42145699 42145699
42145699 42145699 42145699 42145699 42145699 ...
$ startOffset: int 0 0 0 0 0 0 0 0 0 0 ...
$ globpos : int 82542 88128 88139 88175 90818 90857 91131 91147
91250 91807 ...
> chrPlot <- tapply(snps$globpos, snps$chrnumbers, snpposi.plot,
As far as I can see this should be equivalent to the command for your
simulated data set, but every time I run it, my computer crashes
(totally crashes - can't shut down R, Ctrl-Alt-Del doesn't work).
I don't know if I have misunderstood and got the syntax wrong, or the
data set is too big, or of course there could just be a problem with my
computer... I am running R 3.2.1 using Rstudio 0.99.
On 2015-08-17 17:04, Jombart, Thibaut wrote:
> 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:
> 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
> ## 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,
> allPlots[] # chr 1
> allPlots[] # 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[] <- temp[] - 5504 # assuming chr 2 starts at position 5504
> allPlots.scaled <- lapply(1:2, function(i) snpposi.plot(temp[[i]],
> From: adegenet-forum-bounces at lists.r-forge.r-project.org
> [adegenet-forum-bounces at lists.r-forge.r-project.org] on behalf of
> Harriet Hunt [hvh22 at cam.ac.uk]
> Sent: 17 August 2015 15:52
> To: adegenet-forum at lists.r-forge.r-project.org
> Subject: [adegenet-forum] snpposi.plot with multiple chromosomes
> Hello all,
> I have a dataset with SNP positions given as base numbers along
> chromosomes, and the number of the chromosome is in a separate column
> the original data table. Can anyone suggest a way either to easily
> select and plot the SNPs from one particular chromosome using
> snpposi.plot, without having to extract the data for each chromosome
> manually from the original data table? Or even better would be if
> there's a way to use snpposi.plot to show the density plots for all the
> chromosomes in order.
> thanks, Harriet
> adegenet-forum mailing list
> adegenet-forum at lists.r-forge.r-project.org
Dr Harriet Hunt
McDonald Institute for Archaeological Research
University of Cambridge
Cambridge CB2 3ER
Tel: +44 (0)1223 339330
e-mail: hvh22 at cam.ac.uk
More information about the adegenet-forum