Skip to content

Commit

Permalink
update tests; add NEWS; add documentation (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkamvar committed May 2, 2018
1 parent 818199a commit 51f0720
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 36 deletions.
26 changes: 26 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
poppr 2.8.0
===========

BUG FIX
-------

* `win.ia()` now has more consistent behavior with chromosome structure and will
no longer result in an integer overflow
(see https://github.com/grunwaldlab/poppr/issues/179).

ALGORITHMIC CHANGE
------------------

* `win.ia()` may result in slightly different results because of two changes:
1. The windows will now always start at position one on any given chromosome.
This will result in some windows at the beginning of chromosomes having a
value of `NA` if the first variant starts beyond the first window.
2. Windows are now calculated for each chromosome independently. The previous
version first concatenated chromosomes with at least a window-sized gap
between the chromosomes, but failed to ensure that the window always started
at the beginning of the chromosome. This version fixes that issue.
(see https://github.com/grunwaldlab/poppr/issues/179).

DEPRECATION
-----------

* The `chromosome_buffer` argument for `win.ia()` has been permanently set to
`TRUE` and deprecated as it is no longer used.

NEW FEATURES
------------

Expand Down
36 changes: 15 additions & 21 deletions man/win.ia.Rd

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

33 changes: 18 additions & 15 deletions tests/testthat/test-winia.R
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
context("win.ia tests")
options(poppr.debug = FALSE)
set.seed(999)
chrom_pos <- vapply(1:10, function(i) sort(sample(1e3, 100)), integer(100)) %>%
as.vector()
chromo <- rep(1:10, each = 100)
real_pos <- chrom_pos + 1000*(chromo - 1) + 1#+ 100*(chromo - 1) + 1
set.seed(999)
x <- glSim(n.ind = 10, n.snp.nonstruc = 5e2, n.snp.struc = 5e2, ploidy = 2,
parallel = FALSE)


test_that("win.ia will throw an error if duplicate positions are found", {
x.naive <- win.ia(x)
options(poppr.debug = TRUE)
expect_output(x.naive <- win.ia(x), "[|=]{2,}")
position(x) <- chrom_pos
expect_equal(length(x.naive), 10L)
expect_error(win.ia(x), "chromosome")
options(poppr.debug = FALSE)
})

test_that("win.ia will throw a warning if chromosome_buffer is specified", {
expect_warning(x.naive <- win.ia(x, quiet = TRUE, chromosome_buffer = FALSE), "deprecated")
})

test_that("win.ia will use chromosome structure", {
skip_on_cran()
position(x) <- chrom_pos
chromosome(x) <- chromo
x.chrom.bt <- win.ia(x)
expect_equal(sum(is.na(x.chrom.bt) & !is.nan(x.chrom.bt)), 9L)
expect_equal(length(x.chrom.bt), 109L)
x.chrom.bt <- win.ia(x, quiet = TRUE)
expect_equal(length(x.chrom.bt), 100L)
expect_equal(names(x.chrom.bt), as.character(rep(1:10, each = 10)))
})

test_that("win.ia will take into account chromosome buffer", {
test_that("win.ia will always start at the beginning of the chromosome", {
skip_on_cran()
position(x) <- chrom_pos
chromosome(x) <- chromo
x.chrom.bf <- win.ia(x, chromosome_buffer = FALSE)
chromosome(x) <- NULL
position(x) <- real_pos
x.real <- win.ia(x)
expect_equal(length(x.chrom.bf), 100L)
expect_equal(length(x.chrom.bf), length(x.real))
expect_equal(x.chrom.bf, x.real, check.attributes = FALSE)
x.chrom.bf <- win.ia(x, window = 300L, quiet = TRUE)
x.by.chrom <- lapply(levels(chromosome(x)), function(i) win.ia(x[, chromosome(x) == i], window = 300L, quiet = TRUE))
# There should be 4 windows per chromosome.
expect_equal(length(x.chrom.bf), 40L)
# Using the function with and without chromosome structure should not matter.
expect_equal(x.chrom.bf, unlist(x.by.chrom, use.names = FALSE), check.attributes = FALSE)

})

0 comments on commit 51f0720

Please sign in to comment.