Title: | This package provides methods for analysing spatial transcriptomics data and for discovering gene clusters |
---|---|
Description: | This package addresses two broad areas. It allows for in-depth analysis of spatial transcriptomic data by identifying tissue neighbourhoods. These are contiguous regions of tissue surrounding individual cells. 'CatsCradle' allows for the categorisation of neighbourhoods by the cell types contained in them and the genes expressed in them. In particular, it produces Seurat objects whose individual elements are neighbourhoods rather than cells. In addition, it enables the categorisation and annotation of genes by producing Seurat objects whose elements are genes. |
Authors: | Anna Laddach [aut] , Michael Shapiro [aut, cre] |
Maintainer: | Michael Shapiro <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0 |
Built: | 2024-11-29 04:30:47 UTC |
Source: | https://github.com/bioc/CatsCradle |
This function takes a matrix where rows are features and columns are cells, and a neighbourhood list, and creates an matrix where columns are the neighbourhoods, the rows are are the features and the values are aggregated expression values for cells in each neighbourhood.
aggregateFeatureMatrix(M, nbhdList, aggregateFunction)
aggregateFeatureMatrix(M, nbhdList, aggregateFunction)
M |
|
nbhdList |
|
aggregateFunction |
|
a matrix giving aggregated gene expression for a cell's neighbourhood.
This function takes a Seurat object and a list of neighbourhoods and creates a Seurat object where the columns are the neighbourhoods, the rows are are the genes and the values are gene expression totals for the cells in each neighbourhood
aggregateGeneExpression( f, neighbourhoods, verbose = TRUE, returnType = "Seurat" )
aggregateGeneExpression( f, neighbourhoods, verbose = TRUE, returnType = "Seurat" )
f |
|
neighbourhoods |
|
verbose |
|
returnType |
|
a Seurat object giving total gene expression in each neighbourhood or SingleCellExperiment
getExample = make.getExample() smallXenium = getExample('smallXenium',toy=TRUE) extendedNeighbours = getExample('extendedNeighbours',toy=TRUE) agg = aggregateGeneExpression(smallXenium,extendedNeighbours,verbose=FALSE)
getExample = make.getExample() smallXenium = getExample('smallXenium',toy=TRUE) extendedNeighbours = getExample('extendedNeighbours',toy=TRUE) agg = aggregateGeneExpression(smallXenium,extendedNeighbours,verbose=FALSE)
This function returns a numeric indicating which gene sets it does and does not belong to. This vector can be normalised to account for the sizes of the sets.
annotateGeneAsVector(gene, geneSets, normalise = FALSE)
annotateGeneAsVector(gene, geneSets, normalise = FALSE)
gene |
|
geneSets |
|
normalise |
|
a numeric
hallmark = make.getExample()('hallmark') Myc = annotateGeneAsVector('Myc',hallmark) MycNormalised = annotateGeneAsVector('Myc',hallmark,TRUE)
hallmark = make.getExample()('hallmark') Myc = annotateGeneAsVector('Myc',hallmark) MycNormalised = annotateGeneAsVector('Myc',hallmark,TRUE)
This essentially inverts a list of gene sets. It takes a list (e.g., Hallmark or GO) where each list item is a name of a gene set and gives the genes in that set and returns a list where each item is a gene and gives the gene sets that gene is in.
annotateGenesByGeneSet(geneSets)
annotateGenesByGeneSet(geneSets)
geneSets |
|
A list where names are genes and values are lists of terms
hallmark = make.getExample()('hallmark') annotatedGenes = annotateGenesByGeneSet(hallmark)
hallmark = make.getExample()('hallmark') annotatedGenes = annotateGenesByGeneSet(hallmark)
This takes a data frame of interaction counts as found by countLRInteractionsPerCell(), the underlying Seurat object and the neighbourhood Seurat object and annotates the counts with the cell type and the neighbourhood type corresponding to the cells of the interaction counts.
annotateLRInteractionCounts(interactionCounts, obj, nbhdObj)
annotateLRInteractionCounts(interactionCounts, obj, nbhdObj)
interactionCounts |
|
obj |
|
nbhdObj |
|
This returns the interaction counts annotated with the cell type and neighbourhood type of each cell.
This function converts a matrix as found by cellTypesPerCellTypeMatrix into a directed igraph whose vertices correspond to seurat_clusters and whose edge correspond to occupancy fraction.
cellTypesPerCellTypeGraphFromCellMatrix( M, colours = NULL, selfEdges = FALSE, minWeight = 0, edgeWeighting = 20, edgeCurved = 0.2, arrowSize = 4, arrowWidth = 4, plotGraph = TRUE )
cellTypesPerCellTypeGraphFromCellMatrix( M, colours = NULL, selfEdges = FALSE, minWeight = 0, edgeWeighting = 20, edgeCurved = 0.2, arrowSize = 4, arrowWidth = 4, plotGraph = TRUE )
M |
|
colours |
|
selfEdges |
|
minWeight |
|
edgeWeighting |
|
edgeCurved |
|
arrowSize |
|
arrowWidth |
|
plotGraph |
|
This returns a directed igraph whose vertices are the cell types and whose arrows indicate "ownership" of cells of the target type by neighbourhoods of cells of the source type. Layout is done witht the FR algorithm and coordinates are found in the coords attribute of G. If colours were supplied these are found in color attribute of V(G). Edge weights and widths are found in the weight and width attributes of E(G).
getExample = make.getExample() cellTypesPerCellTypeMatrix = getExample('cellTypesPerCellTypeMatrix') colours = getExample('colours') G = cellTypesPerCellTypeGraphFromCellMatrix(cellTypesPerCellTypeMatrix, minWeight = 0.05, colours = colours)
getExample = make.getExample() cellTypesPerCellTypeMatrix = getExample('cellTypesPerCellTypeMatrix') colours = getExample('colours') G = cellTypesPerCellTypeGraphFromCellMatrix(cellTypesPerCellTypeMatrix, minWeight = 0.05, colours = colours)
This function takes a neighbourhood-by-cell type matrix and produces a directed igraph showing the fractions of cells of each type in the neighbourhoods around cells of each type.
cellTypesPerCellTypeGraphFromNbhdMatrix( nbhdByCellType, clusters, colours = NULL, selfEdges = FALSE, minWeight = 0, edgeWeighting = 20, edgeCurved = 0.2, arrowSize = 4, arrowWidth = 4, plotGraph = TRUE )
cellTypesPerCellTypeGraphFromNbhdMatrix( nbhdByCellType, clusters, colours = NULL, selfEdges = FALSE, minWeight = 0, edgeWeighting = 20, edgeCurved = 0.2, arrowSize = 4, arrowWidth = 4, plotGraph = TRUE )
nbhdByCellType |
|
clusters |
|
colours |
|
selfEdges |
|
minWeight |
|
edgeWeighting |
|
edgeCurved |
|
arrowSize |
|
arrowWidth |
|
plotGraph |
|
This returns a directed igraph whose vertices are the cell types and whose arrows indicate "ownership" of cells of the target type by neighbourhoods of cells of the source type. Layout is done witht the FR algorithm and coordinates are found in the coords attribute of G. If colours were supplied these are found in the color attribute of V(G). Edge weights and widths are found in the weight and width attributes of E(G).
This function takes an expanded neighbourhood list and collapses it to a nearest neighbourhood graph where all neighbours of degree <= n in the original graph are considered first neighbours.
collapseExtendedNBHDs( extendedNeighboursList, n = length(extendedNeighboursList) )
collapseExtendedNBHDs( extendedNeighboursList, n = length(extendedNeighboursList) )
extendedNeighboursList |
|
n |
|
a graph in neighbour format, i.e., a data frame with columns nodeA and nodeB, where nodes that were originally of degree <= n are connected.
extendedNeighboursList = make.getExample()('extendedNeighboursList',toy=TRUE) extendedNeighbours = collapseExtendedNBHDs(extendedNeighboursList, 4)
extendedNeighboursList = make.getExample()('extendedNeighboursList',toy=TRUE) extendedNeighbours = collapseExtendedNBHDs(extendedNeighboursList, 4)
Discovers the combinatorial ball of a given radius around a fixed set of genes in the nearest neighbor graph of a Seurat object.
combinatorialSpheres(NN, origin, radius)
combinatorialSpheres(NN, origin, radius)
NN |
|
origin |
|
radius |
|
This returns a data frame whose columns are the gene name, the radius from the origin at which it is found
getExample = make.getExample() NN = getExample('NN',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) spheres = combinatorialSpheres(NN,'Ccl6',3) hallmark = getExample('hallmark') geneSet = intersect(hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]],colnames(STranspose)) sphereAroundSet = combinatorialSpheres(NN,geneSet,1)
getExample = make.getExample() NN = getExample('NN',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) spheres = combinatorialSpheres(NN,'Ccl6',3) hallmark = getExample('hallmark') geneSet = intersect(hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]],colnames(STranspose)) sphereAroundSet = combinatorialSpheres(NN,geneSet,1)
For each cell type, this function looks at the neighbourhoods around cells of that type and discovers the fractions of those cells of each type.
computeCellTypesPerCellTypeMatrix(nbhdByCellType, cellTypes)
computeCellTypesPerCellTypeMatrix(nbhdByCellType, cellTypes)
nbhdByCellType |
|
cellTypes |
|
A square matrix whose rownames and colnames are the seurat_clusters as character strings. Each row corresponds to neighbourhoods around all cells of that type and the entries give the fractions of those neighbourhoods occupied by cells of each type.
getExample = make.getExample() NBHDByCTMatrix = getExample('NBHDByCTMatrix') clusters = getExample('clusters') cellTypesPerCellType = computeCellTypesPerCellTypeMatrix(NBHDByCTMatrix,clusters)
getExample = make.getExample() NBHDByCTMatrix = getExample('NBHDByCTMatrix') clusters = getExample('clusters') cellTypesPerCellType = computeCellTypesPerCellTypeMatrix(NBHDByCTMatrix,clusters)
This function takes a spatial graph and computes a new spatial graph where edges become nodes and A-B edges (in the original graph) become connected to all A- edges and all B- edges.
computeEdgeGraph(spatialGraph, selfEdges = FALSE)
computeEdgeGraph(spatialGraph, selfEdges = FALSE)
spatialGraph |
|
selfEdges |
|
a graph in neighbour format where edges in the original graph become nodes and A-B edges (in the original graph) become connected to all A- edges and all B- edges.
delaunayNeighbours = make.getExample()('delaunayNeighbours') edgeNeighbours = computeEdgeGraph(delaunayNeighbours)
delaunayNeighbours = make.getExample()('delaunayNeighbours') edgeNeighbours = computeEdgeGraph(delaunayNeighbours)
This function takes interactionResults and creates a seurat object where each point represents an edge between cells, and spatial coordinates are the centroids of edges between cells. The "expression matrix" is the binarised presence/absence of an interaction (ligand receptor pair) on an edge.
computeEdgeObject( ligandReceptorResults, centroids, npcs = 10, returnType = "Seurat" )
computeEdgeObject( ligandReceptorResults, centroids, npcs = 10, returnType = "Seurat" )
ligandReceptorResults |
|
centroids |
|
npcs |
|
returnType |
Determines whether to return a Seurat object or a SpatialExperiment. Will do the later if this is set to either SCE, SingleCellExperiment or lower case versions of either. |
This returns a seurat object where each point represents an edge between cells, and spatial coordinates are the centroids of edges between cells. The "expression matrix" is the binarised presence/absence of an interaction (ligand receptor pair) on an edge. Depending on the parameter returnType, this can alternatively be returned as a SpatialExperiment.
getExample = make.getExample() centroids = getExample('centroids') ligandReceptorResults = getExample('ligandReceptorResults') edgeSeurat = computeEdgeObject(ligandReceptorResults, centroids)
getExample = make.getExample() centroids = getExample('centroids') ligandReceptorResults = getExample('ligandReceptorResults') edgeSeurat = computeEdgeObject(ligandReceptorResults, centroids)
This function adds a force directed graph embedding to a seurat object
computeGraphEmbedding( seuratObj, graph = defaultGraph(seuratObj), returnType = "Seurat" )
computeGraphEmbedding( seuratObj, graph = defaultGraph(seuratObj), returnType = "Seurat" )
seuratObj |
|
graph |
|
returnType |
|
a seurat object with a "graph" dimensionality reduction. Can also be a SingleCellExperiment depending on parameter returnType.
NBHDByCTSeurat = make.getExample()('NBHDByCTSeurat',toy=TRUE) objWithEmbedding = computeGraphEmbedding(NBHDByCTSeurat)
NBHDByCTSeurat = make.getExample()('NBHDByCTSeurat',toy=TRUE) objWithEmbedding = computeGraphEmbedding(NBHDByCTSeurat)
This function takes a matrix where rows are features and columns are cells, and a neighbourhood list, and computes Moran's I.
computeMoransI(M, nbhdList)
computeMoransI(M, nbhdList)
M |
|
nbhdList |
|
a matrix giving aggregated gene expression for a cell's neighbourhood.
This function computes a matrix where neighbourhoods are rows and cell types are columns. The values in the matrix indicate the number of cells of a given type within a neighbourhood.
computeNBHDByCTMatrix(spatialGraph, cellTypes)
computeNBHDByCTMatrix(spatialGraph, cellTypes)
spatialGraph |
|
cellTypes |
|
a matrix of neighbourhoods by cell types
getExample = make.getExample() clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') NBHDByCTMatrix = computeNBHDByCTMatrix(delaunayNeighbours,clusters)
getExample = make.getExample() clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') NBHDByCTMatrix = computeNBHDByCTMatrix(delaunayNeighbours,clusters)
This function creates a seurat object using a neighbourhood by cell type matrix
computeNBHDVsCTObject( dataMatrix, resolution = 0.1, npcs = 10, n.neighbors = 30L, transpose = FALSE, verbose = TRUE, returnType = "Seurat" )
computeNBHDVsCTObject( dataMatrix, resolution = 0.1, npcs = 10, n.neighbors = 30L, transpose = FALSE, verbose = TRUE, returnType = "Seurat" )
dataMatrix |
|
resolution |
|
npcs |
|
n.neighbors |
|
transpose |
|
verbose |
|
returnType |
|
a seurat object based on a neighbourhood by cell type matrix or its transpose, containing clusters and UMAP. This can also be a SingleCellExperiment depending on the parameter returnType.
NBHDByCTMatrix = make.getExample()('NBHDByCTMatrix',toy=TRUE) NBHDByCTSeurat = computeNBHDVsCTObject(NBHDByCTMatrix) NBHDByCTSingleCell_sce = computeNBHDVsCTObject(NBHDByCTMatrix,returnType='SCE')
NBHDByCTMatrix = make.getExample()('NBHDByCTMatrix',toy=TRUE) NBHDByCTSeurat = computeNBHDVsCTObject(NBHDByCTMatrix) NBHDByCTSingleCell_sce = computeNBHDVsCTObject(NBHDByCTMatrix,returnType='SCE')
This function calculates P values for whether cell types are more frequently neighbours than expected by chance. It does this by comparison to randomised neighbour graphs where edges are randomised but the degree of each node is preserved.
computeNeighbourEnrichment( spatialGraph, cellTypes, nSim = 1000, maxTries = 1000, verbose = TRUE )
computeNeighbourEnrichment( spatialGraph, cellTypes, nSim = 1000, maxTries = 1000, verbose = TRUE )
spatialGraph |
|
cellTypes |
|
nSim |
|
maxTries |
|
verbose |
|
A square matrix containing upper tail p values describing whether two cell types are more frequently found together than expected by chance.
getExample = make.getExample() delaunayNeighbours = getExample('delaunayNeighbours') clusters = getExample('clusters') cellTypesPerCellTypePValues = computeNeighbourEnrichment(delaunayNeighbours, clusters, nSim = 10, verbose = FALSE)
getExample = make.getExample() delaunayNeighbours = getExample('delaunayNeighbours') clusters = getExample('clusters') cellTypesPerCellTypePValues = computeNeighbourEnrichment(delaunayNeighbours, clusters, nSim = 10, verbose = FALSE)
This function computes a spatial graph where neighbors are identified based on Delaunay triangulation.
computeNeighboursDelaunay(centroids)
computeNeighboursDelaunay(centroids)
centroids |
|
a graph in neighbour format, i.e., a data frame with columns nodeA and nodeB.
centroids = make.getExample()('centroids') delaunayNeighbours = computeNeighboursDelaunay(centroids)
centroids = make.getExample()('centroids') delaunayNeighbours = computeNeighboursDelaunay(centroids)
This function computes a spatial graph where neighbors are identified based on euclidean distance and a user defined threshold.
computeNeighboursEuclidean(centroids, threshold)
computeNeighboursEuclidean(centroids, threshold)
centroids |
|
threshold |
|
a graph in neighbour format, i.e., a data frame with columns nodeA and nodeB.
centroids = make.getExample()('centroids') euclideanNeighbours = computeNeighboursEuclidean(centroids,20)
centroids = make.getExample()('centroids') euclideanNeighbours = computeNeighboursEuclidean(centroids,20)
This function takes a listing of the neighbouring cells together with the presence or absence of each ligand-receptor pair on each edge and produces a count showing for each cell, how many neighbours it has with that interaction either as source or as target
countLRInteractionsPerCell(edges, sourceOrTarget)
countLRInteractionsPerCell(edges, sourceOrTarget)
edges |
|
sourceOrTarget |
|
This returns a data frame with one row for each cell and a column giving the name of that cell and the other columns giving the counts of interactions that it has with its neighbours.
This subsets edges by our chosen critera
cullEdges(annEdges, cutoffSpec)
cullEdges(annEdges, cutoffSpec)
annEdges |
|
cutoffSpec |
|
This returns a subset of the annotated edges
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) tolerance = 5 nbins = 15 cutoffDFWater = edgeCutoffsByWatershed(annEdges, tolerance=tolerance, nbins=nbins) culledEdges = cullEdges(annEdges,cutoffDFWater)
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) tolerance = 5 nbins = 15 cutoffDFWater = edgeCutoffsByWatershed(annEdges, tolerance=tolerance, nbins=nbins) culledEdges = cullEdges(annEdges,cutoffDFWater)
This function takes the data frame of neighbor genes and reduces it so that each undirected edge is represented by only one directed edge. This ensures that randomisation does not magically split undirected edges into two edges.
desymmetriseNN(NN)
desymmetriseNN(NN)
NN |
|
a neighborListDF with only one directed edge per undirected edge.
NN = make.getExample()('NN',toy=TRUE) print(dim(NN)) NNN = desymmetriseNN(NN) print(dim(NNN))
NN = make.getExample()('NN',toy=TRUE) print(dim(NN)) NNN = desymmetriseNN(NN) print(dim(NNN))
This finds the directed Hausdorf distance from A to B
directedHausdorfDistance(A, B)
directedHausdorfDistance(A, B)
A |
|
B |
|
This returns the distance of the furthest point in A from its nearest point in B.
A = matrix(seq_len(8),ncol=2) B = matrix(seq(from=3,to=16),ncol=2) d_hausdorf = directedHausdorfDistance(A,B)
A = matrix(seq_len(8),ncol=2) B = matrix(seq(from=3,to=16),ncol=2) d_hausdorf = directedHausdorfDistance(A,B)
This finds proposed cutoffs for edge lengths by clustering the lengths of the edges for each cell type pair using k-means clustering with k = 2
edgeCutoffsByClustering(annEdges)
edgeCutoffsByClustering(annEdges)
annEdges |
|
This returns a data frame with columns cellTypePair and cutoff.
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByClustering(annEdges)
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByClustering(annEdges)
This finds edge cutoffs by percentile
edgeCutoffsByPercentile(annEdges, percentileCutoff)
edgeCutoffsByPercentile(annEdges, percentileCutoff)
annEdges |
|
percentileCutoff |
|
This returns a data frame with columns cellTypePair and cutoff.
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByPercentile(annEdges,percentileCutoff=95)
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByPercentile(annEdges,percentileCutoff=95)
This finds proposed cutoffs for edge lengths by computing the histogram of edge lengths for each cell type pair and then using the watershed algorithm to find the hump of the histogram containing the median.
edgeCutoffsByWatershed(annEdges, nbins = 15, tolerance = 10)
edgeCutoffsByWatershed(annEdges, nbins = 15, tolerance = 10)
annEdges |
|
nbins |
|
tolerance |
|
This returns a data frame with columns cellTypePair and cutoff.
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByWatershed(annEdges)
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByWatershed(annEdges)
This finds edge cutoffs by z-score
edgeCutoffsByZScore(annEdges, zCutoff)
edgeCutoffsByZScore(annEdges, zCutoff)
annEdges |
|
zCutoff |
|
This returns a data frame with columns cellTypePair and cutoff.
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByZScore(annEdges,zCutoff=1.5)
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByZScore(annEdges,zCutoff=1.5)
This plots histograms of the edge lengths broken out by the cell types of the cells they connect. It optionally plots a cutoff for each pair of types.
edgeLengthPlot(annEdges, cutoffDF, whichPairs, xLim = 100, legend = FALSE)
edgeLengthPlot(annEdges, cutoffDF, whichPairs, xLim = 100, legend = FALSE)
annEdges |
|
cutoffDF |
|
whichPairs |
|
xLim |
|
legend |
|
This returns a ggplot object
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByPercentile(annEdges,95) g = edgeLengthPlot(annEdges,cutoffDF,whichPairs=60)
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids) cutoffDF = edgeCutoffsByPercentile(annEdges,95) g = edgeLengthPlot(annEdges,cutoffDF,whichPairs=60)
This function annotates edges with their distance and the types of cells they connect
edgeLengthsAndCellTypePairs(edges, clusters, centroids)
edgeLengthsAndCellTypePairs(edges, clusters, centroids)
edges |
|
clusters |
|
centroids |
|
a data frame giving the edges (as nodeA and nodeB), their lengths and the cell type pair.
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids)
getExample = make.getExample() centroids = getExample('centroids') clusters = getExample('clusters') delaunayNeighbours = getExample('delaunayNeighbours') annEdges = edgeLengthsAndCellTypePairs(delaunayNeighbours,clusters,centroids)
This returns the names of available example objects.
exampleObjects()
exampleObjects()
A character vector of the names of available example data objects
availableObjects = exampleObjects()
availableObjects = exampleObjects()
A Seurat object of 2000 genes by 540 cells.
exSeuratObj
exSeuratObj
A Seurat object
A Seurat object of cells. It includes a UMAP of the cells and annotated clustering into cell types. It has been severely reduced in size to accommodate Bioconductor size restrictions.
This is subset from the data associated with https://www.nature.com/articles/s41586-021-04006-z
This compares the gene clusters to other gene sets e.g., GO, Hallmark, and determines the p-value for their overlaps when compared to a set of background genes.
geneSetsVsGeneClustersPValueMatrix( geneSets, clusterDF, backgroundGenes, adjust = FALSE )
geneSetsVsGeneClustersPValueMatrix( geneSets, clusterDF, backgroundGenes, adjust = FALSE )
geneSets |
|
clusterDF |
|
backgroundGenes |
|
adjust |
|
a matrix of p-values rows correspond to the gene sets and the columns correspond the the CatsCradle gene clusters
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) clusterDF = data.frame(gene=colnames(STranspose), geneCluster=STranspose$seurat_clusters) hallmark = getExample('hallmark') geneSet = intersect(hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]],colnames(STranspose)) pvalueMatrix = geneSetsVsGeneClustersPValueMatrix(geneSet, clusterDF, colnames(STranspose))
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) clusterDF = data.frame(gene=colnames(STranspose), geneCluster=STranspose$seurat_clusters) hallmark = getExample('hallmark') geneSet = intersect(hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]],colnames(STranspose)) pvalueMatrix = geneSetsVsGeneClustersPValueMatrix(geneSet, clusterDF, colnames(STranspose))
This converts an average gene expression matrix to a data frame.
getAverageExpressionDF(M)
getAverageExpressionDF(M)
M |
|
A data frame with columns cellCluster, geneCluster and average expression
getExample = make.getExample() averageExpMatrix = getExample('averageExpMatrix',toy=TRUE) averageExpDF = getAverageExpressionDF(averageExpMatrix)
getExample = make.getExample() averageExpMatrix = getExample('averageExpMatrix',toy=TRUE) averageExpDF = getAverageExpressionDF(averageExpMatrix)
This computes average expression of each gene cluster in each cell cluster and returns the result as a matrix
getAverageExpressionMatrix( f, fPrime, clusteringName = "seurat_clusters", layer = "scale.data" )
getAverageExpressionMatrix( f, fPrime, clusteringName = "seurat_clusters", layer = "scale.data" )
f |
|
fPrime |
|
clusteringName |
In many cases, this will be the cell clustering, i.e., seurat_clusters, which is the default, but for neighbourhood Seurat objects, this can be neighbourhood_clusters. |
layer |
|
A matrix of the average expression where the rows correspond to cell clusters and the columns correspond to gene clusters.
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) exSeuratObj = getExample('exSeuratObj',toy=TRUE) M = getAverageExpressionMatrix(exSeuratObj,STranspose,layer='data')
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) exSeuratObj = getExample('exSeuratObj',toy=TRUE) M = getAverageExpressionMatrix(exSeuratObj,STranspose,layer='data')
This functions retrieves an expression matrix from a seurat object or SingleCellExperiment and binarises it.
getBinarisedMatrix(obj, cutoff = 0, layer = "count")
getBinarisedMatrix(obj, cutoff = 0, layer = "count")
obj |
|
cutoff |
|
layer |
|
A binarised expression matrix where rows are genes and columns are cells.
This deals with skullduggery in which seurat_clusters has been converted from a factor to a character or a numeric.
getClusterOrder(f)
getClusterOrder(f)
f |
|
A vector of these unique values in order
STranspose = make.getExample()('STranspose',toy=TRUE) geneClusters = getClusterOrder(STranspose)
STranspose = make.getExample()('STranspose',toy=TRUE) geneClusters = getClusterOrder(STranspose)
This function takes a nearest neighbour graph and a radius and calculates nth degree neighbour graphs where max(n) == radius
getExtendedNBHDs(spatialGraph, n)
getExtendedNBHDs(spatialGraph, n)
spatialGraph |
|
n |
|
A named list of neighbour graphs, where each graph contains edges connecting vertices of degree n. Each graph is named according to degree n.
delaunayNeighbours = make.getExample()('delaunayNeighbours') extendedNeighboursList = getExtendedNBHDs(delaunayNeighbours, 4)
delaunayNeighbours = make.getExample()('delaunayNeighbours') extendedNeighboursList = getExtendedNBHDs(delaunayNeighbours, 4)
This gets z-scores for the values of features
getFeatureZScores(f, features = rownames(f), layer = "data")
getFeatureZScores(f, features = rownames(f), layer = "data")
f |
|
layer |
|
featurs |
|
This returns a data frame with a column for each feature and a row for each cell
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) df = getFeatureZScores(exSeuratObj)
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) df = getFeatureZScores(exSeuratObj)
This produces a matrix giving the average expression of gene clusters in cells. By default, it uses all cells and all gene clusters.
getGeneClusterAveragesPerCell( f, fPrime, cells = colnames(f), geneClusters = getClusterOrder(fPrime), layer = "data" )
getGeneClusterAveragesPerCell( f, fPrime, cells = colnames(f), geneClusters = getClusterOrder(fPrime), layer = "data" )
f |
|
fPrime |
|
cells |
|
geneClusters |
|
layer |
|
A matrix where the rows correspond to cells, the columns correspond to geneClusters and the entries give average expression for each cluster in each cell
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) clusterExpression = getGeneClusterAveragesPerCell(exSeuratObj,STranspose)
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) clusterExpression = getGeneClusterAveragesPerCell(exSeuratObj,STranspose)
This function gets the neighbors of a given gene using either the gene Seurat object or its nearest neighbor graph returned from getNearestNeighbourLists
getGeneNeighbors(gene, NN)
getGeneNeighbors(gene, NN)
gene |
|
NN |
|
the neighboring genes
library(Seurat) getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) NN = getExample('NN',toy=TRUE) neighbors = getGeneNeighbors("Ccl6",STranspose) neighborsAgain = getGeneNeighbors("Ccl6",NN)
library(Seurat) getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) NN = getExample('NN',toy=TRUE) neighbors = getGeneNeighbors("Ccl6",STranspose) neighborsAgain = getGeneNeighbors("Ccl6",NN)
This function takes a binarised expression matrix, a set of ligand receptor pairs and a set of edges denoting neighbouring cells and annotates these with the ligand receptor interactions taking place on those edges in each direction.
getInteractionsOnEdges(M, pairDF, spatialGraph)
getInteractionsOnEdges(M, pairDF, spatialGraph)
M |
|
pairDF |
|
spatialGraph |
|
This returns a data frame whose first two columns give the neighbouring cells. Each of the remaining columns is a logical corresponding to a ligand-receptor pair telling whether the ligand is expressed in the first cell and the receptor is expressed in the second cell.
This function retrieves the Nichenetr ligand- receptor network for mouse or human.
getLigandReceptorNetwork(species)
getLigandReceptorNetwork(species)
species |
|
This returns a data frame whose first two columns are from and to, i.e., ligand and receptor. These are derived from the nichenetr ligand receptor networks.
lrn = getLigandReceptorNetwork('human')
lrn = getLigandReceptorNetwork('human')
This functions takes an Seurat object, its species and a ligand receptor network and subsets the ligand receptor network to those pairs that occur in the panel
getLigandReceptorPairsInPanel( obj, species, lrn = getLigandReceptorNetwork(species) )
getLigandReceptorPairsInPanel( obj, species, lrn = getLigandReceptorNetwork(species) )
obj |
|
species |
|
lrn |
|
This returns a data frame with columns ligand and receptor
smallXenium = make.getExample()('smallXenium') lrPairs = getLigandReceptorPairsInPanel(smallXenium, "mouse")
smallXenium = make.getExample()('smallXenium') lrPairs = getLigandReceptorPairsInPanel(smallXenium, "mouse")
This finds the genes near a give subset using either a dimensional reduction or the nearest neighbor graph
getNearbyGenes( fPrime, geneSet, radius, metric = "umap", numPCs = NULL, weights = FALSE )
getNearbyGenes( fPrime, geneSet, radius, metric = "umap", numPCs = NULL, weights = FALSE )
fPrime |
|
geneSet |
|
radius |
|
metric |
|
numPCs |
|
weights |
|
This returns a named vector whose values are distance from geneSet and whose names are the nearby genes.
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark') geneSet = intersect(colnames(STranspose),hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]]) geometricallyNearby = getNearbyGenes(STranspose,geneSet,radius=0.2,metric='umap') combinatoriallyNearby = getNearbyGenes(STranspose,geneSet,radius=1,metric='NN') weightedNearby = getNearbyGenes(STranspose,'Myc',radius=1,metric='NN',weights=TRUE)
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark') geneSet = intersect(colnames(STranspose),hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]]) geometricallyNearby = getNearbyGenes(STranspose,geneSet,radius=0.2,metric='umap') combinatoriallyNearby = getNearbyGenes(STranspose,geneSet,radius=1,metric='NN') weightedNearby = getNearbyGenes(STranspose,'Myc',radius=1,metric='NN',weights=TRUE)
This function extracts a shared nearest neighbor network from a Seurat object
getNearestNeighbourLists(f, graph = defaultGraph(f))
getNearestNeighbourLists(f, graph = defaultGraph(f))
f |
|
graph |
|
This returns dataframe of neighbors: nodeA - node names for node A nodeB - node names for node B weight - edge weight
STranspose = make.getExample()('STranspose',toy=TRUE) NN = getNearestNeighbourLists(STranspose)
STranspose = make.getExample()('STranspose',toy=TRUE) NN = getNearestNeighbourLists(STranspose)
This function computes a p-value for the geometric clustering of a gene set (in UMAP or PCA reduction) based on the median distance from its complement to the set.
getObjectSubsetClusteringPValue( fPrime, geneSubset, numTrials = 1000, reduction = "UMAP", numPCs = 10 )
getObjectSubsetClusteringPValue( fPrime, geneSubset, numTrials = 1000, reduction = "UMAP", numPCs = 10 )
fPrime |
|
geneSubset |
|
numTrials |
|
reduction |
|
numPCs |
|
A p-value reporting how often a random subset of the same size is sufficiently clustered to produce an equally large distance from its complement.
getExample = make.getExample() STranspose = getExample('STranspose') hallmark = getExample('hallmark',toy=TRUE) geneSubset = intersect(colnames(STranspose),hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]]) p = getObjectSubsetClusteringPValue(STranspose,geneSubset,100)
getExample = make.getExample() STranspose = getExample('STranspose') hallmark = getExample('hallmark',toy=TRUE) geneSubset = intersect(colnames(STranspose),hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]]) p = getObjectSubsetClusteringPValue(STranspose,geneSubset,100)
This function computes statistics for the geometric clustering of a gene set (in UMAP or PCA reduction) based on the median distance from its complement to the set.
getObjectSubsetClusteringStatistics( fPrime, geneSubset, numTrials = 1000, reduction = "UMAP", numPCs = 10 )
getObjectSubsetClusteringStatistics( fPrime, geneSubset, numTrials = 1000, reduction = "UMAP", numPCs = 10 )
fPrime |
|
geneSubset |
|
numTrials |
|
reduction |
|
numPCs |
|
A list of statistics resulting from the testing of randomised subsets of the same size as the given gene subset. These include subsetDistance, the actual median complement distance; randomSubsetDistance, the median complement distances for randomised subsets; pValue, computed by comparing the real and randomised distances; and zScore, the z-distance of the actual median distance from the mean of the randomised distances.
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark') geneSubset = intersect(colnames(STranspose),hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]]) stats = getObjectSubsetClusteringStatistics(STranspose,geneSubset,100)
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark') geneSubset = intersect(colnames(STranspose),hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]]) stats = getObjectSubsetClusteringStatistics(STranspose,geneSubset,100)
A data frame giving 12019 human ligand receptor pairs
humanLRN
humanLRN
a data frame with two columns, 'from' and 'to'
A data frame with two columns, 'from' and 'to'. Each row represents a human ligand - receptor pair.
This is taken from the nichenetr package, url = https://www.nature.com/articles/s41592-019-0667-5. Specifically we use the human ligand - receptor network.
The result of performLigandReceptorAnalysis(smallXenium, delaunayNeighbours, "mouse", clusters,verbose=FALSE)
ligandReceptorResults
ligandReceptorResults
A list of data frames.
A list containing: interactionsOnEdges - a data frame whose first two columns give the neighbouring cells and next two columns give their corresponding clusters. Each of the remaining columns is a logical corresponding to a ligand-receptor pair telling whether the ligand is expressed in the first cell and the receptor is expressed in the second cell. totalInteractionsByCluster - a dataframe where the first column gives a directed (sender-receiver) pair of clusters. The second column gives the total number of edges between those clusters. The remaining columns give the total numbers of edges on which particular ligand receptor interactions are present. meanInteractionsByCluster - a dataframe where the first column gives a directed (sender-receiver) pair of clusters. The second column gives the total number of edges between those clusters. The remaining columns give the total numbers of edges on which particular ligand receptor interactions are present (for that cluster pair) divided by the total number of edges between those clusters. simResults - a dataframe where the rownames are sender-receiver cluster pairs and column names are ligand receptor pairs. Values give the number of simulations for which observed values are greater than simulated values. pValues - a dataframe where the rownames are sender-receiver cluster pairs and column names are ligand receptor pairs. Entries are uppertail pvalues describing whether a particular ligand receptor interaction is observed more frequently between 2 clusters than expected.
Created from smallXenium and delaunayNeighbours by using performLigandReceptorAnalysis(()
This function makes the function whichretrieves and makes example data objects.
make.getExample()
make.getExample()
This returns the function which retrieves and makes example data objects. The latter saves any object it has found for quicker return. Using the value 'list' causes it to return the list of all objects found so far.
getExample = make.getExample() ## Provided: smallXenium = getExample('smallXenium') ## Computed: delaunayNeighbours = getExample('delaunayNeighbours')
getExample = make.getExample() ## Provided: smallXenium = getExample('smallXenium') ## Computed: delaunayNeighbours = getExample('delaunayNeighbours')
This function takes ligandReceptorResults and plots a heatmap of -log10(pvalues).
makeLRInteractionHeatmap( ligandReceptorResults, clusters, colours = c(), pValCutoffClusterPair = 0.05, pValCutoffLigRec = 0.05, labelClusterPairs = TRUE )
makeLRInteractionHeatmap( ligandReceptorResults, clusters, colours = c(), pValCutoffClusterPair = 0.05, pValCutoffLigRec = 0.05, labelClusterPairs = TRUE )
ligandReceptorResults |
|
clusters |
|
colours |
|
pValCutoffClusterPair |
|
pValCutoffLigRec |
|
labelClusterPairs |
|
matrix of -log10(pvalues) that underlies the heatmap.
getExample = make.getExample() clusters = getExample('clusters') colours = getExample('colours') ligandReceptorResults = getExample('ligandReceptorResults') ligRecMatrix = makeLRInteractionHeatmap(ligandReceptorResults, clusters, colours = colours, labelClusterPairs = FALSE)
getExample = make.getExample() clusters = getExample('clusters') colours = getExample('colours') ligandReceptorResults = getExample('ligandReceptorResults') ligRecMatrix = makeLRInteractionHeatmap(ligandReceptorResults, clusters, colours = colours, labelClusterPairs = FALSE)
This function takes ligandReceptorResults and plots a heatmap of the total number of ligand receptor interactions between clusters.
makeSummedLRInteractionHeatmap( ligandReceptorResults, clusters, type, logScale = TRUE )
makeSummedLRInteractionHeatmap( ligandReceptorResults, clusters, type, logScale = TRUE )
ligandReceptorResults |
|
clusters |
|
type |
|
logScale |
|
matrix of total ligand receptor interactions that underlies t he heatmap.
getExample = make.getExample() clusters = getExample('clusters') ligandReceptorResults = getExample('ligandReceptorResults') cellTypePerCellTypeLigRecMatrix = makeSummedLRInteractionHeatmap(ligandReceptorResults, clusters, "mean")
getExample = make.getExample() clusters = getExample('clusters') ligandReceptorResults = getExample('ligandReceptorResults') cellTypePerCellTypeLigRecMatrix = makeSummedLRInteractionHeatmap(ligandReceptorResults, clusters, "mean")
This function paints gene expression for a given gene cluster on cell umap.
meanGeneClusterOnCellUMAP(f, fPrime, geneCluster)
meanGeneClusterOnCellUMAP(f, fPrime, geneCluster)
f |
|
fPrime |
|
geneCluster |
|
This returns a ggplot object
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) g = meanGeneClusterOnCellUMAP(exSeuratObj,STranspose,geneCluster=0)
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) g = meanGeneClusterOnCellUMAP(exSeuratObj,STranspose,geneCluster=0)
This finds the mean z-score for features in subsets of cells e.g., in each of the seurat_clusters
meanZPerCluster(f, features, clusterBy = "seurat_clusters", layer = "data")
meanZPerCluster(f, features, clusterBy = "seurat_clusters", layer = "data")
f |
|
features |
|
clusterBy |
|
layer |
|
This returns a data frame each of whose columns corresponds to a value of the clusterBy data. In the case where the clusterBy data is a factor or numeric, it prepends cluster_ to the column name.
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) df = meanZPerCluster(exSeuratObj,features=colnames(STranspose), clusterBy='shortName')
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) df = meanZPerCluster(exSeuratObj,features=colnames(STranspose), clusterBy='shortName')
This collects together mean z-score data together with UMAP coordinates from the gene seurat object for plotting.
meanZPerClusterOnUMAP(f, fPrime, clusterBy = "seurat_clusters", layer = "data")
meanZPerClusterOnUMAP(f, fPrime, clusterBy = "seurat_clusters", layer = "data")
f |
|
fPrime |
|
clusterBy |
|
layer |
|
This returns a data frame with the UMAP coordinates of the gene Seurat object and the average z-score for each gene within each of the cell clusters defined by the clusterBy column of the meta.data of f.
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) df = meanZPerClusterOnUMAP(exSeuratObj,STranspose,clusterBy='shortName')
getExample = make.getExample() exSeuratObj = getExample('exSeuratObj',toy=TRUE) STranspose = getExample('STranspose',toy=TRUE) df = meanZPerClusterOnUMAP(exSeuratObj,STranspose,clusterBy='shortName')
This takes a set S of n points in dimension d given by an n x d matrix and a subset A given by a logical and returns the median distance from the complement to the given subset.
medianComplementDistance(S, idx)
medianComplementDistance(S, idx)
S |
|
idx |
|
This returns the median distance from the complement to the subset
S = matrix(seq_len(12),ncol=2) idx = c(rep(FALSE,3),rep(TRUE,3)) compDist = medianComplementDistance(S,idx)
S = matrix(seq_len(12),ncol=2) idx = c(rep(FALSE,3),rep(TRUE,3)) compDist = medianComplementDistance(S,idx)
This takes a set S of n points in dimension d and a subset A and computes a p-value for the co-localization of the subset by comparing the median complement distance for the given set to values of the median complement distance computed for random subsets of the same size.
medianComplementPValue(S, idx, numTrials = 1000, returnTrials = FALSE)
medianComplementPValue(S, idx, numTrials = 1000, returnTrials = FALSE)
S |
|
idx |
|
numTrials |
|
returnTrials |
|
By default this reports a p-value. If returnTrials is set, this returns a list giving the p-value, the actual complement distance and the random complement distances.
library(Seurat) getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark') S = data.matrix(FetchData(STranspose,c('umap_1','umap_2'))) idx = colnames(STranspose) %in% hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]] mcpv = medianComplementPValue(S,idx,numTrials=100)
library(Seurat) getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark') S = data.matrix(FetchData(STranspose,c('umap_1','umap_2'))) idx = colnames(STranspose) %in% hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]] mcpv = medianComplementPValue(S,idx,numTrials=100)
A data fame containing Moran's I and related pvalues.
moransI
moransI
A data fame containing Moran's I and related pvalues.
Moran's I values calculated for the genes in smallXenium (using the SCT assay). Pvalues derived using 100 permutations.
Created from smallXenium and delaunayNeighbours by using runMoransI()
Moran's I for the ligand receptor pairs
moransILigandReceptor
moransILigandReceptor
A data frame showing the spatial autocorrelation of the 28 ligand receptor pairs
A data frame with rownames giving the 28 ligand-receptor pairs and columns moransI and pValues
Computed using the function runMoransI on the object edgeSeurat and neighbours edgeNeighbours = computeEdgeGraph(delaunayNeighbours) with 100 trials. For more informations see the CatsCradleSpatial vignette.
A data frame giving 11592 mouse ligand receptor pairs
mouseLRN
mouseLRN
a data frame with two columns, 'from' and 'to'
A data frame with two columns, 'from' and 'to'. Each row represents a mouse ligand - receptor pair.
This is taken from the nichenetr package, url = https://www.nature.com/articles/s41592-019-0667-5. Specifically, we use the mouse ligand - receptor network.
This function takes a set of neighbourhoods given by edges and turns it into a named list giving the memberships of each neighbourhood
nbhdsAsEdgesToNbhdsAsList(cells, neighbourhoods)
nbhdsAsEdgesToNbhdsAsList(cells, neighbourhoods)
cells |
|
neighbourhoods |
|
a named list with memberships of the neighbourhoods of cells
delaunayNeighbours = make.getExample()('delaunayNeighbours') cells = unique(c(delaunayNeighbours[,'nodeA'],delaunayNeighbours[,'nodeB'])) nbhdsList = nbhdsAsEdgesToNbhdsAsList(cells,delaunayNeighbours)
delaunayNeighbours = make.getExample()('delaunayNeighbours') cells = unique(c(delaunayNeighbours[,'nodeA'],delaunayNeighbours[,'nodeB'])) nbhdsList = nbhdsAsEdgesToNbhdsAsList(cells,delaunayNeighbours)
This function takes a list of neighbourhoods and and the centroids of the cells and finds their diameters, i.e., for each neighbourhood, the maximum distance between.
neighbourhoodDiameter(neighbourhoods, centroids)
neighbourhoodDiameter(neighbourhoods, centroids)
neighbourhoods |
|
centroids |
|
a named numeric. The names are the names of the list neighbourhoods and the values are the maximum distance within each neighbourhood
getExample = make.getExample() centroids = getExample('centroids') delaunayNeighbours = getExample('delaunayNeighbours') cells = unique(c(delaunayNeighbours[,'nodeA'],delaunayNeighbours[,'nodeB'])) nbhds = nbhdsAsEdgesToNbhdsAsList(cells,delaunayNeighbours) diameters = neighbourhoodDiameter(nbhds[seq_len(100)],centroids)
getExample = make.getExample() centroids = getExample('centroids') delaunayNeighbours = getExample('delaunayNeighbours') cells = unique(c(delaunayNeighbours[,'nodeA'],delaunayNeighbours[,'nodeB'])) nbhds = nbhdsAsEdgesToNbhdsAsList(cells,delaunayNeighbours) diameters = neighbourhoodDiameter(nbhds[seq_len(100)],centroids)
This orders the gene set p-values (or -log10 p-values) and applies a cutoff (if given) to show only the significant gene sets for each gene cluster
orderGeneSetPValues(M, ascending = TRUE, cutoff = NULL, nameTag = "")
orderGeneSetPValues(M, ascending = TRUE, cutoff = NULL, nameTag = "")
M |
|
ascending |
|
cutoff |
|
nameTag |
|
This returns a list of whose entries are data frames, one for each gene cluster, each giving the significant gene sets for that cluster and their significance.
Given a seurat object, a spatial graph, clusters and species this function identifies ligand-receptor interactions between neighbouring cells, identifies ligand-receptor interactions within and between clusters and calculates whether these are observed more frequently than expected by chance.
performLigandReceptorAnalysis( obj, spatialGraph, species, clusters, nSim = 1000, lrn = getLigandReceptorNetwork(species), verbose = TRUE )
performLigandReceptorAnalysis( obj, spatialGraph, species, clusters, nSim = 1000, lrn = getLigandReceptorNetwork(species), verbose = TRUE )
obj |
|
spatialGraph |
|
species |
|
clusters |
|
nSim |
|
lrn |
|
verbose |
|
A list containing: interactionsOnEdges - a data frame whose first two columns give the neighbouring cells and next two columns give their corresponding clusters. Each of the remaining columns is a logical corresponding to a ligand-receptor pair telling whether the ligand is expressed in the first cell and the receptor is expressed in the second cell. totalInteractionsByCluster - a dataframe where the first column gives a directed (sender-receiver) pair of clusters. The second column gives the total number of edges between those clusters. The remaining columns give the total numbers of edges on which particular ligand receptor interactions are present. meanInteractionsByCluster - a dataframe where the first column gives a directed (sender-receiver) pair of clusters. The second column gives the total number of edges between those clusters. The remaining columns give the total numbers of edges on which particular ligand receptor interactions are present (for that cluster pair) divided by the total number of edges between those clusters. simResults - a dataframe where the rownames are sender-receiver cluster pairs and column names are ligand receptor pairs. Values give the number of simulations for which observed values are greater than simulated values. pValues - a dataframe where the rownames are sender-receiver cluster pairs and column names are ligand receptor pairs. Entries are uppertail pvalues describing whether a particular ligand receptor interaction is observed more frequently between 2 clusters than expected.
getExample = make.getExample() smallXenium = getExample('smallXenium') delaunayNeighbours = getExample('delaunayNeighbours') clusters = getExample('clusters') performLigandReceptorAnalysis(smallXenium, delaunayNeighbours, "mouse", clusters, nSim = 10, verbose=FALSE)
getExample = make.getExample() smallXenium = getExample('smallXenium') delaunayNeighbours = getExample('delaunayNeighbours') clusters = getExample('clusters') performLigandReceptorAnalysis(smallXenium, delaunayNeighbours, "mouse", clusters, nSim = 10, verbose=FALSE)
This function permutes the rows of a matrix.
permuteMatrix(M)
permuteMatrix(M)
M |
|
This returns a matrix in which the values have been permuted within rows.
This function makes annotation predictions for a set of genes based on gene sets (e.g., hallmark) and a CatsCradle object by considering the annotations of its neighboring genes.
predictAnnotation( genes, geneSets, fPrime, radius, metric = "umap", numPCs = NULL, normaliseByGeneSet = TRUE, normaliseByDistance = TRUE, normaliseToUnitVector = TRUE )
predictAnnotation( genes, geneSets, fPrime, radius, metric = "umap", numPCs = NULL, normaliseByGeneSet = TRUE, normaliseByDistance = TRUE, normaliseToUnitVector = TRUE )
genes |
|
geneSets |
|
fPrime |
|
radius |
|
metric |
|
numPCs |
|
normaliseByGeneSet |
|
normaliseByDistance |
|
normaliseToUnitVector |
|
This returns a list of prediction vectors, one vector for each gene in genes, each vector corresponding to the sets in geneSets
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) STranspose_sce = getExample('STranspose_sce',toy=TRUE) hallmark = getExample('hallmark',toy=TRUE) set.seed(100) genes = sample(colnames(STranspose),5) predictions = predictAnnotation(genes,hallmark,STranspose,radius=.5) predictions_sce = predictAnnotation(genes,hallmark,STranspose_sce,radius=.5)
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) STranspose_sce = getExample('STranspose_sce',toy=TRUE) hallmark = getExample('hallmark',toy=TRUE) set.seed(100) genes = sample(colnames(STranspose),5) predictions = predictAnnotation(genes,hallmark,STranspose,radius=.5) predictions_sce = predictAnnotation(genes,hallmark,STranspose_sce,radius=.5)
This function predicts the functions of all genes based on the functions of their neighbours.
predictAnnotationAllGenes( geneSets, fPrime, radius, metric = "umap", normaliseByGeneSet = TRUE, normaliseByDistance = TRUE, normaliseToUnitVector = TRUE )
predictAnnotationAllGenes( geneSets, fPrime, radius, metric = "umap", normaliseByGeneSet = TRUE, normaliseByDistance = TRUE, normaliseToUnitVector = TRUE )
geneSets |
|
fPrime |
|
radius |
|
metric |
|
normaliseByGeneSet |
|
normaliseByDistance |
|
normaliseToUnitVector |
|
A list where names are genes and values are vectors of gene annotations whose entries correspond to the geneSets
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark',toy=TRUE) predictions = predictAnnotationAllGenes(hallmark,STranspose,radius=.5)
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark',toy=TRUE) predictions = predictAnnotationAllGenes(hallmark,STranspose,radius=.5)
This function is the implementation for predicting the functions of a gene based on the functions of its neighbours.
predictGeneAnnotationImpl( gene, fPrime, genesAnno, radius, metric, numPCs = NULL, normaliseByDistance = TRUE )
predictGeneAnnotationImpl( gene, fPrime, genesAnno, radius, metric, numPCs = NULL, normaliseByDistance = TRUE )
gene |
|
fPrime |
|
genesAnno |
|
radius |
|
metric |
|
numPCs |
|
normaliseByDistance |
|
This returns a named list. The names are the anotations that apply to the neighbour genes, the values are the relative wieghts of the contributions.
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark',toy=TRUE) genesAnno = annotateGenesByGeneSet(hallmark) predictions = predictGeneAnnotationImpl('Myc',STranspose,genesAnno, radius=.5,metric='umap')
getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark',toy=TRUE) genesAnno = annotateGenesByGeneSet(hallmark) predictions = predictGeneAnnotationImpl('Myc',STranspose,genesAnno, radius=.5,metric='umap')
This function performs degree-preserving randomisation of neighbour graphs.
randomiseGraph(spatialGraph, maxTries = 1000)
randomiseGraph(spatialGraph, maxTries = 1000)
spatialGraph |
|
maxTries |
|
A randomised graph where degree from the original graph is preserved.
This function generates random indices for node B
randomiseNodeIndices(neighborListDf, n = 100, useWeights = FALSE)
randomiseNodeIndices(neighborListDf, n = 100, useWeights = FALSE)
neighborListDf |
|
n |
|
useWeights |
|
a matrix with randomised indices for node B
NN = make.getExample()('NN') NN = desymmetriseNN(NN) randomIndices = randomiseNodeIndices(NN,10,TRUE)
NN = make.getExample()('NN') NN = desymmetriseNN(NN) randomIndices = randomiseNodeIndices(NN,10,TRUE)
This function reads in gene sets in .gmt format
readGmt(gmtFile, addDescr = FALSE)
readGmt(gmtFile, addDescr = FALSE)
gmtFile |
|
addDescr |
|
A named list of gene sets
This function takes a matrix whose rows are geometric coordinates and a subset of these points either given as a character vector which is a subset of the rownames or as a logical vector. It returns statistics on the mean distance of the complement to the subset.
runGeometricClusteringTrials(S, geneSubset, numTrials)
runGeometricClusteringTrials(S, geneSubset, numTrials)
S |
|
geneSubset |
|
numTrials |
|
This returns a list. subsetDistance gives the median complement distance for the actual set, randomSubsetDistance gives the complement distances for the numTrials random sets, pValue gives a p-value based on the rank of the actual distance among the random distances and zScore gives its z-score.
library(Seurat) getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark') S = data.matrix(FetchData(STranspose,c('umap_1','umap_2'))) geneSubset = rownames(S) %in% hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]] geneClustering = runGeometricClusteringTrials(S,geneSubset,100)
library(Seurat) getExample = make.getExample() STranspose = getExample('STranspose',toy=TRUE) hallmark = getExample('hallmark') S = data.matrix(FetchData(STranspose,c('umap_1','umap_2'))) geneSubset = rownames(S) %in% hallmark[["HALLMARK_TNFA_SIGNALING_VIA_NFKB"]] geneClustering = runGeometricClusteringTrials(S,geneSubset,100)
This function takes a matrix where rows are features and columns are cells, and a neighbourhood list, and computes Moran's I.
runMoransI( obj, spatialGraph, assay = "RNA", layer = "data", nSim = 100, verbose = TRUE )
runMoransI( obj, spatialGraph, assay = "RNA", layer = "data", nSim = 100, verbose = TRUE )
obj |
|
spatialGraph |
|
assay |
|
layer |
|
nSim |
|
verbose |
|
a dataframe containing Moran's I and p values for each feature.
getExample = make.getExample() smallXenium = getExample('smallXenium',toy=TRUE) delaunayNeighbours = getExample('delaunayNeighbours',toy=TRUE) moransI = runMoransI(smallXenium, delaunayNeighbours, assay = "SCT", layer = "data", nSim = 10, verbose = FALSE)
getExample = make.getExample() smallXenium = getExample('smallXenium',toy=TRUE) delaunayNeighbours = getExample('delaunayNeighbours',toy=TRUE) moransI = runMoransI(smallXenium, delaunayNeighbours, assay = "SCT", layer = "data", nSim = 10, verbose = FALSE)
This makes a sankey graph from a matrix of average expression. Our "Cat's Cradle".
sankeyFromMatrix( M, disambiguation = c("R_", "C_"), fontSize = 20, minus = "red", plus = "blue", height = 1200, width = 900 )
sankeyFromMatrix( M, disambiguation = c("R_", "C_"), fontSize = 20, minus = "red", plus = "blue", height = 1200, width = 900 )
M |
|
disambiguation |
|
fontSize |
|
minus |
|
plus |
|
height |
|
width |
|
A sankey graph
set.seed(100) M = matrix(runif(12)-.3,nrow=3) rownames(M) = as.character(seq_len(3)) colnames(M) = as.character(seq_len(4)) sankey = sankeyFromMatrix(M)
set.seed(100) M = matrix(runif(12)-.3,nrow=3) rownames(M) = as.character(seq_len(3)) colnames(M) = as.character(seq_len(4)) sankey = sankeyFromMatrix(M)
A vector of cells used for subsetting exSeuratObj
seuratCells
seuratCells
A vector of cells
A vector of cells consisting of half the cells from each seurat_cluster in exSeuratObj used to subset this object to give toy examples.
Computed by retrieving half the cells from each cluster in exSeuratObj
A vector of genes used for subsetting exSeuratObj
seuratGenes
seuratGenes
A vector of genes
A vector of the top 100 most variable genes in exSeuratObj used to subset this object to give toy examples.
Computed by retrieving the data layer from exSeuratObj and subsetting to the 100 genes with the highest standard deviation.
A spatial Seurat object of 4261 cells and 248 genes
smallXenium
smallXenium
A Seurat object
A spatial Seurat object subset from the Xenium object used in https://satijalab.org/seurat/articles/seurat5_spatial_vignette_2.
This is subset from the Xenium spatial Seurat object https://cf.10xgenomics.com/samples/xenium/1.0.2/Xenium_V1_FF_Mouse_Brain_Coronal_Subset_CTX_HP/Xenium_V1_FF_Mouse_Brain_Coronal_Subset_CTX_HP_outs.zip to include a small region of the field of view surrounding the dentate gyrus.
This function strips out non-gene information from the beginning of GO sets, etc.
stripGeneSet(geneSet)
stripGeneSet(geneSet)
geneSet |
|
a named list of gene sets
This first checks to see if the NN graph is symmetric and if not symmetrises it.
symmetriseNN(NN)
symmetriseNN(NN)
NN |
|
a nearest neighbors graph
NN = make.getExample()('NN',toy=TRUE) NNStar = symmetriseNN(NN)
NN = make.getExample()('NN',toy=TRUE) NNStar = symmetriseNN(NN)
The nearest neighbor relationship is not inherently symmetric. This tests whether the nearest neighbor graph retrieved from a Seurat object is.
symmetryCheckNN(NN)
symmetryCheckNN(NN)
NN |
|
TRUE or FALSE
NN = make.getExample()('NN',toy=TRUE) symmetryTest = symmetryCheckNN(NN)
NN = make.getExample()('NN',toy=TRUE) symmetryTest = symmetryCheckNN(NN)
This gussies up the rownames and colnames of M
tagRowAndColNames(M, ccTag = "CC_", gcTag = "GC_")
tagRowAndColNames(M, ccTag = "CC_", gcTag = "GC_")
M |
|
ccTag |
|
gcTag |
|
The same matrix with fancier row and col names
getExample = make.getExample() averageExpMatrix = getExample('averageExpMatrix',toy=TRUE) averageExpMatrix = tagRowAndColNames(averageExpMatrix,'cellCluster_','geneCluster_')
getExample = make.getExample() averageExpMatrix = getExample('averageExpMatrix',toy=TRUE) averageExpMatrix = tagRowAndColNames(averageExpMatrix,'cellCluster_','geneCluster_')
This takes a Seurat object f and creates a new Seurat object whose expression matrix is the transpose of that of f. This can also be a SingleCellExperiment which will be converted to a Seurat object
transposeObject( f, active.assay = "RNA", npcs = 30, dims = seq_len(20), res = 1, returnType = "Seurat", verbose = FALSE )
transposeObject( f, active.assay = "RNA", npcs = 30, dims = seq_len(20), res = 1, returnType = "Seurat", verbose = FALSE )
f |
|
active.assay |
|
npcs |
|
dims |
|
res |
|
returnType |
|
verbose |
|
A Seurat object or SingleCellExperiment
exSeuratObj = make.getExample()('exSeuratObj',toy=TRUE) STranspose = transposeObject(exSeuratObj) STransposeAsSCE = transposeObject(exSeuratObj,returnType='SCE')
exSeuratObj = make.getExample()('exSeuratObj',toy=TRUE) STranspose = transposeObject(exSeuratObj) STransposeAsSCE = transposeObject(exSeuratObj,returnType='SCE')
A vector of cells used for subsetting exSeuratObj
xeniumCells
xeniumCells
A vector of cells
A vector of cells consisting of approximately one quarter of the cells in smallXenium used to subset this object to give toy examples.
We extracted a rectangle whose width and height were one half the width and height of smallXenium and which was centered in the field of view of smallXenium