[adegenet-forum] sPCA with adegenet
Jombart, Thibaut
t.jombart at imperial.ac.uk
Tue Jul 23 15:01:48 CEST 2013
Hello,
sorry for this is a harsh answer, but you really need to do your homework and know at least some basics of R before asking questions on a specialized forum - or attempting any data analysis, for that matter.
This:
##
genind(tab1,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))
##
Converts your data indeed, but DOES NOT SAVE THE CHANGE IN THE OBJECT. This:
##
whateverYouWantToCallYourObject <- genind(tab1, ploidy=2, type="PA"))
##
is what you want to use, for diploid, presence/absence data. Going through this document will be useful:
http://cran.r-project.org/doc/manuals/r-release/R-intro.html
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 tyfanie bourlet [tyfanie.bourlet at florimond-desprez.fr]
Sent: 23 July 2013 10:57
To: adegenet-forum at lists.r-forge.r-project.org
Subject: Re: [adegenet-forum] sPCA with adegenet
Hello,
I'm really sorry to bother you again but I tried again this time with R studio (I thought I would be easier) but it doesn't work either...
This is the beginning of my script :
library(adegenet)
library(adehabitat)
tab1=read.table("test sPCA.csv", header=T, sep=";")
attach(tab1)
genind(tab1,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))
as.genind(tab1,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))
is.genind(tab1)
obj <- tab1$dat2A
obj
And this is the outputs :
> library(adegenet)
Loading required package: ade4
Attaching package: 'ade4'
The following object(s) are masked from 'package:base':
within
==========================
adegenet 1.3-9 is loaded
==========================
- to start, type '?adegenet'
- to browse adegenet website, type 'adegenetWeb()'
- to post questions/comments: adegenet-forum at lists.r-forge.r-project.org
Warning messages:
1: package 'adegenet' was built under R version 2.15.3
2: package 'ade4' was built under R version 2.15.3
3: replacing previous import 'as.igraph' when loading 'ape'
4: replacing previous import 'edges' when loading 'ape'
> library(adehabitat)
Loading required package: tkrplot
Loading required package: tcltk
Loading Tcl/Tk interface ... done
Loading required package: shapefiles
Loading required package: foreign
Attaching package: 'shapefiles'
The following object(s) are masked from 'package:foreign':
read.dbf, write.dbf
Be careful: it is now recommended to use the newpackages adehabitatMA, adehabitatLT, adehabitatHR, and adehabitatHS.
These 4 packages are intended to become the future of adehabitat.
The "classical" version of adehabitat will still be maintained for some
time, but no new method will be added to the package.
Warning messages:
1: package 'adehabitat' was built under R version 2.15.3
2: package 'tkrplot' was built under R version 2.15.2
3: package 'shapefiles' was built under R version 2.15.3
> tab1=read.table("test sPCA.csv", header=T, sep=";")
> attach(tab1)
> genind(tab1,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))
#####################
### Genind object ###
#####################
- genotypes of individuals -
S4 class: genind
@call: genind(tab = tab1, pop = NULL, prevcall = NULL, ploidy = 2, type = c("codom",
"PA"))
@tab: 1114 x 4630 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 4630 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(tab1,pop=NULL,prevcall=NULL, ploidy=2, type=c("codom","PA"))
#####################
### Genind object ###
#####################
- genotypes of individuals -
S4 class: genind
@call: as.genind(tab = tab1, pop = NULL, prevcall = NULL, ploidy = 2,
type = c("codom", "PA"))
@tab: 1114 x 4630 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 4630 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(tab1)
[1] FALSE
> obj <- tab1$dat2A
> obj
NULL
I try also with ploidy=1 and Type="PA" but it didn't work and for Type="PA" R told me that : Error: unexpected symbol in:"genind(tab1,pop=NULL,prevcall=NULL, ploidy=2, type="PA" as.genind"
So I really don't understand why it doesn't work ... I try to continue the analysis but of course R told me that my data set wasn't in genind format....
I join a part of my data set, maybe there is a problem with that...
Sorry again for bothering you but I really don't know what's the problem....
Thanking you in advance,
Best regards,
Tyfanie Bourlet
-----Message d'origine-----
De : Jombart, Thibaut [mailto:t.jombart at imperial.ac.uk]
Envoyé : lundi 22 juillet 2013 12:10
À : tyfanie bourlet
Objet : RE: sPCA with adegenet
No worries. Sorry about that, I understand getting into R in the first place is a bit scary. I'm biaised of course, I would argue it's a worthwhile investment.
Cheers
Thibaut
________________________________________
From: tyfanie bourlet [tyfanie.bourlet at florimond-desprez.fr]
Sent: 22 July 2013 07:06
To: Jombart, Thibaut
Subject: RE: sPCA with adegenet
Hello,
Thank you very much, I will try to fix it all.
Again thank you for the time you spent with me.
Best Regards,
Tyfanie Bourlet
-----Message d'origine-----
De : Jombart, Thibaut [mailto:t.jombart at imperial.ac.uk] Envoyé : vendredi 19 juillet 2013 17:14 À : tyfanie bourlet; adegenet-forum at lists.r-forge.r-project.org
Objet : RE: sPCA with adegenet
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