This commit is contained in:
Tanushree Tunstall 2022-09-09 20:25:09 +01:00
parent f9db5cbc33
commit 27f70afb2c
2 changed files with 350 additions and 325 deletions

View file

@ -124,9 +124,18 @@ function(input, output, session) {
# different data ranges required for SNP distances # different data ranges required for SNP distances
snp_ligand_dist_df3 = merged_df3[merged_df3$ligand_distance<input$snp_ligand_dist,] snp_ligand_dist_df3 = merged_df3[merged_df3[['ligand_distance']]<input$snp_ligand_dist,]
snp_interface_dist_df3 = merged_df3[merged_df3$interface_dist<input$snp_interface_dist,] if ("interface_dist" %in% colnames(merged_df3)){
snp_nca_dist_df3 = merged_df3[merged_df3$nca_distance<input$snp_nca_dist,] snp_interface_dist_df3 = merged_df3[merged_df3[['interface_dist']]<input$snp_interface_dist,]
} else {
snp_interface_dist_df3 = NULL
}
if ("nca_distance" %in% colnames(merged_df3)){
snp_nca_dist_df3 = merged_df3[merged_df3[['nca_distance']]<input$snp_nca_dist,]
} else {
snp_nca_dist_df3 = NULL
}
stability_colname = stability_boxes_df[stability_boxes_df$stability_type==input$stability_snp_param,"stability_colname"] stability_colname = stability_boxes_df[stability_boxes_df$stability_type==input$stability_snp_param,"stability_colname"]
outcome_colname = stability_boxes_df[stability_boxes_df$stability_type==input$stability_snp_param,"outcome_colname"] outcome_colname = stability_boxes_df[stability_boxes_df$stability_type==input$stability_snp_param,"outcome_colname"]
@ -162,7 +171,8 @@ function(input, output, session) {
### NGLViewer #### ### NGLViewer ####
# Structure Viewer WebGL/NGLViewR window # Structure Viewer WebGL/NGLViewR window
output$structure <- renderNGLVieweR({ output$structure <- renderNGLVieweR({
ngl_gene=isolate(input$switch_target) #ngl_gene=isolate(input$switch_target)
ngl_gene=input$switch_target
ngl_drug=target_map[[ngl_gene]] ngl_drug=target_map[[ngl_gene]]
ngl_pdb_file=paste0(load_dir, "Data/", ngl_drug, '/output/depth/', ngl_gene, '_complex.pdb') ngl_pdb_file=paste0(load_dir, "Data/", ngl_drug, '/output/depth/', ngl_gene, '_complex.pdb')
print(ngl_pdb_file) print(ngl_pdb_file)
@ -262,6 +272,8 @@ function(input, output, session) {
geom_ls = 4 geom_ls = 4
) )
) )
# if ("interface_dist" %in% colnames(input$switch_target)) {
output$site_snp_count_interface = renderPlot( output$site_snp_count_interface = renderPlot(
site_snp_count_bp( site_snp_count_bp(
snp_interface_dist_df3, snp_interface_dist_df3,
@ -272,7 +284,14 @@ function(input, output, session) {
geom_ls = 4 geom_ls = 4
) )
) )
output$site_snp_count_nca = renderPlot( # } #else {
# output$site_snp_count_interface = renderPlot(
# ggplot() + annotate(x=1,y=1,"text", label="No interface data for this target")+theme_void()
# )
# }
output$site_snp_count_nca = renderPlot( #{
#if ("nca_distance" %in% colnames(input$switch_target)) {
site_snp_count_bp( site_snp_count_bp(
snp_nca_dist_df3, snp_nca_dist_df3,
title_colour = 'black', title_colour = 'black',
@ -281,8 +300,14 @@ function(input, output, session) {
axis_label_size = 12, axis_label_size = 12,
geom_ls = 4 geom_ls = 4
) )
# } else {
# ggplot() + annotate(x=1,y=1,"text", label="No RNA data for this target")+theme_void()
# }
# }
) )
#### DM OM Plots #### #### DM OM Plots ####
#dm_om_param #dm_om_param
# order needs to be: # order needs to be:

View file

@ -8,341 +8,341 @@
#### Shiny UI ##### #### Shiny UI #####
dashboardPage(skin="purple", dashboardPage(skin="purple",
dashboardHeader(title = "Drug/Target Explorer"), dashboardHeader(title = "Drug/Target Explorer"),
dashboardSidebar( dashboardSidebar(
sidebarMenu( id = "sidebar", sidebarMenu( id = "sidebar",
selectInput( selectInput(
"switch_target", "switch_target",
label="Switch to New Target", label="Switch to New Target",
choices = c( choices = c(
"alr", "alr",
"embb", "embb",
"gid", "gid",
"katg", "katg",
"pnca", "pnca",
"rpob" "rpob"
), ),
selected="embb"), selected="embb"),
menuItem("LogoP SNP", tabName="LogoP SNP"), menuItem("LogoP SNP", tabName="LogoP SNP"),
#menuItem("Lineage Sample Count", tabName="Lineage Sample Count"), #menuItem("Lineage Sample Count", tabName="Lineage Sample Count"),
menuItem("Site SNP count", tabName="Site SNP count"), menuItem("Site SNP count", tabName="Site SNP count"),
menuItem("Stability SNP by site", tabName="Stability SNP by site"), menuItem("Stability SNP by site", tabName="Stability SNP by site"),
menuItem("DM OM Plots", tabName="DM OM Plots"), menuItem("DM OM Plots", tabName="DM OM Plots"),
menuItem("Correlation", tabName="Correlation"), menuItem("Correlation", tabName="Correlation"),
#menuItem("Lineage Distribution", tabName="Lineage Distribution"), #menuItem("Lineage Distribution", tabName="Lineage Distribution"),
menuItem("Consurf", tabName="Consurf"), menuItem("Consurf", tabName="Consurf"),
menuItem("LogoP OR", tabName="LogoP OR"), menuItem("LogoP OR", tabName="LogoP OR"),
menuItem("Lineage", tabName="Lineage"), menuItem("Lineage", tabName="Lineage"),
#menuItem('Stability count', tabName='Stability count'), #menuItem('Stability count', tabName='Stability count'),
# These conditionalPanel()s make extra settings appear in the sidebar when needed # These conditionalPanel()s make extra settings appear in the sidebar when needed
conditionalPanel( conditionalPanel(
condition="input.sidebar == 'LogoP SNP'", condition="input.sidebar == 'LogoP SNP'",
textInput( textInput(
"omit_snp_count", "omit_snp_count",
"Omit SNPs", "Omit SNPs",
value = c(0), value = c(0),
placeholder = "1,3,6" placeholder = "1,3,6"
) )
), ),
# NOTE: # NOTE:
# I *think* we can cheat here slightly and use the min/max from # I *think* we can cheat here slightly and use the min/max from
# merged_df3[['position']] for everything because the various # merged_df3[['position']] for everything because the various
# dataframes for a given gene/drug combination have the # dataframes for a given gene/drug combination have the
# same range of positions. May need fixing, especially # same range of positions. May need fixing, especially
# if we get/shrink the imported data files to something # if we get/shrink the imported data files to something
# more reasonable. # more reasonable.
conditionalPanel( conditionalPanel(
condition=" condition="
input.sidebar == 'LogoP SNP'|| input.sidebar == 'LogoP SNP'||
input.sidebar == 'Stability SNP by site' || input.sidebar == 'Stability SNP by site' ||
input.sidebar == 'Consurf' || input.sidebar == 'Consurf' ||
input.sidebar == 'LogoP OR'", input.sidebar == 'LogoP OR'",
sliderInput( sliderInput(
"display_position_range" "display_position_range"
, "Display Positions" , "Display Positions"
, min=1, max=150, value=c(1,150) # 150 is just a little less than the smallest pos_count , min=1, max=150, value=c(1,150) # 150 is just a little less than the smallest pos_count
) )
), ),
conditionalPanel( conditionalPanel(
condition=" condition="
input.sidebar == 'LogoP SNP' || input.sidebar == 'LogoP SNP' ||
input.sidebar == 'LogoP OR' || input.sidebar == 'LogoP OR' ||
input.sidebar == 'LogoP ED'", input.sidebar == 'LogoP ED'",
selectInput( selectInput(
"logoplot_colour_scheme", "logoplot_colour_scheme",
label="Logo Plot Colour Scheme", label="Logo Plot Colour Scheme",
choices = logoPlotSchemes, choices = logoPlotSchemes,
selected="chemistry" selected="chemistry"
)
),
conditionalPanel(
condition="input.sidebar == 'Correlation'",
selectInput(
"corr_method",
label="Correlation Method",
choices = list("spearman",
"pearson",
"kendall"),
selected="spearman"
)
),
conditionalPanel(
condition="input.sidebar == 'Correlation'",
numericInput(
"corr_lig_dist"
, "Ligand Distance Cutoff (Å)", value=1
)
),
conditionalPanel(
condition="input.sidebar == 'Site SNP count'",
numericInput(
"snp_ligand_dist"
, "Ligand Distance Cutoff (Å)", value=10
)
),
conditionalPanel(
condition="input.sidebar == 'Site SNP count'",
numericInput(
"snp_interface_dist"
, "Interface Distance Cutoff (Å)", value=10
)
),
conditionalPanel(
condition="input.sidebar == 'Site SNP count'",
numericInput(
"snp_nca_dist"
, "NCA Distance Cutoff (Å)", value=10
)
),
conditionalPanel(
condition="input.sidebar == 'Correlation'",
checkboxGroupInput(
"corr_selected",
"Parameters",
choiceNames = c(
"DeepDDG",
"Dynamut2",
"FoldX",
"ConSurf"#,
),
choiceValues = c(
"DeepDDG",
"Dynamut2",
"FoldX",
"ConSurf"#,
),
selected = c(
"DeepDDG",
"Dynamut2",
"FoldX",
"ConSurf"#,
)
)
),
# conditionalPanel(
# condition="input.sidebar == 'DM OM Plots'",
# selectInput(
# "dm_om_param",
# label="Stability Parameter",
# choices = keys(dm_om_map),
# selected="SNAP2")
# ),
# colour_categ
conditionalPanel(
condition="input.sidebar == 'Stability SNP by site'",
selectInput(
"stability_snp_param",
label="Stability Parameter",
choices = stability_boxes_df$stability_type,
selected="Average")
),
conditionalPanel(
condition="input.sidebar == 'Stability SNP by site'",
checkboxInput("reorder_custom_h",
label="Reorder by SNP count",
FALSE)
),
conditionalPanel(
condition="input.sidebar.match(/^Lineage.*/)",
checkboxInput("all_lineages",
label="All Lineages",
FALSE)
),
# an example of how you can match multiple things in frontend JS
conditionalPanel(
condition="input.sidebar == 'LogoP SNP' ||
input.sidebar =='Stability SNP by site' ||
input.sidebar =='Consurf' ||
input.sidebar =='LogoP OR'",
actionButton("clear_ngl",
"Clear Structure")
),
conditionalPanel(
condition="input.sidebar == 'LogoP SNP' ||
input.sidebar =='Stability SNP by site' ||
input.sidebar =='Consurf' ||
input.sidebar =='LogoP OR'",
actionButton("test_ngl",
"Test NGLViewR")
)#,
# downloadButton("save",
# "Download Plot"
# )
# actionButton(
# "reload_target",
# label="Reload Target\nData (slow!)"
# )
)
),
#### body ####
body <- dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
h2("Dashboard tab content")
),
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
),
# creates a 'Conditional Panel' containing a plot object from each of our
# ggplot plot functions (and its associated data frame)
fluidRow(column(width=12,
lapply(plot_functions_df$tab_name,
function(x){
plot_function=plot_functions_df[
plot_functions_df$tab_name==x,
"plot_function"]
plot_df=plot_functions_df[
plot_functions_df$tab_name==x,
"plot_df"]
cat(paste0('\nCreating output: ', x))
generate_conditionalPanel(x, plot_function, plot_df)
}
) )
) ),
), conditionalPanel(
# Explicit fluidRow() for Lineage plots together condition="input.sidebar == 'Correlation'",
fluidRow( selectInput(
column(conditionalPanel( "corr_method",
condition="input.sidebar.match(/^Lineage.*/)", box( label="Correlation Method",
title="Lineage Distribution" choices = list("spearman",
, status = "info" "pearson",
, width=NULL "kendall"),
, plotOutput("lineage_distP", height="700px") %>% withSpinner(color="#0dc5c1"), selected="spearman"
height=800 )
) ),
), width=6 conditionalPanel(
), condition="input.sidebar == 'Correlation'",
column(conditionalPanel( numericInput(
condition="input.sidebar.match(/^Lineage.*/)", box( "corr_lig_dist"
title="Lineage SNP Diversity" , "Ligand Distance Cutoff (Å)", value=1
, status = "info" )
, width=NULL ),
, plotOutput("lin_sc", height="700px") %>% withSpinner(color="#0dc5c1"), conditionalPanel(
height=800 condition="input.sidebar == 'Site SNP count'",
) numericInput(
), width=6 "snp_ligand_dist"
) , "Ligand Distance Cutoff (Å)", value=10
)
), ),
# Explicit fluidRow() for Site SNP Count conditionalPanel(
fluidRow( condition="input.sidebar == 'Site SNP count'",
column(conditionalPanel( numericInput(
condition="input.sidebar == 'Site SNP count'", "snp_interface_dist"
box( , "Interface Distance Cutoff (Å)", value=10
title="Site SNP count" )
, status = "info" ),
, width=NULL conditionalPanel(
, plotOutput("site_snp_count_bp") %>% withSpinner(color="#0dc5c1") condition="input.sidebar == 'Site SNP count'",
) numericInput(
), width=6 "snp_nca_dist"
), , "NCA Distance Cutoff (Å)", value=10
column(conditionalPanel( )
condition="input.sidebar == 'Site SNP count'", ),
box(
title="Ligand Distance" conditionalPanel(
, status = "info" condition="input.sidebar == 'Correlation'",
, width=NULL checkboxGroupInput(
, plotOutput("site_snp_count_bp_ligand") %>% withSpinner(color="#0dc5c1") "corr_selected",
) "Parameters",
), width=6 choiceNames = c(
), "DeepDDG",
column(conditionalPanel( "Dynamut2",
condition="input.sidebar == 'Site SNP count'", "FoldX",
box( "ConSurf"#,
title="Interface Distance" ),
, status = "info" choiceValues = c(
, width=NULL "DeepDDG",
, plotOutput("site_snp_count_interface") %>% withSpinner(color="#0dc5c1") "Dynamut2",
) "FoldX",
), width=6 "ConSurf"#,
), ),
column(conditionalPanel( selected = c(
condition="input.sidebar == 'Site SNP count'", "DeepDDG",
box( "Dynamut2",
title="NCA Distance" "FoldX",
, status = "info" "ConSurf"#,
, width=NULL )
, plotOutput("site_snp_count_nca") %>% withSpinner(color="#0dc5c1") )
) ),
), width=6
) # conditionalPanel(
), # condition="input.sidebar == 'DM OM Plots'",
# selectInput(
# # Explicit fluidRow() for Stability Count # "dm_om_param",
# fluidRow( # label="Stability Parameter",
# column( # choices = keys(dm_om_map),
# conditionalPanel( # selected="SNAP2")
# condition="input.sidebar.match(/^Lineage.*/)", # ),
# lapply( # colour_categ
# # FIXME: using a hardcoded target DF for this IS WRONG AND WILL BREAK conditionalPanel(
# stability_boxes_df[stability_boxes_df$outcome_colname %in% colnames(embb_merged_df3),"outcome_colname"], condition="input.sidebar == 'Stability SNP by site'",
# function(x){ selectInput(
# print(paste0("outcome_colname: ",x)) "stability_snp_param",
# box(plotOutput(x), width=4) label="Stability Parameter",
# } choices = stability_boxes_df$stability_type,
# ), selected="Average")
# width=12 ),
# ) conditionalPanel(
# ) condition="input.sidebar == 'Stability SNP by site'",
# ), checkboxInput("reorder_custom_h",
label="Reorder by SNP count",
#### fluidRow()s for "Stability Count" in the sidebar #### FALSE)
fluidRow( ),
conditionalPanel( conditionalPanel(
condition=" condition="input.sidebar.match(/^Lineage.*/)",
checkboxInput("all_lineages",
label="All Lineages",
FALSE)
),
# an example of how you can match multiple things in frontend JS
conditionalPanel(
condition="input.sidebar == 'LogoP SNP' ||
input.sidebar =='Stability SNP by site' ||
input.sidebar =='Consurf' ||
input.sidebar =='LogoP OR'",
actionButton("clear_ngl",
"Clear Structure")
),
conditionalPanel(
condition="input.sidebar == 'LogoP SNP' ||
input.sidebar =='Stability SNP by site' ||
input.sidebar =='Consurf' ||
input.sidebar =='LogoP OR'",
actionButton("test_ngl",
"Test NGLViewR")
)#,
# downloadButton("save",
# "Download Plot"
# )
# actionButton(
# "reload_target",
# label="Reload Target\nData (slow!)"
# )
)
),
#### body ####
body <- dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
h2("Dashboard tab content")
),
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
),
# creates a 'Conditional Panel' containing a plot object from each of our
# ggplot plot functions (and its associated data frame)
fluidRow(column(width=12,
lapply(plot_functions_df$tab_name,
function(x){
plot_function=plot_functions_df[
plot_functions_df$tab_name==x,
"plot_function"]
plot_df=plot_functions_df[
plot_functions_df$tab_name==x,
"plot_df"]
cat(paste0('\nCreating output: ', x))
generate_conditionalPanel(x, plot_function, plot_df)
}
)
)
),
# Explicit fluidRow() for Lineage plots together
fluidRow(
column(conditionalPanel(
condition="input.sidebar.match(/^Lineage.*/)", box(
title="Lineage Distribution"
, status = "info"
, width=NULL
, plotOutput("lineage_distP", height="700px") %>% withSpinner(color="#0dc5c1"),
height=800
)
), width=6
),
column(conditionalPanel(
condition="input.sidebar.match(/^Lineage.*/)", box(
title="Lineage SNP Diversity"
, status = "info"
, width=NULL
, plotOutput("lin_sc", height="700px") %>% withSpinner(color="#0dc5c1"),
height=800
)
), width=6
)
),
# Explicit fluidRow() for Site SNP Count
fluidRow(
column(conditionalPanel(
condition="input.sidebar == 'Site SNP count'",
box(
title="Site SNP count"
, status = "info"
, width=NULL
, plotOutput("site_snp_count_bp") %>% withSpinner(color="#0dc5c1")
)
), width=6
),
column(conditionalPanel(
condition="input.sidebar == 'Site SNP count'",
box(
title="Ligand Distance"
, status = "info"
, width=NULL
, plotOutput("site_snp_count_bp_ligand") %>% withSpinner(color="#0dc5c1")
)
), width=6
),
column(conditionalPanel(
condition="input.sidebar == 'Site SNP count'",
box(
title="Interface Distance"
, status = "info"
, width=NULL
, plotOutput("site_snp_count_interface") %>% withSpinner(color="#0dc5c1")
)
), width=6
),
column(conditionalPanel(
condition="input.sidebar == 'Site SNP count'",
box(
title="RNA Distance"
, status = "info"
, width=NULL
, plotOutput("site_snp_count_nca") %>% withSpinner(color="#0dc5c1")
)
), width=6
)
),
# # Explicit fluidRow() for Stability Count
# fluidRow(
# column(
# conditionalPanel(
# condition="input.sidebar.match(/^Lineage.*/)",
# lapply(
# # FIXME: using a hardcoded target DF for this IS WRONG AND WILL BREAK
# stability_boxes_df[stability_boxes_df$outcome_colname %in% colnames(embb_merged_df3),"outcome_colname"],
# function(x){
# print(paste0("outcome_colname: ",x))
# box(plotOutput(x), width=4)
# }
# ),
# width=12
# )
# )
# ),
#### fluidRow()s for "Stability Count" in the sidebar ####
fluidRow(
conditionalPanel(
condition="
input.sidebar == 'LogoP SNP' || input.sidebar == 'LogoP SNP' ||
input.sidebar =='Stability SNP by site' || input.sidebar =='Stability SNP by site' ||
input.sidebar =='Consurf' || input.sidebar =='Consurf' ||
input.sidebar =='LogoP OR'", input.sidebar =='LogoP OR'",
column(NGLVieweROutput("structure"), column(NGLVieweROutput("structure"),
width=3 width=3
) )
), ),
conditionalPanel( conditionalPanel(
condition=" condition="
input.sidebar == 'LogoP SNP' || input.sidebar == 'LogoP SNP' ||
input.sidebar == 'Stability SNP by site' || input.sidebar == 'Stability SNP by site' ||
input.sidebar == 'Site SNP count' || input.sidebar == 'Site SNP count' ||
input.sidebar == 'Consurf' || input.sidebar == 'Consurf' ||
input.sidebar == 'LogoP OR'", input.sidebar == 'LogoP OR'",
column( column(
DT::dataTableOutput('table'), DT::dataTableOutput('table'),
width=9 width=9
) )
) )
), ),
) )
) )