diff --git a/global.R b/global.R new file mode 100644 index 0000000..c916a68 --- /dev/null +++ b/global.R @@ -0,0 +1,29 @@ +library(dplyr) +library(DT) +library(ggplot2) +library(grid) # for the info box +library(plotly) +library(NGLVieweR) +library(httr) +library(readr) +library(RCurl) +# make shiny non-stupid +#options(shiny.launch.browser = FALSE) # i am a big girl and can tie my own laces +#options(shiny.port = 8000) # don't change the port every time +#options(shiny.host = '0.0.0.0') # This means "listen to all addresses on all interfaces" +#options(DT.options = list(scrollX = TRUE)) + + +# An "application token" is required here. I generated this one like this: +# curl -H "Content-Type: application/json" -d '{"name":"r-data"}' -u : https://git.tunstall.in/api/v1/users/sethp/tokens + +# Gitea access token +access_token = read_lines("~/secret-token") + +gene_url = "https://git.tunstall.in/api/v1/repos/tanu/fellowship_dcdf/raw/tb_data_fc/data_dashboard/list_unique_missense_genes.csv" +missense_gene_url = "https://git.tunstall.in/api/v1/repos/tanu/fellowship_dcdf/raw/tb_data_fc/data_dashboard/missense_genes_params.csv" +alphafold_url = "https://alphafold.ebi.ac.uk/files/" + +genes=read_csv(paste0(gene_url,"?token=",access_token)) +unique_missense_genes = read_delim(paste0(missense_gene_url,"?token=",access_token)) + diff --git a/server.R b/server.R index 1a4a43a..3acb764 100644 --- a/server.R +++ b/server.R @@ -13,7 +13,7 @@ library(httr) library(readr) library(RCurl) -shinyServer(function(input, output) { +shinyServer(function(input, output){ output$distPlot <- renderPlot({ # generate bins based on input$bins from ui.R @@ -83,11 +83,13 @@ shinyServer(function(input, output) { observeEvent(input$table_rows_selected,{ #req(length(input$table_row_selected) > 0) + mutation_pdb = as.character(unique_missense_genes[input$table_rows_selected,"position_pdb"]) + mutation_af = as.character(unique_missense_genes[input$table_rows_selected,"position_af"]) mutation = as.character(unique_missense_genes[input$table_rows_selected,"hgvd_p"]) chain = as.character(unique_missense_genes[input$table_rows_selected,"chain"]) # what the absolute FUCK is this mess? I JUST WANT THE MATCH ASDLASJASDASHFKLJASDFK # coming down from the trees was a mistake, and abandoning Perl doubly so. - clicked_position = regmatches(mutation, regexpr("[0-9]+", mutation, perl=TRUE)) + #clicked_position = regmatches(mutation, regexpr("[0-9]+", mutation, perl=TRUE)) # Now update the 3D structure to highlight the clicked thing and then zoom in. @@ -96,7 +98,7 @@ shinyServer(function(input, output) { addSelection('spacefill' , param = list( name = "Pos" - , sele = trimws(paste0(clicked_position,':', chain)) + , sele = trimws(paste0(mutation_pdb,':', chain)) , color = "red" #, colorValue="00ff00" #, colorScheme="element" @@ -107,7 +109,7 @@ shinyServer(function(input, output) { addSelection('spacefill' , param = list( name = "Pos" - , sele = clicked_position + , sele = mutation_af , color = "red" #, colorValue="00ff00" #, colorScheme="element" @@ -115,20 +117,20 @@ shinyServer(function(input, output) { ) NGLVieweR_proxy("af_structure") %>% updateZoomMove( - center = clicked_position, - zoom = clicked_position, + center = mutation_af, + zoom = mutation_af, duration = 1000, # animation time in ms z_offSet = -1 ) NGLVieweR_proxy("structure") %>% updateZoomMove( - center = trimws(paste0(clicked_position,':', chain)), - zoom = trimws(paste0(clicked_position,':', chain)), + center = trimws(paste0(mutation_pdb,':', chain)), + zoom = trimws(paste0(mutation_pdb,':', chain)), duration = 1000, # animation time in ms z_offSet = -1 ) output$information <- renderUI({ selected_gene=input$gene - HTML(paste0("Mutation: ", as.character(unique_missense_genes[input$table_rows_selected,"mutationinformation"]),"
", + HTML(paste0("Mutation: ", as.character(unique_missense_genes[input$table_rows_selected,"mutationinformation_pdb"]),"
", "PDB ID: ", as.character(genes[genes$Gene==selected_gene,"PDB"]),"
", "AlphaFold ID: ", as.character(genes[genes$Gene==selected_gene,"AF_PDB"]), "
", "Ligand Distance: ", as.character(unique_missense_genes[input$table_rows_selected,"ligand_distance"]), "
", @@ -186,7 +188,21 @@ shinyServer(function(input, output) { " and (", paste0( apply( - unique_missense_genes[unique_missense_genes$gene_name == gene,c("position","chain")], + unique_missense_genes[unique_missense_genes$gene_name == gene,c("position_pdb","chain")], + 1, + function(x){ + paste0(trimws(x[1]) + )} + ), + collapse=", " + ), ")" + ) + mutations_af = paste0(":", + as.matrix(unique_missense_genes[unique_missense_genes$gene_name == gene,c("chain")])[1], + " and (", + paste0( + apply( + unique_missense_genes[unique_missense_genes$gene_name == gene,c("position_af","chain")], 1, function(x){ paste0(trimws(x[1]) @@ -207,7 +223,7 @@ shinyServer(function(input, output) { opacity = 0.2 ) ) %>% - addSelection(type="ball+stick", #spacefill + addSelection(type="spacefill", #spacefill param = list(name = "all_mutations", color="orange", sele = mutations @@ -225,14 +241,14 @@ shinyServer(function(input, output) { opacity = 0.2 ) ) %>% - addSelection(type="ball+stick", #spacefill + addSelection(type="spacefill", #spacefill param = list(name = "all_mutations", color="orange", - sele = mutations + sele = mutations_af #colorScheme = "bfactor", #opacity = 1 ) ) }) -} -) +}) + diff --git a/ui.R b/ui.R index 5c50730..bc11121 100644 --- a/ui.R +++ b/ui.R @@ -12,7 +12,6 @@ library(NGLVieweR) library(httr) library(readr) library(RCurl) - dashboardPage(skin="purple", dashboardHeader(title="Tuberculosis Host"), dashboardSidebar(