Last updated: 2020-06-07

Checks: 7 0

Knit directory: duplex_sequencing_screen/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200402) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version b12549f. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/bcrabl_hill_ic50s.csv
    Untracked:  analysis/column_definitions_for_twinstrand_data_06062020.csv
    Untracked:  analysis/m351t_deviation.pdf
    Untracked:  analysis/multinomial_sims.Rmd
    Untracked:  analysis/pooled_growth_fig_cifrom4paramlogistic_060420.pdf
    Untracked:  analysis/pooled_growth_fig_cifromrawic50_060420.pdf
    Untracked:  analysis/simple_data_generation.Rmd
    Untracked:  analysis/twinstrand_growthrates_simple.csv
    Untracked:  analysis/twinstrand_maf_merge_simple.csv
    Untracked:  analysis/wildtype_growthrates_sequenced.csv
    Untracked:  clinicalabundancepredictions_BMES_abstract_51320.pdf
    Untracked:  data/Combined_data_frame_IC_Mutprob_abundance.csv
    Untracked:  data/IC50HeatMap.csv
    Untracked:  data/Twinstrand/
    Untracked:  data/gfpenrichmentdata.csv
    Untracked:  data/heatmap_concat_data.csv
    Untracked:  enrichment_simulations_3mutants.pdf
    Untracked:  output/archive/
    Untracked:  output/bmes_abstract_51220.pdf
    Untracked:  output/clinicalabundancepredictions_BMES_abstract_51320.pdf
    Untracked:  output/clinicalabundancepredictions_BMES_abstract_52020.pdf
    Untracked:  output/enrichment_simulations_3mutants_52020.pdf
    Untracked:  output/grant_fig.pdf
    Untracked:  output/grant_fig_v2.pdf
    Untracked:  output/grant_fig_v2updated.pdf
    Untracked:  output/ic50data_all_conc.csv
    Untracked:  shinyapp/

