grunwaldlab / poppr

🌶 An R package for genetic analysis of populations with mixed (clonal/sexual) reproduction
https://grunwaldlab.github.io/poppr
68 stars 26 forks source link

Fix poppr for upcoming release of adegenet/pegas/hierfstat #16

Closed zkamvar closed 9 years ago

zkamvar commented 9 years ago

The adegenet package is going through major changes on github and many functions in poppr will break due to these changes.

Three main things will change:

  1. the tab slot of genind objects will store data as integers as opposed to floats
  2. the ploidy slot will contain the ploidy for all samples
  3. genind and genlight objects will gain genclone's hierarchy slot

Changes that need to be implemented in poppr:

This is not an exhaustive list as I know bugs will crop up as I encounter them, so I'm putting this here:

zkamvar commented 9 years ago
zkamvar commented 9 years ago

Errors after fixing the genclone class.

Amova tests : 12
Graph color conversion tests : 3
Population Distance Tests : 45
Errors and Exceptions : ...
Genclone coercion tests : 67
Greyscale tests : ...
Data import tests : 89
Missing tests : ....a
Multilocus genotype tests : ...bcdef
Polyploid Tests : .gh.
Poppr table tests : ij
Population subset tests : .................kl
Analytical value tests : .....m...

1. Error: Amova returns published values --------------------------------------------------
invalid class “genind” object: slots in class definition but not in object: "strata", "hierarchy"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: poppr.amova(Aeut, ~Pop/Subpop, quiet = TRUE) at test-amova.R:5
5: is.genind(x) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/amova.r:203
6: validObject(x)
7: stop(msg, ": ", errors, domain = NA)

