buildFromAdjacency {miloR} | R Documentation

## Build a graph from an input adjacency matrix

### Description

Construct a kNN-graph from an input adjacency matrix - either binary or distances between NNs.

### Arguments

`x` | An n X n `matrix` of single-cells, where values represent edges between cells; 0 values are taken to mean no edge between cells. If the matrix is not binary, then it is assumed the values are distances; 0 retain the same meaning. This behaviour can be toggled using `is.binary=TRUE`.
`k` | (optional) Scalar value that represents the number of nearest neighbours in the original graph. This can also be inferred directly from the adjacency matrix `x`.
`is.binary` | Logical scalar indicating if the input matrix is binary or not.

### Details

This function will take a matrix as input and construct the kNN graph that it describes. If the matrix is not symmetric then the graph is assumed to be directed, whereas if the matrix is not binary, i.e. all 0's and 1's then the input values are taken to be distances between graph vertices; 0 values are assumed to represent a lack of edge between vertices.

### Value

A `Milo` with the graph slot populated.

### Author(s)

Mike Morgan

### Examples

    r <- 1000
    c <- 1000
    k <- 35
    m <- floor(matrix(runif(r*c), r, c))
    for(i in seq_along(1:r)){
        m[i, sample(1:c, size=k)] <- 1
    }

    milo <- buildFromAdjacency(m)

[Package miloR version 1.2.0 Index]