-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path4.3.0_analyse_ballester.R
258 lines (191 loc) · 10.4 KB
/
4.3.0_analyse_ballester.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Ballester data analysis:
# take liver CREs from macaque, translate to hg38 and then to hg18
# overlap with TFBS (translate to the same coordinate system)
# check if high PD is more conserved (more 1s)
#setwd("/data/share/htp/pleiotropy/paper_data/")
library(tidyverse)
library(data.table)
library(plyranges)
library(readxl)
# these are all the helper functions for the project
source("scripts/helper_functions.R")
source("ATACseq/scripts/functions.R")
source("ATACseq/scripts/helper_functions.R")
mammaltree<-read.tree("/data/share/htp/TRNP1/paper_data/Co-evolution-TRNP1-and-GI/protein/trees/mammaltree.txt")
specificityColors <- c( "#A3753B", "#CC9B57", "#E7CF97", "#F8EDD0", "#F7F7F7", "#D2EEEA", "#99D7CE", "#5DACA5", "#33847E")
names(specificityColors) <- c(1:9)
basic_theme_ins2<- theme(axis.title=element_text(size=8),
axis.text = element_text(color="black", size=7),
legend.title = element_text(size = 7.3),
legend.text = element_text(size = 7),
legend.key.size = unit(0.5, "lines"),
legend.margin=margin(0,0,0,0),
legend.box.margin=margin(0,0,0,0),
legend.background = element_blank(),
legend.box.background = element_blank(),
panel.grid.major = element_line(size = 0.35),
panel.grid.minor = element_blank(),
strip.text = element_text(size = 8))
# Strategy:
# 1) Select collapsed_ids for CREs in macaque that are open in the liver in any of the 5 species
# 2) Identify PD1: the ones that are PD1 in human (i.e. not in our data) AND PD1 in macaque in Roller et al
# 3) Identify PD9: PD9 in human AND PD4 in macaque in Roller et al
# 4) Split by TF etc. Calculate phylogenetic age as for CRE activity
# Get liver CRE coordinates (with PD) -------------------------------------
# need to select collapsed_region_ids from all livers in 4 species that
# these are macaque collapsed CREs
hummac<-readRDS("Roller2021/chipseq_OL_humJamm_mac_collapsed.rds") %>%
dplyr::select(region_id, collapsed_region_id) %>%
left_join(readRDS("Roller2021/chipseq_macregs_collapsed.rds")) %>%
right_join(readRDS("roadmap_DHS_summaries/region_summary/jamm_region_info_full.rds") %>%
dplyr::select(region_id, total))
# Select PD9s (us) and PD4s (Roller)
hummac_pleiotropic<-hummac %>% filter(total_mmul == 4 & total == 9)
# Select liver PD1s (Roller) not present in our data
macregs_PD1_liver<-readRDS("Roller2021/chipseq_macregs_collapsed.rds") %>%
dplyr::filter(tissues_mmul == "Liver", total_mmul ==1) %>%
anti_join(hummac)
# Combine liver-specific and pleiotropic CREs
liverCREs_mmul10<-bind_rows(hummac_pleiotropic %>%
dplyr::select(seqnames, start, end, collapsed_region_id) %>%
dplyr::mutate(type="pleiotropic"),
macregs_PD1_liver %>%
dplyr::select(seqnames, start, end, collapsed_region_id) %>%
dplyr::mutate(type="liver-specific"))
dim(liverCREs_mmul10)
# Translate TFBS from hg18 to mmul10 --------------------------------------
tfbs_liver_hg18 <- read_excel("Ballester2014/elife-02626-fig2-data1-v1.xlsx") %>%
dplyr::transmute(seqnames=chr, start=start_hg18, end=stop_hg18, CRM_or_singleton_name,
CRM_status, shared_status_hsap_mmul_mmus_rnor_cfam, region_id = 1:nrow(.))
tfbs_hg19<-translate_jamm(chain_file = "liftOvers/hg18ToHg19.over.chain",
coordinate_file = as_granges(tfbs_liver_hg18),
extend = 50,
reverse_chain_file = "liftOvers/hg19ToHg18.over.chain")
tfbs_mmul10<-translate_jamm(chain_file = "liftOvers/hg19ToRheMac10.over.chain",
coordinate_file = as_granges(tfbs_hg19),
extend = 50,
reverse_chain_file = "liftOvers/rheMac10ToHg19.over.chain") %>%
left_join(tfbs_liver_hg18 %>%
dplyr::select(region_id, CRM_or_singleton_name,
CRM_status, shared_status_hsap_mmul_mmus_rnor_cfam)) %>%
dplyr::select(-region_id)
# Annotate liver CREs where TFBS are within -------------------------------
liverPD_TFBS<-join_overlap_left(as_granges(liverCREs_mmul10), as_granges(tfbs_mmul10)) %>%
filter(!is.na(shared_status_hsap_mmul_mmus_rnor_cfam)) %>%
as_tibble() %>%
rowwise() %>%
dplyr::mutate(
n_TFspecies = sum(as.numeric(strsplit(as.character(shared_status_hsap_mmul_mmus_rnor_cfam), "")[[1]])),
macaque=ifelse(substring(as.character(shared_status_hsap_mmul_mmus_rnor_cfam), 2, 2) == "1",T,F),
TF = word(CRM_or_singleton_name, 1,1,":"),
TF = ifelse(TF=="HNF6", "ONECUT1", TF))
saveRDS(liverPD_TFBS, "Ballester2014/summarized_PD1_PD9_TFBS_mmul10.rds")
pProps<-ggplot(liverPD_TFBS %>%
mutate(type = ifelse(type=='liver-specific','liver-\nspecific', type)),
aes(x = type, fill = as.factor(n_TFspecies)))+
geom_bar(position="fill")+
theme_bw()+
scale_fill_manual(values=c("1" = "#ffcdb2",
"2" = "#ffb4a2",
"3" = "#e5989b",
"4" = "#b5838d",
"5" = "#6d6875"),
name="# of species\nwith conserved\nTF repertoire")+
xlab("CREs") +
ylab("Fraction")+
basic_theme_ins2+
theme(axis.text = element_text(color="black"))
pProps
# Calculate TFBS repertoire phylogenetic age -----------------------------
liverPD_TFBS_long<-readRDS("Ballester2014/summarized_PD1_PD9_TFBS_mmul10.rds") %>%
dplyr::transmute(collapsed_region_id, CRM_or_singleton_name,
status = shared_status_hsap_mmul_mmus_rnor_cfam, TF, type) %>%
dplyr::mutate(
Homo_sapiens=ifelse(substring(as.character(status), 1, 1) == "1",1,0),
Macaca_mulatta=ifelse(substring(as.character(status), 2, 2) == "1",1,0),
Mus_musculus=ifelse(substring(as.character(status), 3, 3) == "1",1,0),
Rattus_norvegicus=ifelse(substring(as.character(status), 4, 4) == "1",1,0),
Canis_lupus=ifelse(substring(as.character(status), 5, 5) == "1",1,0)
) %>%
pivot_longer(6:10, names_to = "latin") %>%
filter(value == 1) %>%
dplyr::select(-value)
# generate a tree
BallesterSpeciesTree<-drop.tip(mammaltree, mammaltree$tip.label[!mammaltree$tip.label %in% c("Homo_sapiens","Macaca_mulatta","Canis_lupus", "Mus_musculus", "Rattus_norvegicus")])
BallesterSpeciesTree_plot<-BallesterSpeciesTree
BallesterSpeciesTree_plot$tip.label<- case_when(BallesterSpeciesTree_plot$tip.label == "Homo_sapiens" ~ "Human",
BallesterSpeciesTree_plot$tip.label == "Macaca_mulatta" ~ "Macaque",
BallesterSpeciesTree_plot$tip.label == "Canis_lupus" ~ "Dog",
BallesterSpeciesTree_plot$tip.label == "Mus_musculus" ~ "Mouse",
BallesterSpeciesTree_plot$tip.label == "Rattus_norvegicus" ~ "Rat"
)
ggtree(BallesterSpeciesTree_plot, color="grey60", lwd=0.75)+geom_tiplab()+xlim(0,150)
mamtree2<-ggtree(BallesterSpeciesTree_plot, lwd=0.3)+
geom_tiplab(fontface="italic", size=2.5, geom = "text")+
xlim(0,130) +
theme(plot.margin = unit(c(0, 0, 0,0), "cm")) +
geom_treescale(width=20, x=0, y=0.05, offset=0.15, fontsize=2, linesize=0.35)
mamtree2
# calculate relative tree length
treeLengthsBallester<-liverPD_TFBS_long %>%
distinct(collapsed_region_id, TF, type, status) %>%
rowwise() %>%
dplyr::mutate(
tree_length=calculate_tree_length(df = liverPD_TFBS_long,
regid = collapsed_region_id,
regid_column = collapsed_region_id,
tree = BallesterSpeciesTree)) %>%
ungroup() %>%
dplyr::mutate(max_tree_length=max(tree_length)) %>%
rowwise() %>%
mutate(rel_tree_length=tree_length/max_tree_length) %>%
ungroup()
saveRDS(treeLengthsBallester, "Ballester2014/PhyloTreeLengths.rds")
wilcox.test(
treeLengthsBallester$rel_tree_length[treeLengthsBallester$type=="pleiotropic"],
treeLengthsBallester$rel_tree_length[treeLengthsBallester$type=="liver-specific"])
tflist<-list()
for (tf in unique(treeLengthsBallester$TF)){
dff<-treeLengthsBallester %>% filter(TF == tf)
tflist[[tf]]<-wilcox.test(
dff$rel_tree_length[dff$type=="pleiotropic"],
dff$rel_tree_length[dff$type=="liver-specific"]) %>% broom::tidy()
}
TF_df<-tflist %>% bind_rows(.id="TF") %>% mutate(padj = p.adjust(p.value, method = "BH"))
p_age_all<-treeLengthsBallester %>%
group_by(type) %>%
summarize(mean = mean(rel_tree_length),
sem = sd(rel_tree_length)/sqrt(length(type))) %>%
mutate(type = ifelse(type=='liver-specific','liver-\nspecific', type)) %>%
ggplot(aes(x=type, y=mean, color=type))+
geom_point()+
geom_errorbar(aes(ymin = mean-sem, ymax=mean+sem), width=0.2)+
theme_bw()+
xlab("CREs")+
ylab(expression(paste("TF binding conservation (", lambda[i] / lambda, ")")))+
scale_color_manual(values=c(specificityColors[[1]],specificityColors[[9]]))+
basic_theme_ins2+
theme(legend.position = "none",
axis.text = element_text(color="black"))
pTFage<-treeLengthsBallester %>%
group_by(type, TF) %>%
summarize(mean = mean(rel_tree_length),
sem = sd(rel_tree_length)/sqrt(length(type))) %>%
dplyr::mutate(TF = factor(TF, levels=c("CEBPA","FOXA1","HNF4A","ONECUT1","CRM")),
type = ifelse(type=='liver-specific','liver-\nspecific', type)) %>%
ggplot(aes(x=type, y=mean, color=type))+
geom_point()+
geom_errorbar(aes(ymin = mean-sem, ymax=mean+sem), width=0.2)+
theme_bw()+
xlab("CREs")+
ylab(expression(paste("TF binding conservation (", lambda[i] / lambda, ")")))+
scale_color_manual(values=c(specificityColors[[1]],specificityColors[[9]]))+
basic_theme_ins2+
theme(legend.position = "none",
axis.text = element_text(color="black"))+
facet_grid(.~TF)
pTFage
ptop<-plot_grid(mamtree2,pProps, p_age_all, ncol=3,labels=c("A","B","C"), label_size = 12, scale=c(0.9,1,1), rel_widths = c(0.9,1,0.85))
psuppTF<-plot_grid(ptop,pTFage, ncol=1, labels=c("","D"), label_size=12)
psuppTF
ggsave("../figures/TFBS_evoAge.pdf", width =162.5, height=113, units = "mm")