Skip to content

Commit

Permalink
Merge pull request #38 from allaway/drug-selector
Browse files Browse the repository at this point in the history
drug selector
  • Loading branch information
allaway authored Sep 14, 2020
2 parents 69b82bf + 5be930a commit a4e0beb
Show file tree
Hide file tree
Showing 19 changed files with 1,551 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^data-raw$
Expand All @@ -8,3 +10,5 @@ $run_dev.*
^README\.Rmd$
^CODE_OF_CONDUCT\.md$
^\.travis\.yml$
^app\.R$
^rsconnect$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Imports:
forcats,
scales,
ggridges,
maftools
maftools,
pkgload
RoxygenNote: 7.0.2
Suggests:
testthat (>= 2.1.0),
Expand Down
2 changes: 1 addition & 1 deletion R/fct_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ create_boxplot <- function(
I


}
}
15 changes: 10 additions & 5 deletions R/mod_cell_line_selector.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ mod_cell_line_selector_server <- function(input, output, session){
})

output$cell_lines_table <- DT::renderDataTable({
models() %>% dplyr::filter(nf1Genotype %in% input$nf1_genotypes,
nf2Genotype %in% input$nf2_genotypes)
models() %>%
dplyr::filter(nf1Genotype %in% input$nf1_genotypes,
nf2Genotype %in% input$nf2_genotypes)
})

cell_lines <- reactive({models() %>%
purrr::pluck('model_name') %>%
unique()})
cell_lines <- reactive({
models() %>%
dplyr::filter(nf1Genotype %in% input$nf1_genotypes,
nf2Genotype %in% input$nf2_genotypes) %>%
purrr::pluck('model_name') %>%
unique()
})
}

## To be copied in the UI
Expand Down
17 changes: 15 additions & 2 deletions R/mod_compound_selector.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@
mod_compound_selector_ui <- function(id){
ns <- NS(id)
tagList(

)
box(selectizeInput(ns("selected_compounds"), "Select up to 5 compounds",
choices = kairos::drug_names$common_name, options = list(maxItems = 5))),

box(DT::DTOutput(ns('drug_table'))))
}

#' compound_selector Server Function
#'
#' @noRd
mod_compound_selector_server <- function(input, output, session){
ns <- session$ns

output$drug_table <- DT::renderDataTable({
kairos::drug_names %>% dplyr::filter(common_name %in% input$selected_compounds)
})

compounds <- reactive({
kairos::drug_names %>%
dplyr::filter(common_name %in% input$selected_compounds) %>%
dplyr::distinct() %>%
purrr::pluck('DT_explorer_internal_id')
})

}

Expand Down
43 changes: 42 additions & 1 deletion R/mod_dose_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
mod_dose_response_ui <- function(id){
ns <- NS(id)
tagList(

# DT::dataTableOutput(ns("dr_table")),
plotly::plotlyOutput(ns('drug_heatmap')),
plotly::plotlyOutput(ns('dr_plot'))

)
}

