resetUploadedTable = reactive(
{
input$usePathways
print("reset uploaded omics table")
originalOmicsTable(data.frame())
uploadedMappingTable(data.frame())
omicsGlyphIdTable(data.frame())
originalOmicsTitleText("")
uploadedMappingTitleText("")
GlyphIdOmicsTitleText("")
if(input$usePathways %in% c("UsePrePathways","enrichAnalysis")){
uploadedMappingTitleText("Using pre-collected pathways. Mapping table is selected internally.")
}else if(input$usePathways == 'userSBGN'){
uploadedMappingTitleText("Using uploaded SBGN-ML. Please upload a mapping table.")
}
return(NULL)
}
)
originalOmicsTitleText = reactiveVal("")
output$originalOmicsTitle = renderText({
originalOmicsTitleText()
})
originalOmicsTable = reactiveVal(data.frame())
output$OriginalOmics <- DT::renderDataTable({
originalOmicsTable()
})
output$RunLoadOriginalTable = renderText({
loadOriginalTable()
})
output$RunLoadMappingTable = renderText({
loadMappingTable()
})
output$RunGenGlyphIdTable = renderText({
OmicsDataGlyphID()
})
output$RunResetOriginalTable = renderText({
resetUploadedTable()
})
# input$file1 will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
loadOriginalTable = reactive({
req(input$file1)
# originalOmicsTitleText("Omics data with original molecule IDs")
originalOmicsTitleText("")
# when reading semicolon separated files,
# having a comma separator causes `read.csv` to error
tryCatch(
{
df <- read.table(input$file1$datapath,
header = input$header,
sep = input$sep,
as.is = TRUE,
quote = input$quote)
},
error = function(e) {
# return a safeError if a parsing error occurs
stop(safeError(e))
}
)
print(head(df))
originalOmicsTable(df)
return("")
# if(input$disp == "head") {
# return(head(df))
# }
# else {
# return(df)
# }
})
GlyphIdOmicsTitleText = reactiveVal("")
output$GlyphIdOmicsTitle = renderText({
GlyphIdOmicsTitleText()
})
omicsGlyphIdTable = reactiveVal(data.frame())
output$GlyphIdOmics <- DT::renderDataTable({
# df = OmicsDataGlyphID()
# return(df)
omicsGlyphIdTable()
})
SBGN.glyph.id.type = reactiveVal("")
OmicsDataGlyphID = eventReactive(
input$uploadOmics
,{
# GlyphIdOmicsTitleText("Omics data with SBGN-ML file glyph IDs: Please select the correct parameters on the left panel: 'Omics molecule ID type', 'species' and 'How to map Omics ID to SBGN glyph ID'")
GlyphIdOmicsTitleText("")
df <- read.table(input$file1$datapath,
header = input$header,
sep = input$sep,
as.is = TRUE,
quote = input$quote)
cat("\n\n\n uploaded mapping data is\n\n")
print(head(mapping.data()))
cat("\n\n\n")
input.type = input$OmicsIdType
input.org = input$org
# if(input$IdMappingSource == "useUserMapping" & ncol(mapping.data())>1){
if(input$usePathways == 'userSBGN'){
cat("\n\n\n using user mapping table to change id \n\n")
output.type = input$uploadedSbgnGlyphIdType
print(input.type)
print(output.type)
if(!all(c(input.type,output.type) %in% colnames(mapping.data()))){
stop("\n ID mapping table's column names don't match selected 'Omics ID type' and 'SBGN-ML glyph ID types'!\n\n"
,"Your inputs are: \n"
,"SBGN-ML glyph ID type: ", output.type,"\n "
,"Omics molecule ID type: ", input.type,"\n\n"
,"column names of uploaded mapping table are: \n"
,paste(colnames(mapping.data())
,collapse = " "),"\n\n"
,"If you don't have an ID mapping table for this ID type pair
and if you are using our precollected SBGN-ML file,
try to select 'use SBGNview mapping' as 'How to map Omics ID to SBGN glyph ID'."
)
}
# input.type = input$inputIdUser
# input.org = input$orgUser
print(head(mapping.data()))
id.mapping.table = mapping.data()[,c(input.type,output.type)]
print(head(id.mapping.table))
cat("\n\n\n\n printed user mapping parameters \n\n")
}else if(input$usePathways %in% c("UsePrePathways","enrichAnalysis")){
cat("\n\n\n changing to pathway commons \n\n")
# input.type = input$OmicsIdType
output.type = "pathwayCommons"
id.mapping.table = NULL
}
gene.data <- change.data.id(
data.input.id = df,
# input.type = input$OmicsIdType,
# output.type = "pathwayCommons",
input.type = input.type,
output.type = output.type,
cpd.or.gene = "gene",
org = input.org,
sum.method = "sum"
,id.mapping.table = id.mapping.table
)
SBGN.glyph.id.type(output.type)
print("converted omics data id to glyph id")
omicsGlyphIdTable(gene.data)
return(
""
)
}
)
# Code to download example data
output$Example <- downloadHandler(
filename = function() {
# downloadNameVector[input$preData]
"test out"
},
content = function(file) {
# file.copy(input$preData, file)
# if(input$preData == "userSBGN"){
if(input$usePathways == 'userSBGN'){
data("gse16873.d")
out.data = gse16873.d[,1:3]
# }else if(input$preData == "IFNg"){
}else if(input$usePathways %in% c("UsePrePathways","enrichAnalysis")){
print("using sbgnhub")
count.data <- assays(IFNg)$counts
wt <- colnames(IFNg)[IFNg$group == "wt"]
ko <- colnames(IFNg)[IFNg$group == "ko"]
mean.wt <- apply(count.data[,wt] ,1 ,"mean")
head(mean.wt)
mean.ko <- apply(count.data[,ko],1,"mean")
head(mean.ko)
ensemble.to.koVsWt <- mean.ko - mean.wt
out.data = ensemble.to.koVsWt
out.data = as.matrix(ensemble.to.koVsWt)
colnames(out.data) = "Fold Change: IFNg-KO v.s. WT"
}
write.table(out.data, file = file,sep="\t")
}
)
DemoOmicsDataTitleText = reactiveVal("")
output$DemoOmicsDataTitle = renderText({
DemoOmicsDataTitleText()
})
output$demoDataTable <- DT::renderDataTable({
# if(input$preData == "cancer"){
if(input$usePathways == 'userSBGN'){
data("gse16873.d")
out.data = gse16873.d[,1:3]
DemoOmicsDataTitleText("Demo Omics Data: breast cancer dataset")
# }else if(input$preData == "IFNg"){
}else if(input$usePathways %in% c("UsePrePathways","enrichAnalysis")){
count.data <- assays(IFNg)$counts
wt <- colnames(IFNg)[IFNg$group == "wt"]
ko <- colnames(IFNg)[IFNg$group == "ko"]
mean.wt <- apply(count.data[,wt] ,1 ,"mean")
head(mean.wt)
mean.ko <- apply(count.data[,ko],1,"mean")
head(mean.ko)
ensemble.to.koVsWt <- mean.ko - mean.wt
out.data = as.matrix(ensemble.to.koVsWt)
colnames(out.data) = "Fold Change: IFNg-KO v.s. WT"
DemoOmicsDataTitleText("Demo Omics Data: IFNg KO mice dataset")
}
return(out.data)
})
mapping.data = reactiveVal(matrix())
uploadedMappingTitleText = reactiveVal("")
output$uploadedMappingTitle = renderText({
uploadedMappingTitleText()
})
loadedIdPair = reactiveVal("")
output$loadedMappingPairs <- renderText({
loadedIdPair()
})
uploadedMappingTable = reactiveVal(data.frame())
output$uploadedMapping <- DT::renderDataTable({
uploadedMappingTable()
})
loadMappingTable = reactive({
# or all rows if selected, will be shown.
req(input$uploadMapping)
# uploadedMappingTitleText("Uploaded ID mapping table")
uploadedMappingTitleText("")
# when reading semicolon separated files,
# having a comma separator causes `read.csv` to error
tryCatch(
{
df <- read.table(input$uploadMapping$datapath,
header = input$headerMapping,
sep = input$sepMapping,
as.is = TRUE,
quote = input$quoteMapping)
},
error = function(e) {
# return a safeError if a parsing error occurs
stop(safeError(e))
}
)
loadedIdPair(paste0("An ID mapping table has been uploaded: \n\n"
,paste(colnames(df),collapse = "<->")
)
)
mapping.data(df)
uploadedMappingTable(df)
# uploadedMappingTitleText("")
return("")
# return(df)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.