[R-sig-genetics] genlight to genind conversion

Zhian Kamvar kamvarz at science.oregonstate.edu
Tue Nov 17 07:30:48 CET 2015


Hi Dan,

Thanks for pointing that out! It can't be calculated in poppr as it exists on CRAN, but I just pushed a fix for aboot on github that will allow you to use any distance metric with genlight objects (previously, it would force bitwise.dist). 

you can install it with devtools::install_github("grunwaldlab/poppr at devel")

I would also recommend installing the github versions of adegenet and pegas.

Here's an example of bootstrapping with StAMPP:

library(poppr)
library(StAMPP)
x <- glSim(100, 1e3, ploid=2)
pop(x) <- rep(LETTERS[1:5], 20)
aboot(x, distance = function(x) as.dist(stamppNeisD(x)), sample = 100)

Best,
Zhian


> On Nov 16, 2015, at 22:11 , Daniel Fulop <dfulop.ucd at gmail.com> wrote:
> 
> Hi Zhian,
> 
> I’m glad I asked!  The StAMPP package can calculate Nei’s distance on a genlight object using the stamppNeisD() function.  I thought of coding the resampling myself, but if I can incorporate stamppNeisD() within aboot() that’ll save me some trouble.
> 
> Any thoughts about hacking aboot() to use stamppNeisD()?
> 
> Thanks again!
> Dan.
> 
> 
>> On Nov 16, 2015, at 10:03 PM, Zhian Kamvar <kamvarz at science.oregonstate.edu> wrote:
>> 
>> Hi Dan,
>> 
>> There is a slight catch to this:
>> 
>> Bootstrapping for genlight objects defaults to a simple measure of dissimilarity (see the function bitwise.dist). To use Nei's distance, you must convert to either genind or genpop (unless you want to write the function to calculate Nei's distance off of a genlight object).
>> 
>> Zhian
>> 
>> 
>>> On Nov 16, 2015, at 21:32 , Daniel Fulop <dfulop.ucd at gmail.com> wrote:
>>> 
>>> Hi Zhian,
>>> 
>>> Thanks a ton!  That is super helpful.
>>> 
>>> I’m also looking to bootstrap a Nei’s distance NJ tree, and I see that I can do that with about().
>>> 
>>> All the best,
>>> Dan.
>>> 
>>> 
>>>> On Nov 16, 2015, at 9:20 PM, Zhian Kamvar <kamvarz at science.oregonstate.edu> wrote:
>>>> 
>>>> Hi Dan,
>>>> 
>>>> The question of how to analyze genomic SNP data in poppr was recently addressed:
>>>> https://groups.google.com/forum/#!topic/poppr/_0GWvgC85S8
>>>> 
>>>> What functions related to clonal and mixed reproduction are you looking to utilize? Adegenet has several functions for use with genlight objects including DAPC and PCA. Additionally, poppr v2 has the ability to perform the index of association and all multilocus genotype functions on genlight objects. 
>>>> 
>>>> Otherwise, a genlight to genind conversion usually takes the form of:
>>>> 
>>>> x.mat <- as.matrix(x) # x is a genlight object
>>>> x.mat[x.mat == 0] <- "1/1" # homozygote reference
>>>> x.mat[x.mat == 1] <- "1/2" # heterozygote
>>>> x.mat[x.mat == 2] <- "2/2" # homozygote alternate
>>>> x.gid <- df2genind(x, sep = "/", ploidy = 2)
>>>> 
>>>> The object you get back will be ~55Mb
>>>> 
>>>> I hope that addressed some of your questions.
>>>> 
>>>> Best,
>>>> Zhian
>>>> 
>>>>> On Nov 16, 2015, at 20:55 , Daniel Fulop <dfulop.ucd at gmail.com> wrote:
>>>>> 
>>>>> Hi All,
>>>>> 
>>>>> I’d like to use adegenet and poppr to analyze RADseq SNP data from Aspen trees. I am limited in what I can do because I have not been able to convert my data from genlight to genind. At one point I tried, but then gave up because of the long computation time for the conversion I was attempting.
>>>>> 
>>>>> Is there a way to do the genlight to genind conversion? Otherwise, do you know if the functions related to clonal and mixed reproduction in poppr are implemented elsewhere (in R or outside of R)?
>>>>> 
>>>>> I know that genind objects are not efficient for storing SNP data.  For what it’s worth, we have 181 individuals and ~39000 SNPs.
>>>>> 
>>>>> Thanks advance for your help!
>>>>> Dan.
>>>>> 
>>>>> -- 
>>>>> Daniel Fulop, Ph.D.
>>>>> Postdoctoral Scholar
>>>>> Dept. Plant Biology, UC Davis
>>>>> Maloof Lab, Rm. 2220
>>>>> Life Sciences Addition, One Shields Ave.
>>>>> Davis, CA 95616
>>>>> 
>>>> 
>>> 
>> 
> 



More information about the R-sig-genetics mailing list