msa
This commit is contained in:
parent
e69c2a60aa
commit
594c1c24d6
1 changed files with 173 additions and 169 deletions
342
msa/global.R
342
msa/global.R
|
@ -31,12 +31,16 @@ library(hash)
|
||||||
# than previous approaches
|
# than previous approaches
|
||||||
|
|
||||||
# system.time({
|
# system.time({
|
||||||
source("~/git/LSHTM_analysis/scripts/Header_TT.R")
|
if(interactive()){
|
||||||
|
source("~/git/LSHTM_analysis/scripts/Header_TT.R")
|
||||||
|
} else {
|
||||||
|
source("/srv/shiny-server/git/LSHTM_analysis/scripts/Header_TT.R")
|
||||||
|
}
|
||||||
|
|
||||||
load_target_globals=function(target){
|
load_target_globals=function(target){
|
||||||
cat(paste0("Reloading Target: ", target))
|
cat(paste0("Reloading Target: ", target))
|
||||||
source(paste0("~/git/LSHTM_analysis/config/", target, ".R")) # load per-target config file
|
source(paste0("~/git/LSHTM_analysis/config/", target, ".R")) # load per-target config file
|
||||||
|
|
||||||
invisible(assign(paste0(target, "_merged_df3"), read.csv(paste0("~/git/Misc/shiny_dashboard/data/",target,"-merged_df3.csv")), envir = .GlobalEnv))
|
invisible(assign(paste0(target, "_merged_df3"), read.csv(paste0("~/git/Misc/shiny_dashboard/data/",target,"-merged_df3.csv")), envir = .GlobalEnv))
|
||||||
invisible(assign(paste0(target, "_merged_df2"), read.csv(paste0("~/git/Misc/shiny_dashboard/data/",target,"-merged_df2.csv")), envir = .GlobalEnv))
|
invisible(assign(paste0(target, "_merged_df2"), read.csv(paste0("~/git/Misc/shiny_dashboard/data/",target,"-merged_df2.csv")), envir = .GlobalEnv))
|
||||||
invisible(assign(paste0(target, "_corr_df_m3_f"), read.csv(paste0("~/git/Misc/shiny_dashboard/data/",target,"-corr_df_m3_f.csv")), envir = .GlobalEnv))
|
invisible(assign(paste0(target, "_corr_df_m3_f"), read.csv(paste0("~/git/Misc/shiny_dashboard/data/",target,"-corr_df_m3_f.csv")), envir = .GlobalEnv))
|
||||||
|
@ -77,12 +81,12 @@ load_msa_global=function(gene){
|
||||||
print(infile_msa)
|
print(infile_msa)
|
||||||
msa1 = read.csv(infile_msa, header = F)
|
msa1 = read.csv(infile_msa, header = F)
|
||||||
msa_seq = msa1$V1
|
msa_seq = msa1$V1
|
||||||
|
|
||||||
infile_fasta = paste0("~/git/Data/", drug, "/input/", tolower(gene), "2_f2.fasta")
|
infile_fasta = paste0("~/git/Data/", drug, "/input/", tolower(gene), "2_f2.fasta")
|
||||||
print(infile_fasta)
|
print(infile_fasta)
|
||||||
msa2 = read.csv(infile_fasta, header = F)
|
msa2 = read.csv(infile_fasta, header = F)
|
||||||
wt_seq = msa2$V1
|
wt_seq = msa2$V1
|
||||||
|
|
||||||
target_name=paste0(gene, '_unified_msa')
|
target_name=paste0(gene, '_unified_msa')
|
||||||
#print(target_name)
|
#print(target_name)
|
||||||
invisible(assign(target_name, list(msa_seq = msa_seq, wt_seq = wt_seq), envir = .GlobalEnv))
|
invisible(assign(target_name, list(msa_seq = msa_seq, wt_seq = wt_seq), envir = .GlobalEnv))
|
||||||
|
@ -248,182 +252,182 @@ lapply(c(
|
||||||
|
|
||||||
#### Shiny UI #####
|
#### Shiny UI #####
|
||||||
if(interactive()){
|
if(interactive()){
|
||||||
ui <- dashboardPage(
|
ui <- dashboardPage(
|
||||||
#dashboardHeader(title = paste0(gene, "/", drug)),
|
#dashboardHeader(title = paste0(gene, "/", drug)),
|
||||||
dashboardHeader(title = "Sequence Alignment"),
|
dashboardHeader(title = "Sequence Alignment"),
|
||||||
|
|
||||||
dashboardSidebar(
|
dashboardSidebar(
|
||||||
sidebarMenu( id = "sidebar",
|
sidebarMenu( id = "sidebar",
|
||||||
selectInput(
|
selectInput(
|
||||||
"switch_target",
|
"switch_target",
|
||||||
label="Target",
|
label="Target",
|
||||||
choices = c(
|
choices = c(
|
||||||
"alr",
|
"alr",
|
||||||
"embb",
|
"embb",
|
||||||
"gid",
|
"gid",
|
||||||
"katg",
|
"katg",
|
||||||
"pnca",
|
"pnca",
|
||||||
"rpob"
|
"rpob"
|
||||||
|
),
|
||||||
|
selected="embb"),
|
||||||
|
menuItem("LogoP ED", tabName="LogoP ED"),
|
||||||
|
|
||||||
|
sliderInput(
|
||||||
|
"display_position_full_range"
|
||||||
|
, "Display Positions"
|
||||||
|
, min=1, max=150, value=c(1,150)
|
||||||
),
|
),
|
||||||
selected="embb"),
|
|
||||||
menuItem("LogoP ED", tabName="LogoP ED"),
|
conditionalPanel(
|
||||||
|
condition="
|
||||||
sliderInput(
|
|
||||||
"display_position_full_range"
|
|
||||||
, "Display Positions"
|
|
||||||
, min=1, max=150, value=c(1,150)
|
|
||||||
),
|
|
||||||
|
|
||||||
conditionalPanel(
|
|
||||||
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"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
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
|
body <- dashboardBody(
|
||||||
# ggplot plot functions (and its associated data frame)
|
|
||||||
fluidRow(
|
tabItems(
|
||||||
column(
|
tabItem(tabName = "dashboard",
|
||||||
width=12,
|
h2("Dashboard tab content")
|
||||||
plotOutput("LogoPlotMSA",
|
),
|
||||||
click = "plot_click") %>% withSpinner(color="#0dc5c1")
|
|
||||||
|
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,
|
||||||
|
plotOutput("LogoPlotMSA",
|
||||||
|
click = "plot_click") %>% withSpinner(color="#0dc5c1")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
#### Shiny Backend Server #####
|
||||||
#### Shiny Backend Server #####
|
server <- function(input, output, session) {
|
||||||
server <- function(input, output, session) {
|
observeEvent(
|
||||||
observeEvent(
|
{
|
||||||
{
|
input$display_position_full_range #special-purpose for MSA
|
||||||
input$display_position_full_range #special-purpose for MSA
|
input$logoplot_colour_scheme
|
||||||
input$logoplot_colour_scheme
|
input$switch_target
|
||||||
input$switch_target
|
},
|
||||||
},
|
{
|
||||||
{
|
# C O M P A T I B I L I T Y
|
||||||
# C O M P A T I B I L I T Y
|
#gene=input$switch_target
|
||||||
#gene=input$switch_target
|
#drug=target_map[[gene]]
|
||||||
#drug=target_map[[gene]]
|
merged_df3=cbind(get(paste0(input$switch_target, '_merged_df3')))
|
||||||
merged_df3=cbind(get(paste0(input$switch_target, '_merged_df3')))
|
|
||||||
|
position_max=max(merged_df3[['position']])
|
||||||
position_max=max(merged_df3[['position']])
|
position_min=min(merged_df3[['position']])
|
||||||
position_min=min(merged_df3[['position']])
|
min_ligand_distance=min(merged_df3$ligand_distance)
|
||||||
min_ligand_distance=min(merged_df3$ligand_distance)
|
max_ligand_distance=max(merged_df3$ligand_distance)
|
||||||
max_ligand_distance=max(merged_df3$ligand_distance)
|
# FIXME: these are IMPORTANT
|
||||||
# FIXME: these are IMPORTANT
|
# # add "pos_count" position count column
|
||||||
# # add "pos_count" position count column
|
# merged_df3=merged_df3 %>% dplyr::add_count(position)
|
||||||
# merged_df3=merged_df3 %>% dplyr::add_count(position)
|
# merged_df3$pos_count=merged_df3$n
|
||||||
# merged_df3$pos_count=merged_df3$n
|
# merged_df3$n=NULL
|
||||||
# merged_df3$n=NULL
|
#
|
||||||
#
|
mutable_df3 = cbind(merged_df3)
|
||||||
mutable_df3 = cbind(merged_df3)
|
unified_msa = get(paste0(input$switch_target, '_unified_msa'))
|
||||||
unified_msa = get(paste0(input$switch_target, '_unified_msa'))
|
#
|
||||||
#
|
# # re-sort the dataframe according to position count
|
||||||
# # re-sort the dataframe according to position count
|
sorted_df = cbind(merged_df3)
|
||||||
sorted_df = cbind(merged_df3)
|
sorted_df = sorted_df %>% arrange(pos_count)
|
||||||
sorted_df = sorted_df %>% arrange(pos_count)
|
|
||||||
|
#
|
||||||
#
|
outdir = paste0("~/git/Data/", drug, '/output/')
|
||||||
outdir = paste0("~/git/Data/", drug, '/output/')
|
indir = paste0("~/git/Data/", drug , "/input/")
|
||||||
indir = paste0("~/git/Data/", drug , "/input/")
|
#
|
||||||
#
|
# source("~/git/LSHTM_analysis/scripts/plotting/logo_data_msa.R") # probably unnecessary...
|
||||||
# source("~/git/LSHTM_analysis/scripts/plotting/logo_data_msa.R") # probably unnecessary...
|
|
||||||
|
# source("~/git/LSHTM_analysis/scripts/plotting/get_plotting_dfs.R")
|
||||||
# source("~/git/LSHTM_analysis/scripts/plotting/get_plotting_dfs.R")
|
|
||||||
|
#### nasty special-purpose merged_df3 variants ####
|
||||||
#### nasty special-purpose merged_df3 variants ####
|
# FIXME: SLOW
|
||||||
# FIXME: SLOW
|
# corr_plotdf = corr_data_extract(
|
||||||
# corr_plotdf = corr_data_extract(
|
# merged_df3
|
||||||
# merged_df3
|
# , gene = gene
|
||||||
# , gene = gene
|
# , drug = drug
|
||||||
# , drug = drug
|
# , extract_scaled_cols = F
|
||||||
# , extract_scaled_cols = F
|
# )
|
||||||
# )
|
|
||||||
|
#input$stability_snp_param
|
||||||
#input$stability_snp_param
|
|
||||||
|
updateSliderInput(
|
||||||
updateSliderInput(
|
session,
|
||||||
session,
|
"display_position_range",
|
||||||
"display_position_range",
|
min = position_min,
|
||||||
min = position_min,
|
max = position_max
|
||||||
max = position_max
|
#, value = c(position_min, position_min+150)
|
||||||
#, value = c(position_min, position_min+150)
|
|
||||||
)
|
|
||||||
updateSliderInput(
|
|
||||||
session,
|
|
||||||
"display_position_full_range",
|
|
||||||
min = 1,
|
|
||||||
max = position_max #,
|
|
||||||
# value = c(position_min, position_min+150)
|
|
||||||
)
|
|
||||||
updateNumericInput(session, "selected_logop_snp_position", min = position_min, max = position_max, value = position_min)
|
|
||||||
updateNumericInput(session, "selected_logop_ed_position", min = position_min, max = position_max, value = position_min)
|
|
||||||
updateNumericInput(session, "corr_lig_dist", min = min_ligand_distance, max = max_ligand_distance, value = min_ligand_distance)
|
|
||||||
|
|
||||||
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"]
|
|
||||||
|
|
||||||
display_position_range = input$display_position_range
|
|
||||||
plot_min=display_position_range[1]
|
|
||||||
plot_max=display_position_range[2]
|
|
||||||
|
|
||||||
display_position_full_range = input$display_position_full_range
|
|
||||||
full_range_min=display_position_full_range[1]
|
|
||||||
full_range_max=display_position_full_range[2]
|
|
||||||
|
|
||||||
logoplot_colour_scheme = input$logoplot_colour_scheme
|
|
||||||
omit_snp_count = input$omit_snp_count
|
|
||||||
|
|
||||||
print(paste0('Plotting positions between: ', plot_min, ' and ', plot_max))
|
|
||||||
|
|
||||||
subset_mutable_df3=mutable_df3[(mutable_df3$position>=plot_min & mutable_df3$position <=plot_max),]
|
|
||||||
|
|
||||||
subset_mutable_df3=mutable_df3[(mutable_df3$position>=plot_min & mutable_df3$position <=plot_max),]
|
|
||||||
subset_sorted_df=sorted_df[(sorted_df$position>=plot_min & sorted_df$position <=plot_max),]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### LogoPlotMSA/Logo Plot ED ####
|
|
||||||
output$LogoPlotMSA = renderPlot(
|
|
||||||
LogoPlotMSA(target=input$switch_target,
|
|
||||||
plot_positions=full_range_min:full_range_max,
|
|
||||||
my_logo_col = logoplot_colour_scheme,
|
|
||||||
aa_pos_drug = aa_pos_drug,
|
|
||||||
active_aa_pos = active_aa_pos,
|
|
||||||
aa_pos_lig1 = aa_pos_lig1,
|
|
||||||
aa_pos_lig2 = aa_pos_lig2,
|
|
||||||
aa_pos_lig3 = aa_pos_lig3
|
|
||||||
)
|
)
|
||||||
)
|
updateSliderInput(
|
||||||
}
|
session,
|
||||||
)
|
"display_position_full_range",
|
||||||
|
min = 1,
|
||||||
#### EOF Shiny Server ####
|
max = position_max #,
|
||||||
|
# value = c(position_min, position_min+150)
|
||||||
|
)
|
||||||
|
updateNumericInput(session, "selected_logop_snp_position", min = position_min, max = position_max, value = position_min)
|
||||||
|
updateNumericInput(session, "selected_logop_ed_position", min = position_min, max = position_max, value = position_min)
|
||||||
|
updateNumericInput(session, "corr_lig_dist", min = min_ligand_distance, max = max_ligand_distance, value = min_ligand_distance)
|
||||||
|
|
||||||
|
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"]
|
||||||
|
|
||||||
|
display_position_range = input$display_position_range
|
||||||
|
plot_min=display_position_range[1]
|
||||||
|
plot_max=display_position_range[2]
|
||||||
|
|
||||||
|
display_position_full_range = input$display_position_full_range
|
||||||
|
full_range_min=display_position_full_range[1]
|
||||||
|
full_range_max=display_position_full_range[2]
|
||||||
|
|
||||||
|
logoplot_colour_scheme = input$logoplot_colour_scheme
|
||||||
|
omit_snp_count = input$omit_snp_count
|
||||||
|
|
||||||
|
print(paste0('Plotting positions between: ', plot_min, ' and ', plot_max))
|
||||||
|
|
||||||
|
subset_mutable_df3=mutable_df3[(mutable_df3$position>=plot_min & mutable_df3$position <=plot_max),]
|
||||||
|
|
||||||
|
subset_mutable_df3=mutable_df3[(mutable_df3$position>=plot_min & mutable_df3$position <=plot_max),]
|
||||||
|
subset_sorted_df=sorted_df[(sorted_df$position>=plot_min & sorted_df$position <=plot_max),]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### LogoPlotMSA/Logo Plot ED ####
|
||||||
|
output$LogoPlotMSA = renderPlot(
|
||||||
|
LogoPlotMSA(target=input$switch_target,
|
||||||
|
plot_positions=full_range_min:full_range_max,
|
||||||
|
my_logo_col = logoplot_colour_scheme,
|
||||||
|
aa_pos_drug = aa_pos_drug,
|
||||||
|
active_aa_pos = active_aa_pos,
|
||||||
|
aa_pos_lig1 = aa_pos_lig1,
|
||||||
|
aa_pos_lig2 = aa_pos_lig2,
|
||||||
|
aa_pos_lig3 = aa_pos_lig3
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
#### EOF Shiny Server ####
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
################ Running Server ##############
|
||||||
|
app <- shinyApp(ui, server)
|
||||||
|
|
||||||
|
|
||||||
|
runApp(app)
|
||||||
}
|
|
||||||
################ Running Server ##############
|
|
||||||
app <- shinyApp(ui, server)
|
|
||||||
|
|
||||||
|
|
||||||
runApp(app)
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue