Constructs a matrix of gene-gene relationships based on distance metrics.
extract_angles(x_mat, method = "cosine")
An FBM
object containing raw gene
expression data, where rows correspond to genes and columns to samples.
The data will be normalized and scaled within the function.
A character string specifying the method to compute the gene-gene relationships. Options are:
"cosine"
(default): Computes the cosine angle between
genes.
"spearman"
: Computes the Spearman rank correlation
coefficient by rank-transforming the data before computing the
correlation.
An FBM
object containing the gene-gene
correlation matrix. The matrix is square with dimensions equal to the
number of genes and contains the pairwise correlations between genes.
The diagonal elements are set to NA
.
The function returns the gene-gene angle matrix as an
FBM
object.
mat <- matrix(
c(
5, 3, 0, 0,
0, 0, 0, 3,
2, 1, 3, 4,
0, 0, 1, 0,
1, 2, 1, 2,
3, 4, 3, 4
),
nrow = 6, # 6 genes
ncol = 4, # 4 cells
byrow = TRUE
)
mat <- bigstatsr::FBM(nrow = nrow(mat), ncol = ncol(mat), init = mat)
angle_mat <- extract_angles(mat)
angle_mat[]
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] NA -0.5443311 -0.7378648 -0.5443311 -0.2357023 -0.2357023
#> [2,] -0.5443311 NA 0.7745967 -0.3333333 0.5773503 0.5773503
#> [3,] -0.7378648 0.7745967 NA 0.2581989 0.0000000 0.0000000
#> [4,] -0.5443311 -0.3333333 0.2581989 NA -0.5773503 -0.5773503
#> [5,] -0.2357023 0.5773503 0.0000000 -0.5773503 NA 1.0000000
#> [6,] -0.2357023 0.5773503 0.0000000 -0.5773503 1.0000000 NA