Browse code

add tests

add tests for d-ratio to check it filters as expected and computes the ratio correctly

Gavin Rhys Lloyd authored on 10/07/2023 11:04:38
Showing 1 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,33 @@
1
+# filter d-ratio
2
+test_that('d-ratio filter works as expected',{
3
+    set.seed('57475')
4
+    # DatasetExperiment
5
+    DE = MTBLS79_DatasetExperiment(filtered=TRUE)
6
+    M = dratio_filter(
7
+        threshold=20,
8
+        qc_label = 'QC',
9
+        factor_name='Class'
10
+    )
11
+    M = model_apply(M,DE)
12
+    
13
+    # manually compute d-ratio
14
+    qc_mad=unlist(
15
+        lapply(DE$data[DE$sample_meta$Class=='QC',],mad,na.rm=TRUE)
16
+    )
17
+    sa_mad=unlist(
18
+        lapply(DE$data[DE$sample_meta$Class!='QC',],mad,na.rm=TRUE)
19
+    )
20
+    dr = (qc_mad/(qc_mad+sa_mad))*100
21
+    
22
+    # check manual vs fcn
23
+    expect_true(all(dr==M$d_ratio$d_ratio))
24
+    
25
+    # check values havent changed
26
+    expect_equal(dr[[1]],12.39,tolerance = 1e3)
27
+    expect_equal(dr[[100]],32.54,tolerance = 1e3)
28
+    
29
+    # just number of filtered columns
30
+    expect_true(ncol(predicted(M))==1052)
31
+    expect_true(ncol(DE)-ncol(predicted(M))==527)
32
+    expect_true(ncol(DE)-ncol(predicted(M))==sum(dr>20))
33
+})