-
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.
- Loading branch information
Showing
8 changed files
with
172 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Biased Spots Data | ||
#' | ||
#' The `biased_spots` dataset is a `data.frame` containing information about specific | ||
#' spatial spots identified as technical outliers in spatial transcriptomics experiments. | ||
#' Each entry represents a biased spot characterized by its spatial coordinates | ||
#' (row and column) and a unique barcode. This dataset is utilized by the | ||
#' `flagVisiumOutliers` function to flag and exclude these outlier spots from | ||
#' downstream analyses, thereby enhancing data quality and reliability. | ||
#' | ||
#' @docType data | ||
#' | ||
#' @usage data(biased_spots) | ||
#' | ||
#' @format A `data.frame` with the following columns: | ||
#' \describe{ | ||
#' \item{row}{Integer. The row position of a biased spot within the spatial grid.} | ||
#' \item{col}{Integer. The column position of a biased spot within the spatial grid.} | ||
#' \item{barcode}{Character. A unique identifier corresponding to the spatial transcriptomics barcode of the biased spot.} | ||
#' } | ||
#' | ||
#' @keywords datasets | ||
#' | ||
#' @source | ||
#' The `biased_spots.rds` file was generated in the analysis of local outliers. | ||
#' See https://github.com/boyiguo1/Manuscript-SpotSweeper/blob/main/code/03_Visium/figure_3.R for more details. | ||
#' | ||
#' | ||
#' @examples | ||
#' data(biased_spots) | ||
"biased_spots" |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#' Flag Visium Outliers in SpatialExperiment Objects | ||
#' | ||
#' The `flagVisiumoutliers` function identifies and flags Visium systematic outlier spots in a | ||
#' `SpatialExperiment` object based on barcodes. These outliers are marked in the `colData` | ||
#' of the `SpatialExperiment` object, allowing users to exclude them from downstream analyses | ||
#' to enhance data quality and reliability. | ||
#' | ||
#' @param spe A `SpatialExperiment` object containing spatial transcriptomics data. | ||
#' The object must include `array_row` and `array_col` columns in its `colData` that | ||
#' specify the spatial coordinates of each spot. | ||
#' | ||
#' @return A `SpatialExperiment` object identical to the input `spe` but with an additional | ||
#' logical column `systematic_outliers` in its `colData`. This column indicates whether | ||
#' each spot is flagged as a technical outlier (`TRUE`) or not (`FALSE`). | ||
#' | ||
#' @importFrom utils data | ||
#' @import SpatialExperiment | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' library(SpotSweeper) | ||
#' library(SpatialExperiment) | ||
#' | ||
#' # load example data | ||
#' spe <- STexampleData::Visium_humanDLPFC() | ||
#' | ||
#' # Flag outlier spots | ||
#' spe <- flagVisiumOutliers(spe) | ||
#' | ||
#' # drop outlier spots | ||
#' spe <- spe[, !colData(spe)$systematic_outliers] | ||
#' | ||
flagVisiumOutliers <- function(spe) { | ||
|
||
# Check if 'spe' is a SpatialExperiment object | ||
# Check if 'spe' is a valid object with required components | ||
if (!("SpatialExperiment" %in% class(spe))) { | ||
stop("Input data must be either a SpatialExperiment") | ||
} | ||
|
||
# Load the biased_spots dataset | ||
data("biased_spots", package = "SpotSweeper", envir = environment()) | ||
|
||
# Create a logical mask for cells to drop | ||
drop_mask <- rep(FALSE, ncol(spe)) # Start with a mask that keeps everything | ||
|
||
# For each pair of (row, col) in biased_spots, mark the matching cells for removal | ||
for (i in 1:nrow(biased_spots)) { | ||
row_match <- spe$array_row == biased_spots$row[i] | ||
col_match <- spe$array_col == biased_spots$col[i] | ||
|
||
# Mark cells for removal where both conditions are true | ||
drop_mask <- drop_mask | (row_match & col_match) | ||
} | ||
|
||
# Add the drop_mask as a new column in colData | ||
colData(spe)$systematic_outliers <- drop_mask | ||
|
||
return(spe) | ||
} |
Binary file not shown.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.