Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data upload metadatasheet #143

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions program/shinyApp/R/fun_readInSampleTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Search for sample_section save row number
# read in again and skip first row number lines
fun_readInSampleTable <- function(dataFileName){
my_data_tmp <- as.data.frame(read_excel(dataFileName,sheet="Input"))
RowsToSkip <- which(my_data_tmp[,1]%in%"Sample-section")+1
my_data_tmp <- as.data.frame(read_excel(dataFileName,sheet="Input",skip = RowsToSkip))
my_data_tmp <- as.data.frame(readxl::read_excel(dataFileName,sheet="Input"))
RowsToSkip <- which(my_data_tmp[,1]%in%"Sample-Section")+1

my_data_tmp <- as.data.frame(readxl::read_excel(dataFileName,sheet="Input",skip = RowsToSkip))

# Advance: check if subsample etc are present
# for now remove any non complete rows
Expand All @@ -16,6 +17,8 @@ fun_readInSampleTable <- function(dataFileName){
colnames(my_data_tmp) <- my_data_tmp[1,]
my_data_tmp <- as.data.frame(my_data_tmp[-1,])

my_data_tmp <- my_data_tmp[!is.na(my_data_tmp$global_ID),]

return(my_data_tmp)
}

Expand Down
63 changes: 48 additions & 15 deletions program/shinyApp/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,44 @@ server <- function(input,output,session){
req(F)
}
if(!(isTruthy(input$data_matrix1) &
isTruthy(input$data_sample_anno1) &
(isTruthy(input$data_sample_anno1)|isTruthy(input$metadataInput)) &
isTruthy(input$data_row_anno1))){
output$DataMatrix_VI_Info=renderText(
"The Upload has failed completely, or you haven't uploaded anything yet. Need to uploade all three matrices!"
)
}else{
Matrix <- read_file(input$data_matrix1$datapath, check.names=T)
Matrix2 <- read_file(input$data_matrix1$datapath, check.names=F)
flag_csv <- F
tryCatch(
expr = {
Matrix <- read_file(input$data_matrix1$datapath, check.names=T)
Matrix2 <- read_file(input$data_matrix1$datapath, check.names=F)
flag_csv <- T
},
error = function(cond){
print("Not a real csv file!")
}
)
if(!flag_csv){
Matrix <- read.table(input$data_matrix1$datapath,check.names = T)
Matrix2 <- read.table(input$data_matrix1$datapath, check.names = F)
}else{
Matrix <- read_file(input$data_matrix1$datapath, check.names=T)
Matrix2 <- read_file(input$data_matrix1$datapath, check.names=F)
}


output$DataMatrix_VI <- DT::renderDataTable({
DT::datatable(data = Matrix)
})
output$DataMatrix_VI_INFO <- renderText({"Matrix:"})
sample_table <- read_file(input$data_sample_anno1$datapath, check.names=T)
if(isTruthy(input$data_sample_anno1)){
sample_table <- read_file(input$data_sample_anno1$datapath, check.names=T)
}else if(isTruthy(input$metadataInput)){
sample_table <- fun_readInSampleTable(input$metadataInput$datapath)
}else{
sample_table <- data.frame()
}

output$SampleMatrix_VI <- DT::renderDataTable({
DT::datatable(data = sample_table)
})
Expand All @@ -252,6 +277,7 @@ server <- function(input,output,session){
"
})

check0 <- ifelse(flag_csv,snippetYes,snippetNo)
check1 <- ifelse(all(rownames(Matrix) == rownames(annotation_rows)),snippetYes,snippetNo)
check2 <- ifelse(all(colnames(Matrix) == rownames(sample_table)),snippetYes,snippetNo)
check3 <- ifelse(any(is.na(Matrix) == T),snippetNo,snippetYes)
Expand Down Expand Up @@ -281,6 +307,10 @@ server <- function(input,output,session){
}
output$OverallChecks <- renderText({
paste0("Some overall Checks are running run ...\n
Data Matrix is a real csv (has ',' as separators:): ",check0,"\n
Most likely: You had a xlsx and exported to csv but your excel is in german
and / or you use ',' as separators for decimal positions.
Fix: change your decimal separator in Excel and re-export!
Rownames of Matrix are the same as rownames of entitie table ",check1,"\n
Colnames of Matrix are same as rownames of sample table ",check2," \n
Matrix has no na ",check3,"\n
Expand Down Expand Up @@ -339,6 +369,7 @@ server <- function(input,output,session){

## create data object ----
data_input_shiny <- eventReactive(input$refresh1,{
browser()
if(!isTruthy(input$data_preDone) & !FLAG_TEST_DATA_SELECTED()){
# Include here, that the sample anno can be replaced by metadatasheet
# potentially this will be extended to all of the fields
Expand All @@ -360,16 +391,15 @@ server <- function(input,output,session){
}

}else if(isTruthy(input$metadataInput)){

tmp_sampleTable <- fun_readInSampleTable(input$metadataInput$datapath)

tryCatch(
test_data_upload <- function(){
tryCatch(
{
data_input <- list(
type = as.character(input$omicType),
Matrix = read_file(
input$data_matrix1$datapath, check.names=T
)[,rownames(my_data_tmp)],
)[,rownames(tmp_sampleTable)],
sample_table = tmp_sampleTable,
annotation_rows = read_file(input$data_row_anno1$datapath, check.names=T)
)
Expand All @@ -384,9 +414,12 @@ server <- function(input,output,session){
return(NULL)
}
)
}
data_input <- test_data_upload()
}

## TODO Include here possible Data Checks

}else if(FLAG_TEST_DATA_SELECTED() & !isTruthy(input$data_preDone)){
#TODO change test data to also not rely on 'Transcriptomics'

Expand All @@ -397,11 +430,10 @@ server <- function(input,output,session){
fun_LogIt(
message = paste0("**DataInput** - Test Data set used")
)
}else{

uploadedFile <- readRDS(

file = input$data_preDone$datapath

}else{
uploadedFile <- readRDS(
file = input$data_preDone$datapath
)

if(any(names(uploadedFile)%in% input$omicType)){
Expand All @@ -412,7 +444,6 @@ server <- function(input,output,session){
}

}

### Added here gene annotation if asked for
if(input$AddGeneSymbols &
input$omicType == "Transcriptomics"){
Expand Down Expand Up @@ -445,11 +476,12 @@ server <- function(input,output,session){
## Lets Make a SummarizedExperiment Object for reproducibility and further usage
data_input[[paste0(input$omicType,"_SumExp")]]=
SummarizedExperiment(assays = list(raw = data_input$Matrix),
rowData = data_input$annotation_rows[rownames(data_input$Matrix),],
rowData = data_input$annotation_rows[rownames(data_input$Matrix),,drop=F],
colData = data_input$sample_table
)
#TODO make the copy and tab show process dependent if we get here a results object or 'simple' rds
}
browser()
# TODO SumExp only needed hence more restructuring needed
res_tmp[['data_original']] <<- data_input[[paste0(input$omicType,"_SumExp")]]
# Make a copy, to leave original data untouched
Expand Down Expand Up @@ -498,6 +530,7 @@ server <- function(input,output,session){
isTruthy(res_tmp$data)
# Row
output$providedRowAnnotationTypes_ui=renderUI({
browser()
req(data_input_shiny())
shinyWidgets::virtualSelectInput(
inputId = "providedRowAnnotationTypes",
Expand Down
1 change: 1 addition & 0 deletions program/shinyApp/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ library(shinyalert)
library(msigdbr)
library(tidyr)
library(kableExtra)
library(readxl)
# library(svglite)

source("R/C.R")
Expand Down
Loading