Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: R code for Figure 1? #1

Open
morgansobol opened this issue Jun 10, 2023 · 1 comment
Open

Enhancement: R code for Figure 1? #1

morgansobol opened this issue Jun 10, 2023 · 1 comment

Comments

@morgansobol
Copy link

Hi Luca Zoccarato,

First, I would like to say thank you very much for making your R code so easy to follow. I was able to easily adapt it to my data. I was wondering if you happen to have the code you used to produce the final combined plot of the trait presence/absence, LTC, and GTC (Figure 1)? If so, would you be willing to share that here in this repository or with me? Of course, I will be certain to give credit to your work/Github when my work is published :)

Thanks again!
Morgan S.

@lucaz88
Copy link
Owner

lucaz88 commented Jun 20, 2023

Ciao Morgan,
sorry for the late reply. Below you can find the code snippet for the plotting with some explanation. I hope it will be helpful for you. Keep in mind that the figure has been finalized with a graphic editor for minor text/position adjustments.

library(iheatmapr)
library(DescTools)

# required objects:
# gnm_profile -> matrix of genome by trait presence/absence
# LTC_table -> auxiliary matrix with info on annotate traits: trait ids, ann. tool and trait cluster id
# GFC_table -> auxiliary matrix with info on genomes: genome ids, taxonomy, genome cluster id
# trait_hc and gnm_hc are the precomputed dendrograms 

p1_vert = main_heatmap(gnm_profile, name = " ") %>%
  add_row_title("") %>%
  add_row_annotation(data.frame("LTCs" = factor(LTC_table$LTC, levels = LTC_table$LTC[!duplicated(LTC_table$LTC)])),
                     colors = list("LTCs" = LTC_table$LTC_col[!duplicated(LTC_table$LTC)]),
                     size = 0.04, buffer = 0.05, side = "right") %>%
  add_row_dendro(trait_hc, side = "right", size = 0.16, reorder = T) %>%
  add_row_annotation(data.frame("Ann.tool" = factor(LTC_table$Annotation, levels = unique(LTC_table$Annotation))),
                     colors = list("Ann.tool" = brewer.pal(length(unique(LTC_table$Annotation)), "Set3")),
                     size = 0.02, side = "left") %>%
  add_row_summary(layout = list(zeroline = F, title = "Gnm.frac."), size = 0.2, side = "left") %>%
  add_col_title("")  %>%
  add_col_annotation(data.frame("GFCs" = factor(GFC_table$GFC, levels = unique(GFC_table$GFC))),
                     colors = list("GFCs" = DescTools::ColToGray(unique(GFC_table$GFC_col_bw))),
                     size = 0.03, side = "top") %>%
  add_col_dendro(gnm_hc, buffer = 0.02, size = 0.16, side = "top", reorder = T) %>%
  add_col_annotation(data.frame("Taxa" = factor(GFC_table$Taxon_RA, levels = rev(unique(GFC_table$Taxon_RA[gnm_hc$order])))),
                     colors = list("Taxa" = rev(unique(GFC_table$Taxon_col[gnm_hc$order]))),
                     size = 0.03, side = "top")
p1_vert %>% save_iheatmap("hetamap.pdf", vwidth = 1350, vheight = 1000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants