[adegenet-forum] New user and experiencing problems!

Jombart, Thibaut t.jombart at imperial.ac.uk
Wed Jul 15 11:12:56 CEST 2009


Dear Andrew, 

Thanks for your post. I am sorry to read about your exasperation. adegenet is not meant to be amazingly entertaining, but I am sure we can improve on this. 

The reason why you are experiencing troubles is that data are usually read in adegenet from standard genetic formats into genind objects. Here, as you have already frequencies, you will have to construct a genind object 'by hand'. The constructor function 'genind' will help you doing so (you may want to check ?genind). This is briefly illustrated in the adegenet tutorial (p10-11). 

Here's an example. 
Assuming X is your matrix of allele frequencies, with genotypes in rows and alleles in columns, and pop is your population factor, you can try smthg like:

## to get data similar to yours
library(adegenet)
data(nancycats)
X <- truenames(nancycats[loc="L1"])$tab
pop <- truenames(nancycats[loc="L1"])$pop

> head(X)
     fca8.117 fca8.119 fca8.121 fca8.123 fca8.127 fca8.129 fca8.131 fca8.133
N215       NA       NA       NA       NA       NA       NA       NA       NA
N216       NA       NA       NA       NA       NA       NA       NA       NA
N217        0        0        0        0        0        0        0      0.0
N218        0        0        0        0        0        0        0      0.5
N219        0        0        0        0        0        0        0      0.5
N220        0        0        0        0        0        0        0      0.0

> head(pop)
[1] 1 1 1 1 1 1
Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
## ##

## to build a genind object ##
foo <- genind(X,pop=pop)
> foo

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

S4 class:  genind
@call: genind(tab = X, pop = pop)

@tab:  237 x 16 matrix of genotypes

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

Optionnal contents: 
@pop:  factor giving the population of each individual
@pop.names:  factor giving the population of each individual

@other: - empty -

## ##
 
Now you can add any information into the @other slot. If you store spatial information, as a matrix with two columns, in the @other$xy, this info will be automatically detected and used by the sPCA function. Otherwise, you can specify xy coords directly when calling 'spca' (see ?spca).

## adding xy coords ##
xy <- data.frame(x=runif(237), y=runif(237))
> head(xy)
           x         y
1 0.30267351 0.3274833
2 0.12637514 0.3505885
3 0.19725953 0.1904647
4 0.07146548 0.4231209
5 0.97749688 0.9359431
6 0.84156358 0.1084091

> foo$other$xy <- xy
> foo

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

S4 class:  genind
@call: genind(tab = X, pop = pop)

@tab:  237 x 16 matrix of genotypes

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

Optionnal contents: 
@pop:  factor giving the population of each individual
@pop.names:  factor giving the population of each individual

@other: a list containing: xy 

## ## 

Then, to perform a sPCA, just type 'spca(foo)'.

Best regards,

Thibaut.

--
######################################
Dr Thibaut JOMBART
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - Faculty of Medicine
St Mary’s Campus
Norfolk Place
London W2 1PG
United Kingdom
Tel. : 0044 (0)20 7594 3658
t.jombart at imperial.ac.uk
http://www1.imperial.ac.uk/medicine/people/t.jombart/
http://adegenet.r-forge.r-project.org/
________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] On Behalf Of Andrew Close [a.j.close at newcastle.ac.uk]
Sent: 14 July 2009 21:08
To: adegenet-forum at lists.r-forge.r-project.org
Subject: [adegenet-forum] New user and experiencing problems!

Dear all,

I am a new to adegenet and have only been using R for a short period. I hope that someone can help point out the obvious mistake I am making and point me in the right direction.

I have three data frames, each with 111 rows. The first dataframe contains all the frequency data, the second contains the co-ordinates and the location identifiers (three columns), and the third the population identifier for each row object. I have tried to work my way around. genpop and genind all afternoon, and I have reached the point of exasperation!!!! I have not managed to get anywhere. I want to be able to create/merge my data so that I can perform spca.

I am sure I am making some very basic errors here, but I would be immensely grateful if someone could help point me in the right direction.

Yours (very embarrassed)

Andrew




Andrew Close
Research Associate
Institute for Research on Environment and Sustainability (IRES)
School of Biology
4th Floor Devonshire Building
Newcastle University
NE1 7RU
+44 (0)191 2464840
_______________________________________________
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