Skip to contents

Symmetrizes each square matrix in a list by ensuring entries (i, j) and (j, i) are identical, using a specified combination function.

Usage

symmetrize(matrix_list, weight_function = "mean", nCores = 1)

Arguments

matrix_list

A list of square numeric matrices to symmetrize.

weight_function

Character string or function. Method to combine entries (i, j) and (j, i). Options include "mean", "max", "min", or a user-defined function.

nCores

Integer. Number of CPU cores to use for parallel processing. Defaults to the number of available workers in the current BiocParallel backend.

Value

A list of symmetric matrices, where for each matrix \(A[i, j] = A[j, i]\) for all \(i \neq j\).

Details

For each pair of off-diagonal elements (i, j) and (j, i):

  • If one value is zero, the non-zero value is used.

  • If both are non-zero, they are combined using the specified weight_function.

Diagonal entries are preserved as-is and not modified.

Parallelization is managed via BiocParallel for improved performance.

Examples

data("count_matrices")

networks <- infer_networks(
    count_matrices_list = count_matrices,
    method = "GENIE3",
    nCores = 1
)
head(networks[[1]])
#>   regulatoryGene targetGene    weight
#> 1          HLA-A       CD74 0.1928279
#> 2          ARPC2      ARPC3 0.1924564
#> 3          ARPC3      ARPC2 0.1664078
#> 4           CD3E        JUN 0.1549951
#> 5           CD3E       CD3D 0.1495645
#> 6          HLA-E        FOS 0.1492515

wadj_list <- generate_adjacency(networks)
swadj_list <- symmetrize(wadj_list, weight_function = "mean")