buildSNNGraph: Build a nearest-neighbor graph

Description Usage Arguments Value Author(s) See Also Examples

Description

SingleCellExperiment-friendly wrapper around the makeSNNGraph and makeKNNGraph functions for creating nearest-neighbor graphs.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
buildSNNGraph(x, ...)

## S4 method for signature 'ANY'
buildSNNGraph(
  x,
  ...,
  d = 50,
  transposed = FALSE,
  subset.row = NULL,
  BSPARAM = bsparam(),
  BPPARAM = SerialParam()
)

## S4 method for signature 'SummarizedExperiment'
buildSNNGraph(x, ..., assay.type = "logcounts")

## S4 method for signature 'SingleCellExperiment'
buildSNNGraph(x, ..., use.dimred = NULL)

buildKNNGraph(x, ...)

## S4 method for signature 'ANY'
buildKNNGraph(
  x,
  ...,
  d = 50,
  transposed = FALSE,
  subset.row = NULL,
  BSPARAM = bsparam(),
  BPPARAM = SerialParam()
)

## S4 method for signature 'SingleCellExperiment'
buildKNNGraph(x, ..., use.dimred = NULL)

## S4 method for signature 'SingleCellExperiment'
buildKNNGraph(x, ..., use.dimred = NULL)

Arguments

x

A matrix-like object containing expression values for each gene (row) in each cell (column). These dimensions can be transposed if transposed=TRUE.

Alternatively, a SummarizedExperiment or SingleCellExperiment containing such an expression matrix. If x is a SingleCellExperiment and use.dimred is set, its reducedDims will be used instead.

...

For the generics, additional arguments to pass to the specific methods.

For the ANY methods, additional arguments to pass to makeSNNGraph or makeKNNGraph.

For the SummarizedExperiment methods, additional arguments to pass to the corresponding ANY method.

For the SingleCellExperiment methods, additional arguments to pass to the corresponding SummarizedExperiment method.

d

An integer scalar specifying the number of dimensions to use for a PCA on the expression matrix prior to the nearest neighbor search. Ignored for the ANY method if transposed=TRUE and for the SingleCellExperiment methods if use.dimred is set.

transposed

A logical scalar indicating whether x is transposed (i.e., rows are cells).

subset.row

See ?"scran-gene-selection". Only used when transposed=FALSE.

BSPARAM

A BiocSingularParam object specifying the algorithm to use for PCA, if d is not NA.

BPPARAM

A BiocParallelParam object to use for parallel processing.

assay.type

A string specifying which assay values to use.

use.dimred

A string specifying whether existing values in reducedDims(x) should be used.

Value

A graph where nodes are cells and edges represent connections between nearest neighbors, see ?makeSNNGraph for more details.

Author(s)

Aaron Lun

See Also

makeSNNGraph and makeKNNGraph, for the underlying functions that do the work.

See cluster_walktrap and related functions in igraph for clustering based on the produced graph.

Also see findKNN for specifics of the nearest-neighbor search.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(scuttle)
sce <- mockSCE(ncells=500)
sce <- logNormCounts(sce)

g <- buildSNNGraph(sce)
clusters <- igraph::cluster_fast_greedy(g)$membership
table(clusters)

# Any clustering method from igraph can be used:
clusters <- igraph::cluster_walktrap(g)$membership
table(clusters)

# Smaller 'k' usually yields finer clusters:
g <- buildSNNGraph(sce, k=5)
clusters <- igraph::cluster_walktrap(g)$membership
table(clusters)

# Graph can be built off existing reducedDims results:
sce <- scater::runPCA(sce)
g <- buildSNNGraph(sce, use.dimred="PCA")
clusters <- igraph::cluster_fast_greedy(g)$membership
table(clusters)

scran documentation built on April 17, 2021, 6:09 p.m.