[adegenet-forum] sPCA with adegenet

Jombart, Thibaut t.jombart at imperial.ac.uk
Fri Jul 19 17:14:21 CEST 2013


Hello,

unfortunately there is a number of basic errors here and I can't go through all of them. First, you do not assign the value of 'test' after using the constructor to any object. So 'test' remains unchanged. 
When calling the constructor, you have to specify type="PA" in your case, and I'm guessing ploidy is 1 too. 

Then, the call to data(test) does not make sense here. 'data' is used to load data objects distributed with R packages. I am guessing you are reusing code from the sPCA tutorial, but you need to adapt it to your object. As for the read.csv problem, this function is heavily used in R so it is unlikely to be a bug. 

The best thing to do here is to take a couple of days to get started with R in the first place and going through a basic introduction. A fairly complete one can be found on CRAN:
http://cran.r-project.org/doc/manuals/r-release/R-intro.html

Without a basic knowledge of R, analyzing your data in R is going to be hellish, and likely prone to unwanted mistakes/errors.

Good luck and all the best
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 tyfanie bourlet [tyfanie.bourlet at florimond-desprez.fr]
Sent: 19 July 2013 12:48
To: adegenet-forum at lists.r-forge.r-project.org
Subject: [adegenet-forum] sPCA with adegenet

Dear Dr Jombart,

Thank you very much for answering me so fast.
Please find attached a part of my data set in csv file :
marker

sbPb-3066557

sbPb-3066720

sbPb-3066853

Beta patula

0

1

1

Beta patula

0

1

1

Beta macrocarpa

1

1

0

Beta macrocarpa

1

1

0

Beta macrocarpa

1

1

0

Beta macrocarpa

1

1

0

Beta macrocarpa

0

1

1

Beta macrocarpa

1

1

0

Beta macrocarpa

1

1

0

Beta macrocarpa

1

1

0

Beta macrocarpa

1

1

NA


I didn’t know how to add the geographical data, so I put them in a second sheet :
x

y

33.3333

34.7333

33.6167

34.8

27.202148

35.532226

27.202148

35.532226

19.599609

47.115

34.4667

31.4167

34.4667

31.4167

-7.76667

37.0667






The name of my data set in R is : “test”. So I first try to convert my data set into genind object with this script of genind constructor :
test <-
  read.table("//Serveur/m/13 - STAGIAIRES BETTERAVES/2012_tyfanie BOURLET/AKER/sPCA/testspca.txt",
   header=TRUE, sep="", na.strings="NA", dec=".", strip.white=TRUE)
test <- sqlQuery(channel = 3, select * from [test sPCA$])
names(test) <- make.names(names(test))
x <- as.matrix(test)
genind(test,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))
as.genind(test,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))
is.genind(test)

And R put me this :

> test <-
+   read.table("//Serveur/m/13 - STAGIAIRES BETTERAVES/2012_tyfanie BOURLET/AKER/sPCA/testspca.txt",
+    header=TRUE, sep="", na.strings="NA", dec=".", strip.white=TRUE)

> test <- sqlQuery(channel = 3, select * from [test sPCA$])

> names(test) <- make.names(names(test))

> x <- as.matrix(test)

> genind(test,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))

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

S4 class:  genind
@call: genind(tab = test, pop = NULL, prevcall = NULL, ploidy = 2, type = c("codom",
    "PA"))

@tab:  1114 x 255 matrix of genotypes

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

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

@other: - empty -


> as.genind(test,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))

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

S4 class:  genind
@call: as.genind(tab = test, pop = NULL, prevcall = NULL, ploidy = 2,
    type = c("codom", "PA"))

@tab:  1114 x 255 matrix of genotypes

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

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

@other: - empty -


> is.genind(test)
[1] FALSE

So apparently R doesn’t consider that my data set is a genind object…
And then when I want to start the sPCA analysis I enter this script :

library(adegenet)
library(adehabitat)
data(test)
obj <- test$dat2A
obj
test <- test$dat2A
test
head(truenames(obj[loc="sbPb"])$tab)

And R put me this :
 WARNING: Warning in data(test) : data set 'test' not found
ERROR:
error in evaluating the argument 'x' in selecting a method for function 'truenames'

And I have another problem. When I import my data set in csv format, R take only the 255 first columns (I have 4630 columns) so I have to import my data in text format but then, R give me this error message : “[10] ERROR: line 16 did not have 4631 elements” whereas all my lines have 4630 elements…

Thanking you in advance for helping me. I’m not an expert at all with R but it would be very helpful if I can manage this sPCA.
Best regards,

Tyfanie Bourlet
France
Florimond Desprez
Beet laboratory
Student at Agrocampus Ouest
0672610237


More information about the adegenet-forum mailing list