Skip to content

Commit

Permalink
map_df_to_list() - ensure output has numeric positions
Browse files Browse the repository at this point in the history
 - Fixes Issue #17.
  • Loading branch information
kbroman committed Sep 21, 2019
1 parent 9a4f205 commit 5ad341b
Show file tree
Hide file tree
Showing 4 changed files with 33 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.20
Date: 2019-06-03
Version: 0.21-1
Date: 2019-09-21
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
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## qtl2convert 0.21 (2019-09-21)

- Have `map_df_to_list()` ensure that the positions in the output are
numeric.


## qtl2convert 0.20 (2019-06-03)

- Use Markdown for function documentation, throughout
Expand Down
2 changes: 1 addition & 1 deletion R/map_df_to_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ map_df_to_list <-
uchr <- unique(chr)
pos <- map[,pos_column]

result <- split(pos, factor(chr, levels=uchr))
result <- split(as.numeric(pos), factor(chr, levels=uchr))
marker <- split(marker, factor(chr, levels=uchr))
for(i in seq(along=result))
names(result[[i]]) <- marker[[i]]
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-map_df_to_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,28 @@ test_that("map_df_to_list works", {

expect_equal(map_df_to_list(df), expected)


# same thing with character string positions in the input
df <- structure(list(marker = c("JAX00240989", "JAX00240649", "UNCJPD009180",
"JAX00240804", "JAX00240610", "UNCHS003854", "UNCHS003852", "UNCHS003846",
"JAX00482049", "JAX00482064", "JAX00281864", "ICR260", "JAX00014570",
"JAX00281798", "ICR4249", "JAX00708681", "JAX00708630r", "UNCHS048201",
"JAX00176676", "UNCHS048205"), chr = c("1", "1", "1", "1", "1",
"2", "2", "2", "2", "2", "10", "10", "10",
"10", "10", "X", "X", "X", "X", "X"),
Mb_GRC38 = c("5.379217", "3.454984", "5.754074", "4.334891",
"3.266608", "4.118437", "4.115724", "3.74537", "3.23375", "3.362696", "4.306508",
"3.5931", "3.993759", "4.631578", "4.666669", "6.845222", "6.369421", "6.536718",
"6.05422", "6.586892"),
cM = c("0.424118388815167", "0.041241020125091",
"0.466051450603133", "0.0654810203913158", "0.0241660935186957", "0.182846980321827",
"0.182407517001796", "0.130917988391064", "0.000412833594312019", "0.000640569383198255",
"0.0163163877989646", "0.00740695778637858", "0.0124106069176088",
"0.0203760400795549", "0.0208142757155046", "0.827432787823843", "0.235740657791282",
"0.397500188730613", "0.0507409752570731", "0.501406880974154")),
.Names = c("marker", "chr", "Mb_GRC38", "cM"), class = "data.frame",
row.names = c(NA, -20L))

expect_equal(map_df_to_list(df), expected)

})

0 comments on commit 5ad341b

Please sign in to comment.