Skip to content

Commit

Permalink
Updates to data import
Browse files Browse the repository at this point in the history
  • Loading branch information
irzamsarfraz authored and liuming1997 committed Jul 19, 2023
1 parent 81f85e3 commit cc94451
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 11 deletions.
46 changes: 44 additions & 2 deletions R/importMultipleSources.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ importMultipleSources <- function(allImportEntries, delayedArray = FALSE) {

# delete sample folder
unlink(paste0(mytempdir, "/bus_output/"), recursive = TRUE)
}
} else if (entry$type == "seqc") {
newSce <- importSEQC(
seqcDirs = entry$params$seqcDirs,
Expand All @@ -190,6 +190,48 @@ importMultipleSources <- function(allImportEntries, delayedArray = FALSE) {
samples = entry$params$samples,
delayedArray = delayedArray
)
} else if (entry$type == "optimus_files") {
# get current tempDir by shiny
mytempdir <- tempdir(check=TRUE)

if(dir.exists(mytempdir)){
# get uploaded filepaths
matrixLocation <- entry$params$matrixLocation
colIndexLocation <- entry$params$colIndexLocation
rowIndexLocation <- entry$params$rowIndexLocation
cellMetricsLocation <- entry$params$cellMetricsLocation
geneMetricsLocation <- entry$params$geneMetricsLocation
emptyDropsLocation <- entry$params$emptyDropsLocation

# rename to original names
file.rename(matrixLocation, paste0(dirname(matrixLocation), "/sparse_counts.npz"))
file.rename(colIndexLocation, paste0(dirname(colIndexLocation), "/sparse_counts_col_index.npy"))
file.rename(rowIndexLocation, paste0(dirname(rowIndexLocation), "/sparse_counts_row_index.npy"))
file.rename(cellMetricsLocation, paste0(dirname(cellMetricsLocation), "/merged-cell-metrics.csv.gz"))
file.rename(geneMetricsLocation, paste0(dirname(geneMetricsLocation), "/merged-gene-metrics.csv.gz"))
file.rename(emptyDropsLocation, paste0(dirname(emptyDropsLocation), "/empty_drops_result.csv"))

# create a sample folder
dir.create(paste0(mytempdir, "/optimus/"))
dir.create(paste0(mytempdir, "/optimus/call-MergeCountFiles/"))
dir.create(paste0(mytempdir, "/optimus/call-MergeCellMetrics/"))
dir.create(paste0(mytempdir, "/optimus/call-MergeGeneMetrics/"))
dir.create(paste0(mytempdir, "/optimus/call-RunEmptyDrops/"))

# move files to this sample folder
file.copy(paste0(dirname(matrixLocation), "/sparse_counts.npz"), paste0(mytempdir, "/optimus/call-MergeCountFiles/sparse_counts.npz"))
file.copy(paste0(dirname(colIndexLocation), "/sparse_counts_col_index.npy"), paste0(mytempdir, "/optimus/call-MergeCountFiles/sparse_counts_col_index.npy"))
file.copy(paste0(dirname(rowIndexLocation), "/sparse_counts_row_index.npy"), paste0(mytempdir, "/optimus/call-MergeCountFiles/sparse_counts_row_index.npy"))
file.copy(paste0(dirname(cellMetricsLocation), "/merged-cell-metrics.csv.gz"), paste0(mytempdir, "/optimus/call-MergeCellMetrics/merged-cell-metrics.csv.gz"))
file.copy(paste0(dirname(geneMetricsLocation), "/merged-gene-metrics.csv.gz"), paste0(mytempdir, "/optimus/call-MergeGeneMetrics/merged-gene-metrics.csv.gz"))
file.copy(paste0(dirname(emptyDropsLocation), "/empty_drops_result.csv"), paste0(mytempdir, "/optimus/call-RunEmptyDrops/empty_drops_result.csv"))

# make object
newSce <- importOptimus(OptimusDirs = paste0(mytempdir, "/optimus"), samples = "sample1")

# delete sample folder
unlink(paste0(mytempdir, "/optimus/"), recursive = TRUE)
}
} else if (entry$type == "files") {
newSce <- importFromFiles(assayFile = entry$params$assayFile,
annotFile = entry$params$annotFile,
Expand Down Expand Up @@ -222,7 +264,7 @@ importMultipleSources <- function(allImportEntries, delayedArray = FALSE) {
}

# Begin Set Tags
if(entry$type %in% c("cellRanger2", "cellRanger3", "starSolo", "busTools", "seqc", "optimus", "example", "cellRanger3_files", "starSolo_files", "busTools_files")){
if(entry$type %in% c("cellRanger2", "cellRanger3", "starSolo", "busTools", "seqc", "optimus", "example", "cellRanger3_files", "starSolo_files", "busTools_files", "optimus_files")){
newSce <- expSetDataTag(
inSCE = newSce,
assayType = "raw",
Expand Down
111 changes: 109 additions & 2 deletions inst/shiny/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -967,10 +967,10 @@ shinyServer(function(input, output, session) {
if (!is.null(input$countsfile_custom_starSolo$datapath)) {
assayFileCol <- paste0("Assay: ", input$countsfile_custom_starSolo$datapath)
}
if (!is.null(input$annotFile_custom$datapath)) {
if (!is.null(input$annotFile_custom_starSolo$datapath)) {
annotFileCol <- paste0("Annotation: ", input$annotFile_custom_starSolo$datapath)
}
if (!is.null(input$featureFile_custom$datapath)) {
if (!is.null(input$featureFile_custom_starSolo$datapath)) {
featureFileCol <- paste0("Features: ", input$featureFile_custom_starSolo$datapath)
}

Expand All @@ -996,6 +996,113 @@ shinyServer(function(input, output, session) {
style = list("1. Add sample to import:" = "success"))

})

# Event handler to import a file input from busTools
observeEvent(input$addFilesImport_custom_busTools, {
id <- paste0("newSampleFiles", allImportEntries$id_count)
entry <- list(type="busTools_files", id = id, params=list(assayFile = input$countsfile_custom_busTools$datapath, annotFile = input$annotFile_custom_busTools$datapath,
featureFile = input$featureFile_custom_busTools$datapath,
assayName = "counts"))
allImportEntries$samples <- c(allImportEntries$samples, list(entry))
allImportEntries$id_count <- allImportEntries$id_count+1
assayFileCol <- ""
annotFileCol <- ""
featureFileCol <- ""
summaryFileCol <- ""
if (!is.null(input$countsfile_custom_busTools$datapath)) {
assayFileCol <- paste0("Assay: ", input$countsfile_custom_busTools$datapath)
}
if (!is.null(input$annotFile_custom_busTools$datapath)) {
annotFileCol <- paste0("Annotation: ", input$annotFile_custom_busTools$datapath)
}
if (!is.null(input$featureFile_custom_busTools$datapath)) {
featureFileCol <- paste0("Features: ", input$featureFile_custom_busTools$datapath)
}

locCol <- paste(c(assayFileCol, annotFileCol, featureFileCol, summaryFileCol), collapse = "\n")

addToGeneralSampleTable("files", id, locCol, "counts")

observeEvent(input[[paste0("remove", id)]],{
removeUI(
selector = paste0("#", id)
)
toRemove <- vector()
for (entry in allImportEntries$samples) {
if (entry$id == id) {
toRemove <- c(toRemove, FALSE)
} else {
toRemove <- c(toRemove, TRUE)
}
}
allImportEntries$samples <- allImportEntries$samples[toRemove]
})
updateCollapse(session = session, "importUI", open = "2. Create dataset:",
style = list("1. Add sample to import:" = "success"))

})

# Event handler to import a file input from optimus
observeEvent(input$addFilesImport_custom_optimus, {
id <- paste0("newSampleFiles", allImportEntries$id_count)
entry <- list(type="optimus_files", id = id, params=list(matrixLocation = input$matrix_custom_optimus$datapath,
colIndexLocation = input$colIndex_custom_optimus$datapath,
rowIndexLocation = input$rowIndex_custom_optimus$datapath,
cellMetricsLocation = input$cellMetrics_custom_optimus$datapath,
geneMetricsLocation = input$geneMetrics_custom_optimus$datapath,
emptyDropsLocation = input$emptyDrops_custom_optimus$datapath,
assayName = "counts"))
allImportEntries$samples <- c(allImportEntries$samples, list(entry))
allImportEntries$id_count <- allImportEntries$id_count+1
matrixFileCol <- ""
colIndexFileCol <- ""
rowIndexFileCol <- ""
cellMetricsFileCol <- ""
geneMetricsFileCol <- ""
emptyDropsFileCol <- ""

if (!is.null(input$matrix_custom_optimus$datapath)) {
matrixFileCol <- paste0("Matrix: ", input$matrix_custom_optimus$datapath)
}
if (!is.null(input$colIndex_custom_optimus$datapath)) {
colIndexFileCol <- paste0("colIndex: ", input$colIndex_custom_optimus$datapath)
}
if (!is.null(input$rowIndex_custom_optimus$datapath)) {
rowIndexFileCol <- paste0("rowIndex: ", input$rowIndex_custom_optimus$datapath)
}
if (!is.null(input$cellMetrics_custom_optimus$datapath)) {
cellMetricsFileCol <- paste0("cellMetrics: ", input$cellMetrics_custom_optimus$datapath)
}
if (!is.null(input$geneMetrics_custom_optimus$datapath)) {
geneMetricsFileCol <- paste0("geneMetrics: ", input$geneMetrics_custom_optimus$datapath)
}
if (!is.null(input$emptyDrops_custom_optimus$datapath)) {
emptyDropsFileCol <- paste0("emptyDrops: ", input$emptyDrops_custom_optimus$datapath)
}


locCol <- paste(c(matrixFileCol, colIndexFileCol, rowIndexFileCol, cellMetricsFileCol, geneMetricsFileCol, emptyDropsFileCol), collapse = "\n")

addToGeneralSampleTable("files", id, locCol, "counts")

observeEvent(input[[paste0("remove", id)]],{
removeUI(
selector = paste0("#", id)
)
toRemove <- vector()
for (entry in allImportEntries$samples) {
if (entry$id == id) {
toRemove <- c(toRemove, FALSE)
} else {
toRemove <- c(toRemove, TRUE)
}
}
allImportEntries$samples <- allImportEntries$samples[toRemove]
})
updateCollapse(session = session, "importUI", open = "2. Create dataset:",
style = list("1. Add sample to import:" = "success"))

})

# Event handler to import a file input
observeEvent(input$addFilesImport, {
Expand Down
176 changes: 169 additions & 7 deletions inst/shiny/ui_01_import.R
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,181 @@ shinyPanelImport <- fluidPage(
actionButton("addFilesImport_custom_starSolo", "Add to dataset list")
#actionButton("addCR3Sample", "Add a sample"),
),
# conditionalPanel(
# condition = sprintf("input['%s'] == 'busTools'", "uploadChoice"),
# wellPanel(
# h5("Please select your /genecount directory as your base directory.")
# ),
# actionButton("addBUSSample", "Add a sample"),
# ),
conditionalPanel(
condition = sprintf("input['%s'] == 'busTools'", "uploadChoice"),
wellPanel(
h5("Please select your /genecount directory as your base directory.")
h4("Upload data for BUSTools:"),
h5("Select matrix, barcodes and feature files for all samples using the file selectors below:"),
fluidRow(
column(width = 4,
wellPanel(
h5("Matrix (matrix.mtx) file:"),
tags$a(href = "https://drive.google.com/open?id=1n0CtM6phfkWX0O6xRtgPPg6QuPFP6pY8",
"Download an example matrix.mtx file here.", target = "_blank"),
tags$br(),
fileInput(
"countsfile_custom_busTools", "Matrix files:",
accept = c(
"text/csv", "text/comma-separated-values", ".mtx",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
),
column(width = 4,
wellPanel(
h5("Barcodes (barcodes.tsv) file:"),
tags$a(href = "https://drive.google.com/open?id=10IDmZQUiASN4wnzO4-WRJQopKvxCNu6J",
"Download an example barcodes.tsv file here.", target = "_blank"),
tags$br(),
fileInput(
"annotFile_custom_busTools", "Barcodes files:",
accept = c(
"text/csv", "text/comma-separated-values",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
),
column(width = 4,
wellPanel(
h5("Features (features.tsv) file:"),
tags$a(href = "https://drive.google.com/open?id=1gxXaZPq5Wrn2lNHacEVaCN2a_FHNvs4O",
"Download an example features.tsv file here.", target = "_blank"),
tags$br(),
fileInput(
"featureFile_custom_busTools", "Features files:",
accept = c(
"text/csv", "text/comma-separated-values",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
)
),
actionButton("addBUSSample", "Add a sample"),
actionButton("addFilesImport_custom_busTools", "Add to dataset list")
#actionButton("addCR3Sample", "Add a sample"),
),
# conditionalPanel(
# condition = sprintf("input['%s'] == 'seqc'", "uploadChoice"),
# wellPanel(
# h5("Please select the directory that contains your sample files as your base directory.")
# ),
# actionButton("addSEQSample", "Add a sample"),
# ),
conditionalPanel(
condition = sprintf("input['%s'] == 'seqc'", "uploadChoice"),
wellPanel(
h5("Please select the directory that contains your sample files as your base directory.")
condition = sprintf("input['%s'] == 'optimus'", "uploadChoice"),
h4("Upload data for Optimus:"),
h5("Select matrix, barcodes and feature files for all samples using the file selectors below:"),
fluidRow(
column(width = 4,
wellPanel(
h5("Matrix (matrix.mtx) file:"),
tags$a(href = "https://drive.google.com/open?id=1n0CtM6phfkWX0O6xRtgPPg6QuPFP6pY8",
"Download an example matrix.mtx file here.", target = "_blank"),
tags$br(),
fileInput(
"matrix_custom_optimus", "Matrix files:",
accept = c(
"text/csv", "text/comma-separated-values", ".mtx", ".npz",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
),
column(width = 4,
wellPanel(
h5("colIndex file:"),
tags$a(href = "https://drive.google.com/open?id=10IDmZQUiASN4wnzO4-WRJQopKvxCNu6J",
"Download an example barcodes.tsv file here.", target = "_blank"),
tags$br(),
fileInput(
"colIndex_custom_optimus", "colIndex files:",
accept = c(
"text/csv", "text/comma-separated-values", ".npy",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
),
column(width = 4,
wellPanel(
h5("rowIndex file:"),
tags$a(href = "https://drive.google.com/open?id=1gxXaZPq5Wrn2lNHacEVaCN2a_FHNvs4O",
"Download an example features.tsv file here.", target = "_blank"),
tags$br(),
fileInput(
"rowIndex_custom_optimus", "rowIndex files:",
accept = c(
"text/csv", "text/comma-separated-values", ".npy",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
),
column(width = 4,
wellPanel(
h5("cellMetrics file:"),
tags$a(href = "https://drive.google.com/open?id=1gxXaZPq5Wrn2lNHacEVaCN2a_FHNvs4O",
"Download an example features.tsv file here.", target = "_blank"),
tags$br(),
fileInput(
"cellMetrics_custom_optimus", "cellMetrics files:",
accept = c(
"text/csv", "text/comma-separated-values",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
),
column(width = 4,
wellPanel(
h5("geneMetrics file:"),
tags$a(href = "https://drive.google.com/open?id=1gxXaZPq5Wrn2lNHacEVaCN2a_FHNvs4O",
"Download an example features.tsv file here.", target = "_blank"),
tags$br(),
fileInput(
"geneMetrics_custom_optimus", "geneMetrics files:",
accept = c(
"text/csv", "text/comma-separated-values",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
),
column(width = 4,
wellPanel(
h5("emptyDrops file:"),
tags$a(href = "https://drive.google.com/open?id=1gxXaZPq5Wrn2lNHacEVaCN2a_FHNvs4O",
"Download an example features.tsv file here.", target = "_blank"),
tags$br(),
fileInput(
"emptyDrops_custom_optimus", "emptyDrops files:",
accept = c(
"text/csv", "text/comma-separated-values",
"text/tab-separated-values", "text/plain", ".csv", ".tsv", ".gz"
),
multiple = TRUE
)
)
)
),
actionButton("addSEQSample", "Add a sample"),
actionButton("addFilesImport_custom_optimus", "Add to dataset list")
#actionButton("addCR3Sample", "Add a sample"),
),
conditionalPanel(
condition = sprintf("input['%s'] == 'optimus'", "uploadChoice"),
Expand Down

0 comments on commit cc94451

Please sign in to comment.