-
Notifications
You must be signed in to change notification settings - Fork 14
/
test_readGeoMxSet.R
223 lines (183 loc) · 11.9 KB
/
test_readGeoMxSet.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Return colnames and rownames of testData@assayData$expr comparing to expected
# Return colnames and rownames of testData@phenoData@data comparing to expected
# Return colnames and rownames of testData@protocolData@data comparing to expected
# Return genes of testData@featureData@data comparing to expected
# Return testData@experimentData comparing to expected
library(GeomxTools)
library(testthat)
library(stringr)
datadir <- system.file("extdata", "DSP_NGS_Example_Data",
package="GeomxTools")
DCCFiles <- dir(datadir, pattern=".dcc$", full.names=TRUE)
PKCFiles <- unzip(zipfile = file.path(datadir, "/pkcs.zip"))
SampleAnnotationFile <- file.path(datadir, "annotations.xlsx")
testData <-
suppressWarnings(readNanoStringGeoMxSet(dccFiles = DCCFiles,
pkcFiles = PKCFiles,
phenoDataFile = SampleAnnotationFile,
phenoDataSheet = "CW005",
phenoDataDccColName = "Sample_ID",
protocolDataColNames = c("aoi",
"cell_line",
"roi_rep",
"pool_rep",
"slide_rep"),
experimentDataColNames = c("panel")))
pkcFile <- readPKCFile(PKCFiles)
DCCFiles <- DCCFiles[!basename(DCCFiles) %in% unique(sData(testData)$NTC_ID)]
# Spec 1: test that the column names and the rownames of testData@assayData$exprs match those in DCC files and PKC Files respectively:------
testthat::test_that("test that the column names and the rownames of testData@assayData$exprs match those in DCC files and PKC Files respectively", {
expect_true(all(basename(DCCFiles) %in% colnames(testData@assayData$exprs)))
expect_true(all(unique(pkcFile$RTS_ID) %in% rownames(testData@assayData$exprs)))
})
# Spec 2: test that the column names and the rownames of testData@phenoData$data match those in DCC files and PKC Files respectively:------
testthat::test_that("test that the column names and the rownames of testData@phenoData$exprs match those in DCC files and PKC Files respectively", {
phenoDataDccColName <- "Sample_ID"
protocolDataColNames <- c("aoi",
"cell_line",
"roi_rep",
"pool_rep",
"slide_rep")
experimentDataColNames <- c("panel")
pheno_tab <- readxl::read_xlsx(SampleAnnotationFile, sheet = 'CW005')
colnames(pheno_tab) <- str_replace_all(colnames(pheno_tab),'\\.',' ')
expect_true(all(basename(DCCFiles) %in% rownames(testData@phenoData@data)))
expect_true(all(colnames(pheno_tab) %in% c(names(testData@phenoData@data), # what is pheno_tab?
phenoDataDccColName,
protocolDataColNames,
experimentDataColNames)))
})
# Spec 3: test that the column names and the rownames of testData@protocolData$data match those in DCC files and PKC Files respectively:------
testthat::test_that("test that the column names and the rownames of testData@protocolData$exprs match those in DCC files and PKC Files respectively", {
protocolDataColNames <- c("aoi",
"cell_line",
"roi_rep",
"pool_rep",
"slide_rep")
expect_true(all(basename(DCCFiles) %in% rownames(testData@protocolData@data)))
expect_true(all(protocolDataColNames %in% names(testData@protocolData@data)))
})
# Spec 4: test that the genes in testData@featureData@data match those in PKC Files:------
testthat::test_that("test that the genes in testData@featureData$exprs match those in PKC Files", {
expect_true(dim(testData@featureData@data)[1] == length(unique(pkcFile$RTS_ID))) # QuickBase: length(unique(pkcFile$Gene))
expect_true(all(unique(pkcFile$RTS_ID) %in% testData@featureData@data$RTS_ID))
})
# Spec 5: test that the names in testData@experimentData@other are in correct format:------
testthat::test_that("test that the names in testData@experimentData@other are in correct format", {
experimentDataColNames <- c("panel")
experimentDataColNames <- c(experimentDataColNames,
"PKCFileName",
"PKCFileVersion",
"PKCFileDate",
"AnalyteType",
"MinArea",
"MinNuclei")
expect_true(all(experimentDataColNames %in% names(testData@experimentData@other)))
})
#Spec 6: test that the counts in testData@assayData$exprs match those in DCC files
testthat::test_that("test that the counts of testData@assayData$exprs match those in DCC files", {
correct <- TRUE
i <- 1
while(correct == TRUE & i < length(DCCFiles)){
dccFile <- suppressWarnings(readDccFile(DCCFiles[i]))
mtxCount <- testData@assayData$exprs[,basename(DCCFiles[i])]
genes <- match(dccFile$Code_Summary$RTS_ID, names(mtxCount))
correct <- all(mtxCount[genes] == dccFile$Code_Summary$Count) & all(mtxCount[!genes] == 0)
i <- i+1
}
expect_true(correct)
})
n_aois <- 15
testData <-
suppressWarnings(readNanoStringGeoMxSet(dccFiles = DCCFiles,
pkcFiles = PKCFiles,
phenoDataFile = SampleAnnotationFile,
phenoDataSheet = "CW005",
phenoDataDccColName = "Sample_ID",
protocolDataColNames = c("aoi",
"cell_line",
"roi_rep",
"pool_rep",
"slide_rep"),
experimentDataColNames = c("panel"),
col_types = c(rep("text", 4), "numeric", rep("text", 2),
"numeric", rep("text", 4)),
n_max = n_aois + 1))
# Spec 7: test that ... gets translated to read_xlsx():------
testthat::test_that("test that ... gets translated to read_xlsx()", {
expect_true(dim(testData)[2] == n_aois)
expect_true(class(pData(testData)$roi) == "numeric")
expect_true(class(pData(testData)$area) == "numeric")
})
# Spec 8: test that only valid ... gets translated to read_xlsx():------
testthat::test_that("test that only valid ... gets translated to read_xlsx()", {
expect_error(testData <-
suppressWarnings(readNanoStringGeoMxSet(dccFiles = DCCFiles,
pkcFiles = PKCFiles,
phenoDataFile = SampleAnnotationFile,
phenoDataSheet = "CW005",
phenoDataDccColName = "Sample_ID",
protocolDataColNames = c("aoi",
"cell_line",
"roi_rep",
"pool_rep",
"slide_rep"),
experimentDataColNames = c("panel"),
trim_ws = c(rep("text", 4), "numeric", rep("text", 2),
"numeric", rep("text", 4)))))
})
proteinDatadir <- system.file("extdata", "DSP_Proteogenomics_Example_Data",
package="GeomxTools")
proteinPKCs <- unzip(zipfile = file.path(proteinDatadir, "/pkcs.zip"))
# Spec 10. PKCs are removed if they aren't in the provided config file.
testthat::test_that("PKCs are removed if they aren't in the config", {
testDataWithExtraConfig <-
suppressWarnings(readNanoStringGeoMxSet(dccFiles = DCCFiles,
pkcFiles = c(PKCFiles, proteinPKCs[1]),
phenoDataFile = SampleAnnotationFile,
phenoDataSheet = "CW005",
phenoDataDccColName = "Sample_ID",
protocolDataColNames = c("aoi",
"cell_line",
"roi_rep",
"pool_rep",
"slide_rep"),
experimentDataColNames = c("panel"),
configFile = paste0(datadir, "/fakeTesting_config.ini")))
expect_identical(testData@annotation, testDataWithExtraConfig@annotation)
expect_identical(rownames(testData), rownames(testDataWithExtraConfig))
expect_identical(fData(testData), fData(testDataWithExtraConfig))
})
DCCFiles <- unzip(zipfile = file.path(proteinDatadir, "/DCCs.zip"))
annots <- file.path(proteinDatadir, "Annotation.xlsx")
RNAData <- suppressWarnings(readNanoStringGeoMxSet(dccFiles = DCCFiles,
pkcFiles = proteinPKCs,
phenoDataFile = annots,
phenoDataSheet = "Annotations",
phenoDataDccColName = "Sample_ID",
protocolDataColNames = c("Tissue",
"Segment_Type",
"ROI.Size")))
ProteinData <- suppressWarnings(readNanoStringGeoMxSet(dccFiles = DCCFiles,
pkcFiles = proteinPKCs,
phenoDataFile = annots,
phenoDataSheet = "Annotations",
phenoDataDccColName = "Sample_ID",
protocolDataColNames = c("Tissue",
"Segment_Type",
"ROI.Size"),
analyte = "protein"))
# Spec 11: Only a single analyte is read in to a GeomMxSe object
testthat::test_that("only a single analyte is read in to a GeoMxSet object",{
expect_false(dim(RNAData)["Features"] == dim(ProteinData)["Features"])
expect_true(dim(RNAData)["Samples"] == dim(ProteinData)["Samples"])
expect_false(analyte(RNAData) == analyte(ProteinData))
expect_true(analyte(RNAData) == "RNA")
expect_true(analyte(ProteinData) == "Protein")
expect_true(featureType(RNAData) == "Probe")
expect_true(featureType(ProteinData) == "Target")
expect_false(all(annotation(RNAData) == annotation(ProteinData)))
expect_false(any(rownames(RNAData) %in% rownames(ProteinData)))
expect_true(all(colnames(RNAData) %in% colnames(ProteinData)))
expect_true(all(sData(RNAData) == sData(ProteinData)))
})