|
|
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"
|
|
|
)
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
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."
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
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 = ", "))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if ("metadata" %in% validation_rules && ncol(df) > 34) {
|
|
|
|
|
|
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())
|
|
|
global <- reactiveValues(datapath = getwd())
|
|
|
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",
|
|
|
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$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 "))
|
|
|
)
|
|
|
})
|
|
|
|
|
|
|
|
|
output$comparison_choices <- renderUI({
|
|
|
checkboxGroupInput("comparisons", "Select comparisons:",
|
|
|
choices = possible_comparisons(),
|
|
|
selected = possible_comparisons()[1])
|
|
|
})
|
|
|
|
|
|
|
|
|
observeEvent(input$select_all, {
|
|
|
updateCheckboxGroupInput(session, "comparisons",
|
|
|
selected = possible_comparisons())
|
|
|
})
|
|
|
|
|
|
|
|
|
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
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
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"
|
|
|
)
|
|
|
|
|
|
|
|
|
output$exportStyles <- downloadHandler(
|
|
|
filename = function() {
|
|
|
"styles.xml"
|
|
|
},
|
|
|
content = function(file) {
|
|
|
file.copy(styles_xml_path, file)
|
|
|
},
|
|
|
contentType = "application/xml"
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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({
|
|
|
|
|
|
|
|
|
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")
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
})
|
|
|
|
|
|
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",
|
|
|
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(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)
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
} )})} |