-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path08_serine_protease_bigtree.Rmd
177 lines (118 loc) · 7.61 KB
/
08_serine_protease_bigtree.Rmd
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
---
title: "Serine Protease Tree"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(ggtree)
library(ape)
library(phangorn)
#source("https://bioconductor.org/biocLite.R")
#biocLite("ggtree")
source("R/utils.R")
```
```{r, prepare_data}
tree <- read.tree("raw_data/serine_proteases/sp1_200_molluscs_v2.fasta.contree")
tip_data <- serine_protease_treedata()
tissue_expression_data <- readxl::read_excel("figures/tree_sequences.xlsx") %>%
select(ID,Expression) %>%
mutate(PSG = ifelse(Expression=="PSG","YES","NO"))
tip_data <- tip_data %>% left_join(tissue_expression_data)
tree$tip.label <- tree$tip.label %>% str_replace_all(pattern = "_-_PF00089", replacement = "")
```
As a useful aside we save a table of all sequences and metadata used for the tree. This might form a supplementary table for the paper
```{r}
write_tsv(tip_data,"figures/tree_sequences.tsv")
```
Plot the big tree unrooted
```{r}
tip_data$Order <- factor(tip_data$Order, levels = c("Octopus","Cuttlefish","Squid","Gastropod","Bivalve"))
```
```{r}
# ,619,629,327,636,,629,
bootstrap_nodes <- c(337,336,335,334,333,332,512,523,330,509,523,574,596,620,629,626,430,433,340,341,367539,434,504,539,368,453)
sp_unrooted <- ggtree(tree,size=0.1, layout="unrooted") %<+% tip_data +
# geom_text2(aes(subset = !isTip, label=node), hjust=1.2, vjust = -0.5, size=1) + # Uncomment to show node labels
# geom_tiplab(aes(label=simple_label,color=Order),size=1) +
# geom_text2(aes(subset = (!isTip & label>90), label=label), hjust=-0.2, vjust = 0.0, size=1,color="green") +
geom_nodelab(aes(subset = (label > 90) & (node %in% bootstrap_nodes), label=label), hjust=-0.2, vjust = 0.0, size=2, check_overlap = FALSE) +
geom_nodepoint(aes(subset = (label > 90) & (node %in% bootstrap_nodes)), size=1) +
geom_tippoint(aes(color=Order,fill=Order,shape=PSG)) + scale_shape_manual(values=c("YES"=1,"NO"=21)) +
geom_hilight_encircle(node=337) +
guides(fill=FALSE,shape=FALSE) +
scale_color_manual(values= c("Octopus"="#FFB7B7","Cuttlefish"="#FF7474","Squid"="#FF0207","Gastropod"="#5DB330","Bivalve"="#3283EA")) +
scale_fill_manual(values= c("Octopus"="#FFB7B7","Cuttlefish"="#FF7474","Squid"="#FF0207","Gastropod"="#5DB330","Bivalve"="#3283EA")) +
theme(legend.position=c(0.8,0.2), legend.text = element_text(size=7,face = "italic"), legend.title = element_blank(),legend.key.size = unit(2,"mm")) +
guides(color = guide_legend(override.aes = list(size = 3)))
ggsave(sp_unrooted,filename = "figures/serine_proteases_unrooted_tree.png", width = 17.8, height = 14, units = "cm")
ggsave(sp_unrooted,filename = "figures/serine_proteases_unrooted_tree.pdf", width = 17.8, height = 14, units = "cm")
```
Plot big tree unrooted in simplified form suitable for graphical abstract
```{r}
tip_data_simplified <- tip_data %>%
mutate(Class = ifelse( Order %in% c("Octopus", "Cuttlefish", "Squid"), "Cephalopod", as.character(Order)) )
sp_unrooted_simple <- ggtree(tree,size=0.1, layout="unrooted") %<+% tip_data_simplified +
geom_tippoint(aes(color=Class),size=0.5) +
geom_hilight_encircle(node=336) +
# geom_hilight_encircle(node=504) +
scale_color_manual(values= c("Cephalopod"="#FF0001","Gastropod"="#5DB330","Bivalve"="#3283EA")) +
theme(legend.position=c(0.8,0.1),legend.background = element_rect(fill="transparent"), legend.text = element_text(size=6, family = "Helvetica"), legend.title = element_blank(),legend.key.size = unit(2,"mm"))
#+ guides(color = guide_legend(override.aes = list(size = 3)))
ggsave(sp_unrooted_simple,filename = "figures/serine_proteases_unrooted_tree_toc.pdf", width = 5, height = 5, units = "cm")
```
<!-- First plot a large tree with all species -->
<!-- ```{r} -->
<!-- rtree <- midpoint(tree) -->
<!-- tip_data$Order <- factor(tip_data$Order,levels = c("Octopus","Cuttlefish","Squid","Gastropod","Bivalve")) -->
<!-- sp_tree_plot <- ggtree(rtree,size=0.1) %<+% tip_data + geom_tiplab(aes(label=simple_label,color=Order),size=1) + -->
<!-- geom_text2(aes(subset = !isTip, label=label), hjust=1.2, vjust = -0.5, size=1) + # Uncomment to show node labels. This tell us that node 337 is what we want for the detailed tree -->
<!-- # geom_text2(aes(subset = !isTip, label=node), hjust=1.2, vjust = -0.5, size=1) + -->
<!-- geom_treescale(offset = -2) + -->
<!-- theme(legend.position=c(0.8,0.7), legend.text = element_text(size=7,face = "italic"), legend.title = element_blank(), -->
<!-- legend.key.size = unit(2,"mm")) + -->
<!-- xlim(0,3.30) + -->
<!-- #scale_color_manual(values= c("Octopus"="#FF7E79","Cuttlefish"="#FF9300","Squid"="#FFD479","Gastropod"="#0096FF","Bivalve"="#942193")) + -->
<!-- guides(color = guide_legend(override.aes = list(size = 3))) -->
<!-- ggsave(sp_tree_plot,filename = "figures/serine_proteases_tree.png", width = 17.8, height = 20, units = "cm") -->
<!-- ``` -->
<!-- Plot the same tree unrooted to use as an inset -->
<!-- ```{r} -->
<!-- sp_unrooted_tree_plot <- ggtree(tree,size=0.1, layout="equal_angle", aes(color=Order)) %<+% tip_data + -->
<!-- theme(legend.position=c(0.8,0.7), legend.text = element_text(size=7,face = "italic"), legend.title = element_blank(), -->
<!-- legend.key.size = unit(2,"mm")) + -->
<!-- geom_cladelabel(node=337, "A") + -->
<!-- # xlim(0,3.30) + -->
<!-- scale_color_manual(values= c("Octopus"="#FF7E79","Cuttlefish"="#FF9300","Squid"="#FFD479","Gastropod"="#0096FF","Bivalve"="#942193")) + -->
<!-- guides(color = guide_legend(override.aes = list(size = 3))) -->
<!-- ggsave(sp_unrooted_tree_plot,filename = "figures/serine_proteases_unrooted_tree.png", width = 17.8, height = 20, units = "cm") -->
<!-- ``` -->
<!-- Try plotting this with clade 335 collapsed -->
<!-- ```{r} -->
<!-- sp_tree_plot_cc <- collapse(sp_tree_plot,335) + -->
<!-- geom_point2(aes(subset=(node == 335)), size=5, shape=23, fill="steelblue") + -->
<!-- geom_text2(aes(subset=(node == 335)), label="Cephalopod, Bivalve and Gastropod Serine Proteases", hjust=-0.2) -->
<!-- ggsave(flip(sp_tree_plot_cc,335,509), filename = "figures/serine_proteases_tree_cc.png",width = 17.8, height = 60, units = "cm") -->
<!-- ``` -->
Now extract clade 337
```{r}
sp337_tree <- extract.clade(tree,337)
sp337_tree_plot <- ggtree(sp337_tree) %<+% tip_data + geom_tiplab(aes(label=simple_label,color=Species)) +
geom_text2(aes(subset = !isTip, label=label), hjust=1.2, vjust = -0.5, size=3) + # Uncomment to show node labels. This tell us that node 280 is what we want for the detailed tree
# geom_text2(aes(subset = !isTip, label=node), hjust=1.2, vjust = -0.5, size=3) +
geom_treescale(offset = -2) +
theme(legend.position=c(0.8,0.8), legend.text = element_text(face = "italic"), legend.title = element_blank()) +
xlim(0,3.30)
ggsave(sp337_tree_plot,filename = "figures/serine_proteases_tree_zoom.png", width = 17.8, height = 60, units = "cm")
```
Extract sequences for this clade to make a separate analysis ( this serves as input to geneious )
```{r}
write_tsv(tip_data %>% filter(ID %in% sp337_tree$tip.label),path = "raw_data/serine_proteases/octo_sp.tsv")
```
Also write a version restricting to core taxa only
```{r}
#core_species <- c("Octopus bimaculoides","Hapalochlaena maculosa","Octopus vulgaris")
core_species <- c("Octopus bimaculoides","Sepia officinalis","Octopus vulgaris", "Lottia gigantea","Hapalochlaena maculosa")
#core_species <- c("Octopus bimaculoides","Sepia officinalis","Octopus vulgaris")
write_tsv(tip_data %>% filter(ID %in% sp337_tree$tip.label) %>% filter(Species %in% core_species),path = "raw_data/serine_proteases/octo_core_sp.tsv")
```