Title: | Spatial Transcriptomics Analysis |
---|---|
Description: | Spaniel includes a series of tools to aid the quality control and analysis of Spatial Transcriptomics data. Spaniel can import data from either the original Spatial Transcriptomics system or 10X Visium technology. The package contains functions to create a SingleCellExperiment Seurat object and provides a method of loading a histologial image into R. The spanielPlot function allows visualisation of metrics contained within the S4 object overlaid onto the image of the tissue. |
Authors: | Rachel Queen [aut, cre] |
Maintainer: | Rachel Queen <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.21.0 |
Built: | 2024-12-02 06:18:58 UTC |
Source: | https://github.com/bioc/Spaniel |
Add coordinates to Object Adds output of Spot Detector coordinates to Seurat object or SCE object created by createSeurat/createSCE. Details about how to use Spot Detector can be found: https://github.com/SpatialTranscriptomicsResearch/st_spot_detector
addCoordinates(object, coordinatesFile, scaleFactor = NULL)
addCoordinates(object, coordinatesFile, scaleFactor = NULL)
object |
either a Seurat object or SCE |
coordinatesFile |
path to coordinates file exported from Spot Detector |
scaleFactor |
a scaling factor which can be used if the image file has been reduced in size after the coordinates were generated. For example if the image to be used is 10 percent the size of the original factor scaleFactor = 10 |
object
### load a SingleCellExperiment Object sceObj <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/sceData.rds")) ### path to coordinates file exported from spot detector coordinatesFile <- file.path(system.file(package = "Spaniel"), "spot_positions.tsv") sceObj <- addCoordinates(sceObj, coordinatesFile)
### load a SingleCellExperiment Object sceObj <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/sceData.rds")) ### path to coordinates file exported from spot detector coordinatesFile <- file.path(system.file(package = "Spaniel"), "spot_positions.tsv") sceObj <- addCoordinates(sceObj, coordinatesFile)
This function converts a count matrix into a SingleCellExperiment object. The barcodes for each spot are added to the coldata of the SingleCellExperiment object and are used in plotting the data.
createSCE(counts, barcodeFile, projectName=projectName, sectionNumber=sectionNo)
createSCE(counts, barcodeFile, projectName=projectName, sectionNumber=sectionNo)
counts |
Raw count matrix or data frame where each row represents a gene and each column represents barcoded location on a spatial transcriptomics slide. The columns should be named using the spot barcode (eg "GTCCGATATGATTGCCGC") |
barcodeFile |
a tab seperated barcode file supplied by Spatial Trancscriptomics. The file should contains three column: The first column contains the Spatial Transcriptomics barcode, the second and third column equate to the x and y location |
projectName |
The name of the project which is stored in the Seurat Object. |
sectionNumber |
The location of the sample on the slide |
A SingleCellExeriment Object
## Data is taken from DOI: 10.1126/science.aaf2403 examplecounts <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/counts.rds")) exampleBarcodes <- file.path(system.file(package = "Spaniel"), "1000L2_barcodes.txt") seuratOb <- createSCE(examplecounts, exampleBarcodes, projectName = "TestProj", sectionNumber = 1)
## Data is taken from DOI: 10.1126/science.aaf2403 examplecounts <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/counts.rds")) exampleBarcodes <- file.path(system.file(package = "Spaniel"), "1000L2_barcodes.txt") seuratOb <- createSCE(examplecounts, exampleBarcodes, projectName = "TestProj", sectionNumber = 1)
This function converts a count matrix into a Seurat object. The barcodes for each spot are added to the metadata of the Seurat object and are used in plotting the data.
createSeurat(counts, barcodeFile, projectName = projectName, sectionNumber = sectionNo)
createSeurat(counts, barcodeFile, projectName = projectName, sectionNumber = sectionNo)
counts |
Raw count matrix or data frame where each row represents a gene and each column represents barcoded location on a spatial transcriptomics slide. The columns should be named using the spot barcode (eg "GTCCGATATGATTGCCGC") |
barcodeFile |
a tab seperated barcode file supplied by Spatial Trancscriptomics. The file should contains three column: The first column contains the Spatial Transcriptomics barcode, the second and third column equate to the x and y location |
projectName |
The name of the project which is stored in the Seurat Object. |
sectionNumber |
The location of the sample on the slide |
A Seurat Object
## Data is taken from DOI: 10.1126/science.aaf2403 examplecounts <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/counts.rds")) exampleBarcodes <- file.path(system.file(package = "Spaniel"), "1000L2_barcodes.txt") SeuratObj <- createSeurat(examplecounts, exampleBarcodes, projectName = "TestProj", sectionNumber = 1 )
## Data is taken from DOI: 10.1126/science.aaf2403 examplecounts <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/counts.rds")) exampleBarcodes <- file.path(system.file(package = "Spaniel"), "1000L2_barcodes.txt") SeuratObj <- createSeurat(examplecounts, exampleBarcodes, projectName = "TestProj", sectionNumber = 1 )
A function to select to import 10X data into an SCE object
createVisiumSCE(tenXDir = "../outs", resolution = "Low")
createVisiumSCE(tenXDir = "../outs", resolution = "Low")
tenXDir |
The path to Space Ranger outs directory containing spatial directory and filtered_feature_bc_matric |
resolution |
Resolution of the tissue image to be used for plotting. Can be either "High", or "Low". Default is "Low". |
SingleCellExperimentObject
tenXDir <- file.path(system.file(package = "Spaniel"), "extdata/outs") sce <- createVisiumSCE(tenXDir, resolution = "Low")
tenXDir <- file.path(system.file(package = "Spaniel"), "extdata/outs") sce <- createVisiumSCE(tenXDir, resolution = "Low")
A function to mark the columns containing cluster information in the metadata or colData of a Seurat or SCE object. Columns are marked with "cluster_" prefix.
markClusterCol(object, pattern)
markClusterCol(object, pattern)
object |
Either a Seurat or SCE object containing clustering information |
pattern |
pattern indicating which columns contain cluster information |
A Seurat or SCE object
sceObj <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/sceData.rds")) sceObj <- markClusterCol(sceObj, "res")
sceObj <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/sceData.rds")) sceObj <- markClusterCol(sceObj, "res")
This function parses a HE image to use as the background for plots
parseImage(imgFile, imgType = "jpg")
parseImage(imgFile, imgType = "jpg")
imgFile |
Path to the image file |
imgType |
Type of image options jpg (default), png |
A rasterized grob
imgFile <- file.path(system.file(package = "Spaniel"), "extdata/outs/spatial/tissue_lowres_image.png") img <- parseImage(imgFile, imgType = "png")
imgFile <- file.path(system.file(package = "Spaniel"), "extdata/outs/spatial/tissue_lowres_image.png") img <- parseImage(imgFile, imgType = "png")
A function to filter spots from analysis. It requires selectSpots to be run first.
removeSpots(sObj, pointsToRemove = "points_to_remove.txt")
removeSpots(sObj, pointsToRemove = "points_to_remove.txt")
sObj |
Either a Seurat object (version 3) or a SingleCellExperiment object containing barcode coordinates in the metadata (Seurat) or colData (SingleCellExperiment). |
pointsToRemove |
path to points to remove file. Default is "points_to_remove.txt" |
A filtered Seurat or SingleCellExperiment Object
sceObj <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/sceData.rds")) toRemove <- file.path(system.file(package = "Spaniel"), "points_to_remove.txt") sceObj_filtered <- removeSpots(sObj = sceObj, pointsToRemove = toRemove)
sceObj <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/sceData.rds")) toRemove <- file.path(system.file(package = "Spaniel"), "points_to_remove.txt") sceObj_filtered <- removeSpots(sObj = sceObj, pointsToRemove = toRemove)
A function to visualise Spatial Transcriptomics. It requires a prepocessed Seurat Object or a SingleCellExperiment object as well as a rasterised image saved as an .rds object. There are 4 plots available in the app showing: a) the number of genes detected per spot, b) the number of reads detected per spot, c) clustering results, d) the gene expression of a selected gene." To view the clustering results the columns of the meta.data or colData containing clustering results must be prefixed with cluster_ . This can be done by using the markClusterCol() function included in Spaniel.
runShinySpaniel()
runShinySpaniel()
Runs a Shiny App
## mark the columns of metadata/colData that contain clustering ## information see ?markClusterCol for more details#' sObj <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/sceData.rds")) img <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/image.rds")) ## run shinySpaniel (upload data.rds and image.rds in the shiny app) ## Not Run: # runShinySpaniel()
## mark the columns of metadata/colData that contain clustering ## information see ?markClusterCol for more details#' sObj <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/sceData.rds")) img <- readRDS(file.path(system.file(package = "Spaniel"), "extdata/image.rds")) ## run shinySpaniel (upload data.rds and image.rds in the shiny app) ## Not Run: # runShinySpaniel()
A function to select spots to remove from analysis
selectSpots(sObj, imgObj)
selectSpots(sObj, imgObj)
sObj |
Either a Seurat object (version 3) or a SingleCellExperiment object containing barcode coordinates in the metadata (Seurat) or colData (SingleCellExperiment). |
imgObj |
a ggplot grob (see parseImage function) |
Runs a shiny application
## Run the shiny app (Not run): # selectSpots(sObj, imgObj) # Click on the spots to remove from downstream analysis. Once all the spots # have been selected close the shiny app window. A list of spots is # stored in a text file called points_to_remove.txt in the working directory. # Once this step has been run a filtered Seurat or SCE object can be # created using removeSpots (see removeSpots for more details)
## Run the shiny app (Not run): # selectSpots(sObj, imgObj) # Click on the spots to remove from downstream analysis. Once all the spots # have been selected close the shiny app window. A list of spots is # stored in a text file called points_to_remove.txt in the working directory. # Once this step has been run a filtered Seurat or SCE object can be # created using removeSpots (see removeSpots for more details)
This function overlays information from a Seurat object or SingleCellExperiment object containing barcodes onto a H & E image. There are 4 plots available showing a) the number of genes detected per spot, b) the number of reads detected per spot, c) clustering results, d) the gene expression of a selected gene.
spanielPlot(object, grob = NULL, techType = "Original", byCoord = FALSE, imgDims = NULL, plotType = c("NoGenes", "CountsPerSpot", "Cluster", "Gene"), gene= NULL, clusterRes = NULL, customTitle = NULL, scaleData = TRUE, showFilter = NULL, ptSize = 2, ptSizeMin = 0, ptSizeMax = 5)
spanielPlot(object, grob = NULL, techType = "Original", byCoord = FALSE, imgDims = NULL, plotType = c("NoGenes", "CountsPerSpot", "Cluster", "Gene"), gene= NULL, clusterRes = NULL, customTitle = NULL, scaleData = TRUE, showFilter = NULL, ptSize = 2, ptSizeMin = 0, ptSizeMax = 5)
object |
Either a Seurat object (version 3) or a SingleCellExperiment object containing barcode coordinates in the metadata (Seurat) or colData (SingleCellExperiment). |
grob |
an grob to be used as the backgound image see(parseImage). This is used for original Spatial Transcriptomics objects but not Visium |
techType |
Either 1) "Original" (default) for the original Spatial Transcriptomics slides where the image has been cropped to the edge of the spots 2) "Visium" for 10X slides. |
byCoord |
TRUE/FALSE option to plot original Spatial Transcriptomics data using pixel coordinates instead of by spot coordinates. Not required if techType = "Visium". Default is FALSE. |
imgDims |
pixel dimensions of histological image. Required when byCoord parameter is set to TRUE, Not required if techType = "Visium". |
plotType |
There are 5 types of plots avaiable: 1) NoGenes - This shows the number of genes per spot and uses information from "nFeature_RNA" column of Seurat object or "detected" from a SingleCellExperiment object. 2) CountsPerSpot - This shows the number of counts per spot. It uses information from "nCount_RNA" column of Seurat object or "sum" from a singleCellExperiment object. 3) Cluster - This plot is designed to show clustering results stored in the meta.data or colData of an object 4) Gene- This plot shows the expression of a single gene. This plot uses scaled/normalised expressin data from the scale.data slot of Seurat object or logcounts of a SingleCellExperiment object. 5) Other - A generic plot to plot any column from the meta.data or colData of an object. |
gene |
Gene to plot |
clusterRes |
which cluster resolution to plot |
customTitle |
Specify plot title (optional) |
scaleData |
Show scaled data on plot (default is TRUE) |
showFilter |
Logical filter showing pass/fail for spots |
ptSize |
Point size used for cluster plot default is 2 |
ptSizeMin |
Minimum point size used for QC and Gene Expression plots default is 0 |
ptSizeMax |
Maximum point size used for QC and Gene Expression plots default is 5 |
A ggplot spatial transcriptomics plot
pathToTenXOuts <- file.path(system.file(package = "Spaniel"), "extdata/outs") sceObj <- createVisiumSCE(tenXDir=pathToTenXOuts, resolution="Low") filter <- sceObj$detected > 0 spanielPlot(object = sceObj, plotType = "NoGenes", showFilter = filter, techType = "Visium", ptSizeMax = 3)
pathToTenXOuts <- file.path(system.file(package = "Spaniel"), "extdata/outs") sceObj <- createVisiumSCE(tenXDir=pathToTenXOuts, resolution="Low") filter <- sceObj$detected > 0 spanielPlot(object = sceObj, plotType = "NoGenes", showFilter = filter, techType = "Visium", ptSizeMax = 3)