-
Notifications
You must be signed in to change notification settings - Fork 0
/
bradfords.rmd
141 lines (114 loc) · 6.31 KB
/
bradfords.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
---
title: "Generate Fits for Bradfords"
author: "Jared Bard"
date: "2019/08/06"
output:
html_document:
toc: yes
toc_depth: 4
pdf_document:
toc: yes
toc_depth: '4'
---
```{r setup,warning=FALSE,message=FALSE,echo=FALSE}
## knitr options for report generation
knitr::opts_chunk$set(warning=FALSE,message=FALSE,echo=FALSE,cache=FALSE,
results="show",
fig.path="figure/sedfit-",
cache.path="cache/sedfit-")
## data processing options, packages, functions
options(stringsAsFactors=FALSE) # load character strings as strings
library(tidyverse) # more data manipulation
#library(modelr)
#library(tidyquant)
#library(stringr)
#library(ggpubr)
#library(ggrepel)
#library(plotly) # interactive graphics
#library(lmodel2)
#library(zoo)
#library(cowplot) # extensions and nice defaults
library(fs) #allows consistent file system manipulation
library(investr) #for inverse prediction
library(knitr)
library(kableExtra) #extra styling on tables
#library(reticulate) #allows python in notebook
# set default theme for graphics
# theme_set(theme_bw() %+replace% theme(panel.grid.minor=element_blank()))
#theme_set(theme_cowplot(font_size=11) %+replace%
# theme(# panel.grid.major=element_line(size=0.15,colour="grey50"),
# panel.border=element_rect(colour = "grey50",
# linetype = "solid",size=0.5),
# strip.background = element_blank()))
graycol <- "#333333cc"
orangecol <- "#cc5500cc"
bluecol <- "#0000aacc"
greencol <- "#22cc00cc"
purplecol <- "#cc22cccc"
```
# Summary
A script to generate a new .html for each bradford assay that plots the data, generates a line of best fit and calculates the concentrations
# Parameters
```{r set_global, echo = 'fase'}
remove(sample_wells_list)
file_name <- "190806-lysate-bradfords-2" #file name without the trailing csv
data_directory <- path("input")
n_samples <- 4 #used to double check inputs
#all parameters should be entered such that each sample has one entry in the lists
sample_names <- list("30C_minus","30C_plus","42C_minus","42C_plus")
sample_dilutions <- c(0.02,0.02,0.02) %>% list(.,.,.,c(0.02,0.02,0.02,0.02))
sample_wells_list <-list(c("D2","D3","D4"),c("E1","E2","E3"),c("F1","F2","F3"),c("G1","G2","G3","G4"))
sample_mws <- list(50e3,50e3,50e3,50e3) #in Da
#Standards
#Default is BSA
standard_reps <- 3
standard_wells <- list(str_c("A",2:5),str_c("B",2:5),str_c("C",2:5))
standard_concentrations <- c(0.5/2,0.5/4,0.5/8,0.5/16) %>% list(.,.,.)
standard_mw <- 50e3
```
```{r load_data, echo = FALSE, results = 'hide'}
file_path <- path(data_directory,str_c(file_name,".csv"))
# check inputs
if (! file_exists(file_path)) {stop("Please double check that the csv file exists")}
if (n_samples != length(sample_names)) {stop("Check the number of sample_names")}
if (n_samples != length(sample_dilutions)) {stop("Check the number of sample_dilutions")}
if (n_samples != length(sample_wells_list)) {stop("Check the number of sample_wells")}
if (standard_reps != length(standard_wells)) {stop("Check the standards")}
#load the data output by github.com/jabard89/tecan/asc_to_csv
d_orig <- read_csv(file_path)
temp_tibble <- tibble('Well' = character(), 'Type' = character(),'Description' = character(),'MW' = numeric(), 'Concentration' = numeric(), 'Dilution' = numeric())
#Standards
for (i in 1:standard_reps) {
temp_tibble <- add_row(temp_tibble,'Well' = standard_wells[[i]], 'Type' = 'standard', 'Description' = 'BSA', 'MW' = standard_mw, 'Concentration' = standard_concentrations[[i]], 'Dilution' = 1)}
#Samples
for (i in 1:n_samples) {
sample_wells <- sample_wells_list[[i]]
temp_tibble <- add_row(temp_tibble,'Well' = sample_wells, 'Type' = 'Unknown', 'Description' = sample_names[[i]],'MW' = sample_mws[[i]], 'Dilution' = sample_dilutions[[i]])}
#reconfigure data to generate a ratio of 590/450
d <- d_orig %>% select(Well, Channel, Value) %>% spread(Channel,Value) %>% mutate(Ratio = A590 / A450) %>% inner_join(temp_tibble)
```
#Results
```{r fit_data, echo = FALSE, results = 'hide'}
d_model <- lm (Ratio ~ Concentration, data = d)
#use calibrate function from investr package to calculate the approximate concentration for a given ratio
d_calc <- d %>% rowwise() %>% mutate(Calc_conc = calibrate(d_model,Ratio,interval="Wald")$estimate) %>%
mutate(Calc_se = calibrate(d_model,Ratio,interval="Wald")$se) %>%
mutate(Original_conc_mg_per_mL = Calc_conc / Dilution) %>%
mutate(Original_se_mg_per_mL = Calc_se / Dilution) %>%
mutate(Original_conc_uM = Original_conc_mg_per_mL / MW * 1e6) %>%
mutate(Original_se_uM = Original_se_mg_per_mL / MW * 1e6)
```
##Calculated concentrations of the unknowns
```{r unknown_table, echo = FALSE, results = 'asis'}
unknown_table_columns <- c("Well","Description","Ratio (A590/A450)","Calculated Conc (mg/mL)","Dilution Factor","Original Conc (mg/mL)","SE","MW (Da)","Original Conc (uM)","SE")
d_calc %>% filter(Type == 'Unknown') %>% select(Well, Description, Ratio, Calc_conc, Dilution, Original_conc_mg_per_mL, Original_se_mg_per_mL, MW, Original_conc_uM, Original_se_uM) %>% arrange(Description,Well) %>% kable(format='markdown',digits = 4, col.names = unknown_table_columns, align = (c("l","l",rep("c",7)))) %>% kable_styling(bootstrap_options = c("hover","condensed"),full_width = F, position = "left")
```
##Calculated concentrations of standards
```{r standards_table, echo = FALSE, results = 'asis'}
standard_table_columns <- c("Well","Description","Ratio (A590/A450)","Concentration (mg/mL)", "Calculated Conc", "Standard Error")
d_calc %>% filter(Type == 'standard') %>% select(Well, Description, Ratio, Concentration, Calc_conc, Calc_se) %>% arrange(desc(Concentration)) %>% kable(digits = 4, col.names = standard_table_columns, align = c("l","l",rep("c",4))) %>% kable_styling(bootstrap_options = c("hover","condensed"),full_width = F, position = "left")
```
```{r plot, echo = FALSE, results = 'asis'}
p <- ggplot(d_calc,aes(x=Concentration,y=Ratio)) + geom_point(data=d_calc %>% filter(Type == 'standard')) + geom_smooth(method = 'lm') + geom_point(data=d_calc %>% filter(Type == 'Unknown'),aes(x=Calc_conc, colour = Description)) + xlab("Concentration (mg/mL)") + ylab("Ratio (A590/A450")
plot(p)
```