Entering edit mode
6.5 years ago
ionox0
▴
390
This isn't a question as much as an interesting finding, to get grep to work with the -v flag when the entire file is grepped-out, you need to add || true to make sure the jobs doesn't fail due to a nonzero exit code from grep.
For example this tool concatenates several vcf files together, but will fail withouth the || true if grep removes the only line from a vcf that only has the header (no variants):
cwlVersion: v1.0
class: CommandLineTool
requirements:
- class: InlineJavascriptRequirement
- class: ShellCommandRequirement
arguments:
- head
- -n
- '1'
- $(inputs.vcfs[0].path)
- shellQuote: false
valueFrom: '>'
- all_calls.vcf
- shellQuote: false
valueFrom: '&&'
- cat
- $(inputs.vcfs)
- shellQuote: false
valueFrom: '|'
- grep
- -vP
- "^chr1"
# Need this to prevent nonzero exit code if grep runs on header only
- shellQuote: false
valueFrom: '||'
- 'true'
- shellQuote: false
valueFrom: '>>'
- all_calls.vcf
inputs:
vcfs: File[]
outputs:
concatenated_vcf:
type: File
outputBinding:
glob: all_calls.vcf
From the grep manual page
So we can use
successCodes: [0, 1]to document that with|| truewhich could hide an errorAlso, does
really work when
vcfsistype: File[]?Thanks for the tip, I didn't consider using this feature, indeed the
successCodesfeature solves this problem more cleanly.The result of the cwl is the following:
Which looks correct to me in terms of the multiple files being supplied to
cat. Is this not recommended?However I've realized another issue which is that the second command after
&&is not being redirected to theall_calls.txtfile but is rather still being output to stdout. Perhaps I'm misunderstanding the/bin/sh -cusage, but using a subshell for the second command seems to work, although I'm not sure it's recommended:You're in a situation where I would either recommend using a bash script or splitting into multiple
CommandLineToolsI take back my comment about
$(inputs.vcfs), I was thinking of something else :-)