Expand All @@ -19,6 +22,44 @@ mod_dose_response_ui <- function(id){
#' @noRd
mod_dose_response_server <- function(input, output, session, cell_lines, compounds){
ns <- session$ns
dr_data <- reactive({
kairos::drug_raw %>% filter(DT_explorer_internal_id %in% compounds(),
model_name %in% cell_lines()) %>%
dplyr::left_join(kairos::preferred_drug_names) %>%
select(-DT_explorer_internal_id)
})

# output$dr_table <- DT::renderDataTable({
# dr_data()
# })

output$drug_heatmap <- plotly::renderPlotly({

mat <- kairos::drug_screening %>% dplyr::filter(DT_explorer_internal_id %in% compounds(),
model_name %in% cell_lines()) %>%
dplyr::filter(response_type == 'IC50_abs') %>%
dplyr::select(DT_explorer_internal_id, model_name, response) %>%
dplyr::group_by(DT_explorer_internal_id, model_name) %>%
dplyr::summarize(mean_resp = mean(response)) %>%
tidyr::spread(model_name, mean_resp, drop = F) %>%
dplyr::ungroup() %>%
dplyr::left_join(kairos::preferred_drug_names) %>%
select(-DT_explorer_internal_id) %>%
tibble::column_to_rownames('std_name') %>%
as.matrix()

plot_ly(x=colnames(mat),y=rownames(mat),z=mat,type="heatmap",colors=colorRamp(c("darkblue","white","darkred")),colorbar=list(title="Score",len=0.4),hoverinfo='text') %>%
layout(yaxis=list(title="Condition"),xaxis=list(title="Gene"))
})

output$dr_plot <- plotly::renderPlotly({
p1 <- ggplot(dr_data() %>%
dplyr::group_by(model_name, dosage, std_name) %>%
dplyr::summarize(response = mean(response))) +
geom_point(aes(x = log10(dosage), y = response, color = model_name)) +
facet_wrap( ~ std_name)
plotly::ggplotly(p1)
})

}

Expand Down
8 changes: 4 additions & 4 deletions R/mod_latent_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod_latent_variables_server <- function(input, output, session, specimens){
# labs(x = 'Latent Variable', y = "Expression")
#
# plotly::ggplotly(source = 'lv_overview', tooltip = 'x')
kairos::create_boxplot(foo2,
create_boxplot(foo2,
source_name = "mod_lv_a",
color_col = NA,
sort = "desc") %>%
Expand All @@ -104,8 +104,8 @@ mod_latent_variables_server <- function(input, output, session, specimens){
dplyr::filter(latent_var == lv) %>%
dplyr::mutate(x = modelOf, y = value)

kairos::create_boxplot(foo,
source_name = "mod_lv_b",
create_boxplot(foo,
source_name = "mod_lv_b",
color_col = NA) %>%
remove_legend()

Expand All @@ -122,7 +122,7 @@ mod_latent_variables_server <- function(input, output, session, specimens){
dplyr::filter(latent_var == lv) %>%
dplyr::mutate(x = hugo_gene, y = loading)

kairos::create_barplot(foo,
create_barplot(foo,
source_name = "mod_lv_c",
color_col = NA,
sort = "desc") %>%
Expand Down
7 changes: 7 additions & 0 deletions app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Launch the ShinyApp (Do not remove this comment)
# To deploy, run: rsconnect::deployApp()
# Or use the blue button on top of this file

pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE)
options( "golem.app.prod" = TRUE)
kairos::run_app() # add parameters here (if any)
30 changes: 30 additions & 0 deletions data-raw/drug_names.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## code to prepare `drug_names.R` dataset goes here
library(synapser)
library(tidyverse)
synLogin()

drug_screening <- synGet("syn20700260")$path %>% readr::read_csv(
col_types = "cccccdcdccccdcdccdc"
) %>%
select(DT_explorer_internal_id) %>%
distinct()

drug_info <- synTableQuery("SELECT * FROM syn17090820")$filepath %>% readr::read_csv()

drug_names <- drug_info %>%
select(internal_id, common_name) %>%
rename(DT_explorer_internal_id = internal_id) %>%
inner_join(drug_screening)

usethis::use_data(drug_names)

preferred_drug_names <- synTableQuery("select internal_id, std_name from syn17090819")$filepath %>%
readr::read_csv() %>%
select(internal_id, std_name) %>%
rename(DT_explorer_internal_id = internal_id) %>%
inner_join(drug_screening)

usethis::use_data(preferred_drug_names,
# overwrite = T
)

12 changes: 12 additions & 0 deletions data-raw/drug_raw.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## code to prepare `drug_raw` dataset goes here
library(synapser)
library(tidyverse)
synLogin()

drug_raw <- synTableQuery("SELECT * FROM syn20556247", includeRowIdAndRowVersion = F)$filepath %>%
read_csv(col_types = "cddccccccccddcdccccccc") %>%
select(drug_screen_id, model_name, DT_explorer_internal_id, dosage, response)

usethis::use_data(drug_raw,
#overwrite = T
)
Binary file added data/drug_names.rda
Binary file not shown.
Binary file added data/drug_raw.rda
Binary file not shown.
Binary file added data/preferred_drug_names.rda
Binary file not shown.
Loading

0 comments on commit a4e0beb

Please sign in to comment.