-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add phylo
object as metadata
#45
Comments
Should contain: p$phylo # or p$tree ? A phylo (ape) object
p$gg_tree() # A ggtree object |
I am really enjoying my time exploring how to use this R package and like the concept of your suggested enhancement. Would this be something that would provide functionality to say, order the rows of |
Hi @shigdon , I'm glad you found pagoo useful! Yes, that's exactly one of the applications I see of incorporating the phylo object to the pagoo classes. To add this field should be straight-forward, and I haven't done it because we have focused on getting it published (now finishing revisions, so we hope to announce the publication soon). The thing is if I should let this field alone, or to also make other methods "aware" as I said in the issue description. This last thing is much more difficult if I'd want to provide a stable and robust method, and I'm not sure to implement it because there's no obvious or natural way to do it, and will probably look very arbitrary. Still thinking, tho. For now you can use the # Extract only the shell clusters from the panmatrix
pm <- p$pan_matrix[, as.character(p$shell_clusters$cluster) ]
pm[which(pm >= 1, arr.ind = TRUE)] <- 1L # If you just want to show presence/absence, not abundance
# The following is to order the columns to make the hearmap "pretty"
csm <- colSums(pm)
spl <- split(names(csm), csm)
tpm <- t(pm)
norder <- lapply(spl, function(x) {
if (length(x)<2){
x
}else{
d <- vegan::vegdist(tpm[x, , drop=F], method = "jaccard", binary = T, na.rm = T)
hc <- hclust(d, "single")
x[hc$order]
}
})
norder <- norder[order(as.integer(names(norder)), decreasing = T)]
forder <- unlist(norder)
pm <- pm[, forder, drop = F]
# Now transform matrix from integer to character
pm[which(pm == 1 , arr.ind = TRUE)] <- "Present"
pm[which(pm == 0, arr.ind = TRUE)] <- "Absent"
library(phangorn)
library(ggtree)
library(magrittr)
# Suppose you already have a `phylo` object:
tree <- midpoint(phylo) %>% # midpoint root
ggtree() %<+% # Create ggtree
as.data.frame(p$organisms) # Attach organism metadata
tree + geom_tippoint(aes(color = Host)) %>%
gheatmap(pm, colnames = F, color = NA) +
scale_fill_manual(breaks=c("Present", "Absent"),
values=c("darkblue", "white"),
name="genotype") This method works if the selected clusters (columns) are not too many. I usually avoid showing also the core clusters as they would appear as a big square, but under the hood there are potentially hundreds or thousands of small tiles which slow down the rendering. Let me know if this helps you. |
Thank you very much for the great response @iferres! The approach worked very well. The only change I had to make was changing |
Great! Yes, the |
A tree can be considered as pangenome metadata. Provide a method to add a
phylo
object to the pangenome (with$add_metadata()
, and make other methods be aware of it so the can use them to improve, e.g. visualizations.The text was updated successfully, but these errors were encountered: