@@ -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