-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_proc_chromR.R
128 lines (93 loc) · 3.58 KB
/
test_proc_chromR.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# detach(package:vcfR, unload=T)
#
library(testthat)
library(vcfR)
context("proc_chromR")
##### ##### ##### ##### #####
test_that("vcfR_gt_to_popsum",{
data("vcfR_test")
gt <- extract.gt(vcfR_test)
var_info <- as.data.frame(vcfR_test@fix[,1:2])
var_info$mask <- TRUE
tmp <- .Call('vcfR_gt_to_popsum', PACKAGE = 'vcfR', var_info = var_info, gt = gt)
expect_equal(class(tmp), "data.frame")
expect_equal(nrow(tmp), nrow(gt))
expect_equal(ncol(tmp), 7)
expect_equal(as.character(tmp$Allele_counts[1]), "3,3")
# expect_equal(tmp$Allele_counts, structure(c(3L, 4L, 1L, 5L, 2L), .Label = c("0,2,4", "2,3,1", "3,3", "5,1", "6"), class = "factor"))
})
test_that("vcfR_gt_to_popsum, one variant",{
data("vcfR_test")
vcfR_test <- vcfR_test[1,]
gt <- extract.gt(vcfR_test)
var_info <- as.data.frame(vcfR_test@fix[,1:2, drop = FALSE])
var_info$mask <- TRUE
tmp <- .Call('vcfR_gt_to_popsum', PACKAGE = 'vcfR', var_info = var_info, gt = gt)
expect_equal(class(tmp), "data.frame")
expect_equal(nrow(tmp), 1)
})
test_that("vcfR_gt_to_popsum, counts missing alleles",{
data("vcfR_test")
gt <- extract.gt(vcfR_test)
gt[1,] <- "2/2"
gt[2,] <- "0/2"
var_info <- as.data.frame(vcfR_test@fix[,1:2, drop = FALSE])
var_info$mask <- TRUE
tmp <- .Call('vcfR_gt_to_popsum', PACKAGE = 'vcfR', var_info = var_info, gt = gt)
expect_identical(as.character(tmp$Allele_counts[1]), "0,0,6")
expect_equal(as.character(tmp$Allele_counts[2]), "3,0,3")
})
test_that("vcfR_gt_to_popsum, haploid loci",{
data("vcfR_test")
gt <- extract.gt(vcfR_test)
gt[1,] <- "2"
gt[2,] <- "0"
var_info <- as.data.frame(vcfR_test@fix[,1:2, drop = FALSE])
var_info$mask <- TRUE
tmp <- .Call('vcfR_gt_to_popsum', PACKAGE = 'vcfR', var_info = var_info, gt = gt)
expect_identical(as.character(tmp$Allele_counts[1]), "0,0,3")
expect_equal(as.character(tmp$Allele_counts[2]), "3")
})
test_that("vcfR_gt_to_popsum, haploid samples",{
data("vcfR_test")
gt <- extract.gt(vcfR_test)
gt[,1] <- "2"
gt[,2] <- "0"
var_info <- as.data.frame(vcfR_test@fix[,1:2, drop = FALSE])
var_info$mask <- TRUE
tmp <- .Call('vcfR_gt_to_popsum', PACKAGE = 'vcfR', var_info = var_info, gt = gt)
expect_identical(as.character(tmp$Allele_counts[1]), "1,2,1")
expect_equal(as.character(tmp$Allele_counts[2]), "3,0,1")
})
test_that("vcfR_gt_to_popsum, triploid loci",{
data("vcfR_test")
gt <- extract.gt(vcfR_test)
gt[1,] <- "2/2/1"
gt[2,] <- "0/0/0"
var_info <- as.data.frame(vcfR_test@fix[,1:2, drop = FALSE])
var_info$mask <- TRUE
tmp <- .Call('vcfR_gt_to_popsum', PACKAGE = 'vcfR', var_info = var_info, gt = gt)
expect_identical(as.character(tmp$Allele_counts[1]), "0,3,6")
expect_equal(as.character(tmp$Allele_counts[2]), "9")
})
test_that("vcfR_gt_to_popsum, triploid samples",{
data("vcfR_test")
gt <- extract.gt(vcfR_test)
gt[,1] <- "2/2/1"
gt[,2] <- "0/0/0"
var_info <- as.data.frame(vcfR_test@fix[,1:2, drop = FALSE])
var_info$mask <- TRUE
tmp <- .Call('vcfR_gt_to_popsum', PACKAGE = 'vcfR', var_info = var_info, gt = gt)
expect_identical(as.character(tmp$Allele_counts[1]), "3,3,2")
expect_equal(as.character(tmp$Allele_counts[2]), "5,1,2")
})
##### ##### ##### ##### #####
test_that("vcfR_gt_to_popsum, triploid samples",{
data("vcfR_test")
mySeq <- ape::as.DNAbin(matrix(sample(c('a','c','g','t'), size = 1234567, replace = TRUE), nrow=1))
myChrom <- create.chromR(vcfR_test, seq = mySeq, verbose = FALSE)
suppressMessages(suppressWarnings(myChrom <- proc.chromR(myChrom, verbose = TRUE)))
expect_is(myChrom, "chromR")
})
##### ##### ##### ##### #####
# EOF.