Holiday Notice:
The Frontline Support team will be slow to respond December 17-18 due to an institute-wide retreat and offline December 22- January 1, while the institute is closed. Thank you for your patience during these next few weeks. Happy Holidays!

womtool fails on python code in task's command when "_" used as a variable in a list comprehension

myourshawmyourshaw University of ColoradoMember ✭✭

In a task's command block that has a python <<CODE block, womtool gets this error:

Unrecognized token on line 356, column 43:

        barcode_data.append([barcode_dict[_] for _ in header])
                                          ^

Replacing the underscore with 'x' resolves the problem.

The full task:

task CreateBarcodeFile {
  String python3_cmd
  File run_metadata
  Int lane

  command {
    ${python3_cmd} <<CODE
    barcode_data = []

    with open('${run_metadata}', 'r') as ifh:
        metadata = json.load(ifh)

    if metadata['NUM_INDICES'] == 1:
        header = ['barcode_sequence_1', 'barcode_name', 'library_name']
    else:
        header = ['barcode_sequence_1', 'barcode_sequence_2', 'barcode_name', 'library_name']

    lane_metadata = metadata['LANE_METADATA'].get(str(lane))
    for sample_metadata in lane_metadata:
        barcode_1 = sample_metadata['BARCODE_1']
        barcode_2 = sample_metadata.get('BARCODE_2', '')

        barcode_dict = {
            'barcode_sequence_1': barcode_1,
            'barcode_sequence_2': barcode_2,
            'barcode_name': sample_metadata['BARCODE_NAME'],
            'library_name': sample_metadata['LIBRARY_NAME'],
        }
        barcode_data.append([barcode_dict[_] for _ in header])

    print('\t'.join(header))

    for d in barcode_data:
        print('\t'.join(d))
    CODE
  }
  runtime {
    memory: "1G"
    cpu: 1
  }
  output {
    File barcode_file = stdout()
  }
}

Best Answers

Answers

  • myourshawmyourshaw University of ColoradoMember ✭✭

    Thanks Chris! Using <<< >>> also fixed the next problem I was having. And nice catch on the lane variable, an annoying problem when copying from PyCharm into a wdl.

    I had been using Sublime Text for wdl files, which about a year ago had a slightly better wdl plugin than PyCharm, but was not smart enough to detect how wdl is fooled by the braces. I'll be switching to the PyCharm one now. Thanks for the tip.

Sign In or Register to comment.