-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-dratio-filter.R
140 lines (121 loc) · 4.01 KB
/
test-dratio-filter.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
129
130
131
132
133
134
135
136
137
138
139
140
# filter d-ratio
test_that('d-ratio filter works as expected using sd ratio',{
set.seed('57475')
# DatasetExperiment
DE = MTBLS79_DatasetExperiment(filtered=TRUE)
M = dratio_filter(
threshold=20,
qc_label = 'QC',
factor_name='Class',
method = 'ratio',
dispersion = 'sd'
)
M = model_apply(M,DE)
# manually compute d-ratio
qc_mad=unlist(
lapply(DE$data[DE$sample_meta$Class=='QC',],sd,na.rm=TRUE)
)
sa_mad=unlist(
lapply(DE$data[DE$sample_meta$Class!='QC',],sd,na.rm=TRUE)
)
dr = (qc_mad/(sa_mad))*100
# check manual vs fcn
expect_true(all(dr==M$d_ratio$d_ratio))
# check values havent changed
expect_equal(dr[[1]],23.05762,tolerance = 5e-6)
expect_equal(dr[[100]],64.49242,tolerance = 5e-6)
# just number of filtered columns
expect_true(ncol(predicted(M))==725)
expect_true(ncol(DE)-ncol(predicted(M))==854)
expect_true(ncol(DE)-ncol(predicted(M))==sum(dr>20))
})
test_that('d-ratio filter works as expected using mad ratio',{
set.seed('57475')
# DatasetExperiment
DE = MTBLS79_DatasetExperiment(filtered=TRUE)
M = dratio_filter(
threshold=20,
qc_label = 'QC',
factor_name='Class',
method = 'ratio',
dispersion = 'mad'
)
M = model_apply(M,DE)
# manually compute d-ratio
qc_mad=unlist(
lapply(DE$data[DE$sample_meta$Class=='QC',],mad,na.rm=TRUE)
)
sa_mad=unlist(
lapply(DE$data[DE$sample_meta$Class!='QC',],mad,na.rm=TRUE)
)
dr = (qc_mad/(sa_mad))*100
# check manual vs fcn
expect_true(all(dr==M$d_ratio$d_ratio))
# check values havent changed
expect_equal(dr[[1]],14.14758,tolerance = 5e-6)
expect_equal(dr[[100]],48.23871,tolerance = 5e-6)
# just number of filtered columns
expect_true(ncol(predicted(M))==834)
expect_true(ncol(DE)-ncol(predicted(M))==745)
expect_true(ncol(DE)-ncol(predicted(M))==sum(dr>20))
})
test_that('d-ratio filter works as expected using sd euclidean',{
set.seed('57475')
# DatasetExperiment
DE = MTBLS79_DatasetExperiment(filtered=TRUE)
M = dratio_filter(
threshold=20,
qc_label = 'QC',
factor_name='Class',
method = 'euclidean',
dispersion = 'sd'
)
M = model_apply(M,DE)
# manually compute d-ratio
qc_mad=unlist(
lapply(DE$data[DE$sample_meta$Class=='QC',],sd,na.rm=TRUE)
)
sa_mad=unlist(
lapply(DE$data[DE$sample_meta$Class!='QC',],sd,na.rm=TRUE)
)
dr = qc_mad/sqrt((qc_mad^2) + (sa_mad^2))*100
# check manual vs fcn
expect_true(all(dr==M$d_ratio$d_ratio))
# check values havent changed
expect_equal(dr[[1]],22.46809,tolerance = 5e-6)
expect_equal(dr[[100]],54.19862,tolerance = 5e-6)
# just number of filtered columns
expect_true(ncol(predicted(M))==747)
expect_true(ncol(DE)-ncol(predicted(M))==832)
expect_true(ncol(DE)-ncol(predicted(M))==sum(dr>20))
})
test_that('d-ratio filter works as expected using mad euclidean',{
set.seed('57475')
# DatasetExperiment
DE = MTBLS79_DatasetExperiment(filtered=TRUE)
M = dratio_filter(
threshold=20,
qc_label = 'QC',
factor_name='Class',
method = 'euclidean',
dispersion = 'mad'
)
M = model_apply(M,DE)
# manually compute d-ratio
qc_mad=unlist(
lapply(DE$data[DE$sample_meta$Class=='QC',],mad,na.rm=TRUE)
)
sa_mad=unlist(
lapply(DE$data[DE$sample_meta$Class!='QC',],mad,na.rm=TRUE)
)
dr = qc_mad/sqrt((qc_mad^2) + (sa_mad^2))*100
# check manual vs fcn
expect_true(all(dr==M$d_ratio$d_ratio))
# check values havent changed
expect_equal(dr[[1]],14.00808,tolerance = 5e-6)
expect_equal(dr[[100]],43.44776,tolerance = 5e-6)
# just number of filtered columns
expect_true(ncol(predicted(M))==850)
expect_true(ncol(DE)-ncol(predicted(M))==729)
expect_true(ncol(DE)-ncol(predicted(M))==sum(dr>20))
})