Skip to content

Commit

Permalink
Merge pull request compbiomed#4 from irzamsarfraz/dir-test2
Browse files Browse the repository at this point in the history
Import updates
  • Loading branch information
irzamsarfraz authored Jul 19, 2023
2 parents 65dd1a3 + e614278 commit 72bef02
Show file tree
Hide file tree
Showing 3 changed files with 829 additions and 19 deletions.
199 changes: 198 additions & 1 deletion R/importMultipleSources.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,229 @@ importMultipleSources <- function(allImportEntries, delayedArray = FALSE) {
delayedArray = delayedArray
)
}
} else if (entry$type == "cellRanger3_files") {

# get current tempDir by shiny
mytempdir <- tempdir(check=TRUE)

if(dir.exists(mytempdir)){
# get uploaded filepaths
matrixFilePath <- entry$params$assayFile
barcodesFilePath <- entry$params$annotFile
featuresFilePath <- entry$params$featureFile
metricsFilePath <- entry$params$summaryFile

# rename to original names
file.rename(matrixFilePath, paste0(dirname(matrixFilePath), "/matrix.mtx.gz"))
file.rename(barcodesFilePath, paste0(dirname(barcodesFilePath), "/barcodes.tsv.gz"))
file.rename(featuresFilePath, paste0(dirname(featuresFilePath), "/features.tsv.gz"))
if(!is.null(metricsFilePath)){
file.rename(metricsFilePath, paste0(dirname(metricsFilePath), "/metrics_summary.csv"))
}

# create a sample folder
dir.create(paste0(mytempdir, "/cellranger/"))
if(!is.null(metricsFilePath)){
dir.create(paste0(mytempdir, "/cellranger/outs"))
}

# move files to this sample folder
file.copy(paste0(dirname(matrixFilePath), "/matrix.mtx.gz"), paste0(mytempdir, "/cellranger/matrix.mtx.gz"))
file.copy(paste0(dirname(barcodesFilePath), "/barcodes.tsv.gz"), paste0(mytempdir, "/cellranger/barcodes.tsv.gz"))
file.copy(paste0(dirname(featuresFilePath), "/features.tsv.gz"), paste0(mytempdir, "/cellranger/features.tsv.gz"))
if(!is.null(metricsFilePath)){
file.copy(paste0(dirname(metricsFilePath), "/metrics_summary.csv"), paste0(mytempdir, "/cellranger/outs/metrics_summary.csv"))
}

# make object
newSce <- importCellRangerV3Sample(dataDir = paste0(mytempdir, "/cellranger/"))

# delete sample folder
unlink(paste0(mytempdir, "/cellranger/"), recursive = TRUE)
}

} else if (entry$type == "starSolo") {
newSce <- importSTARsolo(
STARsoloDirs = entry$params$STARsoloDirs,
samples = entry$params$samples,
STARsoloOuts = entry$params$STARsoloOuts,
delayedArray = delayedArray
)
} else if (entry$type == "starSolo_files") {

# get current tempDir by shiny
mytempdir <- tempdir(check=TRUE)

if(dir.exists(mytempdir)){
# get uploaded filepaths
matrixFilePath <- entry$params$assayFile
barcodesFilePath <- entry$params$annotFile
featuresFilePath <- entry$params$featureFile
# metricsFilePath <- entry$params$summaryFile

# rename to original names
file.rename(matrixFilePath, paste0(dirname(matrixFilePath), "/matrix.mtx"))
file.rename(barcodesFilePath, paste0(dirname(barcodesFilePath), "/barcodes.tsv"))
file.rename(featuresFilePath, paste0(dirname(featuresFilePath), "/features.tsv"))
# if(!is.null(metricsFilePath)){
# file.rename(metricsFilePath, paste0(dirname(metricsFilePath), "/metrics_summary.csv"))
# }

# create a sample folder
dir.create(paste0(mytempdir, "/Solo.out/"))
dir.create(paste0(mytempdir, "/Solo.out/Gene/"))
dir.create(paste0(mytempdir, "/Solo.out/Gene/filtered"))
# if(!is.null(metricsFilePath)){
# dir.create(paste0(mytempdir, "/cellranger/outs"))
# }

# move files to this sample folder
file.copy(paste0(dirname(matrixFilePath), "/matrix.mtx"), paste0(mytempdir, "/Solo.out/Gene/filtered/matrix.mtx"))
file.copy(paste0(dirname(barcodesFilePath), "/barcodes.tsv"), paste0(mytempdir, "/Solo.out/Gene/filtered/barcodes.tsv"))
file.copy(paste0(dirname(featuresFilePath), "/features.tsv"), paste0(mytempdir, "/Solo.out/Gene/filtered/features.tsv"))
# if(!is.null(metricsFilePath)){
# file.copy(paste0(dirname(metricsFilePath), "/metrics_summary.csv"), paste0(mytempdir, "/cellranger/outs/metrics_summary.csv"))
# }

# make object
newSce <- importSTARsolo(STARsoloDirs = paste0(mytempdir, "/Solo.out"), samples = "sample1")

# delete sample folder
unlink(paste0(mytempdir, "/Solo.out/"), recursive = TRUE)

# newSce <- importSTARsolo(
# STARsoloDirs = entry$params$STARsoloDirs,
# samples = entry$params$samples,
# STARsoloOuts = entry$params$STARsoloOuts,
# delayedArray = delayedArray
# )
}
} else if (entry$type == "busTools") {
newSce <- importBUStools(
BUStoolsDirs = entry$params$BUStoolsDirs,
samples = entry$params$samples,
delayedArray = delayedArray
)
} else if (entry$type == "busTools_files") {
# get current tempDir by shiny
mytempdir <- tempdir(check=TRUE)

if(dir.exists(mytempdir)){
# get uploaded filepaths
matrixFilePath <- entry$params$assayFile
barcodesFilePath <- entry$params$annotFile
featuresFilePath <- entry$params$featureFile
# metricsFilePath <- entry$params$summaryFile

# rename to original names
file.rename(matrixFilePath, paste0(dirname(matrixFilePath), "/genes.mtx"))
file.rename(barcodesFilePath, paste0(dirname(barcodesFilePath), "/genes.barcodes.txt"))
file.rename(featuresFilePath, paste0(dirname(featuresFilePath), "/genes.genes.txt"))
# if(!is.null(metricsFilePath)){
# file.rename(metricsFilePath, paste0(dirname(metricsFilePath), "/metrics_summary.csv"))
# }

# create a sample folder
dir.create(paste0(mytempdir, "/bus_output/"))

# move files to this sample folder
file.copy(paste0(dirname(matrixFilePath), "/genes.mtx"), paste0(mytempdir, "/bus_output/genes.mtx"))
file.copy(paste0(dirname(barcodesFilePath), "/genes.barcodes.txt"), paste0(mytempdir, "/bus_output/genes.barcodes.txt"))
file.copy(paste0(dirname(featuresFilePath), "/genes.genes.txt"), paste0(mytempdir, "/bus_output/genes.genes.txt"))

# make object
newSce <- importBUStools(BUStoolsDirs = paste0(mytempdir, "/bus_output"), samples = "sample1")

# delete sample folder
unlink(paste0(mytempdir, "/bus_output/"), recursive = TRUE)
}
} else if (entry$type == "seqc") {
newSce <- importSEQC(
seqcDirs = entry$params$seqcDirs,
samples = entry$params$samples,
prefix = entry$params$prefix,
delayedArray = delayedArray
)
} else if (entry$type == "seqc_files") {
# get current tempDir by shiny
mytempdir <- tempdir(check=TRUE)

if(dir.exists(mytempdir)){
# get uploaded filepaths
readCountsLocation <- entry$params$readCountsLocation
moleculeCountsLocation <- entry$params$moleculeCountsLocation
barcodesLocation <- entry$params$barcodesLocation
genesLocation <- entry$params$genesLocation

# rename to original names
file.rename(readCountsLocation, paste0(dirname(readCountsLocation), "/seqc_sparse_read_counts.mtx"))
file.rename(moleculeCountsLocation, paste0(dirname(moleculeCountsLocation), "/seqc_sparse_molecule_counts.mtx"))
file.rename(barcodesLocation, paste0(dirname(barcodesLocation), "/seqc_sparse_counts_barcodes.csv"))
file.rename(genesLocation, paste0(dirname(genesLocation), "/seqc_sparse_counts_genes.csv"))

# create a sample folder
dir.create(paste0(mytempdir, "/seqc/"))

# move files to this sample folder
file.copy(paste0(dirname(readCountsLocation), "/seqc_sparse_read_counts.mtx"), paste0(mytempdir, "/seqc/seqc_sparse_read_counts.mtx"))
file.copy(paste0(dirname(moleculeCountsLocation), "/seqc_sparse_molecule_counts.mtx"), paste0(mytempdir, "/seqc/seqc_sparse_molecule_counts.mtx"))
file.copy(paste0(dirname(barcodesLocation), "/seqc_sparse_counts_barcodes.csv"), paste0(mytempdir, "/seqc/seqc_sparse_counts_barcodes.csv"))
file.copy(paste0(dirname(genesLocation), "/seqc_sparse_counts_genes.csv"), paste0(mytempdir, "/seqc/seqc_sparse_counts_genes.csv"))

# make object
newSce <- importSEQC(seqcDirs = paste0(mytempdir, "/seqc"), samples = "sample1", prefix = "seqc")

# delete sample folder
unlink(paste0(mytempdir, "/seqc/"), recursive = TRUE)
}
} else if (entry$type == "optimus") {
newSce <- importOptimus(
OptimusDirs = entry$params$OptimusDirs,
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 @@ -99,7 +296,7 @@ importMultipleSources <- function(allImportEntries, delayedArray = FALSE) {
}

# Begin Set Tags
if(entry$type %in% c("cellRanger2", "cellRanger3", "starSolo", "busTools", "seqc", "optimus", "example")){
if(entry$type %in% c("cellRanger2", "cellRanger3", "starSolo", "busTools", "seqc", "optimus", "example", "cellRanger3_files", "starSolo_files", "busTools_files", "optimus_files", "seqc_files")){
newSce <- expSetDataTag(
inSCE = newSce,
assayType = "raw",
Expand Down
Loading

0 comments on commit 72bef02

Please sign in to comment.