File size: 28,506 Bytes
bd8cdd3 |
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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
validate_dataframe <- function(df, validation_rules = c("structure", "peak_headers", "metadata")
) {
expected_headers <- c(
"Alignment ID", "Average Rt(min)", "Average Mz", "Metabolite name",
"Adduct type", "Post curation result", "Fill %", "MS/MS assigned",
"Reference RT", "Reference m/z", "Formula", "Ontology", "INCHIKEY",
"SMILES", "Annotation tag (VS1.0)", "RT matched", "m/z matched",
"MS/MS matched", "Comment", "Manually modified for quantification",
"Manually modified for annotation", "Isotope tracking parent ID",
"Isotope tracking weight number", "RT similarity", "m/z similarity",
"Simple dot product", "Weighted dot product", "Reverse dot product",
"Matched peaks count", "Matched peaks percentage", "Total score",
"S/N average", "Spectrum reference file name", "MS1 isotopic spectrum",
"MS/MS spectrum"
)
# Input check
if (!is.data.frame(df)) {
stop("Input must be a dataframe")
}
if (!is.character(validation_rules)) {
stop("validation_rules must be a character vector")
}
if (!all(validation_rules %in% c("structure", "peak_headers", "metadata"))) {
stop("Invalid validation_rules specified")
}
validation_results <- list()
# Check data structure
if ("structure" %in% validation_rules) {
if (nrow(df) < 5) {
validation_results$insufficient_rows <-
"Data has less than 5 rows. At least 5 rows are required."
}
if (ncol(df) < 34) {
validation_results$insufficient_cols <-
"Missing 34 columns required for peak information."
}
}
# Check peak information headers (row 5)
if ("peak_headers" %in% validation_rules) {
if (is.null(expected_headers)) {
stop("expected_headers required for peak_headers validation")
}
if (nrow(df) >= 5) {
headers <- df[5, 1:min(34, ncol(df))]
missing_headers <- expected_headers[1:length(headers)][headers != expected_headers[1:length(headers)]]
if (length(missing_headers) > 0) {
validation_results$incorrect_headers <-
paste("Headers in row 5 differ from expected headers:",
paste(missing_headers, collapse = ", "))
}
}
}
# Check metadata (rows 1-2, columns 35+)
if ("metadata" %in% validation_rules && ncol(df) > 34) {
# Check for Sample in columns 36+
if (ncol(df) > 35) {
file_types <- df[2, 36:ncol(df)]
if (!"Sample" %in% file_types) {
validation_results$no_sample <-
"'Sample' not found in columns 36 onward"
}
}
}
return(validation_results)
}
server <- function(input, output,session) {
options(shiny.maxRequestSize=150*1024^100)
originaldir <- reactiveValues(datapath = getwd()) # directry of shiny R script
global <- reactiveValues(datapath = getwd()) # directory of file path in lipidomics tab
col = reactiveValues(col = col)
validation_status <- reactiveVal(FALSE)
svg_path <- paste(getwd(),"/svg",sep = "")
host <- session$request$HTTP_HOST %>%
gsub("http:", "https:", .)
output$downloadData <- downloadHandler(
filename = function() {
"Demo_data.zip" # ダウンロード時のファイル名
},
content = function(file) {
file.copy("./pathwaymap/demodata.zip", file)
},
contentType = "application/zip"
)
observeEvent(input$filetype,{
if(input$filetype =="Sample in rows"){
shinyjs::show("ontfile")
}else{
shinyjs::hide("ontfile")
}
if(input$ClassorMol =="TRUE"){
shinyjs::show("X1")
shinyjs::show("X2")
}else{
shinyjs::hide("X1")
shinyjs::hide("X2")
}
})
observeEvent(input$ClassorMol,{
if(input$ClassorMol =="TRUE"){
shinyjs::show("X1")
shinyjs::show("X2")
}else{
shinyjs::hide("X1")
shinyjs::hide("X2")
}
})
observeEvent(input$file1, {
tryCatch({
originaldata <- read.csv(input$file1$datapath, header = F, check.names = F, fileEncoding = "UTF-8-BOM")
}, error = function(e) {
showNotification(paste("Failed to load the file", e$message), type = "error")
})
if(input$filetype == "Sample in rows"){
}else if(input$filetype == "MS-DIAL export"){
validateresults <- validate_dataframe(originaldata, validation_rules = c("structure", "peak_headers", "metadata"))
if (length(validateresults) == 0) {
validation_status(TRUE)
shinyalert(
"Success",
"All validation checks passed successfully!",
type = "success"
)
} else {
validation_status(FALSE)
error_message <- "<div style='text-align: left;'><strong>Validation Errors:</strong><br><br>"
# 各エラーメッセージの処理
for (error_name in names(validateresults)) {
error_message <- paste0(
error_message,
"<span style='color: #dc3545;'>• ", # 赤色のブレット
switch(error_name,
"insufficient_cols" = "<strong>Column Error:</strong> ",
"incorrect_headers" = "<strong>Header Error:</strong> ",
"no_sample" = "<strong>Sample Error:</strong> "),
validateresults[[error_name]],
"</span><br><br>"
)
}
error_message <- paste0(error_message, "</div>")
# エラーメッセージの表示
shinyalert(
"Validation Failed",
html = TRUE,
text = error_message,
type = "error",
size = "l",
closeOnEsc = TRUE,
closeOnClickOutside = TRUE,
showConfirmButton = TRUE,
confirmButtonText = "OK",
timer = FALSE
)
}
}
observeEvent(input$submit,{
tryCatch({
if(input$filetype == "Sample in rows"){
Lipidomedata <- processSampleInRows(originaldata, session, input)[[1]]
lipidont <- read.csv(input$ontfile$datapath, sep = ",", check.names = FALSE)
metadata <- processSampleInRows(originaldata, session, input)[[2]]
alitable <- read.csv(input$ontfile$datapath, check.names = FALSE, fileEncoding = "UTF-8-BOM")
colnames(alitable) <- c("Metabolite name","Ontology")
letchoice <- c(colnames(Lipidomedata)[!colnames(Lipidomedata) %in% colnames(metadata)],"Others")
moldata <- processSampleInRowstomoldata(originaldata, session, input)[[1]]
}else if(input$filetype == "MS-DIAL export"){
Lipidomedata <- processMSDIALExport(originaldata, session, input)[[1]]
metadata <- processMSDIALExport(originaldata, session, input)[[2]]
alitable <- process_alignment_file(originaldata)[[1]] %>% select(c(1,2))
moldata <- processMSDIALExporttomoldata(originaldata, session, input)[[1]]
}
if(length(input$transcriptomefile) !=0){
transcriptome <- read.csv(input$transcriptomefile$datapath,check.names = F,fileEncoding ="UTF-8-BOM") %>% t()
colnames(transcriptome) <- transcriptome[1,]
transcriptome <- transcriptome[-1,] %>% data.frame()
transcriptome[,-c(1)] <- apply(transcriptome[,-c(1)],2,as.numeric) %>% data.frame()
transcriptome <- rownames_to_column(transcriptome,"name")
transcriptome[,2] <- as.character(transcriptome[,2])
}
if(length(input$file1) !=0 & length(input$transcriptomefile) != 0){
Ensembl <- gconvert(query = colnames(transcriptome)[-c(1:2)] , organism = "mmusculus",#sapiens
target="ENSG", mthreshold = Inf, filter_na = TRUE) %>% select(input,target)
transcriptome <- transcriptome %>% select(-2)
data <- inner_join(Lipidomedata,transcriptome,by =c("name"))
moldata <- inner_join(moldata,transcriptome,by =c("name"))
}
else{
data <- Lipidomedata
}
}, error = function(e) {
showNotification(paste("Error:Invalid CSV file format. Please ensure your file is a properly formatted CSV.", e$message), type = "error")
})
metainfocol <- ncol(metadata)
lipidclassproperties <- read_csv("./pathwaymap/lipidclassproperties.csv")
processAndUpdateInputs(data, session, metadata, metainfocol)
processAndUpdateInputs2(moldata, session, metadata, metainfocol)
shinyalert(
"Success",
"GO to Plot tab",
type = "success"
)
observeEvent(input$y,{
targetclass <- filter(alitable,Ontology %in% input$y)
shiny::updateSelectInput(session, "mol", selected = targetclass$`Metabolite name`[1], choices = targetclass$`Metabolite name`)
})
#observeEvent(input$Colorpicker,{
#print("boton")
# ShowtestModaldialog4(data,input,col$col)
#}
#)
observeEvent(input$exportgraph,{
ShowtestModaldialog2(data,input,col$col)
}
)
observeEvent(input$Colorpicker, {
ShowtestModaldialog(data,input,col$col)
})
observeEvent(input$saveConfirm, {
removeModal()
showNotification("保存が完了しました", type = "success")
})
observeEvent(input$w,{
updateOrderInput(session, "levels",
items = c(unique(as.matrix(select(data,input$w)))),
item_class = "success")
shiny::updateSelectInput(session, "q", selected = c(unique(as.matrix(select(data,input$w))))[1], choices = c(unique(as.matrix(select(data,input$w)))))
col$col <<- rainbow_hcl(length(unique(as.matrix(select(data,input$w)))))
col$col <<- setNames(col$col,unique(as.matrix(select(data,input$w))))
})
observeEvent(input$levels,{
if (!is.null(input$levels) && any(input$levels != "")) {
dataa <<- mutate(data, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
moldataa <<- mutate(moldata, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
}
})
observe({
if (length(grep("selectcolor", names(input), value = TRUE)) != 0) {
col$col <<- process_select_color_input(input,data)
}
})
# 可能な比較の組み合わせを生成
possible_comparisons <- reactive({
groups <- unique(data[[input$w]])
combs <- combn(groups, 2, simplify = FALSE)
setNames(
lapply(combs, function(x) paste(x, collapse = "vs")),
lapply(combs, function(x) paste(x, collapse = " vs "))
)
})
# 比較選択用のUI生成
output$comparison_choices <- renderUI({
checkboxGroupInput("comparisons", "Select comparisons:",
choices = possible_comparisons(),
selected = possible_comparisons()[1])
})
# Select All ボタンの処理
observeEvent(input$select_all, {
updateCheckboxGroupInput(session, "comparisons",
selected = possible_comparisons())
})
# Clear All ボタンの処理
observeEvent(input$clear_all, {
updateCheckboxGroupInput(session, "comparisons",
selected = character(0))
})
# 統計検定の実行
stat_test <- reactive({
req(input$comparisons, input$test_method)
# 検定関数の選択
test_func <- get(input$test_method, asNamespace("rstatix"))
# 結果を格納するデータフレーム
results <- data.frame()
for(comp in input$comparisons) {
# グループを分割
groups <- strsplit(comp, "vs")[[1]]
# データのサブセット作成
subset_data <- data %>%
dplyr::filter(!!sym(input$w) %in% groups)
# 検定実行
test_result <- test_func(subset_data, as.formula(paste(input$y, "~", input$w))) %>%
adjust_pvalue(method = input$p_adjust) %>%
add_significance()
results <- rbind(results, test_result)
}
results
})
stat_testmol <- reactive({
req(input$comparisons, input$test_method)
# 検定関数の選択
test_func <- get(input$test_method, asNamespace("rstatix"))
# 結果を格納するデータフレーム
results <- data.frame()
for(comp in input$comparisons) {
# グループを分割
groups <- strsplit(comp, "vs")[[1]]
# データのサブセット作成
subset_data <- moldata %>%
dplyr::filter(!!sym(input$w) %in% groups)
# 検定実行
test_result <- test_func(subset_data, as.formula(paste(paste("`",input$mol,"`",sep =""), "~", input$w))) %>%
adjust_pvalue(method = input$p_adjust) %>%
add_significance()
results <- rbind(results, test_result)
}
results
})
#if(input$pvaluecheck == TRUE){
# サマリー統計の表示
output$stat_results <- renderPrint({
req(stat_test())
results <- stat_test()
cat("Results:\n")
print(summary(results))
})
#}
observeEvent(input$levels,{
observe({
if (!is.null(input$mol) && input$mol != "") {
if(!is.null(input$levels) && any(input$levels != "")){
output$plottest <- renderPlot({
if(input$mydrop == "box"){
process_boxplot(input,input$y,dataa,col$col,stat_test())
}
else if(input$mydrop == "bar"){
process_barplot(input,input$y,dataa,col$col,stat_test())
}
else if(input$mydrop == "violin"){
process_violinplot(input,input$y,dataa,col$col,stat_test())
}
else if(input$mydrop == "polar"){
process_polarplot(input,input$y,dataa,col$col,stat_test())
}
else if(input$mydrop == "coding"){
process_dotplot(input,input$y,dataa,col$col,stat_test())
}
}
)
output$mappingraph <- renderPlot({
if(input$mydrop == "box"){
process_boxplot_diagram(input,input$y,dataa,col$col,stat_test())
}
else if(input$mydrop == "bar"){
process_barplot_diagram(input,input$y,dataa,col$col,stat_test())
}
else if(input$mydrop == "violin"){
process_violinplot_diagram(input,input$y,dataa,col$col,stat_test())
}
else if(input$mydrop == "polar"){
process_polar_diagram(input,input$y,dataa,col$col,stat_test())
}
else if(input$mydrop == "coding"){
process_dotplot_diagram(input,input$y,dataa,col$col,stat_test())
}
}
)
observeEvent(input$mol,{
output$plottest2 <- renderPlot({
if(input$mydrop == "box"){
process_boxplot(input, paste("`",input$mol,"`",sep =""),moldataa,col$col,stat_testmol())
}
else if(input$mydrop == "bar"){
process_barplot(input, paste("`",input$mol,"`",sep =""),moldataa,col$col,stat_testmol())
}
else if(input$mydrop == "violin"){
process_violinplot(input,paste("`",input$mol,"`",sep =""),moldataa,col$col,stat_testmol())
}
else if(input$mydrop == "polar"){
process_polarplot(input,paste("`",input$mol,"`",sep =""),moldataa,col$col,stat_testmol())
}
else if(input$mydrop == "coding"){
process_dotplot(input,paste("`",input$mol,"`",sep =""),moldataa,col$col,stat_testmol())
}
})
})
}
}
})
})
graph_json <- reactive({
if (input$pathwaytype == "Global pathway") {
read_graph_json("./pathwaymap/globalpathway.cyjs") %>% gsub("localhost:9000", paste0(host,"/api"), .)
} else if (input$pathwaytype == "Ceramide pathway") {
read_graph_json("./pathwaymap/ceramidepathway.cyjs") %>% gsub("localhost:9000", paste0(host,"/api"), .)
} else if (input$pathwaytype == "Remodeling pathway") {
read_graph_json("./pathwaymap/remodeling.cyjs") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}
})
style_file_path <- "./pathwaymap/nodestyle1.js"
styles_xml_path <- "./pathwaymap/styles.xml"
# CYJSファイルのダウンロード
output$exportCYJS <- downloadHandler(
filename = function() {
paste0(input$pathwaytype, "_", format(Sys.Date(), "%Y%m%d"), ".cyjs")
},
content = function(file) {
writeLines(graph_json, file)
},
contentType = "application/json"
)
# styles.xmlファイルのダウンロード
output$exportStyles <- downloadHandler(
filename = function() {
"styles.xml"
},
content = function(file) {
file.copy(styles_xml_path, file)
},
contentType = "application/xml"
)
#observeEvent(input$sidebarCollapse, {
# toggleClass(id = "content", class = "active")
#})
observeEvent(input$toggle_sidebar, {
shinyjs::runjs("toggleSidebar()")
})
observeEvent(input$actionplottest,{
observeEvent(input$pathway, {
output$graphContainer <- renderUI({
cyjShinyOutput("cyjShinytest", height = "90%", width = "90%")
})
})
output$cyjShinytest <- renderCyjShiny({
#p <- input$pathway
#if (p != 0) {
if (input$pathwaytype == "Global pathway") {
graph_json <<- paste(readLines("./pathwaymap/globalpathway.cyjs"), collapse = "") %>% gsub("localhost:9000", paste0(host,"/api"), .)
} else if (input$pathwaytype == "Ceramide pathway") {
graph_json <<- paste(readLines("./pathwaymap/ceramidepathway.cyjs"), collapse = "") %>% gsub("localhost:9000", paste0(host,"/api"), .)
} else if (input$pathwaytype == "Remodeling pathway") {
graph_json <<- paste(readLines("./pathwaymap/remodeling.cyjs"), collapse = "") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}
test <- fromJSON(graph_json)
test <- as.data.frame(test$elements$nodes)
if (input$viewacyllevel == TRUE) {
cyjShiny(graph_json, layoutName = "preset", styleFile = "./pathwaymap/nodestyle1.js")
} else {
cyjShiny(graph_json, layoutName = "preset", styleFile = "./pathwaymap/nodestyle2.js")
}
# } else {
#}
})
observeEvent(input$getSelectedNodes, ignoreInit=TRUE, {
output$selectedNodesDisplay <- renderText({" "})
getSelectedNodes(session)
})
output$corselect <- renderPlotly({
if(input$pathwaytype == "Global pathway"){
graph_json <<- paste(readLines("./pathwaymap/globalpathway.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}else if(input$pathwaytype == "Ceramide pathway"){
graph_json <<- paste(readLines("./pathwaymap/ceramidepathway.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}else if(input$pathwaytype == "Remodeling pathway"){
graph_json <<- paste(readLines("./pathwaymap/remodeling.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}
test <- fromJSON(graph_json)
test <- as.data.frame(test$elements$nodes)
test1 <- test[test$data$id %in% unlist(input$selectedNodes),]
dataa <- mutate(data, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
if(length(test1$data$shared_name) == 2){
moldataa <- mutate(moldata, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
targetclass <- filter(alitable,Ontology %in% test1$data$shared_name)
if(! test1$data$shared_name[1] %in% colnames(data)) {
a <- Ensembl[Ensembl$target %in% test1$data$Ensembl_ID[1],]
test1$data$shared_name[1] <- a$input
}
if(! test1$data$shared_name[2] %in% colnames(data)) {
b <- Ensembl[Ensembl$target %in% test1$data$Ensembl_ID[2],]
test1$data$shared_name[2] <- b$input
}
if(input$ClassorMol == FALSE){
cor_value <- cor(dataa[,test1$data$shared_name[1]], dataa[,test1$data$shared_name[2]],method = "spearman")
g <- ggplot(dataa,aes_string(test1$data$shared_name[1],test1$data$shared_name[2],fill = input$w,size = input$size))+geom_point(shape =21,color = "black")+
scale_fill_manual(values = unlist(col$col)) + ggtitle(paste("r = ",round(cor_value, 2)))
}else{
moldataa <- mutate(moldata, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
cor_value <- cor(moldataa[,input$X1], moldataa[,input$X2],method = "spearman")
g <- ggplot(moldataa,aes_string(paste("`",input$X1,"`",sep =""),paste("`",input$X2,"`",sep =""),fill = input$w,size = input$size))+geom_point(shape =21,color = "black")+
scale_fill_manual(values = unlist(col$col))+ ggtitle(paste("r = ",round(cor_value, 2)))
}
plotly::ggplotly(g)
}
})
output$textOutput <- renderText({
if(input$ClassorMol == FALSE){
"Select two nodes from the network to analyze their correlation."}
else{
"Select two features to analyze their correlation."
}
})
observeEvent(input$selectedNodes, {
if(input$pathwaytype == "Global pathway"){
graph_json <<- paste(readLines("./pathwaymap/globalpathway.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}else if(input$pathwaytype == "Ceramide pathway"){
graph_json <<- paste(readLines("./pathwaymap/ceramidepathway.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}else if(input$pathwaytype == "Remodeling pathway"){
graph_json <<- paste(readLines("./pathwaymap/remodeling.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}
test <- fromJSON(graph_json)
test <- as.data.frame(test$elements$nodes)
test1 <- test[test$data$id %in% unlist(input$selectedNodes),]
moldataa <- mutate(moldata, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
targetclass <- filter(alitable,Ontology %in% test1$data$shared_name)
shiny::updateSelectInput(session, "selectmol", selected = targetclass$`Metabolite name`[1], choices = targetclass$`Metabolite name`)
},ignoreNULL = TRUE)
output$corselect2 <- renderPlot({
if(input$pathwaytype == "Global pathway"){
graph_json <<- paste(readLines("./pathwaymap/globalpathway.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}else if(input$pathwaytype == "Ceramide pathway"){
graph_json <<- paste(readLines("./pathwaymap/ceramidepathway.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}else if(input$pathwaytype == "Remodeling pathway"){
graph_json <<- paste(readLines("./pathwaymap/remodeling.cyjs"), collapse="") %>% gsub("localhost:9000", paste0(host,"/api"), .)
}
test <- fromJSON(graph_json)
test <- as.data.frame(test$elements$nodes)
test1 <- test[test$data$id %in% unlist(input$selectedNodes),]
moldataa <- mutate(moldata, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
targetclass <- filter(alitable,Ontology %in% test1$data$shared_name)
if(length(test1$data$shared_name) > 0 && input$selectmol != " "){
if(test1$data$shared_name[1] %in% colnames(data)) {
if(input$mydrop == "box"){
g <- process_boxplot_diagram(input,paste("`",input$selectmol,"`",sep =""),moldataa,col$col,stat_testmol())
}
else if(input$mydrop == "bar"){
g <- process_barplot_diagram(input,paste("`",input$selectmol,"`",sep =""),moldataa,col$col,stat_testmol())
}
else if(input$mydrop == "violin"){
g <- process_violinplot_diagram(input,paste("`",input$selectmol,"`",sep =""),moldataa,col$col,stat_testmol())
}
else if(input$mydrop == "polar"){
g <- process_polar_diagram(input,paste("`",input$selectmol,"`",sep =""),moldataa,col$col,stat_testmol())
}
else if(input$mydrop == "coding"){
g <- process_dotplot_diagram(input,paste("`",input$selectmol,"`",sep =""),moldataa,col$col,stat_testmol())
}}
plot(g)
}
})
})
observeEvent(input$save_pdf,{
shinyscreenshot::screenshot(selector="#cyjShinytest")
})
#Creating heatmap
observeEvent(input$actionplottest, {
waiter::waiter_show(
id = NULL,
html = tagList(waiter::spin_loader(),
"Loading ..."),
color = "#333e48",
logo = "",
image = ""
)
file_list <- list.files(svg_path)
if (length(unlist(file_list)) > 0) {
file.remove(file.path(svg_path, file_list))
} else {
}
if(is.null(input$transcriptomefile) == FALSE){
Ensembl <- gconvert(query = colnames(transcriptome)[-c(1:2)] , organism = "mmusculus",#sapiens
target="ENSG", mthreshold = Inf, filter_na = TRUE) %>% select(input,target)
graph_json1 <- paste(readLines("./pathwaymap/ceramidepathway.cyjs"), collapse="") %>% fromJSON()
graph_json2 <- paste(readLines("./pathwaymap/remodeling.cyjs"), collapse="") %>% fromJSON()
Ensemblinmap <- c(graph_json1$elements$nodes$data$Ensembl_ID,graph_json2$elements$nodes$data$Ensembl_ID)
Ensemblinmap <- Ensemblinmap[-which(Ensemblinmap %in% "")]
geneinmap <- Ensembl[Ensembl[,2] %in% Ensemblinmap,]
transcriptome2 <- colnames(transcriptome)[colnames(transcriptome) %in% geneinmap$input]
data <- data[,colnames(data) %in% c(colnames(data)[1:metainfocol],colnames(Lipidomedata),transcriptome2)]
dataa <- mutate(data, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
names(dataa)[match(geneinmap$input, names(dataa))] <- geneinmap$target
} else {
dataa <- mutate(data, !!as.symbol(input$w) := !!as.symbol(input$w) %>% factor(levels = input$levels))
}
# if (length(grep("selectcolor", names(input), value = TRUE)) != 0) {
# col <<- process_select_color_input(input,data)
# }
if(input$mydrop == "box"){
process_action_boxplot(input,dataa,metainfocol,svg_path,col$col,output,data)
}
else if(input$mydrop == "bar"){
process_action_barplot(input,dataa,metainfocol,svg_path,col$col,output,data)
}
else if(input$mydrop == "violin"){
process_action_violinplot(input,dataa,metainfocol,svg_path,col$col,output,data)
}
else if(input$mydrop == "polar"){
process_action_polarplot(input,dataa,metainfocol,svg_path,col$col,output,data)
}
else if(input$mydrop == "coding"){
process_action_dotplot(input,dataa,metainfocol,svg_path,col$col,output,data)
}
# if(input$filetype == "MS-DIAL export"){
# exportgroupnodeheatmap(originaldata,metadata,paste(global$datapath,"",sep =""),input$w,input$levels,originaldir,input)}
Sys.sleep(3)
waiter::waiter_hide()
shinyalert(
"Success",
"GO to Pathway analysis tab",
type = "success"
)
}
)
observeEvent(input$w,{
output$heatmap <- renderPlot({
if(length(unlist(input$selectedNodes)) > 0 ) {
test <- fromJSON(graph_json)
test <- as.data.frame(test$elements$nodes)
test1 <- test[test$data$id %in% unlist(input$selectedNodes),]
groupnodeheatmap(lipidclassproperties,originaldata,metadata,input$w,input$levels,test1$data$shared_name[1],input)
}
})
})
} )})} |