question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use optional workflow inputs as non optional input for task

See original GitHub issue

Hi,

I have a workflow with an optional input that needs to be used in task where the same input is not optional.

example


version 1.0

task PicardCollectHsMetrics {
    meta {
        description: "Collects hybrid-selection (HS) metrics for a SAM or BAM file."
    }

    input {
        File input_bam
        File bait_intervals_bed
        File target_intervals_bed

        FastaReference reference_fasta

        String docker_image = "quay.io/biocontainers/gatk4:4.1.9.0--py39_0"
    }

    String input_bam_basename = basename(input_bam, ".bam")
    String bait_name = basename(bait_intervals_bed, ".bed")

    command {
        set -e

        # bait regions
        gatk BedToIntervalList \
            -I ~{target_intervals_bed} \
            -O target.interval_list \
            -SD ~{reference_fasta.ref_dict}

        # target regions
        gatk BedToIntervalList \
            -I ~{bait_intervals_bed} \
            -O bait.interval_list \
            -SD ~{reference_fasta.ref_dict}

        gatk CollectHsMetrics \
            -I ~{input_bam} \
            -O ~{input_bam_basename}_hs_metrics.txt \
            -R ~{reference_fasta.ref_fasta} \
            -N ~{bait_name} \
            -BAIT_INTERVALS bait.interval_list \
            -TARGET_INTERVALS target.interval_list
    }

    runtime {
        docker: docker_image
        cpu: 1
        maxRetries: 2
    }

    output {
        File hs_metrics = "~{input_bam_basename}_hs_metrics.txt"
    }
}


task PicardCollectWgsMetrics {
    meta {
        description: "Collect metrics about coverage and performance of whole genome sequencing (WGS) experiments."
    }

    input {
        File input_bam

        FastaReference reference_fasta

        String docker_image = "quay.io/biocontainers/gatk4:4.1.9.0--py39_0"
    }

    String input_bam_basename = basename(input_bam, ".bam")

    command {
        set -e
        gatk CollectWgsMetrics \
            -I ~{input_bam} \
            -O ~{input_bam_basename}_wgs_metrics.txt \
            -R ~{reference_fasta.ref_fasta}
    }

    runtime {
        docker: docker_image
        cpu: 1
        maxRetries: 2
    }

    output {
        File wgs_metrics = "~{input_bam_basename}_wgs_metrics.txt"
    }
}


workflow Metrics {
    input {
        File input_bam
        File? bait_intervals_bed
        File? target_intervals_bed
        FastaReference reference_fasta
    }

    if (defined(bait_intervals_bed) && defined(target_intervals_bed)) {
        call PicardCollectHsMetrics {
            input:
                input_bam  = MergeSortMarkDupBams.output_bam,
                bait_intervals_bed = bait_intervals_bed,
                target_intervals_bed = target_intervals_bed,
                reference_fasta = bwa_reference.reference_fasta
        }
    }
    if (!defined(bait_intervals_bed) && !defined(target_intervals_bed)) {
        call qc.PicardCollectWgsMetrics {
            input:
                input_bam  = MergeSortMarkDupBams.output_bam,
                reference_fasta = bwa_reference.reference_fasta
        }
    }
}

...

How do I accomplish such a thing? womtool says Cannot coerce expression of type 'File?' to 'File'.

Thanks for the help. Matthias

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pshapiro4broadcommented, Apr 12, 2021

I think you get the behavior you want by not using select_first(). If you have an optional value, and you’re passing it to a workflow that accepts an optional value, then you can pass it directly. You only need to use select_first() if you’re passing an optional value to a workflow that accepts a non-optional value.

1reaction
mlincommented, Mar 5, 2021

Yea everybody learning WDL gets tripped up by this at some point. I have made (future versions of) miniwdl suggest select_first() on this type error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clarifying typechecking of optional values #271 - openwdl/wdl
Re the final example about optional inputs - I think that this is now tidied up in WDL 1.0. In WDL 1.0 the...
Read more >
Workflow Optional Input Problem ("simple-inputs") - Galaxy Help
The problem occurs only when I run the workflow through an API call with no argument for the optional field. When I run...
Read more >
How to check if an optional workflow_dispatch input is set or not
I've tested it in this workflow and the correct way to check if an input (or any variable) is empty or not in...
Read more >
Style Guidelines - BioWDL
Different groupings of inputs (in call, task and workflow blocks) and items in runtime ... outputPath # Optional input(s) separated from mandatory input(s) ......
Read more >
Solved: Optional script input parameters - Esri Community
I have created a script (see below) that works ok but only in case if all parameters are required inputs. Quite simple, Roads(line)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found