This is a test version of Biostars. For the public version, visit https://www.biostars.org.
CWL: word counting

Hello there!

I am a total newbie in CWL and I'm struggling to write a simple workflow counting words in input file and writing the number (and the number only!) in output file. To remove the file name from wc output I wrote this:

file.cwl:

cwlVersion: v1.0
class: CommandLineTool
requirements:
    class: ShellCommandRequirement
inputs:
    input_file:
        type: File

outputs:
    output_file:
        type: File
        outputBinding:
            glob: output/output

stdout: output/output

baseCommand: wc
arguments:
  - valueFrom: '-w'
    shellQuote: false
    position: 1
  - valueFrom: input_file
    shellQuote: false
    position: 2
  - valueFrom: '|'
    shellQuote: false
    position: 3
  - valueFrom: 'awk'
    shellQuote: false
    position: 4
  - valueFrom: '"'
    shellQuote: false
    position: 5
  - valueFrom: '{print $1;}'
    shellQuote: false
    position: 6
  - valueFrom: '"'
    shellQuote: false
    position: 7

file.yml:
input_file:
    class: File
    path: input/input

And I got error mapSubject '%s' value '%s' is not a dict and does not have a mapPredicate

What does it mean? What am I doing wrong?

common-workflow-language cwl

Where is the bioinformatics part of your question?

Hello gultagr,

Can you edit your question and reformat your code? There should be a button in the interface that looks like "101 010"

I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

1 answer

Hello gultagr,

requirements:
    class: ShellCommandRequirement

should be

requirements:
    - class: ShellCommandRequirement

or

requirements:
    ShellCommandRequirement: {}

You can also write the baseCommand and arguments this way:

baseCommand: []

arguments:
  - wc
  - -w
  - $(inputs.input_file)
  - '|'
  - awk
  - '{print $1;}'

Here is a simpler version, taking advantage of how wc changes its behavior when the input is piped in via stdin

#!/usr/bin/env cwl-runner
cwlVersion: v1.0

class: CommandLineTool

inputs:
  text: File

outputs:
  number_of_words: stdout

stdin: $(inputs.text.path)

stdout: words  # optional line, but gives the output a nicer file name

baseCommand: [ wc, -w ]

Thanks for the example. Just what I needed right now. Was trying to use stdin: $(inputs.text) instead of $(inputs.text.path). Also, interesting way to do a pipe using the arguments field instead of connecting wc and awk with a workflow.

Log in to answer this question.