Skip to content
Snippets Groups Projects
pivot_cluster_tbl_wider.R 781 B
#' Make wide table of clusters (listing all sequences in each cluster)
#'
#' @param cluster_tbl A data frame containing the cluster and sequence information
#'
#' @return A wide table of clusters with all sequences in each cluster listed
#'
#' @import dplyr
#' @import tidyr
#' @export
#'
pivot_cluster_tbl_wider <- function(cluster_tbl) {
  # First: get names of each cluster
  cluster_names <- cluster_tbl %>%
    dplyr::rename(clus_name = seqnames) %>%
    group_by(cluster) %>%
    slice_head(n = 1)
  # Second: combine names with clusters and reshape tbls
  cluster_tbl <- left_join(stable_cluster, cluster_names, by = 'cluster') %>%
    group_by(cluster) %>%
    mutate(num = row_number()) %>%
    pivot_wider(names_from = clus_name, values_from = seqnames, id_cols = num)
}