Example #1
0
def collect_args():
    parser = argparse.ArgumentParser(
        prog="cwl2wdl",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    parser._optionals.title = "Options"
    parser.add_argument("FILE", type=str, help="CWL file.")
    parser.add_argument("-f", "--format", type=str, default="wdl",
                        choices=["wdl", "ast"],
                        help="specify the output format")
    parser.add_argument("--validate", action="store_true",
                        help="validate the resulting WDL code with PyWDL")
    parser.add_argument("--version", action='version',
                        version=str(cwl2wdl.__version__))
    return parser
Example #2
0
def collect_args():
    parser = argparse.ArgumentParser(
        prog="cwl2wdl", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser._optionals.title = "Options"
    parser.add_argument("FILE", type=str, help="CWL file.")
    parser.add_argument("-f",
                        "--format",
                        type=str,
                        default="wdl",
                        choices=["wdl", "ast"],
                        help="specify the output format")
    parser.add_argument("--validate",
                        action="store_true",
                        help="validate the resulting WDL code with PyWDL")
    parser.add_argument("--version",
                        action='version',
                        version=str(cwl2wdl.__version__))
    return parser
Example #3
0
def cli():
    command_help = {
        "run": "Run you a WDL",
        "parse": "Parse a WDL file, print parse tree",
        "expr": "Expression testing"
    }

    parser = argparse.ArgumentParser(description='Workflow Description Language (WDL)')
    parser.add_argument(
        '--version', action='version', version=str(pkg_resources.get_distribution('wdl'))
    )
    parser.add_argument(
        '--debug', required=False, action='store_true', help='Open the floodgates'
    )
    parser.add_argument(
        '--no-color', default=False, required=False, action='store_true', help="Don't colorize output"
    )

    subparsers = parser.add_subparsers(help='WDL Actions', dest='action')
    subparsers.required = True
    commands = {}
    commands['run'] = subparsers.add_parser(
        'run', description=command_help['run'], help=command_help['run']
    )
    commands['run'].add_argument(
        'wdl_file', help='Path to WDL File'
    )
    commands['run'].add_argument(
        '--inputs', help='Path to JSON file to define inputs'
    )
    commands['run'].add_argument(
        '--sge', action="store_true", help='Use SGE to execute tasks'
    )
    commands['parse'] = subparsers.add_parser(
        'parse', description=command_help['parse'], help=command_help['parse']
    )
    commands['parse'].add_argument(
        'wdl_file', help='Path to WDL File'
    )

    cli = parser.parse_args()

    if cli.action == 'run':
        sys.exit('Currently unsupported')

        inputs = {}
        run_service_name = "local"

        if cli.sge:
            run_service_name = "sge"

        if cli.inputs:
            with open(cli.inputs) as fp:
                inputs = json.loads(fp.read())

        try:
            wdl.engine.run(cli.wdl_file, run_service_name, inputs)
        except wdl.engine.MissingInputsException as error:
            print("Your workflow cannot be run because it is missing some inputs!")
            if cli.inputs:
                print("Add the following keys to your {} file and try again:".format(cli.inputs))
            else:
                print("Use the template below to specify the inputs.  Keep the keys as-is and change the values to match the type specified")
                print("Then, pass this file in as the --inputs option:\n")
            print(json.dumps(error.missing, indent=4))
    if cli.action == 'parse':
        with open(cli.wdl_file) as fp:
            ast = wdl.parser.parse(fp.read(), os.path.basename(cli.wdl_file)).ast()
            print(ast.dumps(indent=2))
Example #4
0
def main():
    parser = argparse.ArgumentParser(description='Convert WDL to Toil')
    parser.add_argument('wdl_file',
                        help='a WDL workflow or a directory with WDL files')
    parser.add_argument('secondary_file',
                        help='secondary data file (json or yml)')
    parser.add_argument('--tsv',
                        help='file with sample names for the scatter function')
    args = parser.parse_args()

    wdl_file_path = os.path.abspath(args.wdl_file)
    args.secondary_file = os.path.abspath(args.secondary_file)

    w = wdltoil(wdl_file_path, args)

    ##############################################################################
    # read secondary file; create dictionary to hold variables
    if args.secondary_file.endswith('.json'):
        w.dict_from_JSON(args.secondary_file)
    elif args.secondary_file.endswith('.yml'):
        w.dict_from_YML(args.secondary_file)
    else:
        print('Unsupported Secondary File Type.  Please specify json or yml.')
    ##############################################################################

    formatted_WDL = w.format_WDL_code(wdl_file_path)

    w.create_definitions(formatted_WDL)
    w.create_jobs(formatted_WDL)

    module_section = w.write_modules(w.module_list)
    fn_section = w.write_functions()
    main_section = w.write_main()
    job_section = w.write_jobs()

    # print('\n\n')
    # for each_task in w.tasks_dictionary:
    #     print(each_task)
    #     for each_section in w.tasks_dictionary[each_task]:
    #         print('    ' + str(each_section))
    #         for each_variable in w.tasks_dictionary[each_task][each_section]:
    #             print('        ' + str(each_variable))
    #
    # print('\n\n')
    # for each_task in w.jobs_dictionary:
    #     print(each_task)
    #     if 'wf_declarations' in w.jobs_dictionary[each_task]:
    #         print('    wf_declarations')
    #         for d in w.jobs_dictionary[each_task]['wf_declarations']:
    #             print('        ' + str(d))
    #     if 'job_declarations' in w.jobs_dictionary[each_task]:
    #         print('    job_declarations')
    #         for j in w.jobs_dictionary[each_task]['job_declarations']:
    #             print('        ' + str(j))
    #             for g in w.jobs_dictionary[each_task]['job_declarations'][j]:
    #                 print('            ' + g + ': ' + w.jobs_dictionary[each_task]['job_declarations'][j][g])
    #
    # print('\n\n')
    # for each_task in w.saved_scatter_input_vars:
    #     print(each_task)
    #     print(w.saved_scatter_input_vars[each_task])

    w.write_python_file(module_section, fn_section, main_section, job_section,
                        w.output_file)

    subprocess.check_call(['python', w.output_file])