Skip to content

Commit

Permalink
Add bootgen2genind() to fix #112
Browse files Browse the repository at this point in the history
  • Loading branch information
zkamvar committed Oct 15, 2016
1 parent 34e97ec commit 32ebe40
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(as.genclone)
export(as.snpclone)
export(bitwise.dist)
export(bitwise.ia)
export(bootgen2genind)
export(bruvo.boot)
export(bruvo.dist)
export(bruvo.msn)
Expand Down
32 changes: 31 additions & 1 deletion R/methods.r
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ setMethod(
}
num_alleles <- slot(gen, "loc.n.all")
num_loci <- length(num_alleles)
slot(.Object, "tab") <- tab(gen, NA.method = na, freq = freq)
slot(.Object, "tab") <- tab(gen, NA.method = na, freq = freq)
slot(.Object, "loc.fac") <- slot(gen, "loc.fac")
slot(.Object, "loc.n.all") <- num_alleles
slot(.Object, "all.names") <- slot(gen, "all.names")
Expand All @@ -176,6 +176,30 @@ setMethod(
return(x@tab)
})

#==============================================================================#
#' @export
#' @rdname coercion-methods
#' @param bg a bootgen object
#' @aliases bootgen2genind,bootgen-method
#' @docType methods
#==============================================================================#
bootgen2genind <- function(bg){
standardGeneric("bootgen2genind")
}

#' @export
setGeneric("bootgen2genind")

setMethod(
f = "bootgen2genind",
signature = "bootgen",
definition = function(bg){
xtab <- tab(bg)
if (is.numeric(xtab)) xtab[] <- as.integer(xtab*bg@ploidy)
res <- new("genind", tab = xtab)
return(res)
})

################################################################################
#------------------------------------------------------------------------------#
# BRUVOMAT METHODS
Expand Down Expand Up @@ -713,6 +737,7 @@ setMethod(
#'
#' @seealso \code{\link{splitStrata}}, \code{\linkS4class{genclone}},
#' \code{\link{read.genalex}}
#' \code{\link{aboot}}
#' @author Zhian N. Kamvar
#' @examples
#' data(Aeut)
Expand All @@ -721,6 +746,11 @@ setMethod(
#' Aeut.gc
#' Aeut.gi <- genclone2genind(Aeut.gc)
#' Aeut.gi
#' data(nancycats)
#' nan.bg <- new("bootgen", nancycats[pop = 9])
#' nan.bg
#' nan.gid <- bootgen2genind(nan)
#' nan.gid
#==============================================================================#
as.genclone <- function(x, ..., mlg, mlgclass = TRUE){
standardGeneric("as.genclone")
Expand Down
14 changes: 13 additions & 1 deletion man/coercion-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/test-trees.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ test_that("aboot can utilize anonymous functions", {
expect_is(nantree, "phylo")
})

test_that("aboot can utilize bootgen2genind", {
skip_on_cran()
suppressWarnings(nantreebg <- aboot(nan9, dist = function(x) nei.dist(bootgen2genind(x)), sample = 20, quiet = TRUE))
suppressWarnings(nantree <- aboot(nan9, dist = "nei.dist", sample = 20, quiet = TRUE))
expect_is(nantreebg, "phylo")
expect_is(nantree, "phylo")
expect_equivalent(nantreebg$edge.length, nantree$edge.length)
})


test_that("aboot can handle populations", {
skip_on_cran()
set.seed(999)
Expand Down

0 comments on commit 32ebe40

Please sign in to comment.