grunwaldlab / Population_Genetics_in_R

A primer for computational tools to analyze genetics of populations in R
http://grunwaldlab.github.io/Population_Genetics_in_R
Other
84 stars 50 forks source link

(nanhwe.pop <- seppop(nancycats) %>% lapply(hw.test, B = 0)) not working #38

Open DrK-Lo opened 6 years ago

DrK-Lo commented 6 years ago

Hi guys, This line of code is not working in your tutorial, but it worked for me last year (I use it in teaching)

(nanhwe.pop <- seppop(nancycats) %>% lapply(hw.test, B = 0))

I get the error message:

is.na() applied to non-(list or vector) of type 'NULL'The following loci were dropped (not the same ploidy for all individuals):
fca45longer argument not a multiple of length of shorterError in dimnames(ans) <- list(names(y), c("chi^2", "df", "Pr(chi^2 >)")) : 
  length of 'dimnames' [1] not equal to array extent

I traced the error to population 17:

for (i in 1:length(pops)){
  print(c("population", i))
  #in each population, calculate HWE
  (hw.test <- hw.test(pops[[i]], B=0))
  print(hw.test)
}
# the error message indicates that locus fca45 is having an issue
colSums(is.na(pops[[17]]@tab))
# check if this locus is missing data
# there is more missing data at this locus than other loci

rem.fca45 <- grep("fca45",colnames(nancycats@tab))
# columns in the data that contain information for the problem locus

hw.test(pops[[17]][, -rem.fca45], B=0)
# redo the test for population 17, but this time remove data for fca45

So, removing the locus for that one population works. But I know the code worked for me last year, so suggestions welcome!

zkamvar commented 6 years ago

Hi @DrK-Lo,

This is a bug in pegas that will be fixed with the next release. You can see the issue here: https://github.com/emmanuelparadis/pegas/issues/36

The output gives a more informative warning when run with the new version, but not an error.

remotes::install_github('emmanuelparadis/pegas/pegas')
#> Downloading GitHub repo emmanuelparadis/pegas@master
#> Installing 2 packages: digest, spData
#> Installing packages into '/home/zkamvar/Documents/RLibrary'
#> (as 'lib' is unspecified)
#> Installing package into '/home/zkamvar/Documents/RLibrary'
#> (as 'lib' is unspecified)
library('pegas')
#> Loading required package: ape
#> Loading required package: adegenet
#> Loading required package: ade4
#> 
#>    /// adegenet 2.1.1 is loaded ////////////
#> 
#>    > overview: '?adegenet'
#>    > tutorials/doc/questions: 'adegenetWeb()' 
#>    > bug reports/feature requests: adegenetIssues()
#> 
#> Attaching package: 'pegas'
#> The following object is masked from 'package:ade4':
#> 
#>     amova
#> The following object is masked from 'package:ape':
#> 
#>     mst
data(nancycats)
hw.test(nancycats[pop = 17], B=0)
#> Warning in hw.test.loci(x = x, B = B, ...): The following locus was ignored: fca45
#> (not the same ploidy for all individuals, or too many missing data)
#>           chi^2 df Pr(chi^2 >)
#> fca8  22.100000 15   0.1052085
#> fca23 10.631111 10   0.3869703
#> fca43 22.071111 10   0.0147464
#> fca45        NA NA          NA
#> fca77 24.180000 21   0.2844190
#> fca78  1.764543  3   0.6226810
#> fca90  6.686359  6   0.3508286
#> fca96  0.312500  1   0.5761501
#> fca37  5.097337  3   0.1648068

Created on 2018-09-18 by the reprex package (v0.2.0).

