R/get_jac_mat.R

Defines functions get_jac_mat

Documented in get_jac_mat

#' Create matrix for Jaccard calculation
#'
#' @param list A named list of pathways and their constituent genes
#'
#' @import purrr
#' @import dplyr
#' @import tidyr
#' @import tibble
#'
#' @description An internal helper function to construct a matrix from the list
#' of pathways and their genes.
#'
#' @return A matrix of overlapping genes among all pathways
#'
get_jac_mat <- function(list) {
  list %>%
    map(~data.frame(id = .x)) %>%
    bind_rows(.id = "name") %>%
    mutate(present = 1) %>%
    distinct(name, id, .keep_all = TRUE) %>%
    pivot_wider(
      id_cols     = "id",
      names_from  = "name",
      values_from = "present"
    ) %>%
    replace(is.na(.), 0) %>%
    column_to_rownames(var = "id")
}
hancockinformatics/clusterPathways documentation built on March 19, 2022, 7:23 p.m.