-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathggtree.R
105 lines (87 loc) · 3.18 KB
/
ggtree.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# powerfull vittage at:
# https://bioconductor.org/packages/devel/bioc/vignettes/ggtree/inst/doc/treeManipulation.html#scale-clade
# http://pluie.xyz/2018/Bioc_ggtree/
library("treeio")
library("ggtree")
dir <- c("/Users/cigom/Desktop/viki")
setwd(dir)
# Load tree :::::
#netwick <- args[0]
tree <- treeio::read.newick("bacterial.trim.contigs.ALL.fasta.NJ.tree.2.txt")
tbl <- read.csv("contigs.sina.csv", sep=",", stringsAsFactors = FALSE, header=TRUE)
png(filename = "tree_type.png",
width = 20, height = 10, units = "in",
res = 460)
multiplot(
ggtree(tree) + geom_treescale(width=0.4),
ggtree(tree, branch.length = "none") + geom_treescale(width=0.4),
ggtree(tree, branch.length='none', layout="daylight") + geom_treescale(width=0.4) + geom_nodepoint(),
ggtree(tree, branch.length='none', layout='circular') + geom_treescale(width=0.4),
ncol=4,labels = LETTERS[1:4])
dev.off()
# and labels
p <- ggtree(tree) +
geom_nodepoint(color="#b5e521", alpha=1/4, size=4) + geom_treescale(width=0.4)
png(filename = "node_type.png",
width = 18, height = 10, units = "in",
res = 460)
multiplot(# add node points
p + geom_nodepoint(),
# add tip points
p + geom_tippoint(),
# Label the tips
p + geom_tiplab(),
ncol=3,labels = LETTERS[1:3])
dev.off()
# other approach
d <- ggtree(tree) + geom_treescale(width=0.4) + geom_nodepoint()
png(filename = "tree.png",
width = 16, height = 10, units = "in",
res = 460)
d %<+% tbl +
geom_tiplab(size=4, aes(label=paste0('italic(', label, ')~bolditalic(', Family, ')~', Genus)), parse=TRUE)
dev.off()
png(filename = "tree.2.png",
width = 16, height = 10, units = "in",
res = 460)
d %<+% tbl +
geom_tiplab(size=4, aes(label=paste0('italic(', label, ')~bolditalic(', Family, ')~', Genus)), parse=TRUE) +
geom_point(aes(color=Family), size=5, alpha=.5) + theme(legend.position="right")
dev.off()
# :: plot aligment
m <- d + geom_tiplab()
# geom_tiplab(align=TRUE, linesize=.5)
fst <- read.fasta("./bacterial.trim.contigs.ALL.fasta.clustalw.2.txt")
png(filename = "tree.3.png",
width = 16, height = 10, units = "in",
res = 460)
msaplot(p=m, fasta=fst, height = 0.4, offset=0.05)
dev.off()
#:::::
png(filename = "tree.nodes.png",
width = 20, height = 12, units = "in",
res = 460)
multiplot(d + geom_treescale(),
d + geom_text(aes(label=node), hjust=-.3),
d + geom_tiplab(),
ncol=3,labels = LETTERS[1:3])
dev.off()
#:::: paint something more
n <- MRCA(tree, tip=c("A7_7", "A7_8"))
n
# [1] 16
png(filename = "tree.further.png",
width = 20, height = 12, units = "in",
res = 460)
multiplot(
ggtree(tree) + geom_cladelabel(node = n, label="Random text", color="red"),
ggtree(tree) + geom_hilight(node = n, "steelblue"),
ggtree(tree) + geom_hilight(node = n, "steelblue") + geom_cladelabel(node=16, label="Random text", color="red"),
ncol=3,labels = LETTERS[1:3] )
dev.off()
#:: in python reverse complementary sequence from
from Bio.Seq import Se
from Bio import SeqIO
for record in SeqIO.parse("../reverse_only.fasta", "fasta"):
print(record.id)
print(record.seq.reverse_complement())