buildGraph {miloR} | R Documentation

## Build a k-nearest neighbour graph

### Description

This function is borrowed from the old buildKNNGraph function in scran. Instead of returning an igraph object it populates the graph and distance slots in a Milo object. If the input is a SingleCellExperiment object or a matrix then it will return a de novo Milo object with the same slots filled.

### Usage

    buildGraph(
      x,
      k = 10,
      d = 50,
      transposed = FALSE,
      get.distance = FALSE,
      reduced.dim = "PCA",
      BNPARAM = KmknnParam(),
      BSPARAM = bsparam(),
      BPPARAM = SerialParam()
    )

### Arguments

`x` | A matrix, `SingleCellExperiment` or Milo object containing feature X cell gene expression data.
`k` | An integer scalar that specifies the number of nearest-neighbours to consider for the graph building.
`d` | The number of dimensions to use if the input is a matrix of cells X reduced dimensions. If this is provided, transposed should also be set=TRUE.
`transposed` | Logical if the input x is transposed with rows as cells.
`get.distance` | A logical scalar whether to compute distances during graph construction.
`reduced.dim` | A character scalar that refers to a specific entry in the `reduceDim` slot of the `Milo` object.
`BNPARAM` | refer to `buildKNNGraph` for details.
`BSPARAM` | refer to `buildKNNGraph` for details.
`BPPARAM` | refer to `buildKNNGraph` for details.

### Details

This function computes a k-nearest neighbour graph. Each graph vertex is a single-cell connected by the edges between its neighbours. Whilst a kNN-graph is strictly directed, we remove directionality by forcing all edge weights to 1; this behaviour can be overriden by providing `directed=TRUE`.

If you wish to use an alternative graph structure, such as a shared-NN graph I recommend you construct this separately and add to the relevant slot in the `Milo` object.

### Value

A `Milo` object with the graph and distance slots populated.

### Author(s)

Mike Morgan, with KNN code written by Aaron Lun & Jonathan Griffiths.

### Examples

    library(SingleCellExperiment)
    ux <- matrix(rpois(12000, 5), ncol=200)
    vx <- log2(ux + 1)
    pca <- prcomp(t(vx))

    sce <- SingleCellExperiment(assays=list(counts=ux, logcounts=vx),
                                reducedDims=SimpleList(PCA=pca$x))

    milo <- Milo(sce)
    milo <- buildGraph(milo, d=30, transposed=TRUE)

    milo

[Package miloR version 1.2.0 Index]