Update: July 26, 2019
This section of the forum is now closed; we are working on a new support model for WDL that we will share here shortly. For Cromwell-specific issues, see the Cromwell docs and post questions on Github.

Conditional Assignment of Variable

Hi,

I would like to conditionally assign a value to a variable. Here is my use case below, in which I assign the output of CopyFastq to the array variable fq_set if the length of my scatter array is 3, and if the length of my scatter array is 2, I instead assign fq_set the output from SamToFastq.

    scatter(sample in read_tsv(samples_file)) {
        call MakeDirs {
            input:
            output_dir = output_dir,
            sample_name = sample[0]
        }
        if (length(sample) == 2) {
            call SamToFastq {
                input:
                picard_path = picard_path,
                read_data = sample[1],
                sample_name = sample[0],
                sample_dir = MakeDirs.sample_dir
            }
            Array[String]fq_set_out = SamToFastq.fq_set
        }
        if (length(sample) == 3) {
            call CopyFastq {
                input:
                fq1 = sample[1],
                fq2 = sample[2],
                sample_name = sample[0],
                sample_dir = MakeDirs.sample_dir
            }
            Array[String]fq_set_out = CopyFastq.fq_set
        }
        call AlignBAM {
            input:
            new_ref = IndexReference.gatk_ref,
            sample_dir = MakeDirs.sample_dir,
            sample_name = sample[0],
            fq_set = fq_set_out
        }

This WDL fails at the AlignBAM step and returns the error "Couldn't resolve all inputs for gatk.AlignBAM at index Some(1)" as seen below:

"gatk.AlignBAM": [
      {
        "executionStatus": "QueuedInCromwell",
        "shardIndex": 0,
        "callCaching": {
          "allowResultReuse": false,
          "effectiveCallCachingMode": "CallCachingOff"
        },
        "backend": "SGE",
        "attempt": 1,
        "executionEvents": [
          {
            "startTime": "2017-05-01T09:35:03.994-04:00",
            "description": "PreparingJob",
            "endTime": "2017-05-01T09:35:04.002-04:00"
          },
          {
            "startTime": "2017-05-01T09:35:03.994-04:00",
            "description": "RequestingExecutionToken",
            "endTime": "2017-05-01T09:35:03.994-04:00"
          },
          {
            "startTime": "2017-05-01T09:35:03.994-04:00",
            "description": "Pending",
            "endTime": "2017-05-01T09:35:03.994-04:00"
          }
        ],
        "start": "2017-05-01T09:35:03.994-04:00"
      },
      {
        "retryableFailure": false,
        "executionStatus": "Failed",
        "shardIndex": 1,
        "callCaching": {
          "allowResultReuse": false,
          "effectiveCallCachingMode": "CallCachingOff"
        },
        "failures": [
          {
            "causedBy": [
              {
                "causedBy": [
                  {
                    "causedBy": [
                      {
                        "causedBy": [],
                        "message": "No coercion defined from 'null' of type 'String?' to 'String'."
                      }
                    ],
                    "message": "new_ref"
                  },
                  {
                    "causedBy": [
                      {
                        "causedBy": [],
                        "message": "No coercion defined from 'null' of type 'Array[String]?' to 'Array[String]'."
                      }
                    ],
                    "message": "fq_set"
                  }
                ],
                "message": "Input evaluation for Call gatk.AlignBAM failed."
              }
            ],
            "message": "Couldn't resolve all inputs for gatk.AlignBAM at index Some(1)."
          }
        ],
        "backend": "SGE",
        "end": "2017-05-01T09:35:04.001-04:00",
        "attempt": 1,
        "executionEvents": [
          {
            "startTime": "2017-05-01T09:35:03.994-04:00",
            "description": "Pending",
            "endTime": "2017-05-01T09:35:03.994-04:00"
          },
          {
            "startTime": "2017-05-01T09:35:03.994-04:00",
            "description": "PreparingJob",
            "endTime": "2017-05-01T09:35:04.001-04:00"
          },
          {
            "startTime": "2017-05-01T09:35:03.994-04:00",
            "description": "RequestingExecutionToken",
            "endTime": "2017-05-01T09:35:03.994-04:00"
          }
        ],
        "start": "2017-05-01T09:35:03.993-04:00"
      }
    ]
  },
  "outputs": {},
  "workflowRoot": "/cil/shed/apps/internal/cromwell_gaag/cromwell-executions/gatk/caa464b9-3d28-4fb5-856a-0b9b69b39b6b",
  "id": "caa464b9-3d28-4fb5-856a-0b9b69b39b6b",
  "inputs": {
    "gatk.ref_file": "CneoH99_supercont2.1_200k_300k.fa",
    "gatk.output_dir": "/cil/shed/sandboxes/amr/dev/gatk_pipeline/output/small_test",
    "gatk.samples_file": "/cil/shed/sandboxes/amr/dev/gatk_pipeline/data/small/input.tsv",
    "gatk.picard_path": "/cil/shed/apps/external/picard/current/bin/picard.jar",
    "gatk.ref_path": "/cil/shed/sandboxes/amr/dev/gatk_pipeline/data/small"
  },
  "submission": "2017-05-01T09:33:27.047-04:00",
  "status": "Failed",
  "failures": [
    {
      "causedBy": [
        {
          "causedBy": [
            {
              "causedBy": [
                {
                  "causedBy": [],
                  "message": "No coercion defined from 'null' of type 'String?' to 'String'."
                }
              ],
              "message": "new_ref"
            },
            {
              "causedBy": [
                {
                  "causedBy": [],
                  "message": "No coercion defined from 'null' of type 'Array[String]?' to 'Array[String]'."
                }
              ],
              "message": "fq_set"
            }
          ],
          "message": "Input evaluation for Call gatk.AlignBAM failed."
        }
      ],
      "message": "Couldn't resolve all inputs for gatk.AlignBAM at index Some(1)."
    }
  ],

I'm guessing that fq_set_out isn't being passed properly to gatk.AlignBAM or that it isn't getting the assignment. Is this because AlignBAM is not in the same scope as the conditional block where fq_set_out is being assigned?

Any advice on how to make this work appreciated.

Answers

  • jsotojsoto Broad InstituteMember, Broadie, Dev ✭✭

    There are two issues going on here, one is discussed here - https://github.com/broadinstitute/cromwell/issues/2232. You shouldn't be allowed to declare the same variable name in multiple conditional statements because you can run into odd situations.

    The other issue is that because Array[String]fq_set_out is declared inside of a conditional so its type is an optional Array of strings or Array[String]?. Your AlignBam task is probably expecting the input to be Array[String] which is partially why it is throwing that error you see.

    It should work if you change your two Array[String]fq_set_out declarations to like Array[String]fq_set_out_1 and Array[String]fq_set_out_2 or however you want to name it. Then before your AlignBam call, you want to use select_first, described here - https://github.com/broadinstitute/wdl/blob/develop/SPEC.md#conditionals , on your two new variable names and then pass that value to the AlignBam task.

Sign In or Register to comment.