Files in a cellranger run
Cellranger removes the intermediary files after the clusters have been computed. This can be observed in the following path from the cellranger project directory. This contains empty directories.
However, the clusters generated by cellranger can be found in the file:
Clusters can also be "exported" from
outs/cloupe.cloupe file into a CSV using the Cloupe Browser. These CSVs can be imported and used for plotting in R or Python.
The graph structure used to compute these (with the Louvian algorithm) cannot be found in the files generated by cellranger.
Reproducing graph-based clustering
The Suerat R package performs graph-based clustering. The shared nearest neighbour (SNN) modularity optimisation uses the same parameters as the Python scripts called by cellranger (
k=30). This generates an SNN matrix which can be used to generate a graph structure from an adjacency matrix. For a Seurat object
test the SNN sparse matrix can be extract with:
FindClusters(test, dims.use = 1:20, algorithm = 1,
resolution = 0.6, k.param = 30, save.SNN = TRUE,
reduction.use = "pca", metric = "euclidean")
SNN_Matrix <- as.matrix(ceiling(as.matrix(test@snn)
graph_structure <- igraph::graph_from_adjacency(SNN_matrix)
FindClusters from the
Seurat package requires a Seurat object that has already has a dimension reduction run on it such as
algorithm = 1 is the Louvian algorithm as performed by cellranger. The
metric can be changed as mentioned in the
Suerat package documentation. Clustering algorithms not yet supported by Seurat can be run on the
graph_structure resulting from extracting the SNN matrix. It is not necessary to compute the edges separately, the Seurat functions will compute and return these.
For example, the Leiden algorithm can be computed as follows:
clusters <- leiden(SNN_Matrix)