View source: R/add_qc_metrics.R
add_qc_metrics | R Documentation |
This function identify spots in a
SpatialExperiment-class (SPE)
with outlier quality control values: low sum_umi
or sum_gene
, or high
expr_chrM_ratio
, utilizing scuttle::isOutlier. Also identifies in-tissue
edge spots and distance to the edge for each spot.
add_qc_metrics(spe, overwrite = FALSE)
spe |
a SpatialExperiment
object that has |
overwrite |
a |
The initial version of this function lives at https://github.com/LieberInstitute/Visium_SPG_AD/blob/master/code/07_spot_qc/01_qc_metrics_and_segmentation.R.
A SpatialExperiment
with added quality control information added to the colData()
.
scran_low_lib_size
shows spots that have a low library size.
scran_low_n_features
spots with a low number of expressed genes.
scran_high_Mito_percent
spots with a high percent of mitochondrial gene expression.
scran_discard
spots belonging to either scran_low_lib_size
,
scran_low_n_feature
, or scran_high_Mito_percent
.
edge_spot
spots that are automatically detected as the edge spots
of the in_tissue
section.
edge_distance
closest distance in number of spots to either the vertical or horizontal edge.
scran_low_lib_size_edge
spots that have a low library size and are an edge spot.
Louise A. Huuki-Myers
## Obtain the necessary data
spe_pre_qc <- fetch_data("spatialDLPFC_Visium_example_subset")
## For now, we fake out tissue spots in example data
spe_qc <- spe_pre_qc
spe_qc$in_tissue[spe_qc$array_col < 10] <- FALSE
## adds QC metrics to colData of the spe
spe_qc <- add_qc_metrics(spe_qc, overwrite = TRUE)
vars <- colnames(colData(spe_qc))
vars[grep("^(scran|edge)", vars)]
## visualize edge spots
vis_clus(spe_qc, sampleid = "Br6432_ant", clustervar = "edge_spot")
## specify your own colors
vis_clus(
spe_qc,
sampleid = "Br6432_ant",
clustervar = "edge_spot",
colors = c(
"TRUE" = "lightgreen",
"FALSE" = "pink",
"NA" = "red"
)
)
vis_gene(spe_qc, sampleid = "Br6432_ant", geneid = "edge_distance", minCount = -1)
## Visualize scran QC flags
## Check the spots with low library size as detected by scran::isOutlier()
vis_clus(spe_qc, sample_id = "Br6432_ant", clustervar = "scran_low_lib_size")
## Violin plot of library size with low library size highlighted in a
## different color.
scater::plotColData(spe_qc[, spe_qc$in_tissue], x = "sample_id", y = "sum_umi", colour_by = "scran_low_lib_size")
## Check any spots that scran::isOutlier() flagged
vis_clus(spe_qc, sampleid = "Br6432_ant", clustervar = "scran_discard")
## Low library spots that are on the edge of the tissue
vis_clus(spe_qc, sampleid = "Br6432_ant", clustervar = "scran_low_lib_size_edge")
## Use `low_library_size` (or other variables) and `edge_distance` as you
## please.
spe_qc$our_low_lib_edge <- spe_qc$scran_low_lib_size & spe_qc$edge_distance < 5
vis_clus(spe_qc, sample_id = "Br6432_ant", clustervar = "our_low_lib_edge")
## Clean up
rm(spe_qc, spe_pre_qc, vars)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.