[adegenet-forum] convert genlight into genind

Jombart, Thibaut t.jombart at imperial.ac.uk
Sat May 31 05:45:04 CEST 2014


Hi Pauline

You can use as.data.frame and then df2genind, but you need to use a trick because by default df2genind considers "0" to be NA. 

For instance:

> x=glSim(10,10)

> x
 === S4 class genlight ===
 10 genotypes,  10 binary SNPs
 Ploidy: 1
 0 (0 %) missing data
 @other: a list containing: ancestral.pops 

> z=df2genind(y+1, ploidy=1)
> z

   #####################
   ### Genind object ### 
   #####################
- genotypes of individuals - 

S4 class:  genind
@call: df2genind(X = y + 1, ploidy = 1)

@tab:  10 x 18 matrix of genotypes

@ind.names: vector of  10 individual names
@loc.names: vector of  10 locus names
@loc.nall: number of alleles per locus
@loc.fac: locus factor for the  18 columns of @tab
@all.names: list of  10 components yielding allele names for each locus
@ploidy:  1
@type:  codom

Optional contents: 
@pop:  - empty -
@pop.names:  - empty -

@other: - empty -

> genind2df(z)
   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1   2  2  2  2  2  1  1  2  2   2
2   2  2  2  2  2  2  2  2  2   2
3   2  2  2  1  2  2  2  2  2   2
4   2  2  2  1  2  2  2  2  2   2
5   2  2  1  2  2  1  1  2  1   1
6   2  2  2  2  2  2  2  2  2   1
7   2  2  1  1  1  2  1  1  1   1
8   2  2  2  2  2  1  2  2  2   1
9   2  2  2  2  2  2  1  2  2   1
10  2  2  2  1  2  2  2  1  1   2

> as.matrix(x)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    1    1    1    1    0    0    1    1     1
 [2,]    1    1    1    1    1    1    1    1    1     1
 [3,]    1    1    1    0    1    1    1    1    1     1
 [4,]    1    1    1    0    1    1    1    1    1     1
 [5,]    1    1    0    1    1    0    0    1    0     0
 [6,]    1    1    1    1    1    1    1    1    1     0
 [7,]    1    1    0    0    0    1    0    0    0     0
 [8,]    1    1    1    1    1    0    1    1    1     0
 [9,]    1    1    1    1    1    1    0    1    1     0
[10,]    1    1    1    0    1    1    1    0    0     1

This only works in haploid data though. Because genind objects are usually too heavy for large SNP datasets, I never implemented a proper conversion genlight -> genind.

Cheers
Thibaut


________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] on behalf of Pauline OLIVIER [pauline.olivier1 at etu.univ-nantes.fr]
Sent: 30 May 2014 17:23
To: adegenet-forum at lists.r-forge.r-project.org
Subject: [adegenet-forum] convert genlight into genind

Hello,

 i would like to convert a genlight object into a genind object.

I obtained a genlight object using "Mygenlihgt =read.PLINK("Myfile.raw")"
where Myfile.raw looks like this :

     IID      rs3934834_T  rs6687776_T  rs9651273_A rs9729550_C rs2887286_C
1 611518           0            0                      0
1                 0
2 611515           0            0                      1
1                 0
3 611514           1            0                      1
0                 0
4 611513           1            1                      0
1                 1
5 611512           0            0                      0
0                 1

then i try :

mydf<-do.call(rbind, lapply(Mygenlihgt at gen, as.integer))
mygenind<-df2genind(mydf)

But it does not work, i have this message :

Error in df2genind(mydf) :
  2 alleles cannot be coded by a total of 1 characters

Can you help me please.

Thank you, Pauline.

_______________________________________________
adegenet-forum mailing list
adegenet-forum at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum


More information about the adegenet-forum mailing list