From 4cdca7d29cc25491e74eec2cf7bb4087b3194a94 Mon Sep 17 00:00:00 2001 From: Michael Totty Date: Wed, 20 Nov 2024 16:19:18 -0500 Subject: [PATCH] NEWS update. --- NAMESPACE | 2 ++ NEWS.md | 5 ++++ R/biased_spots.R | 30 +++++++++++++++++++ R/flagVisiumOutliers.R | 61 ++++++++++++++++++++++++++++++++++++++ data/biased_spots.rda | Bin 0 -> 253 bytes inst/CITATION | 8 ++--- man/biased_spots.Rd | 33 +++++++++++++++++++++ man/flagVisiumOutliers.Rd | 38 ++++++++++++++++++++++++ 8 files changed, 172 insertions(+), 5 deletions(-) create mode 100644 R/biased_spots.R create mode 100644 R/flagVisiumOutliers.R create mode 100644 data/biased_spots.rda create mode 100644 man/biased_spots.Rd create mode 100644 man/flagVisiumOutliers.Rd diff --git a/NAMESPACE b/NAMESPACE index e4f0ab3..94d737a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(findArtifacts) +export(flagVisiumOutliers) export(localOutliers) export(localVariance) export(plotQCmetrics) @@ -27,3 +28,4 @@ importFrom(stats,kmeans) importFrom(stats,prcomp) importFrom(stats,resid) importFrom(stats,var) +importFrom(utils,data) diff --git a/NEWS.md b/NEWS.md index 1db4bcf..969e541 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # SpotSweeper Package News +# Verison 1.3.2 + +## New Features +- **Added** the 'flagVisiumOutliers()' function to identify and flag systematic outlier spots in Visium datasets. This feature enhances data quality by allowing users to efficiently detect and exclude problematic spots from downstream analyses. + # Version 1.3.1 ## Major Changes diff --git a/R/biased_spots.R b/R/biased_spots.R new file mode 100644 index 0000000..294edaa --- /dev/null +++ b/R/biased_spots.R @@ -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" diff --git a/R/flagVisiumOutliers.R b/R/flagVisiumOutliers.R new file mode 100644 index 0000000..3702ecb --- /dev/null +++ b/R/flagVisiumOutliers.R @@ -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) +} diff --git a/data/biased_spots.rda b/data/biased_spots.rda new file mode 100644 index 0000000000000000000000000000000000000000..7565933d002ea8d049ffc85689d5481d634e46de GIT binary patch literal 253 zcmVcNw@T@exV7)G3vmt}_-k!eM*V>JjjYl!=+RqS{ zZ8L_48{3s_RZktt#=77T#JsXwyL{?kJ}J-Oy$ntL56-?Y^?m=1<;U|2DutEvx&Z(H DU`%;N literal 0 HcmV?d00001 diff --git a/inst/CITATION b/inst/CITATION index 8d9500d..3dab3b8 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -1,4 +1,4 @@ -citHeader("SpotSweeper is described in the following preprint:") +citHeader("To cite SpotSweeper in publications, please use the following reference:") citEntry( entry = "Article", @@ -8,8 +8,6 @@ citEntry( as.person("Boyi Guo")), journal = "bioRxiv", year = "2024", - doi = "10.1101/2024.06.06.597765v1", - textVersion = paste0( - "Totty et al. (2024), SpotSweeper: spatially-aware quality control for spatial transcriptomics, bioRxiv." - ) + doi = "10.1101/2024.06.06.597765", + textVersion = "Michael Totty, Stephanie Hicks, Boyi Guo (2024). SpotSweeper: spatially-aware quality control for spatial transcriptomics. bioRxiv. doi:10.1101/2024.06.06.597765." ) diff --git a/man/biased_spots.Rd b/man/biased_spots.Rd new file mode 100644 index 0000000..827e493 --- /dev/null +++ b/man/biased_spots.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/biased_spots.R +\docType{data} +\name{biased_spots} +\alias{biased_spots} +\title{Biased Spots Data} +\format{ +A \code{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.} +} +} +\source{ +The \code{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. +} +\usage{ +data(biased_spots) +} +\description{ +The \code{biased_spots} dataset is a \code{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 +\code{flagVisiumOutliers} function to flag and exclude these outlier spots from +downstream analyses, thereby enhancing data quality and reliability. +} +\examples{ +data(biased_spots) +} +\keyword{datasets} diff --git a/man/flagVisiumOutliers.Rd b/man/flagVisiumOutliers.Rd new file mode 100644 index 0000000..416d2e8 --- /dev/null +++ b/man/flagVisiumOutliers.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/flagVisiumOutliers.R +\name{flagVisiumOutliers} +\alias{flagVisiumOutliers} +\title{Flag Visium Outliers in SpatialExperiment Objects} +\usage{ +flagVisiumOutliers(spe) +} +\arguments{ +\item{spe}{A \code{SpatialExperiment} object containing spatial transcriptomics data. +The object must include \code{array_row} and \code{array_col} columns in its \code{colData} that +specify the spatial coordinates of each spot.} +} +\value{ +A \code{SpatialExperiment} object identical to the input \code{spe} but with an additional +logical column \code{systematic_outliers} in its \code{colData}. This column indicates whether +each spot is flagged as a technical outlier (\code{TRUE}) or not (\code{FALSE}). +} +\description{ +The \code{flagVisiumoutliers} function identifies and flags Visium systematic outlier spots in a +\code{SpatialExperiment} object based on barcodes. These outliers are marked in the \code{colData} +of the \code{SpatialExperiment} object, allowing users to exclude them from downstream analyses +to enhance data quality and reliability. +} +\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] + +}