def validate_wdl(wdl: str, cmd: Command = None, explore=True): """ :param explore: If true, we're in explore mode, and we should ignore subcommands """ try: doc = parse_document(wdl) except Error.SyntaxError as e: print(wdl) raise e task = doc.tasks[0] # task.inputs might be None cmd_input_names = {inp.name for inp in task.inputs or []} # Verify that every parameter has been documented wdl_input_names = {meta for meta in task.parameter_meta.keys()} assert cmd_input_names == wdl_input_names # wdl_input_descriptions = {meta for meta in doc.tasks[0].parameter_meta.values()} # cmd_input_descriptions = {arg.description for arg in [*cmd.subcommands, *cmd.named, *cmd.positional]} # assert wdl_input_descriptions == cmd_input_descriptions, wdl_input_descriptions ^ cmd_input_descriptions # Check that the generated WDL has the correct parameter meta fields if cmd: cmd_names = [arg.full_name() for arg in [*cmd.named, *cmd.positional]] target = len(cmd.named) + len(cmd.positional) # If we're not in explore mode, subcommands will be parsed as inputs if not explore: target += len(cmd.subcommands) assert len(task.parameter_meta) == target, "{} vs {}".format( task.parameter_meta.keys(), cmd_names) # We should have all the official outputs, plus stdout assert len(task.outputs) == len(cmd.outputs) + 1
def __find_workflow_meta(self, key): """Find value for a key in workflow's meta section Returns: None if key not found or any error occurs. """ try: wdl = parse_document(self._wdl_str) if key in wdl.workflow.meta: return wdl.workflow.meta[key] except: pass return None
def __init__(self, wdl): """Wraps miniwdl's parse_document(). """ u = AutoURI(wdl) if not u.exists: raise FileNotFoundError( 'WDL does not exist: wdl={wdl}'.format(wdl=wdl)) self._wdl = wdl self._wdl_contents = AutoURI(wdl).read() try: self._wdl_doc = parse_document(self._wdl_contents) except Exception: logger.error('Failed to parse WDL with miniwdl.') self._wdl_doc = None
def test_docker_conversion(bedtools_cmd): intersect = bedtools_cmd["intersect"] container = "quay.io/biocontainers/bedtools:2.29.2--hc088bd4_0" intersect.docker_image = container with tempfile.NamedTemporaryFile() as cwl_file: CwlGenerator().save_to_file(intersect, path=Path(cwl_file.name)) cwl_file.seek(0) parsed_cwl = yaml.load(cwl_file) assert any([ hint["class"] == "DockerRequirement" and hint["dockerPull"] == container for hint in parsed_cwl["hints"] ]) wdl = WdlGenerator().save_to_string(intersect) parsed_wdl = parse_document(wdl).tasks[0] assert parsed_wdl.runtime["docker"].literal.value == container