Passing numeric values in workflow

I would like to extract a floating point value and pass it to the next task. Below is my Command Line tool description.

#!/usr/bin/env cwl-runner

class: CommandLineTool
cwlVersion: v1.2

baseCommand: [samtools]

requirements:
  ShellCommandRequirement: {}

inputs:
  bam_input:
    type: File
    inputBinding:
      position: 2

arguments: 
  - valueFrom: depth
    position: 1
    shellQuote: False
  - valueFrom: "|"
    position: 3
    shellQuote: False
  - valueFrom: awk
    position: 4
    shellQuote: False
  - valueFrom: "'{sum+=$3} END { print sum/NR}'"
    position: 5
    shellQuote: False



outputs: 
  output_coverage_genome:
    type: float

And this is my two task pipeline

  coverage_genome:
    run: tasks/genome_coverage_extract.cwl
    in: 
      bam_input: bam_input
    out: [output_coverage_genome]

  reads_coverage:
    run: tasks/next_task.cwl
    in:
      coverage: coverage_genome/output_coverage_genome
    out: [outputs]

However I get the following error:

[2023-09-20T09:27:53-0600] [MainThread] [I] [cwltool] [job pipeline_.cwl.coverage_genome.coverage_genome_float.cwl] /tmpdir_cwl/tmp291u2x1k$ sh
coverage_genome.sh
49.6596
[2023-09-20T09:29:35-0600] [MainThread] [I] [cwltool] [job pipeline_.cwl.coverage_genome.coverage_genome_float.cwl] Max memory used: 11MiB
[2023-09-20T09:29:35-0600] [MainThread] [E] [cwltool] [job pipeline_.cwl.coverage_genome.coverage_genome_float.cwl] Job error:
Error validating output record. the ā€˜output_coverage_genomeā€™ field is not valid because
the value ā€˜Noneā€™ is not float or double
in {
ā€œoutput_coverage_genomeā€: null
}

Most examples in CWL are about passing files from one task to the next but I havenā€™t seen one passing a an int/float value.
I looked at this one Using floats / decimals as integers in a workflow and vice versa - #2 by mrc
but it is more about the input than output values.
I also looked at this post How to output non-file types from a CommandLineTool? but it is for v1.0 and Iā€™m not sure if there is a more modern way to write the same example marked as a solution.
Most hello_world style examples in the documentation (if not all) are about passing files between tasks.

Thanks for your help!

I think you need to direct stdout to the output ā€˜output_coverage_genomeā€™

Using Common Workflow Language (CWL) Command Line Tool Description, v1.0.2 (commonwl.org) as a guide,

Try adding in the stdout key as below, and also updating the outputs with the following:


stdout: genome_coverage_stdout

outputs: 
  output_coverage_genome:
    type: float
    outputBinding:
      glob: genome_coverage_stdout
      loadContents: true
      outputEval: $(self[0].contents)

Thanks Alexis,
This did the trick. I had to make an additional change to transform to float since the previous output was a string. Here is the complete solution.

outputs: 
  output_coverage_genome:
    type: float
    outputBinding:
      glob: genome_coverage_stdout
      loadContents: true
      outputEval: $(parseFloat(self[0].contents.trim()))

Thank you very much for your help!

2 Likes