merge_clusters {seqsetvis} | R Documentation

## merge_clusters

### Description

merge_clusters

### Usage

    merge_clusters(
      clust_dt,
      to_merge,
      row_ = "id",
      cluster_ = "cluster_id",
      reapply_cluster_names = TRUE
    )

### Arguments

`clust_dt` | data.table output from `ssvSignalClustering`
`to_merge` | Clusters to merge. Must be items in clust_dt variable defined by cluster_ parameter.
`row_` | variable name mapped to row, likely id or gene name for ngs data. Default is "id" and works with ssvFetch* output.
`cluster_` | variable name to use for cluster info. Default is "cluster_id".
`reapply_cluster_names` | If TRUE, clusters will be renamed according to new order instead of their original names. Default is TRUE.

### Value

data.table as output from `ssvSignalClustering`

### Examples

    set.seed(0)
    clust_dt = ssvSignalClustering(CTCF_in_10a_profiles_dt, nclust = 6)
    ssvSignalHeatmap(clust_dt)
    agg_dt = clust_dt[, list(y = mean(y)), list(x, cluster_id, sample)]
    ggplot(agg_dt, aes(x = x, y = y, color = sample)) +
      geom_path() +
      facet_grid(cluster_id~.)

    to_merge = c(2, 3, 5)
    # debug(merge_clusters)
    new_dt = merge_clusters(clust_dt, c(2, 3, 5), reapply_cluster_names = FALSE)
    new_dt.relabel = merge_clusters(clust_dt, c(2, 3, 5), reapply_cluster_names = TRUE)
    new_dt.relabel.sort = within_clust_sort(new_dt.relabel, within_order_strategy = "sort")

    table(clust_dt$cluster_id)
    table(new_dt$cluster_id)

    cowplot::plot_grid(
      ssvSignalHeatmap(clust_dt) + labs(title = "original"),
      ssvSignalHeatmap(new_dt) + labs(title = "2,3,5 merged"),
      ssvSignalHeatmap(new_dt.relabel) + labs(title = "2,3,5 merged, renumbered"),
      ssvSignalHeatmap(new_dt.relabel.sort) + labs(title = "2,3,5 merged, renumbered and sorted")
    )

[Package seqsetvis version 1.14.4 Index]