scaledColRanks {scran} | R Documentation

## Compute scaled column ranks

### Description

Compute scaled column ranks from each cell's expression profile for distance calculations based on rank correlations.

### Usage

    scaledColRanks(
      x,
      subset.row = NULL,
      min.mean = NULL,
      transposed = FALSE,
      as.sparse = FALSE,
      withDimnames = TRUE,
      BPPARAM = SerialParam()
    )

### Arguments

`x` | A numeric matrix-like object containing cells in columns and features in the rows.
`subset.row` | A logical, integer or character scalar indicating the rows of `x` to use, see `?"scran-gene-selection"`.
`min.mean` | A numeric scalar specifying the filter to be applied on the average normalized count for each feature prior to computing ranks. Disabled by setting to `NULL`.
`transposed` | A logical scalar specifying whether the output should be transposed.
`as.sparse` | A logical scalar indicating whether the output should be sparse.
`withDimnames` | A logical scalar specifying whether the output should contain the dimnames of `x`.
`BPPARAM` | A BiocParallelParam object specifying whether and how parallelization should be performed. Currently only used for filtering if `min.mean` is not provided.

### Details

Euclidean distances computed based on the output rank matrix are equivalent to distances computed from Spearman's rank correlation. This can be used in clustering, nearest-neighbour searches, etc. as a robust alternative to Euclidean distances computed directly from `x`.

If `as.sparse=TRUE`, the most common average rank is set to zero in the output. This can be useful for highly sparse input data where zeroes have the same rank and are themselves returned as zeroes. Obviously, this means that the ranks are not centred, so this will have to be done manually prior to any downstream distance calculations.

### Value

A matrix of the same dimensions as `x`, where each column contains the centred and scaled ranks of the expression values for each cell. If `transposed=TRUE`, this matrix is transposed so that rows correspond to cells. If `as.sparse`, the columns are not centered to preserve sparsity.

### Author(s)

Aaron Lun

### See Also

`quickCluster`, where this function is used.

### Examples

    library(scuttle)
    sce <- mockSCE()
    rout <- scaledColRanks(counts(sce), transposed=TRUE)

    # For use in clustering:
    d <- dist(rout)
    table(cutree(hclust(d), 4))

    g <- buildSNNGraph(rout, transposed=TRUE)
    table(igraph::cluster_walktrap(g)$membership)

[Package scran version 1.18.7 Index]