Skip to content

Commit

Permalink
encode_geno() now gives a warning if allele_codes have >1 character
Browse files Browse the repository at this point in the history
- Issue rqtl#16
  • Loading branch information
kbroman committed Sep 25, 2019
1 parent 9dfb6b0 commit 34c43dd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: qtl2convert
Version: 0.21-2
Date: 2019-09-24
Version: 0.21-3
Date: 2019-09-25
Title: Convert Data among R/qtl2, R/qtl, and DOQTL
Description: Functions to convert data structures among the R/qtl2, R/qtl, and DOQTL packages.
Author: Karl W Broman [aut, cre] (<https://orcid.org/0000-0002-4914-6671>)
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## qtl2convert 0.21 (2019-09-24)
## qtl2convert 0.21 (2019-09-25)

### New features

Expand All @@ -19,6 +19,9 @@

- Fix bug for the case `marker_column=NULL`.

- `encode_geno()` now gives a warning if any allele codes have >1 character.
([Issue #16](https://github.com/rqtl/qtl2convert/issues/16))


## qtl2convert 0.20 (2019-06-03)

Expand Down
3 changes: 3 additions & 0 deletions R/encode_geno.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function(geno, allele_codes, output_codes=c("-", "A", "H", "B"), cores=1)
stopifnot(nrow(geno) == nrow(allele_codes))
stopifnot(ncol(allele_codes) == 2)

if(any(is.na(allele_codes))) stop("allele_codes can't have missing values")
if(any(nchar(allele_codes)>1)) stop("allele_codes should be single characters")

if(!is.matrix(geno)) geno <- as.matrix(geno)
if(!is.matrix(allele_codes)) allele_codes <- as.matrix(allele_codes)

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-encode_geno.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ test_that("encode_geno works", {

expect_equal(encode_geno(geno, cbind(codes[,2], codes[,1])), expected2)

# errors: multiple characters, NAs
expect_error(encode_geno(geno, cbind(paste0(codes[,1], codes[,1]), codes[,2])))
expect_error(encode_geno(geno, cbind(codes[,1], paste0(codes[,2], codes[,2]))))
codes[1,2] <- NA
expect_error(encode_geno(geno, codes))

})


Expand Down

0 comments on commit 34c43dd

Please sign in to comment.