def cli(): parser = collect_args() arguments = parser.parse_args() if os.path.exists(arguments.FILE): pass else: raise IOError("%s does not exist." % (arguments.FILE)) parsed_cwl = ParsedDocument(CwlParser(arguments.FILE).parse_document()) wdl_parts = [] if parsed_cwl.tasks is not None: for task in parsed_cwl.tasks: wdl_task = WdlTaskGenerator(task).generate_wdl() wdl_parts.append(wdl_task) if parsed_cwl.workflow is not None: wdl_workflow = WdlWorkflowGenerator(parsed_cwl.workflow).generate_wdl() wdl_parts.append(wdl_workflow) wdl_doc = str("\n".join(wdl_parts)) if arguments.validate: try: is_validated = wdl.parser.parse(wdl_doc) except Exception as e: raise e if arguments.format == "ast": warnings.warn( "By specifying 'ast' format you are implicity imposing validation." ) ast = wdl.parser.parse(wdl_doc).ast() print(ast.dumps(indent=2)) else: print(wdl_doc)
def cli(): parser = collect_args() arguments = parser.parse_args() if os.path.exists(arguments.FILE): pass else: raise IOError("%s does not exist." % (arguments.FILE)) parsed_cwl = ParsedDocument( CwlParser(arguments.FILE).parse_document() ) wdl_parts = [] if parsed_cwl.tasks is not None: for task in parsed_cwl.tasks: wdl_task = WdlTaskGenerator(task).generate_wdl() wdl_parts.append(wdl_task) if parsed_cwl.workflow is not None: wdl_workflow = WdlWorkflowGenerator(parsed_cwl.workflow).generate_wdl() wdl_parts.append(wdl_workflow) wdl_doc = str("\n".join(wdl_parts)) if arguments.validate: try: is_validated = wdl.parser.parse(wdl_doc) except Exception as e: raise e if arguments.format == "ast": warnings.warn("By specifying 'ast' format you are implicity imposing validation.") ast = wdl.parser.parse(wdl_doc).ast() print(ast.dumps(indent=2)) else: print(wdl_doc)
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))
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])