Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where genlight subsetting with no loci specified results in an extra bit #364

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/recheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
workflow_dispatch:
inputs:
which:
type: choice
description: Which dependents to check
options:
- strong
- most

name: Reverse dependency check

jobs:
revdep_check:
name: Reverse check ${{ inputs.which }} dependents
uses: r-devel/recheck/.github/workflows/recheck.yml@v1
with:
which: ${{ inputs.which }}
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
CHANGES IN ADEGENET VERSION 2.1.11

BUG FIX

- genlight objects subset without any arguments to loci no longer gain an
extra byte. (reported: @maxecoulter, #363)

CHANGES IN ADEGENET VERSION 2.1.10

CRAN MAINTENANCE
Expand Down
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: adegenet
Title: Exploratory Analysis of Genetic and Genomic Data
Version: 2.1.10
Version: 2.1.11
Authors@R:
c(person(given = "Thibaut",
family = "Jombart",
Expand Down Expand Up @@ -67,7 +67,10 @@ Authors@R:
person(given = "Pavel",
family = "Dimens",
role = "ctb",
comment = c(ORCID = "0000-0003-3823-0373"))
comment = c(ORCID = "0000-0003-3823-0373")),
person(given = "Max",
family = "Coulter",
role = "ctb")
)
Description: Toolset for the exploration of genetic and genomic
data. Adegenet provides formal (S4) classes for storing and handling
Expand Down
5 changes: 4 additions & 1 deletion R/glHandle.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# Take a raw vector, subset the bits and then convert to integers.
xint <- as.integer(rawToBits(x)[i])
# Figure out how many zeroes are needed to pad the end.
zeroes <- 8 - (length(xint) %% 8)
extra_bits <- length(xint) %% 8
# https://github.com/thibautjombart/adegenet/issues/363
# Fix to a bug caught by @maxcoulter. In the case
zeroes <- if (extra_bits > 0) 8 - extra_bits else 0
# Convert the integer vector with zeroes on the end back into a raw vector.
return(packBits(c(xint, rep(0L, zeroes))))
}
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test_genlight.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ test_that("Genlight objects can be created predictably", {
})


test_that("(#363) genlight objects don't gain extra byte after subsetting", {
# https://github.com/thibautjombart/adegenet/issues/363

dat <- list(toto=c(1,2,0,0), titi=c(NA,1,2,0), tata=c(NA,0,2, NA))#3 individuals, 4 binary snps

x <- new("genlight", gen = dat, ploidy = c(2,2,2,2),
loc.names = c("m1", "m2", "m3", "m4"),
loc.all = c("A/T", "A/T", "A/T", "A/T")
)
x2 <- x[]
# the output tables should be equal
expect_equal(tab(x), tab(x2))
# the snps should be equal
expect_equal(x, x2)

})


x <- new("genlight", list(a=1,b=0,c=1), other=list(1:3, letters, data.frame(2:4)), parallel = FALSE)
pop(x) <- c("pop1","pop1", "pop2")

Expand Down
Loading