Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Use one function (getOutputFileName) to infer the outputFileName of t…
Browse files Browse the repository at this point in the history
…he process

Plus prepend exceptions with VSN ERROR
  • Loading branch information
dweemx committed Sep 16, 2020
1 parent 6260b79 commit 67b4c92
Showing 1 changed file with 56 additions and 57 deletions.
113 changes: 56 additions & 57 deletions src/utils/processes/utils.nf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def detectCellRangerVersionData = { cellRangerV2Data, cellRangerV3Data ->
if(cellRangerV2Data.exists()) {
// Sanity checks
if(new File(Paths.get(cellRangerV2Data.toString(), "genes.tsv.gz").toString()).exists())
throw new Exception("Found genes.tsv.gz but expecting genes.tsv. The gene file should be uncompressed.")
throw new Exception("VSN ERROR: Found genes.tsv.gz but expecting genes.tsv. The gene file should be uncompressed.")
if(new File(Paths.get(cellRangerV2Data.toString(), "genes.tsv").toString()).exists())
return [
version: 2,
Expand All @@ -26,36 +26,36 @@ def detectCellRangerVersionData = { cellRangerV2Data, cellRangerV3Data ->
// Extract genome folder if a single one exists
genomes = cellRangerV2Data.list()
if(genomes.size() > 1 || genomes.size() == 0)
throw new Exception("None or multiple genomes detected for the output generated by CellRanger v2. Selecting custom genome is currently not implemented.")
throw new Exception("VSN ERROR: None or multiple genomes detected for the output generated by CellRanger v2. Selecting custom genome is currently not implemented.")
genomeFilePath = Paths.get(cellRangerV2Data.toString(), genomes[0])
// Sanity checks
if(!new File(genomeFilePath.toString()).isDirectory())
throw new Exception("Expecting a genome directory from the output generated by CellRanger v2.")
throw new Exception("VSN ERROR: Expecting a genome directory from the output generated by CellRanger v2.")
if(new File(Paths.get(genomeFilePath.toString(), "genes.tsv.gz").toString()).exists())
throw new Exception("Found compressed gene file (genes.tsv.gz) but expecting uncompressed gene file (genes.tsv). Use gunzip for instance to uncompress it.")
throw new Exception("VSN ERROR: Found compressed gene file (genes.tsv.gz) but expecting uncompressed gene file (genes.tsv). Use gunzip for instance to uncompress it.")
if(new File(Paths.get(genomeFilePath.toString(), "barcodes.tsv.gz").toString()).exists())
throw new Exception("Found compressed gene file (barcodes.tsv.gz) but expecting uncompressed gene file (barcodes.tsv). Use gunzip for instance to uncompress it.")
throw new Exception("VSN ERROR: Found compressed gene file (barcodes.tsv.gz) but expecting uncompressed gene file (barcodes.tsv). Use gunzip for instance to uncompress it.")
if(new File(Paths.get(genomeFilePath.toString(), "matrix.mtx.gz").toString()).exists())
throw new Exception("Found compressed gene file (matrix.mtx.gz) but expecting uncompressed gene file (matrix.mtx.gz). Use gunzip for instance to uncompress it.")
throw new Exception("VSN ERROR: Found compressed gene file (matrix.mtx.gz) but expecting uncompressed gene file (matrix.mtx.gz). Use gunzip for instance to uncompress it.")
if(!new File(Paths.get(genomeFilePath.toString(), "genes.tsv").toString()).exists())
throw new Exception("Expecting a gene file genes.tsv file but none are found.")
throw new Exception("VSN ERROR: Expecting a gene file genes.tsv file but none are found.")
if(!new File(Paths.get(genomeFilePath.toString(), "barcodes.tsv").toString()).exists())
throw new Exception("Expecting a barcode file barcodes.tsv file but none are found.")
throw new Exception("VSN ERROR: Expecting a barcode file barcodes.tsv file but none are found.")
if(!new File(Paths.get(genomeFilePath.toString(), "matrix.mtx").toString()).exists())
throw new Exception("Expecting a matrix file matrix.mtx file but none are found.")
throw new Exception("VSN ERROR: Expecting a matrix file matrix.mtx file but none are found.")
return [
version: 2,
path: file(genomeFilePath)
]
} else if(cellRangerV3Data.exists()) {
if(!new File(Paths.get(cellRangerV3Data.toString(), "features.tsv").toString()).exists() && !new File(Paths.get(cellRangerV3Data.toString(), "features.tsv.gz").toString()).exists())
throw new Exception("Expecting either a features.tsv or features.tsv.gz file but none are found.")
throw new Exception("VSN ERROR: Expecting either a features.tsv or features.tsv.gz file but none are found.")
return [
version: 3,
path: cellRangerV3Data
]
} else {
throw new Exception("Cannot detect the version of the data format of CellRanger.")
throw new Exception("VSN ERROR: Cannot detect the version of the data format of CellRanger.")
}
} else {
if(cellRangerV2Data.exists()) {
Expand All @@ -69,7 +69,7 @@ def detectCellRangerVersionData = { cellRangerV2Data, cellRangerV3Data ->
path: cellRangerV3Data
]
} else {
throw new Exception("Cannot detect the version of the data format of CellRanger.")
throw new Exception("VSN ERROR: Cannot detect the version of the data format of CellRanger.")
}
}
}
Expand Down Expand Up @@ -132,27 +132,15 @@ process SC__FILE_CONVERTER {
// Nothing to be done here
break;
case "csv":
// Nothing to be done here
break;

case "tsv":
// Nothing to be done here
break;

case "h5ad":
// Nothing to be done here
break;

case "loom":
// Nothing to be done here
break;

case "seurat_rds":
// Nothing to be done here
break;

default:
throw new Exception("The given input format ${inputDataType} is not recognized.")
throw new Exception("VSN ERROR: The given input format ${inputDataType} is not recognized.")
break;
}

Expand Down Expand Up @@ -255,6 +243,39 @@ process SC__STAR_CONCATENATOR() {

}

def getOutputFileName(params, tag, f, fileOutputSuffix, isParameterExplorationModeOn, stashedParams) {
// - In parameter exploration mode,
// - returns
// - <tag>.<fileOutputSuffix>.<stashedParams>.<f.extension> if fileOutputSuffix is null
// - <tag>.<stashedParams (joined)>.<f.extension> otherwise
// - If not in parameter exporation mode AND
// - If pipelineOutputSuffix exists AND
// - If it is set to 'none'
// - returns:
// - <tag>.<f.extension>
// - <tag>.<pipelineOutputSuffix>.<f.extension>
// - If fileOutputSuffix is null
// - returns:
// - <f.baseName>.<f.extension>
// - In all other cases
// - returns:
// - <f.baseName>.<fileOutputSuffix>.<f.extension>
if(isParameterExplorationModeOn && !isParamNull(stashedParams))
return isParamNull(fileOutputSuffix) ?
"${tag}.${stashedParams.findAll { it != 'NULL' }.join('_')}.${f.extension}" :
"${tag}.${fileOutputSuffix}.${stashedParams.findAll { it != 'NULL' }.join('_')}.${f.extension}"
if(params.utils.containsKey("publish")
&& params.utils.publish.containsKey("pipelineOutputSuffix")) {
if(params.utils.publish.pipelineOutputSuffix == 'none')
return "${tag}.${f.extension}"
if(params.utils.publish.pipelineOutputSuffix.length() == 0)
throw new Exception("VSN ERROR: The parameter 'params.utils.publish.outputFileSuffix' cannot be empty. If you don't want to add a suffix to the final output, please set this param to 'none'.")
return params.utils.publish.pipelineOutputSuffix
}
if(isParamNull(fileOutputSuffix))
return "${f.baseName}.${f.extension}"
return "${tag}.${fileOutputSuffix}.${f.extension}"
}

process SC__PUBLISH {

Expand All @@ -264,16 +285,6 @@ process SC__PUBLISH {
return "${outDir}/data/${toolName.toLowerCase()}"
}

def getOutputFileName = { tag, f, fileOutputSuffix, toolName, isParameterExplorationModeOn, stashedParams ->
if(isParameterExplorationModeOn && !isParamNull(stashedParams))
return isParamNull(fileOutputSuffix) ?
"${tag}.${stashedParams.findAll { it != 'NULL' }.join('_')}.${f.extension}" :
"${tag}.${fileOutputSuffix}.${stashedParams.findAll { it != 'NULL' }.join('_')}.${f.extension}"
if(isParamNull(fileOutputSuffix))
return "${f.baseName}.${f.extension}"
return "${tag}.${fileOutputSuffix}.${f.extension}"
}

clusterOptions "-l nodes=1:ppn=2 -l pmem=3gb -l walltime=1:00:00 -A ${params.global.qsubaccount}"
publishDir \
"${getPublishDir(params.global.outdir,toolName)}", \
Expand All @@ -282,7 +293,6 @@ process SC__PUBLISH {
saveAs: {
filename -> "${outputFileName}"
}


input:
tuple \
Expand All @@ -301,10 +311,10 @@ process SC__PUBLISH {

script:
outputFileName = getOutputFileName(
params,
tag,
f,
fileOutputSuffix,
toolName,
isParameterExplorationModeOn,
stashedParams
)
Expand All @@ -323,18 +333,6 @@ process COMPRESS_HDF5() {
clusterOptions "-l nodes=1:ppn=2 -l pmem=30gb -l walltime=1:00:00 -A ${params.global.qsubaccount}"
publishDir "${params.global.outdir}/data/intermediate", mode: 'symlink', overwrite: true

def getFileOutputSuffix = { params, fileOutputSuffix, toolName ->
if(isParamNull(fileOutputSuffix) && isParamNull(toolName) &&
params.utils.containsKey("publish") && params.utils.publish.containsKey("fileOutputSuffix")) {
if(params.utils.publish.pipelineOutputSuffix.length() == 0)
throw new Exception("The parameter 'params.utils.publish.outputFileSuffix' cannot be empty.")
return params.utils.publish.pipelineOutputSuffix
}
if(isParamNull(fileOutputSuffix) && !isParamNull(toolName))
return null
return fileOutputSuffix
}

input:
tuple \
val(id), \
Expand All @@ -350,18 +348,19 @@ process COMPRESS_HDF5() {
val(stashedParams)

shell:
if(!isParamNull(stashedParams))
uuid = stashedParams.findAll { it != 'NULL' }.join('_')
def _fileOutputSuffix = getFileOutputSuffix(
params,
fileOutputSuffix,
toolName
)
def compressionLevel = params.utils.containsKey("publish") &&
params.utils.publish.containsKey("compressionLevel") ?
params.utils.publish.compressionLevel :
6
outputFileName = "${isParamNull(_fileOutputSuffix) ? f.baseName : _fileOutputSuffix}.${!isParamNull(stashedParams) ? uuid + '.' : ''}${f.extension}"

outputFileName = getOutputFileName(
params,
id,
f,
fileOutputSuffix,
!isParamNull(stashedParams),
stashedParams
)
"""
GZIP_COMPRESSION_LEVEL=${compressionLevel}
mv $f tmp
Expand Down

0 comments on commit 67b4c92

Please sign in to comment.