2. Error: AMOVA handles subsetted genclone objects ----------------------------------------
no slot of name "strata" for this object of class "genind"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: as.genclone(Aeut) at test-amova.R:26
5: as.genclone(Aeut)
6: new("genclone", x) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:555
7: initialize(value, ...)
8: initialize(value, ...)
9: .local(.Object, ...)
10: lapply(names(gen), function(y) slot(.Object, y) <<- slot(gen, y)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407
11: FUN(c("strata", "hierarchy", "tab", "loc.names", "loc.fac", "loc.nall", "all.names", "call", 
   "ind.names", "pop", "pop.names", "ploidy", "type", "other")[[1L]], ...)
12: slot(gen, y) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407

3. Error: graph colors are correctly converted --------------------------------------------
no slot of name "strata" for this object of class "genind"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: partial_clone[1:11] at test-colors.R:6
5: partial_clone[1:11]
6: .local(x, i, j, ..., drop = drop)

4. Error: dist.genpop matches distance ----------------------------------------------------
$ operator is invalid for atomic vectors
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: as.vector(nei.dist(nanpop)) at test-distpop.R:6
5: nei.dist(nanpop)
6: get_gen_mat(x) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/distances.r:222

5. Error: aboot works with diss.dist ------------------------------------------------------
REAL() can only be applied to a 'numeric', not a 'integer'
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: aboot(nan1, dist = diss.dist, sample = 2, quiet = TRUE, showtree = FALSE) at test-distpop.R:21
5: treefunk(xboot) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/distances.r:495
6: TREEFUNK(do.call(DISTFUNK, distargs)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/internal.r:1585
7: as.dist(D)
8: do.call(DISTFUNK, distargs)
9: (function (x, percent = FALSE, mat = FALSE) 
   {
       stopifnot(is(x, "gen"))
       ploid <- x@ploidy
       if (is(x, "bootgen")) {
           ind.names <- x@names
       }
       else {
           ind.names <- x@ind.names
       }
       inds <- nrow(x@tab)
       np <- choose(inds, 2)
       dist.mat <- matrix(data = 0, nrow = inds, ncol = inds)
       numLoci <- length(x@loc.names)
       type <- x@type
       if (type == "PA") {
           dist_by_locus <- matrix(.Call("pairdiffs", x@tab))
           ploid <- 1
       }
       else if (is(x, "bootgen")) {
           dist_by_locus <- vapply(1:numLoci, function(i) {
               .Call("pairdiffs", get_gen_mat(x[, i])) * (ploid/2)
           }, numeric(np))
       }
       else {
           x <- seploc(x)
           dist_by_locus <- vapply(x, function(x) .Call("pairdiffs", x@tab) * (ploid/2), numeric(np))
       }
       dist.mat[lower.tri(dist.mat)] <- rowSums(dist_by_locus)
       colnames(dist.mat) <- ind.names
       rownames(dist.mat) <- ind.names
       if (percent) {
           dist.mat <- dist.mat/(numLoci * ploid)
       }
       dist.mat <- as.dist(dist.mat)
       if (mat == TRUE) {
           dist.mat <- as.matrix(dist.mat)
       }
       return(dist.mat)
   })(x = <S4 object of class structure("bootgen", package = "poppr")>, percent = FALSE, mat = FALSE)
10: vapply(1:numLoci, function(i) {
       .Call("pairdiffs", get_gen_mat(x[, i])) * (ploid/2)
   }, numeric(np)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/distances.r:104
11: FUN(1:9[[1L]], ...)

6. Error: A genclone object contains a genind object --------------------------------------
no slot of name "strata" for this object of class "genind"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: as.genclone(partial_clone) at test-genclone.R:6
5: as.genclone(partial_clone)
6: new("genclone", x) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:555
7: initialize(value, ...)
8: initialize(value, ...)
9: .local(.Object, ...)
10: lapply(names(gen), function(y) slot(.Object, y) <<- slot(gen, y)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407
11: FUN(c("strata", "hierarchy", "tab", "loc.names", "loc.fac", "loc.nall", "all.names", "call", 
   "ind.names", "pop", "pop.names", "ploidy", "type", "other")[[1L]], ...)
12: slot(gen, y) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407

7. Error: Hierarchy methods work for genclone objects. ------------------------------------
no slot of name "strata" for this object of class "genind"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: as.genclone(Aeut) at test-genclone.R:23
5: as.genclone(Aeut)
6: new("genclone", x) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:555
7: initialize(value, ...)
8: initialize(value, ...)
9: .local(.Object, ...)
10: lapply(names(gen), function(y) slot(.Object, y) <<- slot(gen, y)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407
11: FUN(c("strata", "hierarchy", "tab", "loc.names", "loc.fac", "loc.nall", "all.names", "call", 
   "ind.names", "pop", "pop.names", "ploidy", "type", "other")[[1L]], ...)
12: slot(gen, y) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407

8. Error: basic text connections work -----------------------------------------------------
no slot of name "strata" for this object of class "genclone"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: expect_equal(gen@tab, monpop[1:6, drop = TRUE]@tab) at test-import.R:16
5: expect_that(object, equals(expected, label = expected.label, ...), info = info, label = label)
6: condition(object)
7: compare(expected, actual, ...)
8: monpop[1:6, drop = TRUE]
9: monpop[1:6, drop = TRUE]
10: callNextMethod() at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:297
11: .nextMethod(x = x, i = i, drop = drop, ...)
12: .local(x, i, j, ..., drop = drop)

9. Error: genclone objects can be saved and restored --------------------------------------
argument "tab" is missing, with no default
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: genind2genalex(monpop, filename = mp, quiet = TRUE) at test-import.R:21
5: is.genind(pop) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/file_handling.r:438
6: validObject(x)
7: anyStrings(validityMethod(as(object, superClass)))
8: validityMethod(as(object, superClass))
9: ncol(object@tab)
10: as(object, superClass)
11: asMethod(object)
12: new(structure("genind", package = "adegenet"))
13: initialize(value, ...)
14: initialize(value, ...)
15: .local(.Object, ...)
16: colnames(tab)
17: is.data.frame(x)

a. Error: missingno matches na.replace ----------------------------------------------------
could not find function "na.replace"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: expect_identical(missingno(nancycats, "zero", quiet = TRUE), na.replace(nancycats, "0", quiet = TRUE)) at test-missing.R:16
5: expect_that(object, is_identical_to(expected, label = expected.label), info = info, label = label)
6: condition(object)
7: identical(actual, expected)
8: missingno(nancycats, "zero", quiet = TRUE)

b. Error: multilocus genotype vector is same length as samples ----------------------------
invalid class “genind” object: slots in class definition but not in object: "strata", "hierarchy"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: expect_that(length(unique(amlg)), equals(mlg(Aeut, quiet = TRUE))) at test-mlg.R:13
5: condition(object)
6: compare(expected, actual, ...)
7: mlg(Aeut, quiet = TRUE)
8: is.genind(pop) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/mlg.r:180
9: validObject(x)
10: stop(msg, ": ", errors, domain = NA)

c. Error: multilocus genotype matrix matches mlg.vector and data --------------------------
no slot of name "strata" for this object of class "genind"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: as.genclone(Aeut) at test-mlg.R:22
5: as.genclone(Aeut)
6: new("genclone", x) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:555
7: initialize(value, ...)
8: initialize(value, ...)
9: .local(.Object, ...)
10: lapply(names(gen), function(y) slot(.Object, y) <<- slot(gen, y)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407
11: FUN(c("strata", "hierarchy", "tab", "loc.names", "loc.fac", "loc.nall", "all.names", "call", 
   "ind.names", "pop", "pop.names", "ploidy", "type", "other")[[1L]], ...)
12: slot(gen, y) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407

d. Error: mlg.crosspop will work with subsetted genclone objects --------------------------
no slot of name "strata" for this object of class "genind"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: as.genclone(Aeut) at test-mlg.R:39
5: as.genclone(Aeut)
6: new("genclone", x) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:555
7: initialize(value, ...)
8: initialize(value, ...)
9: .local(.Object, ...)
10: lapply(names(gen), function(y) slot(.Object, y) <<- slot(gen, y)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407
11: FUN(c("strata", "hierarchy", "tab", "loc.names", "loc.fac", "loc.nall", "all.names", "call", 
   "ind.names", "pop", "pop.names", "ploidy", "type", "other")[[1L]], ...)
12: slot(gen, y) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/methods.r:407

e. Error: mlg.id Aeut works ---------------------------------------------------------------
invalid class “genind” object: slots in class definition but not in object: "strata", "hierarchy"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: mlg.id(Aeut) at test-mlg.R:103
5: is.genind(pop) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/mlg.r:405
6: validObject(x)
7: stop(msg, ": ", errors, domain = NA)

f. Error: mlg.id Pinf works ---------------------------------------------------------------
argument "tab" is missing, with no default
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: mlg.id(Pinf) at test-mlg.R:142
5: is.genind(pop) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/mlg.r:405
6: validObject(x)
7: anyStrings(validityMethod(as(object, superClass)))
8: validityMethod(as(object, superClass))
9: ncol(object@tab)
10: as(object, superClass)
11: asMethod(object)
12: new(structure("genind", package = "adegenet"))
13: initialize(value, ...)
14: initialize(value, ...)
15: .local(.Object, ...)
16: colnames(tab)
17: is.data.frame(x)

g. Failure(@test-polyploids.R#8): recode_polyploids works as expected ---------------------
testgid@tab[2, -1] not equal to expected
Mean absolute difference: 1

h. Failure(@test-polyploids.R#9): recode_polyploids works as expected ---------------------
testrec@tab[1, ] not equal to expected
Mean relative difference: 1

i. Error: poppr returns expected PA values ------------------------------------------------
invalid class “genind” object: slots in class definition but not in object: "strata", "hierarchy"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: poppr(Aeut, quiet = TRUE) at test-poppr.R:5
5: process_file(dat, missing = missing, cutoff = cutoff, clonecorrect = clonecorrect, hier = hier, 
       dfname = dfname, keep = keep, quiet = TRUE) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/Index_calculations.r:222
6: is.genind(input) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/internal.r:181
7: validObject(x)
8: stop(msg, ": ", errors, domain = NA)

j. Error: poppr returns expected codominant values ----------------------------------------
invalid class “genind” object: slots in class definition but not in object: "strata", "hierarchy"
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: poppr(partial_clone, quiet = TRUE) at test-poppr.R:39
5: process_file(dat, missing = missing, cutoff = cutoff, clonecorrect = clonecorrect, hier = hier, 
       dfname = dfname, keep = keep, quiet = TRUE) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/Index_calculations.r:222
6: is.genind(input) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/internal.r:181
7: validObject(x)
8: stop(msg, ": ", errors, domain = NA)

k. Error: subsetting doesn't work without populations -------------------------------------
error in evaluating the argument 'x' in selecting a method for function 'nInd': 
  no slot of name "strata" for this object of class "genind"

1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: expect_that(nInd(popsub(partial_clone, 1)), equals(nInd(partial_clone[p1, ]))) at test-popsub.R:57
5: condition(object)
6: compare(expected, actual, ...)
7: nInd(partial_clone[p1, ])

l. Error: subsetting works with genclone objects ------------------------------------------
argument "tab" is missing, with no default
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: popsub(nancycats, c(4, 8), drop = FALSE) at test-popsub.R:69
5: is.genind(gid) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/data_subset.r:285
6: validObject(x)
7: anyStrings(validityMethod(as(object, superClass)))
8: validityMethod(as(object, superClass))
9: ncol(object@tab)
10: as(object, superClass)
11: asMethod(object)
12: new(structure("genind", package = "adegenet"))
13: initialize(value, ...)
14: initialize(value, ...)
15: .local(.Object, ...)
16: colnames(tab)
17: is.data.frame(x)

m. Error: Dissimilarity distance works as expected. ---------------------------------------
REAL() can only be applied to a 'numeric', not a 'integer'
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: diss.dist(nan1, mat = TRUE) at test-values.R:29
5: vapply(x, function(x) .Call("pairdiffs", x@tab) * (ploid/2), numeric(np)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/distances.r:109
6: FUN(X[[1L]], ...)
zkamvar commented 9 years ago
zkamvar commented 9 years ago
zkamvar commented 9 years ago

As of 77c262d Fix bug in pairdiffs:

Testing poppr
Loading required package: adegenet
Loading required package: ade4
   ==========================
    adegenet 2.0.0 is loaded
   ==========================

 - to start: type '?adegenet'
 - to browse the adegenet website: type 'adegenetWeb()'
 - to post questions/comments: adegenet-forum@lists.r-forge.r-project.org
 - to report bugs, request features, contribute: http://goo.gl/dZuu5X

This is poppr version 1.1.4.99.89. To get started, type package?poppr
Amova tests : 12
Graph color conversion tests : ...
Population Distance Tests : ......
Errors and Exceptions : ...
Genclone coercion tests : ...................
Greyscale tests : ...
Data import tests : ..
Missing tests : ......
Multilocus genotype tests : ...............No multilocus genotypes were detected across populations
3No multilocus genotypes were detected across populations
4.........
Polyploid Tests : ....
Poppr table tests : ......................
Population subset tests : ..................................
Analytical value tests : ............

1. Error: Amova returns published values ---------------------------------------
NA/NaN argument
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: poppr.amova(Aeut, ~Pop/Subpop, quiet = TRUE) at test-amova.R:5
5: pool_haplotypes(x, dfname = dfname) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/amova.r:238
6: repool(separate_haplotypes(x)) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/internal.r:1417
7: separate_haplotypes(x)
8: which(1:geno_length%%(allele_length + 1) == 0) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/internal.r:1391

2. Error: AMOVA handles subsetted genclone objects -----------------------------
argument of length 0
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: poppr.amova(Athena, ~Subpop, quiet = TRUE) at test-amova.R:30
5: pool_haplotypes(x, dfname = dfname) at /Users/zhian/Documents/Grunwald/short-scripts/poppr/R/amova.r:238

3. Failure(@test-mlg.R#50): mlg.crosspop will work with subsetted genclone objects
x <- mlg.crosspop(Athena, quiet = TRUE) not equal to expected_output
Modes: list, numeric
names for target but not for current
Length mismatch: comparison on first 1 components
Component 1: names for target but not for current
Component 1: Numeric: lengths (2, 1) differ

4. Failure(@test-mlg.R#51): mlg.crosspop will work with subsetted genclone objects
y <- mlg.crosspop(Athena, indexreturn = TRUE) not equal to expected_mlgout
Numeric: lengths (6, 1) differ

There were 11 warnings (use warnings() to see them)
zkamvar commented 9 years ago

Look Ma! No bugs!