-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_QTL.R
More file actions
334 lines (297 loc) · 15.1 KB
/
mod_QTL.R
File metadata and controls
334 lines (297 loc) · 15.1 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
mod_QTL_UI <- function(id) {
ns <- NS(id)
tagList(
tags$div(class = "alert alert-success", role = "alert",
strong("ANote:"), "You can search for a particular QTL of interest on this page and get the corresponding information,the landscape contains a total of 431 QTLs."),
h3("Search QTL information online"),
layout_column_wrap(
1/2,
card(
textInputIcon(
ns("input_QTL_ID"),"Find the QTL ( Example : Yr30、QYr.nw008、QYr.wgp11)",value = "Yr30",placeholder = "Yr30",icon = icon("magnifying-glass"),width = "100%"
),
actionButton(ns("run_search_QTL"),"Search QTL in Ladnscape", icon("magnifying-glass"), class = "btn-success m-2")
),
card(
card_header("Tip"),
card_body("Wheat is one of the most important grain crops. Currently, the global wheat production is threatened by the potential of wheat stripe rust. The best measure to control wheat stripe rust is to cultivate disease-resistant varieties with excellent resistance to wheat stripe rust.")
)
),
card(
h4(textOutput(ns("home_box_ID"))),
markdown(textOutput(ns("home_box_index"))),
textOutput(ns("home_box_pos")),
textOutput(ns("home_box_know_gene")),
textOutput(ns("home_box_QTL_size")),
reactableOutput(ns("search_line_table"),width = "100%")
),
h3("The genotype frequency variation of this QTL"),
reactableOutput(ns("search_QTL_genetype_table"),width = "100%"),
br(),
layout_column_wrap(
1/3,
card(
card_header("Diversity between breeding times"),
echarts4rOutput(ns("home_search_line_plot"),height = "300")
),
card(
card_header("Diversity between breeding region"),
echarts4rOutput(ns("home_search_bar_plot"),height = "300")
),
card(
card_header("The number of samples of different alleles"),
echarts4rOutput(ns("home_search_pie_GT")),height = "300")
),
h3("List of superior type materials (inferred from genotype)"),
card(
reactableOutput(ns("home_search_out_reactable"),width = "100%")
),
tags$div(class = "alert alert-success", role = "alert",
strong("Note:"), "The above only shows the information of the material that contains the excellent type of this QTL. "),
h3("Phenotypic box-and-line plot showing different genotypes"),
card(
full_screen = T,
plotOutput(ns("home_search_phe_boxplot")),
card_footer("Tip: if you need to know more information about the phenotypes, please click on the Trait function for detailed analysis.")
),
h3("The gene information corresponding to this QTL"),
card(
full_screen = T,
DTOutput(ns("QTL_include_gene")),
height = 590
),
h3("Explore more QTL information"),
card(
full_screen = T,
p("The following figure shows the distribution of QTLS on 21 chromosomes. The green site is the QTL for rust resistance. You can click the green area with the mouse for detailed information"),
chromoMapOutput(ns("QTL_map"),height = 500),
tags$div(class = "alert alert-success", role = "alert",
strong("tip:"), "The above is the distribution of different QTLs on chromosomes. Green indicates the location of QTLs. You can click on a QTL with the mouse and jump to the corresponding QTL detailed page in the prompt box."),
hr(),
reactableOutput(ns("home_table_QTL"),width = "100%")
)
)
}
mod_QTL_Server <- function(id) {
moduleServer(
id,
function(input, output, session) {
#QTL-map----
output$QTL_map <- renderChromoMap({
chr_file_1 <- "3_Data/CS21_Ref/chromeMap_chr_data.txt"
anno_file_1 <- "3_Data/chromap_QTL_anno.txt"
chromoMap(chr_file_1,anno_file_1,
interactivity = T,
data_type = "categorical",
chr_length = 11,
chr_width = 10,
chr_color = "gray",
# labels=T,
# label_angle = -60,
# segment_annotation = T,
hlinks=T)
})
# 首页QTL表格----
output$home_table_QTL <- renderReactable(
reactable(S2_QTL_freq[,c(2,3,7,8,6,11,14,21)],
# defaultColDef = colDef(
# header = function(value) gsub(".", " ", value, fixed = TRUE),
# cell = function(value) format(value, nsmall = 1),
# align = "center",
# minWidth = 70,
# headerStyle = list(background = "#ddf5eb")
# ),
defaultPageSize = 10,
# pagination = FALSE,
# height = 700,
searchable = F,
showPageSizeOptions = T,
striped = T,
bordered = F,
highlight = F,
filterable = F
# defaultSortOrder = "desc",
# defaultSorted = c("Chinese Name")
)
)
# 创建响应值- 默认
user_input_QTL_ID <- reactiveValues(QTL = "Yr30")
# 点击后更新响应值
observeEvent(input$run_search_QTL, {
user_input_QTL_ID$QTL = input$input_QTL_ID
})
# 观察URL参数变化
observe({
# 获取URL中的查询参数
query <- parseQueryString(session$clientData$url_search)
# 如果URL包含名为'QTL'的参数,则更新文本输入框的内容
if (!is.null(query$QTL_search)) {
user_input_QTL_ID$QTL = query$QTL_search
url_QTL <- query$QTL_search
updateTextInputIcon(session = session,"input_QTL_ID",value = url_QTL)
}
})
# 根据响应值观察结果输出
observe({
# 获取搜索结果
home_search_out_data <- get_search_gene_name(user_input_QTL_ID$QTL)
if (!is.list(home_search_out_data)){
shinyalert(
title = "Error",
type = "error",text = "Search failed, Please check the input text"
)
}else{
# infomation
output$home_box_index <- renderText(str_c("Landscape unique Index:",home_search_out_data$search_out_all$Index[1]))
output$home_box_ID <- renderText(str_c("Success! Search Index:",home_search_out_data$search_out_all$QTL_ID[1]))
output$home_box_pos <- renderText(str_c("QTL position (IWGSC CS 2.1) : Chr",home_search_out_data$search_out_all$Chrome[1]," [ From ",
home_search_out_data$search_out_all$Start_CS21_MB[1]," MB to ",home_search_out_data$search_out_all$End_CS21_MB[1]," MB ]"))
output$home_box_know_gene <- renderText(str_c("Information:",home_search_out_data$search_out_all$Known_Gene[1]))
output$home_box_QTL_size <- renderText(str_c(home_search_out_data$search_out_all$QTL_ID[1]," Linkage block size: ",home_search_out_data$search_out_all$Size_MB[1]," MB.",
" There are ",home_search_out_data$search_out_all$Gene_Number[1], " genes in this QTL region."))
# search_line_table
output$search_line_table <- renderReactable(
reactable(home_search_out_data$search_line_table,
defaultColDef = colDef(
align = "center",
minWidth = 70,
headerStyle = list(background = "#f6ffed")
),
defaultPageSize = 15,
# pagination = FALSE,
# height = 700,
searchable = F,
showPageSizeOptions = F,
striped = T,
bordered = T
)
)
output$search_QTL_genetype_table <- renderReactable(
reactable(home_search_out_data$search_out_all[,c(2,3,12,14:17)],
defaultColDef = colDef(
align = "center",
minWidth = 70,
headerStyle = list(background = "#f6ffed")
),
# defaultPageSize = 15,
# pagination = FALSE,
# height = 700,
searchable = F,
showPageSizeOptions = F,
striped = F,
bordered = T
)
)
# 不同年代折线图变化趋势
output$home_search_line_plot <- renderEcharts4r(
home_search_out_data$freq_year %>%
e_charts(year) %>%
e_line(freq, areaStyle = list(color = list(
type = 'linear',
x = 0, y = 0, x2 = 0, y2 = 1,
colorStops = list(
list(offset = 0, color = '#3d8e86'), # 颜色在 0% 处
list(offset = 1, color = 'white') # 颜色在 100% 处
)
))) %>%
e_tooltip(trigger = "axis", formatter = htmlwidgets::JS("
function(params) {
var year = params[0].name;
var value = params[0].value;
return 'Usage frequency: ' + value + '%';
}
")) %>%
e_title("Frequency in Breeding Years",x="center") %>%
e_x_axis(type = "category", boundaryGap = FALSE) %>%
e_y_axis(
axisLabel = list(
formatter = "{value}%"
)
) %>%
e_legend(show = FALSE)
)
# 不同地区之间的频率图
output$home_search_bar_plot <- renderEcharts4r(
home_search_out_data$freq_BG %>%
e_charts(Group) %>%
e_bar(freq, itemStyle = list(color = list(
type = 'linear',
x = 0, y = 0, x2 = 0, y2 = 1,
colorStops = list(
list(offset = 0, color = '#509296'), # 颜色在 0% 处
list(offset = 1, color = 'white') # 颜色在 100% 处
)
))) %>%
e_tooltip(trigger = "axis", formatter = htmlwidgets::JS("
function(params) {
var year = params[0].name;
var value = params[0].value;
return 'Usage frequency: ' + value + '%';
}
")) %>%
e_title("Frequency in Breeding Group",x="center") %>%
e_x_axis(type = "category", boundaryGap = TRUE) %>%
e_y_axis(
axisLabel = list(
formatter = "{value}%"
)
) %>%
e_legend(show = FALSE)
)
# 饼图-展示基因型占比
output$home_search_pie_GT <- renderEcharts4r(
home_search_out_data$GT_pie %>%
e_charts(type) %>%
e_pie(value, label = list(
position = 'inside',
formatter = '{b}: {d}%'
)) %>%
e_title("Proportion of GenoType",x="center") %>%
e_tooltip(trigger = "item", formatter = htmlwidgets::JS("
function(params) {
return 'Sample Number: ' + params.value;
}
")) %>%
e_legend(show = F)
)
# 含有抗病位点的材料信息表格
output$home_search_out_reactable <- renderReactable(
reactable(home_search_out_data$R_sample_out
# defaultColDef = colDef(
# header = function(value) gsub(".", " ", value, fixed = TRUE),
# cell = function(value) format(value, nsmall = 1),
# align = "center",
# minWidth = 70,
# headerStyle = list(background = "#f6ffed")
# ),
# columns = list(
# weight = colDef(cell = function(values) {
# sparkline(values, type = "bar", chartRangeMin = 0, chartRangeMax = max(chickwts$weight))
# })
# ),
# defaultPageSize = 15,
# # pagination = FALSE,
# # height = 700,
# searchable = F,
# showPageSizeOptions = T,
# striped = T,
# bordered = T,
# highlight = T,
# filterable = TRUE,
# defaultSortOrder = "desc",
# defaultSorted = c("Material Type")
)
)
# 箱线图——展示表型信息
output$home_search_phe_boxplot <- renderPlot(
plot_boxplot_phe_home(home_search_out_data$phe_boxplot)
)
# QTL 对应的基因
output$QTL_include_gene <- renderDT(
get_QTL_include_gene_table(user_input_QTL_ID$QTL)
)
}
})
}
)
}