ggtree
ggtree copied to clipboard
ggtree::msaplot in your own example posted on Rbloggers is not working
I searched for issues related to the function 'ggtree::msaplot' and found this website: https://www.r-bloggers.com/2016/08/ggtree-for-microbiome-data/
I am unable to get this line working: msaplot(p, Biostrings::BStringSet(barcode), width=.3, offset=.05)
I get this error: Error in msaplot(p, Biostrings::BStringSet(barcode), width = 0.3, offset = 0.05) : multiple sequence alignment is not available... -> check the parameter 'fasta'...
I am trying it out with ggtree in v ‘3.12.0’ in R version 4.4.1 (2024-06-14) in Rstudio 2024.04.2 Build 764 on Ubuntu 22.04.4 LTS
I think I have tracked down the problem. The fasta argument in the msaplot() function appears to be a file location. Writing Biostrings::BStringSet(barcode) to a file fixes the problem.
This does not work:
library(phyloseq)
library(Biostrings)
data(GlobalPatterns)
GP <- prune_taxa(taxa_sums(GlobalPatterns) > 0, GlobalPatterns)
GP.chl <- subset_taxa(GP, Phylum=="Chlamydiae")
p <- ggtree(GP.chl, ladderize = FALSE) + geom_text2(aes(subset=!isTip, label=label), hjust=-.2, size=4) +
geom_tiplab(aes(label=Genus), hjust=-.3) +
geom_point(aes(x=x+hjust, color=SampleType, shape=Family, size=Abundance),na.rm=TRUE) +
scale_size_continuous(trans=log_trans(5)) +
theme(legend.position="right") + ggtitle("reproduce phyloseq by ggtree")
df <- fortify(GP.chl)
barcode <- as.character(df$Barcode_full_length)
names(barcode) <- df$label
barcode <- barcode[!is.na(barcode)]
msaplot(p, Biostrings::BStringSet(barcode), width=.3, offset=.05)
This works:
library(phyloseq)
library(Biostrings)
data(GlobalPatterns)
GP <- prune_taxa(taxa_sums(GlobalPatterns) > 0, GlobalPatterns)
GP.chl <- subset_taxa(GP, Phylum=="Chlamydiae")
p <- ggtree(GP.chl, ladderize = FALSE) + geom_text2(aes(subset=!isTip, label=label), hjust=-.2, size=4) +
geom_tiplab(aes(label=Genus), hjust=-.3) +
geom_point(aes(x=x+hjust, color=SampleType, shape=Family, size=Abundance),na.rm=TRUE) +
scale_size_continuous(trans=log_trans(5)) +
theme(legend.position="right") + ggtitle("reproduce phyloseq by ggtree")
df <- fortify(GP.chl)
barcode <- as.character(df$Barcode_full_length)
names(barcode) <- df$label
barcode <- barcode[!is.na(barcode)]
writeXStringSet(Biostrings::BStringSet(barcode), "file.fasta")
msaplot(p, "file.fasta", width = 0.3, offset = 0.05)