This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bedtools sort -faidx in CWL

How does one uses a secondairy file as the input to a command in CWL?

I try to do :

bedtools sort -header -faidx hg38.fasta.fai

So in CWL i got to

#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: CommandLineTool
label: "sort a bed file based on occurrence in fasta"

requirements:
  - class: DockerRequirement
    dockerPull: "biocontainers/bedtools:v2.28.0_cv2"

baseCommand: ["bedtools", "sort", "-header"]

stdout: $(inputs.output_name)

inputs:
  input_bed:
    type: File
    inputBinding:
      position: 2
      prefix: -i

  reference_genome:
    type: File
    secondaryFiles:
       - .fai
    inputBinding:
      position: 1
      prefix: -faidx
      valueFrom: {$(inputs.reference_genome.basename).fai}

  output_name:
    type: string?
    default: sorted_coverage.bed

outputs:
  sorted_bed:
    type: stdout

But that does not work for the ValueFrom method under reference_genome/inputbinding.

Does anyone know how to do this?

cwl bedtools sort

I have not yet used bedtools, so i'm not sure i understand correctly. Can you spell out the names of the files which bedtools needs to access for the line you have given in the beginning? I guess one is g38.fasta.fai. But what are the names of the other files?

You are right, the bed file to be sorted needs to be added to the command at the top with the -i flag so that you get:

bedtools sort -header -faidx ref.fasta.fai -i some.bed

If the command that you are trying to produce is bedtools sort -header -faidx hg38.fasta.fai it looks like you don't need secondaryFiles at all. You should just be able to pass in hg38.fasta.fai as your input file.

Thanks for your response! What you are saying is true, However, if this is part of a bigger pipeline where the .fai is also needed as a fasta index file its repetitive to add it everywhere manually. So I was hoping that there was a way to access the secondary files directly.

1 answer

Hello @dami, there was a typo in your valueFrom field the {} should not be there

#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: CommandLineTool
label: "sort a bed file based on occurrence in fasta"

requirements:
  - class: DockerRequirement
    dockerPull: "biocontainers/bedtools:v2.28.0_cv2"

baseCommand: ["bedtools", "sort", "-header"]

stdout: $(inputs.output_name)

inputs:
  input_bed:
    type: File
    inputBinding:
      position: 2
      prefix: -i

  reference_genome:
    type: File
    secondaryFiles:
       - .fai
    inputBinding:
      position: 1
      prefix: -faidx
      valueFrom: $(inputs.reference_genome.basename).fai

  output_name:
    type: string?
    default: sorted_coverage.bed

outputs:
  sorted_bed:
    type: stdout

Log in to answer this question.