Skip to content

Commit

Permalink
NEWS update.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicTott committed Nov 20, 2024
1 parent 3d4e417 commit 4cdca7d
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(findArtifacts)
export(flagVisiumOutliers)
export(localOutliers)
export(localVariance)
export(plotQCmetrics)
Expand All @@ -27,3 +28,4 @@ importFrom(stats,kmeans)
importFrom(stats,prcomp)
importFrom(stats,resid)
importFrom(stats,var)
importFrom(utils,data)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 30 additions & 0 deletions R/biased_spots.R
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"
61 changes: 61 additions & 0 deletions R/flagVisiumOutliers.R
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 added data/biased_spots.rda
Binary file not shown.
8 changes: 3 additions & 5 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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."
)
33 changes: 33 additions & 0 deletions man/biased_spots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions man/flagVisiumOutliers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4cdca7d

Please sign in to comment.