-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprecheckboxapp.R
204 lines (154 loc) · 8.42 KB
/
precheckboxapp.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#Experiment: Gene Regulatory Networks of Developmental Plasticity
#Last updated: June 24, 2024
#https://julie-jung.shinyapps.io/grn-shiny/
library(shiny)
library(ggplot2)
library(data.table)
#read in our csv file with the expression values from DEseq
DEseq <- read.csv("values_All.csv", stringsAsFactors=TRUE)
str(DEseq)
#we see that we have a dataframe of 24,678 genes with 173 variables (expression)
#ultimately we want to be able to search (use input text widget and search for an exact string match) among the 24678 genes
#The 173 variables are a mix of condition_development_replicate
#The main challenge here will be to tidy the data from the input in the right long format.
#First I want to convert the values in the first column into row names in the existing dataframe
DEseq2<-DEseq[,-1]
rownames(DEseq2) <- DEseq[,1]
#Let's start by transposing the dataframe
t_DEseq<-as.data.frame(t(DEseq2))
#now, split that string into condition_timepoint_replicate
suppressMessages(library(tidyverse))
rn <- rownames(t_DEseq) #rn lists the conditions, dev hours, and replicates
#use strsplit to get the output into a 'list', rbind the output to get a matrix "m1"
m1 <- do.call(rbind, strsplit(rn, "_"))
m1 #now they're split
t_DEseq$condition <- m1[,1] #assigns condition as new column
t_DEseq$development <- m1[,2]
t_DEseq$replicate <- m1[,3]
# Define UI -----
# Peruse widgets from here: https://shiny.posit.co/r/gallery/widgets/widget-gallery/
# More/extension of widgets: https://dreamrs.github.io/shinyWidgets/
ui <- fluidPage(
# App title -----
titlePanel("Search gene expression values from DEseq"),
# Sidebar layout with input and output definitions -----
sidebarLayout(position="left",
# Sidebar panel for inputs -----
sidebarPanel( #"sidebar panel", #insert name here if you want
#checkboxInput("do2", "Make 2 plots", value = T),
# Drop down selection for conditions
selectInput(inputId = "conditionInput", #name to use to look up the value of the widget (as a character string)
label = "Condition:", #label to display above the drop-down box
choices = c("Agar WT" = "AG", #a list of values. The widget will include a menu option for each value of the list. If the list has names, these will be displayed in the drop down menu. Otherwise the values themselves will be displayed.
"eud1 k/o" = "eud1",
"eud1 t/g" = "eud1TG",
"Expectatus WT" = "Exp",
"Liquid Culture WT" = "LC",
"lsy12 k/o" = "lsy12",
"mbd2 k/o" = "mbd2",
"nag1 and nag2 k/o" = "nag12",
"nhr40 k/o" = "nhr40",
"RS5410 St bias" = "RS5410",
"RS5427 Eu bias" = "RS5427",
"RSA100 Eu bias" = "RSA100",
"RSC017 St bias" = "RSC017",
"sult1 k/o" = "sult1")),
# Text input to subset by gene (must be an exact match)
textInput(inputId = "geneID", #the name to use to look up the value of the widget (as a character string)
label = "Gene:", #a label to display above the text field
value = "Contig0-snapTAU.703"), #placeholder
# ALTERNATIVE: Choose gene from checkboxes of possible genes (instead of providing an exact match)
## Text input to subset by a second gene (must be an exact match)
#textInput(inputId = "geneID2", #the name to use to look up the value of the widget (as a character string)
# label = "Another Gene:", #a label to display above the text field
# value = "Contig13-snapTAU.388"), #placeholder
# Drop down selection for a second condition
selectInput(inputId = "conditionInput2", #name to use to look up the value of the widget (as a character string)
label = "Another Condition:", #label to display above the drop-down box
choices = c("Agar WT" = "AG", #a list of values. The widget will include a menu option for each value of the list. If the list has names, these will be displayed in the drop down menu. Otherwise the values themselves will be displayed.
"eud1 k/o" = "eud1",
"eud1 t/g" = "eud1TG",
"Expectatus WT" = "Exp",
"Liquid Culture WT" = "LC",
"lsy12 k/o" = "lsy12",
"mbd2 k/o" = "mbd2",
"nag1 and nag2 k/o" = "nag12",
"nhr40 k/o" = "nhr40",
"RS5410 St bias" = "RS5410",
"RS5427 Eu bias" = "RS5427",
"RSA100 Eu bias" = "RSA100",
"RSC017 St bias" = "RSC017",
"sult1 k/o" = "sult1"))
), # This closes out the sidebar panel.
# Main panel for displaying outputs -----
mainPanel( #"main panel",
#fluidRow(
# splitLayout(cellWidths = c("50%", "50%"), plotOutput("boxplot1", plotOutput("boxplot2"))
# )), #close fluidRow
plotOutput("boxplot"), #delete this comma and on
# I think this is also where we'd want to put our download button
downloadButton("downloadPlot", "Download")
#fluidPage(downloadButton('downloadPlot'))
) # This closes out the main panel.
)) # This closes out the UI
# Define server logic
# Function to produce summary statistics (mean and +/- se)
se <- function(x) sqrt(var(x)/length(x))
data_summary <- function(x) {
m <- mean(x, na.rm=T)
ymin <- m-se(x)
ymax <- m+se(x)
return(c(y=m,ymin=ymin,ymax=ymax))
}
#server
server <- function(input, output) {
output$boxplot <- renderPlot({
#you can access the value of the select widget with input$select (or in our case, input$conditionInput)
subset.DEseq <- subset(t_DEseq, t_DEseq$condition == input$conditionInput)
# still have all columns
#separate out the development column so that we don't lose it.
development<-subset.DEseq$development
#subset the gene too! currently column name. but without losing development column
keeps <- c(colnames(subset.DEseq) %in% input$geneID) #specify which columns to keep in a vector
subset.DEseq<- cbind(subset.DEseq[keeps], development)
colnames(subset.DEseq)<-c("geneID", "development")
##second conditions input
# subset.DEseq <- subset(t_DEseq, t_DEseq$condition == input$conditionInput | t_DEseq$condition == input$conditionInput2)
# development_cond2<-subset.DEseq_cond2$development
# keeps_cond2 <- c(colnames(subset.DEseq_cond2) %in% input$geneID)
# subset.DEseq_cond2<- cbind(subset.DEseq_cond2[keeps_cond2], development)
# colnames(subset.DEseq_cond2)<-c("geneID", "development")
# str(subset.DEseq_cond2)
# draw the plot of expression over development
boxplot <- ggplot(data=subset.DEseq, aes(x=development, y=geneID))+
geom_jitter(pch=16, size= 2.5, width=0.1, na.rm=T) +
stat_summary(fun.data=data_summary, color='gray')+
#geom_jitter(data= subset.DEseq_cond2, pch=16, size= 2.5, width=0.1, na.rm=T, color="red") +
#stat_summary(fun.data=data_summary, color='pink')+
labs(x = "development",
y = "gene expression") +
theme_bw(base_size=12, base_family="Palatino")
boxplot
#plotly::ggplotly(expression_plot)
#
# # draw the plot of expression over development
# boxplot2 <- ggplot(data=subset.DEseq_cond2, aes(x=development, y=geneID))+
# geom_jitter(pch=16, size= 2.5, width=0.1, na.rm=T) +
# stat_summary(fun.data=data_summary, color='gray')+
# labs(x = "development",
# y = "gene expression") +
# theme_bw(base_size=12, base_family="Palatino")
# boxplot2
# #plotly::ggplotly(expression_plot)
})
#output$boxplot2 <- renderPlot({boxplot2()})
# Download button for plot
output$downloadPlot <- downloadHandler(
filename = function() { paste(input$dataset, '.png', sep='') },
content = function(file) {
ggsave(file, plot = plotInput(), device = "png")
}
)
}
# Create Shiny app
shinyApp(ui = ui, server = server)