Hello, I have question about reusing expressions. I’d like to write a CommandLineTool for a tool that produces different output files with a certain prefix in their path. That prefix is generated by the tool from an input file’s base name like so:
SRR1659960_minimal_R1.fastq.gz
SRR1659960_minimal_R2.fastq.gz >> SRR1659960_minimal
SRR1659960_minimal_R1.fastq.gz
SRR1659960_maximal_R2.fastq.gz >> SRR1659960_maximal
At the moment, I try to bind these output files by a glob using a JS expression that mimics the generation of the prefix to generate it myself and add a suffix.
This leads to several repetitions of the prefix generation code as I couldn’t find any other way.
cwlVersion: 'v1.2'
class: 'CommandLineTool'
label: 'Tool'
$namespaces:
edam: 'http://edamontology.org/'
$schemas:
- 'EDAM_1.25.owl'
requirements:
- class: 'InlineJavascriptRequirement'
- class: 'DockerRequirement'
dockerPull: 'path_to_image'
baseCommand: ['tool']
inputs:
- id: "input_reads_r1"
type: 'File'
format: 'edam:format_1930' # FASTQ
inputBinding:
prefix: '--input-reads-r1'
position: 100
label: 'Input reads file R1 (forward)'
doc: >-
Path to R1 (i.e. forward/left) reads file in gzipped fastq format.
- id: "input_reads_r2"
type: 'File'
format: 'edam:format_1930' # FASTQ
inputBinding:
prefix: '--input-reads-r2'
position: 101
label: 'Input reads file R2 (reverse)'
doc: >-
Path to R2 (i.e. reverse/right) reads file in gzipped fastq format.
####################################################################################################
arguments:
- prefix: "--output-dir"
position: 600
separate: true
valueFrom: |
${
// obtain the common prefix of the input files for output directory naming
var r1=inputs.input_reads_r1.nameroot;
var r2=inputs.input_reads_r2.nameroot;
var i = 0;
while (r1[i] === r2[i]) {
i++;
}
// remove trailing _R or _
if (r1.slice(0,i).endsWith('_R')) {
i = i - 2;
} else if (r1.slice(0,i).endsWith('_')) {
i--;
}
return r1.slice(0,i) + "_tool_output";
}
outputs:
- id: "zipped_output_directory"
type: 'File?'
format: 'edam:format_3989' # GZIP
outputBinding:
glob: |
${
// obtain the common prefix of the input files for output directory naming
var r1=inputs.input_reads_r1.nameroot;
var r2=inputs.input_reads_r2.nameroot;
var i = 0;
while (r1[i] === r2[i]) {
i++;
}
// remove trailing _R or _
if (r1.slice(0,i).endsWith('_R')) {
i = i - 2;
} else if (r1.slice(0,i).endsWith('_')) {
i--;
}
return r1.slice(0,i) + "_tool_output.tar.gz";
}
streamable: true
doc: 'All final and intermediary outputs of the tool as a gzipped tar archive.'
- id: "final_prediction_csv"
type: 'File?'
format: 'edam:format_3751' # DSV
outputBinding:
glob: |
${
// obtain the common prefix of the input files for output directory naming
var r1=inputs.input_reads_r1.nameroot;
var r2=inputs.input_reads_r2.nameroot;
var i = 0;
while (r1[i] === r2[i]) {
i++;
}
// remove trailing _R or _
if (r1.slice(0,i).endsWith('_R')) {
i = i -2;
} else if (r1.slice(0,i).endsWith('_')) {
i--;
}
var final_pred_dir = r1.slice(0,i) + '_tool_output/Summary/'
return final_pred_dir + r1.slice(0,i) + '_something.csv';
}
- id: "standard_error"
type: 'stderr'
outputBinding:
glob: |
${
// obtain the common prefix of the input files for output directory naming
var r1=inputs.input_reads_r1.nameroot;
var r2=inputs.input_reads_r2.nameroot;
var i = 0;
while (r1[i] === r2[i]) {
i++;
}
// remove trailing _R or _
if (r1.slice(0,i).endsWith('_R')) {
i = i -2;
} else if (r1.slice(0,i).endsWith('_')) {
i--;
}
return r1.slice(0,i) + '_interesting.stderr';
}
streamable: true
- id: "standard_output"
type: 'stdout'
outputBinding:
glob: |
${
// obtain the common prefix of the input files for output directory naming
var r1=inputs.input_reads_r1.nameroot;
var r2=inputs.input_reads_r2.nameroot;
var i = 0;
while (r1[i] === r2[i]) {
i++;
}
// remove trailing _R or _
if (r1.slice(0,i).endsWith('_R')) {
i = i -2;
} else if (r1.slice(0,i).endsWith('_')) {
i--;
}
return r1.slice(0,i) + '_interesting.stdout';
}
streamable: true
Is there a way to circumenvent this?