Skip to content

Commit 5f75bf3

Browse files
authored
Merge pull request #187 from kbroman/master
Fix Issue #146 so predict_snpgeno() works with RIL
2 parents 0a78628 + bf004dc commit 5f75bf3

4 files changed

Lines changed: 59 additions & 13 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: qtl2
2-
Version: 0.23-11
3-
Date: 2020-12-08
2+
Version: 0.23-12
3+
Date: 2020-12-09
44
Title: Quantitative Trait Locus Mapping in Experimental Crosses
55
Description: Provides a set of tools to perform quantitative
66
trait locus (QTL) analysis in experimental crosses. It is a

NEWS.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## qtl2 0.23-11 (2020-12-08)
1+
## qtl2 0.23-12 (2020-12-09)
22

33
### Major changes
44

@@ -40,19 +40,22 @@
4040
`genoprob_to_alleleprob()` for general AIL crosses. We had not
4141
implemented the `geno2allele_matrix()` function.
4242

43-
- Fix Issue #164, so `plot_pxg()` can handle a phenotype that is a
43+
- Fixed Issue #164, so `plot_pxg()` can handle a phenotype that is a
4444
single-column data frame.
4545

46-
- Fix Issue #135, so `plot_scan1()` can take vector input (which is
46+
- Fixed Issue #135, so `plot_scan1()` can take vector input (which is
4747
then converted to a single-column matrix).
4848

49-
- Fix Issue #157, to have `calc_genoprob()` give a better error
49+
- Fixed Issue #157, to have `calc_genoprob()` give a better error
5050
message about missing genetic map.
5151

52-
- Fix Issue #178, to have `read_cross2()` give a warning not an error
52+
- Fixed Issue #178, to have `read_cross2()` give a warning not an error
5353
if incorrect number of alleles.
5454

55-
- Fix Issue #180 re `scan1()` error if phenotypes' rownames have rownames.
55+
- Fixed Issue #180 re `scan1()` error if phenotypes' rownames have rownames.
56+
57+
- Fixed Issue #146, revising `predict_snpgeno()` so that it works for
58+
homozygous populations, like MAGIC lines or the Collaborative Cross.
5659

5760

5861
## qtl2 0.22-11 (2020-07-09)

R/predict_snpgeno.R

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,27 @@ function(cross, geno, cores=1)
4343
# ensure same chromosomes
4444
if(n_chr(cross) != length(geno) ||
4545
any(chr_names(cross) != names(geno))) {
46-
chr <- get_common_ids(setNames(chr_names(cross), NULL), setNames(names(geno), NULL))
46+
chr <- get_common_ids(setNames(names(geno), NULL), setNames(chr_names(cross), NULL))
4747
cross <- cross[,chr]
4848
geno <- geno[,chr]
4949
}
5050

5151
# ensure same individuals
5252
if(n_ind_geno(cross) != nrow(geno[[1]]) ||
5353
any(ind_ids_geno(cross) != rownames(geno[[1]]))) {
54-
ind <- get_common_ids(setNames(ind_ids_geno(cross), NULL), setNames(rownames(geno[[1]]), NULL))
54+
ind <- get_common_ids(setNames(rownames(geno[[1]]), NULL), setNames(ind_ids_geno(cross), NULL))
5555
cross <- cross[ind,]
5656
geno <- geno[ind,]
5757
}
5858

59+
phase_known <- is_phase_known(cross)
60+
5961
# guess phase
60-
ph <- qtl2::guess_phase(cross, geno, cores=cores)
62+
if(!phase_known) {
63+
ph <- guess_phase(cross, geno, cores=cores)
64+
} else {
65+
ph <- cross$geno
66+
}
6167

6268
# subset cross chromosomes
6369
cross <- cross[,names(ph)]
@@ -72,8 +78,12 @@ function(cross, geno, cores=1)
7278
by_chr_func <- function(chr) {
7379
# ensure the same markers
7480
fg <- cross$founder_geno[[chr]]
75-
ph1 <- ph[[chr]][,,1]
76-
ph2 <- ph[[chr]][,,2]
81+
if(phase_known) {
82+
ph1 <- ph2 <- geno[[chr]]
83+
} else {
84+
ph1 <- ph[[chr]][,,1]
85+
ph2 <- ph[[chr]][,,2]
86+
}
7787
if(ncol(fg) != ncol(ph1) ||
7888
any(colnames(fg) != colnames(ph1))) {
7989
mar <- get_common_ids(setNames(colnames(fg), NULL), setNames(colnames(ph1), NULL))

tests/testthat/test-predict_snpgeno.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,36 @@ test_that("predict_snpgeno works", {
2222
expect_equivalent(infg[[1]][11,51:60], c(NA,NA,NA,NA,1,3,1,2,2,3))
2323

2424
})
25+
26+
27+
test_that("predict_snpgeno works for magic lines", {
28+
29+
skip_if(isnt_karl(), "this test only run locally")
30+
31+
# load example data and calculate genotype probabilities
32+
file <- paste0("https://raw.githubusercontent.com/rqtl/",
33+
"qtl2data/master/ArabMAGIC/arabmagic_tair9.zip")
34+
magic <- read_cross2(file)
35+
ind <- paste0("MAGIC", ".", 1:20)
36+
chr <- "2"
37+
probs <- calc_genoprob(magic[ind,chr], error_prob=0.002)
38+
m <- maxmarg(probs)
39+
40+
infg <- predict_snpgeno(magic, m)
41+
42+
expect_equal(class(infg), "list")
43+
expect_equal(length(infg), 1)
44+
expect_equal(names(infg), chr)
45+
expect_equal(dim(infg[[1]]), c(20,211))
46+
expect_equivalent(infg[[1]][,1], c(3,1,3,1,NA,3,1,3,1,1,3,3,NA,1,3,NA,1,1,NA,1))
47+
expect_equivalent(infg[[1]][9,1:10], c(1,1,1,3,3,1,1,3,3,1))
48+
expect_equivalent(infg[[1]][10,101:110], c(rep(1,9), 3))
49+
expect_equivalent(infg[[1]][11,51:60], c(1,1,3,1,1,1,1,1,1,1))
50+
51+
fg <- magic$founder_geno[[chr]]
52+
fg[fg==0] <- NA
53+
infg_hard <- t(sapply(1:20, function(wh_ind) sapply(seq_along(m[[chr]][wh_ind,]), function(i) {
54+
g <- m[[chr]][wh_ind,i]; ifelse(is.na(g), NA, fg[g,i]) })))
55+
expect_equivalent(infg[[chr]], infg_hard)
56+
57+
})

0 commit comments

Comments
 (0)