Tree with reverse branches / sequence alignment problem

796 views
Skip to first unread message

Radwa Sharaf

unread,
Mar 19, 2017, 3:52:23 PM3/19/17
to ggtree
Hi,

I am new to R and am trying to use ggtree to draw a phylogenetic tree annotated with the sequences aligned next to each branch.

1. In my first step, I am getting a tree with the branches 'reversed'. See pic attached. I am not sure why that is, but here is the code I have used for it:

biocLite(“ggtree”,type=“source”)

library(“ggplot2”)

library(ggtree)

tree <- read.tree("tree.tre")

ggtree(tree)



fasta<-readDNAStringSet("aligned.fas",format="fasta")

msaplot(ggtree(tree),fasta)

When I set the parameter branch.length="none", it looks like a normal tree again.


2. In my second step, to visualize the tree with multiple sequence alignment, every time I run msaplot(ggtree(tree),fasta), I get this:


Error in msaplot(ggtree(tree), fasta) : multiple sequence alignment is not available... -> check the parameter 'fasta'...


but when I check "fasta" by itself, it looks like a fasta file:


> fasta A DNAStringSet instance of length 4 width seq names [1] 9003 GCGCCCGAACAGGGACTTGAAAG...CAATAAAGCTTGCCTTGAGTGC 1 9003 bp [2] 9003 GCGCCCGAACAGGGACCTGAAAA...CAATAAAGCTTGCCTTGAGTGC 4 9003 bp [3] 9003 A----------------------...CAATAAAGCTTGCCTTGAGTGC 2 9003 bp [4] 9003 GCGCCCGAACAGGGACTTGAAAG...CAATAAAGCTTGCCTTGAGTGC 3 9003 bp


Any help would be appreciated!


Thanks,

Radwa

Yu, Guangchuang

unread,
Mar 19, 2017, 10:03:30 PM3/19/17
to Radwa Sharaf, ggtree
I don't know how you 'reverse' your tree. You need to give me a sample tree for testing.


--
G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
 
Homepage: https://guangchuangyu.github.io/ggtree
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree+unsubscribe@googlegroups.com.
To post to this group, send email to bioc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/0cf6bff8-465f-43a4-a54c-932e6fb65976%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu, PhD Candidate
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---

Yu, Guangchuang

unread,
Mar 19, 2017, 10:24:11 PM3/19/17
to Radwa Sharaf, ggtree

ggtree did plotting your tree correctly as you can check:

> x = read.tree("four.tre")
> x$edge.length
[1] -0.00267  0.00361 -0.00230  0.00471  0.00287

that your tree contains negative branch length. You can plot the tree topology without branch length using ggtree(x, branch.length='none').

For the msaplot issue, it is due to the taxa name in your tree not matched with fasta sequences.

> x$tip.label
[1] "1" "4" "2" "3"
> readDNAStringSet("Four.txt") -> s
> names(s)
[1] "1 9003 bp" "4 9003 bp" "2 9003 bp" "3 9003 bp"

If you modify the taxa name, you can align the sequence with the tree.

names(s)  = sub("(\\d).*", "\\1", names(s))
msaplot(ggtree(x), BStringSet(s)) -> p1
msaplot(ggtree(x, branch.length='none'), BStringSet(s)) -> p2
p1 + ggtitle("msaplot(ggtree(x), BStringSet(s))") -> p1
p2 + ggtitle("msaplot(ggtree(x, branch.length='none'), BStringSet(s))") -> p2
multiplot(p1, p2, ncol=2)



On Mon, Mar 20, 2017 at 10:10 AM, Radwa Sharaf <radwa...@gmail.com> wrote:
Hello Guangchuang,

thanks for your reply. I attached a sample tree here, only four sequences. The original aligned four sequences are also attached.

Best,
Radwa

Radwa Sharaf

unread,
Mar 19, 2017, 10:50:35 PM3/19/17
to ggtree
Many thanks Guangchuang!

Working perfectly now :) 
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree...@googlegroups.com.

To post to this group, send email to bioc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/0cf6bff8-465f-43a4-a54c-932e6fb65976%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu, PhD Candidate
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages