Package 'SpaceMarkers'

Title: Spatial Interaction Markers
Description: Spatial transcriptomic technologies have helped to resolve the connection between gene expression and the 2D orientation of tissues relative to each other. However, the limited single-cell resolution makes it difficult to highlight the most important molecular interactions in these tissues. SpaceMarkers, R/Bioconductor software, can help to find molecular interactions, by identifying genes associated with latent space interactions in spatial transcriptomics.
Authors: Atul Deshpande [aut, cre] , Ludmila Danilova [ctb], Dimitrijs Lvovs [ctb]
Maintainer: Atul Deshpande <[email protected]>
License: MIT + file LICENSE
Version: 1.1.0
Built: 2024-09-22 04:36:01 UTC
Source: https://github.com/bioc/SpaceMarkers

Help Index


Latent Feature Space for each pattern

Description

A CoGAPS object where the major requirements for SpaceMarkers are the matrices of genes, barcodes and patterns learned of the latent-feature space

Format

CogapsResult object with 24228 features and 6 samples:

featureLoadings

Data frame of Gene for each pattern

sampleFactors

Data frame of cell barcodes and the 5 patterns

Value

A matrix of statistics for each pattern across each barcode


Curated Genes for example purposes

Description

A vector with genes selected based on previous runs of SpaceMarkers on the Visium 10x breast ductal carcinoma spatial transcriptomics dataset

Format

A vector with 114 pre-selected genes

Value

a vector of genes


find_genes_of_interest Identify genes associated with pattern interaction. This function identifies genes exhibiting significantly higher values of testMat in the Interaction region of the two patterns compared #' to regions with exclusive influence from either pattern. It uses Kruskal-Wallis test followed by posthoc analysis using Dunn's Test to identify the genes.

Description

find_genes_of_interest Identify genes associated with pattern interaction. This function identifies genes exhibiting significantly higher values of testMat in the Interaction region of the two patterns compared #' to regions with exclusive influence from either pattern. It uses Kruskal-Wallis test followed by posthoc analysis using Dunn's Test to identify the genes.

Usage

find_genes_of_interest(
    testMat,
    goodGenes = NULL,
    region,
    fdr.level = 0.05,
    analysis = c("enrichment", "overlap")
)

Arguments

testMat

A matrix of counts with cells as columns and genes as rows

goodGenes

A vector of user specified genes expected to interact a priori. The default for this is NULL as the function can find these genes itself

region

A data frame of the reference pattern regions that overlap with the other patterns

fdr.level

False Discovery Rate. The default value is 0.05.

analysis

a character string that specifies the type of analysis to carry out, whether overlap or enrichment.

Value

a list of genes exhibiting significantly higher values of testMat in the Interaction region of the two #' patterns compared to regions with exclusive influence from either pattern.


getInteractingGenes Calculate Interaction Regions and Associated Genes This function calculates statistically significant genes using a non-parametric Kruskal-Wallis test for genes in any one region of influence and a post hoc Dunn's test is used for analysis of genes between regions.

Description

getInteractingGenes Calculate Interaction Regions and Associated Genes This function calculates statistically significant genes using a non-parametric Kruskal-Wallis test for genes in any one region of influence and a post hoc Dunn's test is used for analysis of genes between regions.

Usage

getInteractingGenes(
  data,
  spPatterns,
  refPattern = "Pattern_1",
  mode = c("residual", "DE"),
  optParams = NULL,
  reconstruction = NULL,
  hotspots = NULL,
  minOverlap = 50,
  ...
)

Arguments

data

original spatial data matrix.

spPatterns

A data frame that contains the spatial coordinates for each cell type. The column names must include 'x' and 'y' as well as a set of numbered columns named 'Pattern_1.....N'.

refPattern

a character string that specifies the pattern whose "interaction" with every other pattern we want to study. The default value is "Pattern_1".

mode

SpaceMarkers mode of operation. Possible values are "residual" (the default) or "DE".

optParams

a matrix with dimensions 2 X N, where N is the number of patterns with optimal parameters for outlier detection calculated from function getSpatialParameters(). The first row contains the kernel width sigmaOpt for each pattern, and the second row is the threshOpt (outlier threshold) for each pattern. Users can also input their preferred param values. The default value is NULL.

