Snitkin-Lab-Umich / regentrans

regentrans: R package for investigating regional pathogen transmission using genomic data
Other
5 stars 1 forks source link

[Add to vignette] Code to assign each isolate to a cluster based on the get_clusters output #19

Closed kylegontjes closed 3 years ago

kylegontjes commented 3 years ago

Consider adding code to assign each isolate into a cluster based on the get_clusters output.

This would assist the reader in visualizing the cluster results across the phylogeny!

Furthermore, it would be appreciated if the clusters could be visualized across the phylogeny (e.g., add to the "Visualize the Phylogenetic Tree Annotated by Location" gheatmap).

See:

 clusts <- get_clusters(tr_sub, col_sub_w_muts[tr_sub$tip.label], pureness = 1)
isolates_clusters <- sapply(1:nrow(clusts$pure_subtree_info), function(x){
  i <- clusts$pure_subtree_info$index[x]
  name <- clusts$pure_subtree_info$isolate_name[x]
  if(!is.na(i)){
    name <- clusts$subtrees[[i]]$tip.label
  }
  name
})
r_clusters <- isolates_clusters[clusts$pure_subtree_info$f_id == 'R']
names(r_clusters) <- 1:length(r_clusters)
cluster_nums <- unlist(sapply(names(r_clusters), function(x){
  rep(x, length(r_clusters[[x]]))
}))
names(cluster_nums) <- unlist(r_clusters)