Skip to content

Commit abc7683

Browse files
authored
Merge pull request #56 from 3mmaRand/feature/regression-sds-page
Feature/regression sds page
2 parents b94f6d1 + eefd99d commit abc7683

File tree

10 files changed

+658
-10
lines changed

10 files changed

+658
-10
lines changed

pgt52m/week-7/workshop.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ compared and the *p*-value. The `annotate()` function can be used to
304304
draw the line and then to add the value. The line is a `segment` and the
305305
*p*-value is a `text`.
306306

307-
#### Annotation - method 1 {#week-7-annotation-method-1}
307+
#### Annotation - method 1 {#sec-week-7-annotation-method-1}
308308

309309
You can annotate the *p*-value manually by typing it in to the
310310
appropriate `annotate()` function.
@@ -336,7 +336,7 @@ annotate("text", x = 1.5, y = 11.7,
336336
However, it is more reproducible to extract the *p*-value from the model
337337
object.
338338

339-
#### Annotation - method 2 {#week-7-annotation-method-2}
339+
#### Annotation - method 2 {#sec-week-7-annotation-method-2}
340340

341341
![](images/do_in_R.png) Extract the *p*-value from the model object:
342342

pgt52m/week-8/workshop.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ We will again use both our `seal` and `seal_summary` dataframes.
319319
![](images/do_in_R.png) Create the plot
320320

321321
::: callout-tip
322-
Use method 1 (see [@week-7-annotation-method-1]) OR method 2 (see
323-
[@week-7-annotation-method-2]) to add the p value
322+
Use method 1 (see [@sec-week-7-annotation-method-1]) OR method 2 (see
323+
[@sec-week-7-annotation-method-2]) to add the p value
324324

325325
If you want to use method 2 for annotating the *p*-value, you can
326326
extract the *p*-value with
997 KB
Loading
246 KB
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
kda
2+
250
3+
130
4+
100
5+
70
6+
55
7+
35
8+
25
9+
15
10+
10
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
kda,dist_to_band
2+
250,138
3+
130,213
4+
100,270
5+
70,309
6+
55,356
7+
35,435
8+
25,478
9+
15,563
10+
10,623

r4babs2/week-2/sds-page.R

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
library(tidyverse)
2+
library(imager)
3+
4+
# import gel
5+
gel <- load.image("data-image/26C-10-Coomassie-Blue.jpg")
6+
7+
# import molecular weights
8+
mw <- read_table("data-image/standard-mw.txt")
9+
10+
plot(gel)
11+
12+
# crop
13+
gel_cropped <- crop.borders(gel, nx = 300, ny = 150)
14+
15+
plot(gel_cropped)
16+
17+
gel_top <- 180
18+
gel_bottom <- 990
19+
20+
# add a line to plot
21+
abline(h = gel_top, col = "red")
22+
abline(h = gel_bottom, col = "red")
23+
24+
# vertical guides just to help with locator
25+
abline(v = 220, col = "red")
26+
abline(v = 510, col = "red")
27+
28+
gel_length <- gel_bottom - gel_top
29+
30+
# Number of bands in your marker lane
31+
# click from the top or gel to the bottom
32+
# i.e., high MW to low
33+
marker_positions <- locator(n = 9)
34+
35+
pos_patB <- locator(n = 1)
36+
dist_to_patB <- pos_patB$y - 180
37+
patB_Rf = (gel_length - dist_to_patB) / gel_length
38+
39+
40+
# add marker positions to the mw data frame
41+
mw <- mw |>
42+
mutate(x = marker_positions$x,
43+
y = marker_positions$y,
44+
dist_to_band = y - 180,
45+
Rf = (gel_length - dist_to_band) / gel_length,
46+
log_kda = log(kda))
47+
48+
49+
ggplot(data = mw, aes(x = Rf, y = log_kda)) +
50+
geom_point(size = 4) +
51+
geom_smooth(method = "lm",
52+
se = FALSE,
53+
colour = "gray30") +
54+
theme_classic()
55+
56+
# fit a linear model
57+
mod <- lm(log_kda ~ Rf, data = mw)
58+
59+
patB_log_kda <- predict(mod, newdata = data.frame(Rf = patB_Rf))
60+
61+
62+
ggplot(data = mw, aes(x = Rf, y = log_kda)) +
63+
geom_point(size = 3) +
64+
geom_smooth(method = "lm",
65+
se = FALSE,
66+
colour = "gray30") +
67+
annotate("segment", x = patB_Rf, xend = patB_Rf,
68+
y = 0, yend = patB_log_kda,
69+
linetype = "dashed",
70+
colour = "red") +
71+
annotate("segment", x = 0, xend = patB_Rf,
72+
y = patB_log_kda, yend = patB_log_kda,
73+
linetype = "dashed",
74+
colour = "red") +
75+
scale_x_continuous(expand = c(0, 0),
76+
limits = c(0, 1)) +
77+
scale_y_continuous(expand = c(0, 0),
78+
limits = c(0, 6)) +
79+
theme_classic()
80+
81+
82+
83+
patB_kda <- exp(patB_log_kda)
84+
85+
86+
# check results are the same.
87+
# option one
88+
# > mw_positions
89+
# # A tibble: 9 × 2
90+
# kda dist_to_band
91+
# <dbl> <dbl>
92+
# 1 250 138
93+
# 2 130 213
94+
# 3 100 270
95+
# 4 70 309
96+
# 5 55 356
97+
# 6 35 435
98+
# 7 25 478
99+
# 8 15 563
100+
# 9 10 623
101+
102+
# gel_length <- 810
103+
# pos_patB <- 394
104+
105+
# mw_positions
106+
# # A tibble: 9 × 4
107+
# kda dist_to_band Rf log_kda
108+
# <dbl> <dbl> <dbl> <dbl>
109+
# 1 250 138 0.830 5.52
110+
# 2 130 213 0.737 4.87
111+
# 3 100 270 0.667 4.61
112+
# 4 70 309 0.619 4.25
113+
# 5 55 356 0.560 4.01
114+
# 6 35 435 0.463 3.56
115+
# 7 25 478 0.410 3.22
116+
# 8 15 563 0.305 2.71
117+
# 9 10 623 0.231 2.30
118+
# Coefficients:
119+
# (Intercept) Rf
120+
# 1.091 5.231
121+
122+
123+
# patB_Rf
124+
# [1] 0.5135802
125+
126+
# > patB_kda
127+
# 1
128+
# 43.69469
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+

0 commit comments

Comments
 (0)