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

ggtree::msaplot in your own example posted on Rbloggers is not working #626

Open
monis4567 opened this issue Aug 15, 2024 · 1 comment
Open

Comments

@monis4567
Copy link

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

@yasche
Copy link

yasche commented Sep 10, 2024

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)

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