-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
107 lines (81 loc) · 3.79 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(dplyr)
library(shinycssloaders)
# Define UI for data upload app ----
ui <- fluidPage(
# App title ----
titlePanel("Reciprocal Best App"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
helpText("Compute the reciprocal best hits from two sets of protein sequences"),
helpText("Usage : Browse to select two sets of protein sequences (FASTA format) and wait for rbhXpress to create a downloadable output"),
# Input: Select a file ----
fileInput("file1", "Choose 1st Fasta File",
multiple = FALSE,
accept = c(".fa",
".fasta",
".pep")),
fileInput("file2", "Choose 2nd Fasta File",
multiple = FALSE,
accept = c(".fa",
".fasta",
".pep")),
actionButton("do","Compute orthologs")
),
# Main panel for displaying outputs ----
mainPanel(
verbatimTextOutput("rbhXpressLOG"),
uiOutput("DownloadData")
# downloadButton("DownloadData","Download")
# Output: Data file ----
)
)
)
options(shiny.maxRequestSize=30*1024^2)
# Define server logic to read selected file ----
server <- function(input, output,session) {
# Copy data to the local folder
observeEvent(input$do, {
# The whole process can be called only if the two fasta files were successfully uploaded :
req(input$file1)
req(input$file2)
# read 1st fasta and write to the data folder :
df <- read.csv(input$file1$datapath,
header = FALSE,
sep = ",") %>% select(V1)
write.table(df,"sessionFolder/file1.fa",col.names = FALSE,row.names = FALSE,sep=",", quote = FALSE)
# read 2nd fasta and write to the data folder :
df <- read.csv(input$file2$datapath,
header = FALSE,
sep = ",") %>% select(V1)
write.table(df,"sessionFolder/file2.fa",col.names = FALSE,row.names = FALSE,sep=",", quote = FALSE)
# run rbhXpress :
rbh_command_line <- "bash scripts/rbhXpress/rbhXpress.sh -a sessionFolder/file1.fa -b sessionFolder/file2.fa -t 1 > sessionFolder/reciprocal_best_hits.tab"
system(rbh_command_line,intern = F)
orthologs <- read.csv("sessionFolder/reciprocal_best_hits.tab",header = FALSE,sep="\t")
# display amount of orthologs found and download button :
output$rbhXpressLOG <- renderText({paste0("Found ",length(orthologs$V1)," reciprocal best hits !")})
output$DownloadData <- renderUI({if (!is.null(orthologs)) {downloadButton("Downloadrbh","Download") }})
output$Downloadrbh <- downloadHandler(filename = "reciprocal_best_hits.tab",
content = function(file){
write.table(orthologs,file,col.names = FALSE,row.names = FALSE,sep = "\t",quote = FALSE)
})
})
session$onSessionEnded(function() { unlink(c("sessionFolder/file1.fa",
"sessionFolder/file2.fa",
"sessionFolder/reciprocal_best_hits.tab",
"sessionFolder/p1_p2","sessionFolder/p2.dmnd","sessionFolder/p2_p1.s",
"sessionFolder/p1.dmnd","sessionFolder/p1_p2.s","sessionFolder/p2_p1") )})
}
# Create Shiny app ----
shinyApp(ui, server)