Session info ``` r devtools::session_info() #> Session info ------------------------------------------------------------- #> setting value #> version R version 3.5.1 (2018-07-02) #> system x86_64, linux-gnu #> ui X11 #> language en_GB:en #> collate en_GB.UTF-8 #> tz Europe/London #> date 2018-09-18 #> Packages ----------------------------------------------------------------- #> package * version date source #> ade4 * 1.7-13 2018-08-31 CRAN (R 3.5.1) #> adegenet * 2.1.1 2018-02-02 CRAN (R 3.5.1) #> ape * 5.1 2018-04-04 CRAN (R 3.5.1) #> assertthat 0.2.0 2017-04-11 CRAN (R 3.5.1) #> backports 1.1.2 2017-12-13 CRAN (R 3.5.1) #> base * 3.5.1 2018-07-03 local #> bindr 0.1.1 2018-03-13 CRAN (R 3.5.1) #> bindrcpp 0.2.2 2018-03-29 CRAN (R 3.5.1) #> boot 1.3-20 2017-07-30 CRAN (R 3.5.1) #> cluster 2.0.7-1 2018-04-09 CRAN (R 3.5.1) #> coda 0.19-1 2016-12-08 CRAN (R 3.5.1) #> colorspace 1.3-2 2016-12-14 CRAN (R 3.5.1) #> compiler 3.5.1 2018-07-03 local #> crayon 1.3.4 2017-09-16 CRAN (R 3.5.1) #> datasets * 3.5.1 2018-07-03 local #> deldir 0.1-15 2018-04-01 CRAN (R 3.5.1) #> devtools 1.13.6 2018-06-27 CRAN (R 3.5.1) #> digest 0.6.17 2018-09-12 CRAN (R 3.5.1) #> dplyr 0.7.6 2018-06-29 CRAN (R 3.5.1) #> evaluate 0.11 2018-07-17 CRAN (R 3.5.1) #> expm 0.999-2 2017-03-29 CRAN (R 3.5.1) #> gdata 2.18.0 2017-06-06 CRAN (R 3.5.1) #> ggplot2 3.0.0 2018-07-03 CRAN (R 3.5.1) #> glue 1.3.0 2018-07-17 CRAN (R 3.5.1) #> gmodels 2.18.1 2018-06-25 CRAN (R 3.5.1) #> graphics * 3.5.1 2018-07-03 local #> grDevices * 3.5.1 2018-07-03 local #> grid 3.5.1 2018-07-03 local #> gtable 0.2.0 2016-02-26 CRAN (R 3.5.1) #> gtools 3.8.1 2018-06-26 CRAN (R 3.5.1) #> htmltools 0.3.6 2017-04-28 CRAN (R 3.5.1) #> httpuv 1.4.5 2018-07-19 CRAN (R 3.5.1) #> igraph 1.2.2 2018-07-27 CRAN (R 3.5.1) #> knitr 1.20 2018-02-20 CRAN (R 3.5.1) #> later 0.7.4 2018-08-31 CRAN (R 3.5.1) #> lattice 0.20-35 2017-03-25 CRAN (R 3.5.1) #> lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.1) #> LearnBayes 2.15.1 2018-03-18 CRAN (R 3.5.1) #> magrittr 1.5 2014-11-22 CRAN (R 3.5.1) #> MASS 7.3-50 2018-04-30 CRAN (R 3.5.1) #> Matrix 1.2-14 2018-04-09 CRAN (R 3.5.1) #> memoise 1.1.0 2017-04-21 CRAN (R 3.5.1) #> methods * 3.5.1 2018-07-03 local #> mgcv 1.8-24 2018-06-18 CRAN (R 3.5.1) #> mime 0.5 2016-07-07 CRAN (R 3.5.1) #> munsell 0.5.0 2018-06-12 CRAN (R 3.5.1) #> nlme 3.1-137 2018-04-07 CRAN (R 3.5.1) #> nvimcom * 0.9-75 2018-08-22 local #> parallel 3.5.1 2018-07-03 local #> pegas * 0.11-3 2018-09-18 Github (emmanuelparadis/pegas@a989da2) #> permute 0.9-4 2016-09-09 CRAN (R 3.5.1) #> pillar 1.3.0 2018-07-14 CRAN (R 3.5.1) #> pkgconfig 2.0.2 2018-08-16 CRAN (R 3.5.1) #> plyr 1.8.4 2016-06-08 CRAN (R 3.5.1) #> promises 1.0.1 2018-04-13 CRAN (R 3.5.1) #> purrr 0.2.5 2018-05-29 CRAN (R 3.5.1) #> R6 2.2.2 2017-06-17 CRAN (R 3.5.1) #> Rcpp 0.12.18 2018-07-23 CRAN (R 3.5.1) #> remotes 1.1.1 2017-12-20 CRAN (R 3.5.1) #> reshape2 1.4.3 2017-12-11 CRAN (R 3.5.1) #> rlang 0.2.2 2018-08-16 CRAN (R 3.5.1) #> rmarkdown 1.10 2018-06-11 CRAN (R 3.5.1) #> rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.1) #> scales 1.0.0 2018-08-09 CRAN (R 3.5.1) #> seqinr 3.4-5 2017-08-01 CRAN (R 3.5.1) #> shiny 1.1.0 2018-05-17 CRAN (R 3.5.1) #> sp 1.3-1 2018-06-05 CRAN (R 3.5.1) #> spData 0.2.9.4 2018-09-15 CRAN (R 3.5.1) #> spdep 0.7-8 2018-08-15 CRAN (R 3.5.1) #> splines 3.5.1 2018-07-03 local #> stats * 3.5.1 2018-07-03 local #> stringi 1.2.4 2018-07-20 CRAN (R 3.5.1) #> stringr 1.3.1 2018-05-10 CRAN (R 3.5.1) #> tibble 1.4.2 2018-01-22 CRAN (R 3.5.1) #> tidyselect 0.2.4 2018-02-26 CRAN (R 3.5.1) #> tools 3.5.1 2018-07-03 local #> utils * 3.5.1 2018-07-03 local #> vegan 2.5-2 2018-05-17 CRAN (R 3.5.1) #> withr 2.1.2 2018-03-15 CRAN (R 3.5.1) #> xtable 1.8-3 2018-08-29 CRAN (R 3.5.1) #> yaml 2.2.0 2018-07-25 CRAN (R 3.5.1) ```