Unstaged changes:
    Modified:   analysis/E255K_alphas_figure.Rmd
    Modified:   analysis/clinical_abundance_predictions.Rmd
    Modified:   analysis/dosing_normalization.Rmd
    Modified:   analysis/index.Rmd
    Modified:   analysis/misc.Rmd
    Modified:   analysis/nonlinear_growth_analysis.Rmd
    Modified:   analysis/spikeins_depthofcoverages.Rmd
    Modified:   analysis/twinstrand_spikeins_data_generation.Rmd
    Deleted:    data/README.md
    Modified:   output/twinstrand_maf_merge.csv
    Modified:   output/twinstrand_simple_melt_merge.csv

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/dose_response_curve_fitting.Rmd) and HTML (docs/dose_response_curve_fitting.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd b12549f haiderinam 2020-06-07 wflow_publish(“analysis/dose_response_curve_fitting.Rmd”)

####Please change required directories this chunk if compiling in R rather than RmD

#Inputs:
conc_for_predictions=0.8
net_gr_wodrug=0.05
#Reading required tables
ic50data=read.csv("data/heatmap_concat_data.csv",header = T,stringsAsFactors = F)
# ic50data=read.csv("../data/heatmap_concat_data.csv",header = T,stringsAsFactors = F)

##Data Parsing– Dose Response Data
###Importing model with BCR-ABL mutant dose responses (Chuan’s data) ###Also applying the 2-parameter logistic. Upper and lower limits are fixed. May be good or bad.

#Deciding not to use nls() because it's a pain in the ...
#https://www.youtube.com/watch?v=aXpJE7IGiPY this has a nice overview of curve fitting
# library(dplyr)
# rm(list=ls())
####Getting effect of drug on growth rate####

ic50data=ic50data[c(1:10),]
ic50data_long=melt(ic50data,id.vars = "conc",variable.name = "species",value.name = "y")
#Removing useless mutants (for example keeping only maxipreps and removing low growth rate mutants)
ic50data_long=ic50data_long%>%filter(species%in%c("Wt","V299L_H","E355A","D276G_maxi","H396R","F317L","F359I","E459K","G250E","F359C","F359V","M351T","L248V","E355G_maxi","Q252H_maxi","Y253F","F486S_maxi","H396P_maxi","E255K","Y253H","T315I","E255V"))



#Making standardized names
ic50data_long$mutant=ic50data_long$species
ic50data_long=ic50data_long%>%
  # filter(conc=="0.625")%>%
  # filter(conc=="1.25")%>%
  mutate(mutant=case_when(species=="F486S_maxi"~"F486S",
                          species=="H396P_maxi"~"H396P",
                          species=="Q252H_maxi"~"Q252H",
                          species=="E355G_maxi"~"E355G",
                          species=="D276G_maxi"~"D276G",
                          species=="V299L_H" ~ "V299L",
                          species==mutant ~as.character(mutant)))

# ic50data_long_625$species[order((ic50data_long_625$y),decreasing = T)]

#In the next step, I'm ordering mutants by decreasing resposne to the 625nM dose. Then I use this to change the levels of the species factor from more to less resistant. This helps with ggplot because now I can color the mutants with decreasing resistance
ic50data_long_625=ic50data_long%>%filter(conc==.625)
ic50data_long$species=factor(ic50data_long$species,levels = as.character(ic50data_long_625$species[order((ic50data_long_625$y),decreasing = T)]))

#Plotting the normalized dose response curves
getPalette = colorRampPalette(brewer.pal(9, "Spectral"))

plotly=ggplot(ic50data_long,aes(x=log(conc),y=y,color=factor(species)))+
  facet_wrap(~factor(species))+
  geom_line()+
  geom_point()+
  cleanup+
  scale_color_manual(values = getPalette(length(unique(ic50data_long$species))))+
  theme(axis.text = element_blank(),
        axis.ticks = element_blank())
ggplotly(plotly)

###Dose response curve fitting with 4-parameter logistic ####First iteration: Have a y_model for only the drug concentrations Chuan used Essentially, all this is doing is adding a column for y-model to IC50data_long. Default was just y (proportion alive).

########Four parameter logistic########
#Reference: https://journals.plos.org/plosone/article/file?type=supplementary&id=info:doi/10.1371/journal.pone.0146021.s001
#In short: For each dose in each species, get the response
# rm(list=ls())
ic50data_long_model=data.frame()
for (species_curr in sort(unique(ic50data_long$species))){
  ic50data_species_specific=ic50data_long%>%filter(species==species_curr)
  x=ic50data_species_specific$conc
  y=ic50data_species_specific$y
  #Next: Appproximating Response from dose (inverse of the prediction)
  ic50.ll4=drm(y~conc,data=ic50data_long%>%filter(species==species_curr),fct=LL.3(fixed=c(NA,1,NA)))
    b=coef(ic50.ll4)[1]
    c=0
    d=1
    e=coef(ic50.ll4)[2]
  ###Getting predictions
  ic50data_species_specific=ic50data_species_specific%>%group_by(conc)%>%mutate(y_model=c+((d-c)/(1+exp(b*(log(conc)-log(e))))))
  ic50data_species_specific=data.frame(ic50data_species_specific) #idk why I have to end up doing this
  ic50data_long_model=rbind(ic50data_long_model,ic50data_species_specific)
}
ic50data_long=ic50data_long_model

#In the next step, I'm ordering mutants by decreasing resposne to the 625nM dose. Then I use this to change the levels of the species factor from more to less resistant. This helps with ggplot because now I can color the mutants with decreasing resistance
ic50data_long_625=ic50data_long%>%filter(conc==.625)
ic50data_long$species=factor(ic50data_long$species,levels = as.character(ic50data_long_625$species[order((ic50data_long_625$y_model),decreasing = T)]))

#Adding drug effect
##########Changed this on 2/20. Using y from 4 parameter logistic rather than raw values
ic50data_long=ic50data_long%>%
  # filter(!species=="Wt")%>%
  mutate(drug_effect=-log(y_model)/72)

#Adding Net growth rate
ic50data_long$netgr_pred=.05-ic50data_long$drug_effect

####Plotting modeled dose responses

getPalette = colorRampPalette(brewer.pal(9, "Spectral"))
plotly=ggplot(ic50data_long,aes(x=log(conc),color=factor(species)))+
  facet_wrap(~factor(species))+
  geom_line(aes(y=y_model))+
  geom_point(aes(y=y))+
  cleanup+
  scale_color_manual(values = getPalette(length(unique(ic50data_long$species))))+
  theme(axis.text = element_blank(),
        axis.ticks = element_blank())
ggplotly(plotly)

####Plotting species changes in dose responses over different concentrations

plotly=ggplot(ic50data_long,aes(x=species,y=y_model))+
  facet_wrap(~factor(conc))+
  geom_col(aes(fill=factor(species)))+
  cleanup+
  scale_fill_manual(values = getPalette(length(unique(ic50data_long$species))))+
  theme(axis.text = element_blank(),
        axis.ticks = element_blank())
ggplotly(plotly)

###Dose response curve fitting with 4-parameter logistic ####Second iteration: Get y_model for predefined concentration ranges of interest

conc.list=seq(.5,1.5,by=.1)
ic50.model.pred=data.frame(matrix(NA,nrow=length(conc.list)*length(unique(ic50data_long$species)),ncol=0))
for(species_curr in sort(unique(ic50data_long$mutant))){
  ic50data_species_specific=ic50data_long%>%filter(mutant==species_curr)
  #Next: Appproximating Response from dose (inverse of the prediction)
  ic50.ll4=drm(y~conc,data=ic50data_species_specific,fct=LL.3(fixed=c(NA,1,NA)))
  #Extracting coefficients
  b=coef(ic50.ll4)[1]
  c=0
  d=1
  e=coef(ic50.ll4)[2]
  rm(ic50.model.pred.species.specific)
  ic50.model.pred.species.specific=data.frame(matrix(NA,nrow=length(conc.list),ncol=0))
  i=1
  ic50.model.pred.species.specific$mutant=species_curr
  #For loop for the unique concentrations
  for(conc.curr in conc.list){
    ic50.model.pred.species.specific$conc[i]=conc.curr
    ic50.model.pred.species.specific$y_model[i]=c+((d-c)/(1+exp(b*(log(conc.curr)-log(e)))))
    i=i+1
  }
  ic50.model.pred=rbind(ic50.model.pred,ic50.model.pred.species.specific)
}
Warning in rm(ic50.model.pred.species.specific): object
'ic50.model.pred.species.specific' not found
#Adding drug effect
ic50.model.pred=ic50.model.pred%>%
  # filter(!mutant=="Wt")%>%
  mutate(drug_effect=-log(y_model)/72)

    #Adding Net growth rate
    # ic50.model.pred$netgr_pred=.05-ic50.model.pred$drug_effect
ic50data_long=ic50.model.pred
ic50data_all_conc=ic50data_long

####Changing the format of the IC50s dataframe so that it matches twinstrand data labeling etc
####Also converting dose response to expected change in growth rate ####This requires estimating a growth rate without drug. Note that I am using k=0.05 or 14 hours right now.

#Variables when making predictions:
#Your assumed fitness without drug
ic50data_long$netgr_pred=net_gr_wodrug-ic50data_long$drug_effect
#Your assumed concentration
ic50data_long=ic50data_long%>%filter(conc==conc_for_predictions) ###Can remove this filter if you wanna look at how well predictions would match up if there was a systematic difference in the concentrations Chuan used and you used in your IC50s
    ##########Changed this on 2/20. Using y from 4 parameter logistic rather than raw values
# ic50data_formerge=ic50data_long%>%filter(!species=="Wt")%>%mutate(drug_effect=-log(y)/72)
# ic50data_formerge=ic50data_long%>%filter(!species=="Wt")%>%mutate(drug_effect=-log(y_model)/72)
head(ic50data_all_conc)
  mutant conc    y_model drug_effect
1  D276G  0.5 0.22194952  0.02090702
2  D276G  0.6 0.17731828  0.02402512
3  D276G  0.7 0.14534373  0.02678686
4  D276G  0.8 0.12165238  0.02925816
5  D276G  0.9 0.10359142  0.03149029
6  D276G  1.0 0.08948725  0.03352304
# write.csv(ic50data_all_conc,"ic50data_all_conc.csv")

sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel  grid      stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] drc_3.0-1           MASS_7.3-51.5       BiocManager_1.30.10
 [4] plotly_4.9.2.1      ggsignif_0.6.0      devtools_2.3.0     
 [7] usethis_1.6.1       RColorBrewer_1.1-2  reshape2_1.4.4     
