-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessivity_ps.Rmd
186 lines (124 loc) · 6.79 KB
/
processivity_ps.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
175
176
177
178
179
180
181
182
183
184
185
---
title: "Relationships between cohesin processivity and P(s) curves"
output: html_notebook
---
```{r}
library(ggplot2)
library(scales)
library(dplyr)
library(foreach)
```
```{r}
frag_length <- 1000e3
step <- 10000
dist <- seq(step, frag_length, step)
contact_freq <- function(dist, D=-2) {
y <- dist ^ D
y <- y / sum(y)
y
}
plot(log(dist), log(contact_freq(dist)))
```
```{r}
loop_length <- 200e3
loop_mid <- loop_length/2
# Effective distance
extruded_dist_eff <- c(seq(step, loop_mid, step), seq(loop_mid, step, -step))
unextruded_dist_eff <- seq(step, by=step, length.out=length(dist)-length(extruded_dist_eff))
dist_eff <- c(extruded_dist_eff, unextruded_dist_eff)
plot(dist, dist_eff)
```
```{r}
y <- contact_freq(dist_eff)
data.frame(dist, y) %>% ggplot(aes(dist, y)) + geom_line() + scale_x_continuous(labels=comma) + theme_bw() + ggtitle("Original Scale")
data.frame(dist, y) %>% ggplot(aes(dist, y)) + geom_line() + scale_x_log10(labels=comma) + scale_y_log10() + theme_bw() + ggtitle("Log-Log scale")
```
# Simulate a set of extruding molecules
```{r}
frag_length <- 1000e3
step <- 5000
dist <- seq(step, frag_length, step)
effective_distance <- function(loop_length) {
loop_mid <- loop_length/2
extruded_dist_eff <- c(seq(step, loop_mid, step), seq(loop_mid, step, -step))
unextruded_dist_eff <- seq(step, by=step, length.out=length(dist)-length(extruded_dist_eff))
c(extruded_dist_eff, unextruded_dist_eff)
}
plot(dist, effective_distance(loop_length = 100e3), main="Loop length = 100kb", ylab="Effective distance", xlab="Linear Distance")
plot(dist, effective_distance(loop_length = 200e3), main="Loop length = 200kb", ylab="Effective distance", xlab="Linear Distance")
plot(dist, effective_distance(loop_length = 400e3), main="Loop length = 400kb", ylab="Effective distance", xlab="Linear Distance")
```
```{r}
# All cohesins extrude to 150kb
# One molecule per iteration, with changing extruded loop length
df <- foreach(l = seq(step*2, 150e3, step), .combine=rbind) %do% {
data.frame(dist=dist, effective_dist = effective_distance(loop_length = l), loop_length=l, type="extruded")
}
df$contact_freq <- contact_freq(df$effective_dist)
df_extruded <- df %>% group_by(dist, type) %>% summarize(effective_dist=mean(effective_dist), contact_freq=mean(contact_freq))
df_extruded$contact_freq <- df_extruded$contact_freq / sum(df_extruded$contact_freq)
# Add survival curve
df_extruded$S <- 1 - cumsum(df_extruded$contact_freq)
# Make the unextruded P(s) curve and survival curves
df_unextruded <- data.frame(dist=dist, effective_dist=dist, contact_freq=contact_freq(dist), type="unextruded")
df_unextruded$S <- 1 - cumsum(df_unextruded$contact_freq)
df <- rbind(df_extruded, df_unextruded)
df %>% ggplot(aes(dist, contact_freq, group=type, color=type)) + geom_line() + theme_bw() + scale_x_log10(labels=comma) + scale_y_log10() + geom_vline(xintercept = 150e3, color='darkgreen')
```
# Survival curves
```{r}
df %>% ggplot(aes(dist, S, group=type, color=type)) + geom_line() + theme_bw() + geom_vline(xintercept = 150e3, color='darkgreen') + ggtitle("Original scale")
df %>% ggplot(aes(dist, S, group=type, color=type)) + geom_line() + theme_bw() + scale_x_log10(labels=comma) + scale_y_log10(limits=c(1e-5,NA)) + geom_vline(xintercept = 150e3, color='darkgreen') + ggtitle("Log-Log scale")
```
# Cohesins extrude to a mean distance of 150kb, sd=30e3
# One molecule per iteration, with changing extruded loop length
```{r}
hist(pmax(20e3, rnorm(1000, mean=150e3, sd=30e3)))
df <- foreach(l = pmax(20e3, rnorm(1000, mean=150e3, sd=30e3)), .combine=rbind) %do% {
data.frame(dist=dist, effective_dist = effective_distance(loop_length = l), loop_length=l, type="extruded")
}
df$contact_freq <- contact_freq(df$effective_dist)
df_extruded <- df %>% group_by(dist, type) %>% summarize(effective_dist=mean(effective_dist), contact_freq=mean(contact_freq))
df_extruded$contact_freq <- df_extruded$contact_freq / sum(df_extruded$contact_freq)
# Add survival curve
df_extruded$S <- 1 - cumsum(df_extruded$contact_freq)
# Make the unextruded P(s) curve. slope and survival curves
df_unextruded <- data.frame(dist=dist, effective_dist=dist, contact_freq=contact_freq(dist), type="unextruded")
df_unextruded$S <- 1 - cumsum(df_unextruded$contact_freq)
df <- rbind(df_extruded, df_unextruded)
df %>% ggplot(aes(dist, contact_freq, group=type, color=type)) + geom_line() + theme_bw() + scale_x_log10(labels=comma) + scale_y_log10() + geom_vline(xintercept = 150e3, color='darkgreen')
```
# Cohesins extrude to a mean distance of 150kb, sd=75e3
# One molecule per iteration, with changing extruded loop length
```{r}
hist(pmax(20e3, rnorm(1000, mean=150e3, sd=75e3)))
df <- foreach(l = pmax(20e3, rnorm(1000, mean=150e3, sd=75e3)), .combine=rbind) %do% {
data.frame(dist=dist, effective_dist = effective_distance(loop_length = l), loop_length=l, type="extruded")
}
df$contact_freq <- contact_freq(df$effective_dist)
df_extruded <- df %>% group_by(dist, type) %>% summarize(effective_dist=mean(effective_dist), contact_freq=mean(contact_freq))
df_extruded$contact_freq <- df_extruded$contact_freq / sum(df_extruded$contact_freq)
# Add survival curve
df_extruded$S <- 1 - cumsum(df_extruded$contact_freq)
# Make the unextruded P(s) curve. slope and survival curves
df_unextruded <- data.frame(dist=dist, effective_dist=dist, contact_freq=contact_freq(dist), type="unextruded")
df_unextruded$S <- 1 - cumsum(df_unextruded$contact_freq)
df <- rbind(df_extruded, df_unextruded)
df %>% ggplot(aes(dist, contact_freq, group=type, color=type)) + geom_line() + theme_bw() + scale_x_log10(labels=comma) + scale_y_log10() + geom_vline(xintercept = 150e3, color='darkgreen')
```
# Survival curves
```{r}
df %>% ggplot(aes(dist, S, group=type, color=type)) + geom_line() + theme_bw() + geom_vline(xintercept = 150e3, color='darkgreen') + ggtitle("Original scale")
df %>% ggplot(aes(dist, S, group=type, color=type)) + geom_line() + theme_bw() + scale_x_log10(labels=comma) + scale_y_log10(limits=c(1e-5,NA)) + geom_vline(xintercept = 150e3, color='darkgreen') + ggtitle("Log-Log scale")
```
# Slope of extruded P(s) curve
```{r}
df <- rbind(df_extruded, df_unextruded)
# Smooth the P(s) curves on the log scale
fit <- loess(log10(df_extruded$contact_freq) ~ log10(df_extruded$dist), span = 0.1)
df_extruded$contact_freq_smooth <- 10^predict(fit)
df_extruded %>% ggplot(aes(dist, contact_freq_smooth, group=type, color=type)) + geom_line() + theme_bw() + scale_x_log10(labels=comma) + scale_y_log10() + geom_vline(xintercept = 150e3, color='darkgreen')
# Add slope of contact freq
df_extruded$contact_freq_slope <- c(NA, diff(log10(df_extruded$contact_freq_smooth)))
df_extruded %>% ggplot(aes(dist, contact_freq_slope, group=type, color=type)) + geom_line() + theme_bw() + geom_vline(xintercept = 150e3, color='darkgreen') + geom_hline(yintercept = 0)
```