reconstruction

reconstruction of the data matrix from latent spaces. Required for "residual" mode.

hotspots

a vector that specifies the patterns to compare to the 'refPattern'. The default is NULL which indicates that all patterns would be compared to the 'refPattern'.

minOverlap

a number that specifies the minimum overlap between genes in two patterns to be considered for the statistical tests. The default is 50.

...

Arguments passed to methods

Value

a list of data frames with information about the interacting genes of the refPattern and each latent feature pattern matrix (interacting_genes object). There is also a data frame with all of the regions of influence for any two of patterns (the hotspots object).

Examples

library(SpaceMarkers)
#Visium data links
urls <- read.csv(system.file("extdata","visium_data.txt",
package="SpaceMarkers",mustWork = TRUE))
counts_url <- urls[["visium_url"]][1]
sp_url <- urls[["visium_url"]][2]
#Remove present Directories if any
unlink(basename(sp_url))
unlink("spatial", recursive = TRUE)
files <- list.files(".")[grepl(basename(counts_url),list.files("."))]
unlink(files)
download.file(counts_url,basename(counts_url), mode = "wb")
counts_matrix<-load10XExpr(visiumDir=".",h5filename = basename(counts_url))
#Obtaining CoGAPS Patterns
cogaps_result <- readRDS(system.file("extdata","CoGAPS_result.rds",
package="SpaceMarkers",mustWork = TRUE))
features <- intersect(rownames(counts_matrix),rownames(
    slot(cogaps_result,"featureLoadings")))
barcodes <- intersect(colnames(counts_matrix),rownames(
    slot(cogaps_result,"sampleFactors")))
counts_matrix <- counts_matrix[features,barcodes]
cogaps_matrix <- slot(cogaps_result,"featureLoadings")[features,]%*%
    t(slot(cogaps_result,"sampleFactors")[barcodes,])
#Obtaining Spatial Coordinates
download.file(sp_url, basename(sp_url), mode = "wb")
untar(basename(sp_url))
spCoords <- load10XCoords(visiumDir = ".")
rownames(spCoords) <- spCoords$barcode
spCoords <- spCoords[barcodes,]
spPatterns <- cbind(spCoords,slot(cogaps_result,"sampleFactors")[barcodes,])
data("curated_genes")
spPatterns<-spPatterns[c("barcode","y","x","Pattern_1","Pattern_5")]
counts_matrix <- counts_matrix[curated_genes,]
cogaps_matrix <- cogaps_matrix[curated_genes, ]
data("optParams")
SpaceMarkersMode <- "DE"
ref_Pattern <- "Pattern_1"
SpaceMarkers_test <- getInteractingGenes(
    data=counts_matrix,reconstruction=NULL,
    optParams = optParams,
    spPatterns = spPatterns,
    refPattern = "Pattern_1",
    mode="DE",analysis="overlap")
#Remove present Directories if any
unlink(basename(sp_url))
unlink("spatial", recursive = TRUE)
files <- list.files(".")[grepl(basename(counts_url),list.files("."))]
unlink(files)

getSpatialFeatures Load spatial features

Description

This function loads spatial features from a file containing spatial features

Usage

getSpatialFeatures(filePath, method = "CoGAPS", featureNames = NULL)

Arguments

filePath

A string path to the location of the file containing the spatial features.

method

A string specifying the method used to obtain spatial features. e.g., "CoGAPS", "Seurat", or "BayesTME".

featureNames

An array of strings specifying the column names corresponding to the feature names. If input is NULL, in the case of CoGAPS and BayesTME, all features are selected In the case of Seurat, all metadata columns with "_Feature" suffix are selected.

Value

a matrix of spatial features with barcodes associated with individual coordinates

Examples

library(SpaceMarkers)
#CoGAPS data filePath
filePath <- system.file("extdata","CoGAPS_result.rds", 
package = "SpaceMarkers",mustWork = TRUE)
spFeatures <- getSpatialFeatures(filePath, method = "CoGAPS")
head(spFeatures)