[10] ggplot2_3.3.0       doParallel_1.0.15   iterators_1.0.12   
[13] foreach_1.5.0       dplyr_0.8.5         VennDiagram_1.6.20 
[16] futile.logger_1.4.3 tictoc_1.0          knitr_1.28         
[19] workflowr_1.6.2    

loaded via a namespace (and not attached):
 [1] fs_1.4.1             httr_1.4.1           rprojroot_1.3-2     
 [4] tools_4.0.0          backports_1.1.7      R6_2.4.1            
 [7] lazyeval_0.2.2       colorspace_1.4-1     withr_2.2.0         
[10] tidyselect_1.1.0     prettyunits_1.1.1    processx_3.4.2      
[13] curl_4.3             compiler_4.0.0       git2r_0.27.1        
[16] cli_2.0.2            formatR_1.7          sandwich_2.5-1      
[19] desc_1.2.0           labeling_0.3         scales_1.1.1        
[22] mvtnorm_1.1-0        callr_3.4.3          stringr_1.4.0       
[25] digest_0.6.25        foreign_0.8-78       rmarkdown_2.1       
[28] rio_0.5.16           pkgconfig_2.0.3      htmltools_0.4.0     
[31] sessioninfo_1.1.1    plotrix_3.7-8        htmlwidgets_1.5.1   
[34] rlang_0.4.6          readxl_1.3.1         zoo_1.8-8           
[37] jsonlite_1.6.1       crosstalk_1.1.0.1    gtools_3.8.2        
[40] zip_2.0.4            car_3.0-7            magrittr_1.5        
[43] Matrix_1.2-18        Rcpp_1.0.4.6         munsell_0.5.0       
[46] fansi_0.4.1          abind_1.4-5          lifecycle_0.2.0     
[49] stringi_1.4.6        multcomp_1.4-13      whisker_0.4         
[52] yaml_2.2.1           carData_3.0-3        pkgbuild_1.0.8      
[55] plyr_1.8.6           promises_1.1.0       forcats_0.5.0       
[58] crayon_1.3.4         lattice_0.20-41      splines_4.0.0       
[61] haven_2.2.0          hms_0.5.3            ps_1.3.3            
[64] pillar_1.4.4         codetools_0.2-16     pkgload_1.0.2       
[67] futile.options_1.0.1 glue_1.4.1           evaluate_0.14       
[70] lambda.r_1.2.4       data.table_1.12.8    remotes_2.1.1       
[73] vctrs_0.3.0          httpuv_1.5.2         testthat_2.3.2      
[76] cellranger_1.1.0     gtable_0.3.0         purrr_0.3.4         
[79] tidyr_1.0.3          assertthat_0.2.1     xfun_0.13           
[82] openxlsx_4.1.5       later_1.0.0          survival_3.1-12     
[85] viridisLite_0.3.0    tibble_3.0.1         memoise_1.1.0       
[88] TH.data_1.0-10       ellipsis_0.3.1