NESCent / popgenInfo

Vignettes for Population Genetics in R
http://popgen.nescent.org
MIT License
21 stars 50 forks source link

Fix code in vignettes to pass tests after CRAN package changes #79

Closed hlapp closed 8 years ago

hlapp commented 8 years ago

From @smanel:

I added the option ncode=2 in the command df2genind. But the command genind2hierfstat still does not work.

hlapp commented 8 years ago

@smanel your change fixed the call to df2genind(), but now genind2hierfstat() fails:

Quitting from lines 80-87 (DifferentiationSNP.Rmd) 
Error in genind2hierfstat(Mydata1) : 
  alleles must be encoded as numbers or nucleotides. Exiting

Perhaps @zkamvar knows how to fix this? (I don't.)

jgx65 commented 8 years ago

This error message means that alleles are not encoded as integer or in c("a","c","g","t","A","C","G",T") . I am puzzled, because from the version of the data file I've just downloaded, I did not get this error message. What is the result of names(table(unlist(Mydata1@all.names)))? This should contain only c("a","c","g","t","A","C","G",T") .

smanel commented 8 years ago

(table(unlist(Mydata1@all.names)))

A C G T 19 6 13 2

jgx65 commented 8 years ago

@smanel OK, I believe the source of the error is the argument ncode=2 in the call to df2genind prior to calling genind2hierfstat. Try replacing this with sep="" . It worked for me... @thibautjombart, @zkamvar any idea why this behavior?

hlapp commented 8 years ago

Thanks @jgx65, that indeed fixes it. Now we have the next error showing up:

Quitting from lines 117-120 (DifferentiationSNP.Rmd) 
Error in eval(expr, envir, enclos) : could not find function "pp.fst"

Where did this function use to be, and which package is it in now?

jgx65 commented 8 years ago

I have sent a working version of the markdown file to Stephanie Manel. Indeed, pp.fst has been replaced with pairwise.WCfst. Better still, use genet.dist(Mydata1, method="WC84")

Sent using OWA for iPad


hlapp commented 8 years ago

Are there more changes needed than the one you suggest? Can you send me the file with your edits as well (or much better yet, simply put up a Gist and add a link here). I'd like to reduce @smanel's frustrations with things not directly related to developing her vignette :smile:

jgx65 commented 8 years ago

this should be it:

https://gist.github.com/jgx65/bd5d1fc7f16bd6de8161

hlapp commented 8 years ago

Thanks @jgx65. That fixes DifferentiationSNP.Rmd. Now there is a failure involving Fst() in another vignette:

Quitting from lines 61-63 (PopDiffSequenceData.Rmd) 
Error in Fst(allData_loci) : Fst() requires diploid data

Anyone have any ideas for how to correct that?

jgx65 commented 8 years ago

Had a quick look. Fst is from pegas I believe. allData_Loci mixes haploid (mt) and diploid (CAD) data, which is strange. I tried running things on CAD data set only, but no better success. genind object says diploid but the tab slot contains haploid data only (each row sums to 1). One can run basic.stats on the genind object with argument diploid=F, but, since, each individual is different, this does not give very meaningful results...

> Mydata2tab<-as.genind.DNAbin(tmp2, rep(c("CA","Ch","Am","AF"), each=5))
> Mydata2tab
/// GENIND OBJECT /////////

 // 20 individuals; 1 locus; 19 alleles; size: 9.6 Kb

 // Basic content
   @tab:  20 x 19 matrix of allele counts
   @loc.n.all: number of alleles per locus (range: 19-19)
   @loc.fac: locus factor for the 19 columns of @tab
   @all.names: list of allele names for each locus
   @ploidy: ploidy of each individual  (range: 2-2)
   @type:  codom
   @call: .local(.Object = .Object, tab = ..1, pop = ..2)

 // Optional content
   @pop: population of each individual (group size range: 5-5)
> basic.stats(Mydata2tab,diploid=F)
$perloc
          Ho Hs    Ht    Dst    Htp    Dstp    Fst    Fstp Fis        Dest
L1        NA  1 0.995 -0.005 0.9933 -0.0067 -0.005 -0.0067  NA -6.0048e+13
dummy.loc NA  1 0.995 -0.005 0.9933 -0.0067 -0.005 -0.0067  NA -6.0048e+13

$overall
  Ho   Hs   Ht  Dst  Htp Dstp  Fst Fstp  Fis Dest 
  NA    1   NA   NA   NA   NA   NA   NA   NA   NA