# This package provides methods for analysing spatial transcriptomics data and for discovering gene clusters

## Documentation for package ‘CatsCradle’ version 1.5.2

- DESCRIPTION file.
- User guides, package vignettes and other documentation.
- Package NEWS.

## Help Pages

aggregateFeatureMatrix | 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.
aggregateGeneExpression | 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
annotateGeneAsVector | 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.
annotateGenesByGeneSet | This function annotates genes with terms
annotateLRInteractionCounts | 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.
cellTypesPerCellTypeGraphFromCellMatrix | 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.
cellTypesPerCellTypeGraphFromNbhdMatrix | 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.
collapseExtendedNBHDs | 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.
combinatorialSpheres | Discovers the combinatorial ball of a given radius around a fixed set of genes in the nearest neighbor graph of a Seurat object.
computeCellTypesPerCellTypeMatrix | For each cell type, this function looks at the neighbourhoods around cells of that type and discovers the fractions (or numbers if normalise = F) of those cells of each type.
computeEdgeGraph | 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.
computeEdgeObject | 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.
computeGraphEmbedding | This function adds a force directed graph embedding to a seurat object
computeMoransI | This function takes a matrix where rows are features and columns are cells, and a neighbourhood list, and computes Moran's I.
computeNBHDByCTMatrix | 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.
computeNBHDVsCTObject | This function creates a seurat object using a neighbourhood by cell type matrix
computeNeighbourEnrichment | This function calculates P values for whether cell types are more frequently neighbours than expected by chance. By default it calculates P values analytically using a hypergeometric test on the edges, where the arguments to the R phyper function are as follows: q = number of edges between cell type A and B m = number of edges between cell type B and any other cell type n = the number of edges between any cell type apart from cell type B k = number of edges between cell type B and any other cell type The purist may object to the use of the hypergeometric test here. We may think of "edges out of a cell of type A" as being the random draw balls (here, edges) from the urn and "edges out of cells of type B" as being success. However, all edges out of a given cell of type A are in this "random draw". Clearly the edges in this draw are not independent. However, empirically we find that p-values computed using this method correspond very closely to those computed using permutation while the computation time is orders of magnitude faster.
computeNeighboursDelaunay | This function computes a spatial graph where neighbors are identified based on Delaunay triangulation.
computeNeighboursEuclidean | This function computes a spatial graph where neighbors are identified based on euclidean distance and a user defined threshold.
convertToLong | This is a utility function for converting ligandReceptor cluster-level results to long format and calculates adjusted p-values.
countLRInteractionsPerCell | 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
cullEdges | This subsets edges by our chosen critera
desymmetriseNN | 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.
directedHausdorfDistance | This finds the directed Hausdorf distance from A to B
edgeCutoffsByClustering | 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
edgeCutoffsByPercentile | This finds edge cutoffs by percentile
edgeCutoffsByWatershed | 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.
edgeCutoffsByZScore | This finds edge cutoffs by z-score
edgeLengthPlot | edgeLengthPlot
edgeLengthsAndCellTypePairs | This function annotates edges with their distance and the types of cells they connect
exampleObjects | This returns the names of available example objects.
exSeuratObj | exSeuratObj
formatData | This is a utility function for converting entries in ligandReceptorResults to long format.
geneSetsVsGeneClustersPValueMatrix | 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.
getAverageExpressionDF | This converts an average gene expression matrix to a data frame.
getAverageExpressionMatrix | This computes average expression of each gene cluster in each cell cluster and returns the result as a matrix
getBinarisedMatrix | This functions retrieves an expression matrix from a seurat object or SingleCellExperiment and binarises it.
getClusterOrder | This gets the clusters in their cannonical order
getExtendedNBHDs | This function takes a nearest neighbour graph and a radius and calculates nth degree neighbour graphs where max(n) == radius
getFeatureZScores | This gets z-scores for the values of features
getGeneClusterAveragesPerCell | This produces a matrix giving the average expression of gene clusters in cells. By default, it uses all cells and all gene clusters.
getGeneNeighbors | This function gets the neighbors of a given gene using either the gene Seurat object or its nearest neighbor graph returned from getNearestNeighbourLists
getInteractionsOnEdges | 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.
getLigandReceptorNetwork | This function retrieves the Nichenetr ligand- receptor network for mouse or human.
getLigandReceptorPairsInPanel | 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
getNearbyGenes | Nearby genes
getNearestNeighbourLists | This function extracts a shared nearest neighbor network from a Seurat object
getObjectSubsetClusteringPValue | 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.
getObjectSubsetClusteringStatistics | 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.
getSubsetComponents | This is designed to dectect the components of a gene subset in the case where median complement distance detects clustering.
humanLRN | humanLRN
ligandReceptorResults | ligandReceptorResults
make.getExample | This function makes the function whichretrieves and makes example data objects.
makeLRInteractionHeatmap | This function takes ligandReceptorResults and plots a heatmap of -log10(pvalues). If the minimum p-value is 0 a pseudocount of 0.001 will be added before log transformation.
makeSummedLRInteractionHeatmap | This function takes ligandReceptorResults and plots a heatmap of the total number of ligand receptor interactions between clusters.
meanGeneClusterOnCellUMAP | Mean gene cluster on cell umap
meanZPerCluster | This finds the mean z-score for features in subsets of cells e.g., in each of the seurat_clusters
meanZPerClusterOnUMAP | This collects together mean z-score data together with UMAP coordinates from the gene seurat object for plotting.
medianComplementDistance | 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.
medianComplementPValue | 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.
moransI | moransI
moransILigandReceptor | moransILigandReceptor
mouseLRN | mouseLRN
nbhdsAsEdgesToNbhdsAsList | nbhdsAsEdgesToNbhdsAsList
neighbourhoodDiameter | neighbourhoodDiameter
orderGeneSetPValues | 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
performLigandReceptorAnalysis | 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. If the "analytical" method is selected, an upper tail p-value for observing a given number of A-B edges positive for a given interaction is calculated using a binomial test (R pbinom function) where: q = number of A-B edges positive for an interaction size = total number of A-B edges prob = pL*pR Where pL is the probability of a cell expressing a specific ligand (number of cells positive for a ligand/total cells), and pR is the probability of a cell expressing a specific receptor (number of cells positive for a receptor/total cells). If conditional = True p-values will be calculated given the proportion of cells that express ligands and receptors in the specific clusters (pL = number of cells in cluster A positive for a ligand/number of cells in cluster A, pR = number of cells in cluster B positive for a receptor/number of cells in cluster B). We recommend to use the analytical method, which has a much faster runtime than the permutation-based method, however for legacy purposes and user flexibility we retain the permutation-based method.
performLigandReceptorAnalysisAnalytical | 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 using an analytical approach.
performLigandReceptorAnalysisPermutation | 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 using a permutation-based approach.
permuteColumns | This function permutes the columns of a sparse dcG matrix.
permuteMatrix | This function permutes the rows of a matrix.
plotLRDotplot | This is a function to create a dotplot using the ligand receptor results
predictAnnotation | 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.
predictAnnotationAllGenes | This function predicts the functions of all genes based on the functions of their neighbours.
predictGeneAnnotationImpl | This function is the implementation for predicting the functions of a gene based on the functions of its neighbours.
randomiseGraph | This function performs degree-preserving randomisation of neighbour graphs.
randomiseNodeIndices | This function generates random indices for node B
readGmt | This function reads in gene sets in .gmt format
runGeometricClusteringTrials | This runs random trials to determine the statistical significance of the clustering of a set of points within a larger set.
runMoransI | This function takes a matrix where rows are features and columns are cells, and a neighbourhood list, and computes Moran's I.
sankeyFromMatrix | This makes a sankey graph from a matrix of average expression. Our "Cat's Cradle".
seuratCells | seuratCells
seuratGenes | seuratGenes
smallXenium | smallXenium
stripGeneSet | This function strips out non-gene information from the beginning of GO sets, etc.
symmetriseNN | This symmetrises a nearest neighbors graph.
symmetryCheckNN | Tests whether a nearest neighbor graph is symmetric
tagRowAndColNames | This gussies up the rownames and colnames of M
transposeObject | Create the transpose of a Seurat object
xeniumCells | xeniumCells