getSpatialParameters Calculate the Optimal Parameters for Interacting Cells

Description

This function calculates the optimal width of the gaussian distribution (sigmaOpt) as well as the outlier threshold around the set of spots (thresOpt) for each pattern from a latent feature space.

Usage

getSpatialParameters(spatialPatterns, ...)

Arguments

spatialPatterns

A data frame that contains the spatial coordinates for each cell type. The column names must include 'x' and 'y' as well as a set of numbered columns named 'Pattern_1.....N'.

...

Arguments passed to methods

Value

a numeric matrix of sigmaOpts - the optimal width of the gaussian distribution, and the thresOpt - outlier threshold around the set of spots for each pattern

Examples

library(SpaceMarkers)
# Create test data
cells <- c()
test_num <- 500
for(i in 1:test_num){
    cells[length(cells)+1] <- paste0("cell_",i)
}
spPatterns <- data.frame(barcode = cells,
y = runif(test_num, min=0, max=test_num),
x = runif(test_num, min=0, max=test_num),
Pattern_1 = runif(test_num, min=0, max=1),
Pattern_2 = runif(test_num, min=0, max=1) )
# Call the getSpatialParameters function with the test data
optParams <- getSpatialParameters(spPatterns)

load10XCoords Load 10x Visium Spatial Coordinates

Description

This function loads spatial coordinates for each cell from a 10X Visium spatial folder.

Usage

load10XCoords(visiumDir, resolution = "lowres")

Arguments

visiumDir

A string path to the location of the folder containing the spatial coordinates. The folder in your visiumDir must be named 'spatial' and must contain files 'scalefactors_json.json' and 'tissue_positions_list.csv.'

resolution

A string specifying which values to look for in the .json object. Can be either lowres or highres.

Value

a data frame of the spatial coordinates ( x and y) for each spot/cell

Examples

library(SpaceMarkers)
#Visium data links
urls <- read.csv(system.file("extdata","visium_data.txt",
package = "SpaceMarkers",mustWork = TRUE))
sp_url <- urls[["visium_url"]][2]
# Spatial Coordinates
download.file(sp_url, basename(sp_url), mode = "wb")
untar(basename(sp_url))
spCoords <- load10XCoords(visiumDir = ".")
unlink("spatial", recursive = TRUE)
unlink("Visium_Human_Breast_Cancer_spatial.tar.gz")

load10XExpr load 10X Visium Expression Data

Description

This loads log-transformed 10X Visium expression data from standard 10X Visium folder.

Usage

load10XExpr(visiumDir = NULL, h5filename = "filtered_feature_bc_matrix.h5")

Arguments

visiumDir

A string path to the h5 file with expression information.

h5filename

A string of the name of the h5 file in the directory.

Value

A matrix of class dgeMatrix or Matrix that contains the expression info for each sample (cells) across multiple features (genes)

Examples

library(SpaceMarkers)
#Visium data links
urls <- read.csv(system.file("extdata","visium_data.txt",
package = "SpaceMarkers",mustWork = TRUE))
counts_url <- urls[["visium_url"]][1]
#Remove present Directories if any
files <- list.files(".")[grepl(basename(counts_url),list.files("."))]
unlink(files)
download.file(counts_url,basename(counts_url), mode = "wb")
counts_matrix<-load10XExpr(visiumDir=".",h5filename = basename(counts_url))
files <- list.files(".")[grepl(basename(counts_url),list.files("."))]
unlink(files)

Optimal paramters of 5 patterns from CoGAPS.

Description

A dataset with the optimal width of the gaussian distribution (sigmaOpt) and the outlier threshold around the set of spots (thresOpt) for each pattern obtained from CoGAPS. CoGAPS was ran on spatial transcriptomic data from a breast cancer sample.

Format

A data frame with 2 rows and 5 columns:

Pattern_1

immune cell pattern paramters

Pattern_2

Disp.1 parameters

Pattern_3

intraductal carcinoma (DCIS) parameters

Pattern_4

Disp.2 parameters

Pattern_5

invasive carcinoma lesion pattern paramters

Value

A matrix of optimal parameters for patterns identified by CoGAPS