-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated localOutliers example and unit test
- Loading branch information
Showing
2 changed files
with
75 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,57 @@ | ||
# run examples from localOutliers() function documentation | ||
example(localOutliers, echo = FALSE) | ||
library(SpatialExperiment) | ||
|
||
test_that("example objects have correct class", { | ||
# matrices?? | ||
}) | ||
# load example data | ||
spe <- STexampleData::Visium_humanDLPFC() | ||
|
||
test_that("example objects have correct dimensions", { | ||
expect_equal(dim(spe), c(X, XXXXX)) | ||
}) | ||
# change from gene id to gene names | ||
rownames(spe) <- rowData(spe)$gene_name | ||
|
||
test_that("example objects gives correct number of outliers", { | ||
expect_equal(length(colnames(colData(spe))), XY) | ||
}) | ||
# drop out-of-tissue spots | ||
spe <- spe[, spe$in_tissue == 1] | ||
spe <- spe[, !is.na(spe$ground_truth)] | ||
|
||
# Identifying the mitochondrial transcripts in our SpatialExperiment. | ||
is.mito <- rownames(spe)[grepl("^MT-", rownames(spe))] | ||
|
||
# Calculating QC metrics for each spot using scuttle | ||
spe <- scuttle::addPerCellQCMetrics(spe, subsets = list(Mito = is.mito)) | ||
colnames(colData(spe)) | ||
|
||
# Identifying local outliers using SpotSweeper | ||
spe <- localOutliers(spe, | ||
metric = "sum", | ||
direction = "lower", | ||
log = TRUE | ||
) | ||
|
||
test_that("combined SPE gives contains correct colData", { | ||
spe <- localOutliers(spe, | ||
metric = "detected", | ||
direction = "lower", | ||
log = TRUE | ||
) | ||
|
||
spe <- localOutliers(spe, | ||
metric = "subsets_Mito_percent", | ||
direction = "higher", | ||
log = FALSE | ||
) | ||
|
||
# combine all outliers into "local_outliers" column | ||
spe$local_outliers <- as.logical(spe$sum_outliers) | | ||
as.logical(spe$detected_outliers) | | ||
as.logical(spe$subsets_Mito_percent_outliers) | ||
|
||
|
||
|
||
# === Tests === | ||
test_that("example objects have correct class", { | ||
expect_s4_class(spe, "SpatialExperiment") | ||
}) | ||
|
||
test_that("correct outliers were found", { | ||
expect_equal(sum(as.logical(spe$sum_outliers)), 7) | ||
expect_equal(sum(as.logical(spe$detected_outliers)), 9) | ||
expect_equal(sum(as.logical(spe$subsets_Mito_percent_outliers)), 2) | ||
expect_equal(sum(as.logical(spe$local_outliers)), 11) | ||
}) |