def _convert_internal(parsed_ctds, **kwargs): # parse all input files into models using CTDopts (via utils) # the output is a tuple containing the model, output destination, origin file for parsed_ctd in parsed_ctds: model = parsed_ctd.ctd_model origin_file = parsed_ctd.input_file output_file = parsed_ctd.suggested_output_file if kwargs["skip_tools"] is not None and model.name in kwargs["skip_tools"]: logger.info("Skipping tool %s" % model.name, 0) continue elif kwargs["required_tools"] is not None and model.name not in kwargs["required_tools"]: logger.info("Tool %s is not required, skipping it" % model.name, 0) continue else: logger.info("Converting %s (source %s)" % (model.name, utils.get_filename(origin_file)), 0) tool = create_tool(model) write_header(tool, model) create_description(tool, model) expand_macros(tool, model, **kwargs) create_command(tool, model, **kwargs) create_inputs(tool, model, **kwargs) create_outputs(tool, model, **kwargs) create_help(tool, model) # wrap our tool element into a tree to be able to serialize it tree = ElementTree(tool) logger.info("Writing to %s" % utils.get_filename(output_file), 1) tree.write(open(output_file, 'w'), encoding="UTF-8", xml_declaration=True, pretty_print=True)
def generate_tool_conf(parsed_ctds, tool_conf_destination, galaxy_tool_path, default_category): # for each category, we keep a list of models corresponding to it categories_to_tools = dict() for parsed_ctd in parsed_ctds: category = strip(parsed_ctd.ctd_model.opt_attribs.get("category", "")) if not category.strip(): category = default_category if category not in categories_to_tools: categories_to_tools[category] = [] categories_to_tools[category].append(utils.get_filename(parsed_ctd.suggested_output_file)) # at this point, we should have a map for all categories->tools toolbox_node = Element("toolbox") if galaxy_tool_path is not None and not galaxy_tool_path.strip().endswith("/"): galaxy_tool_path = galaxy_tool_path.strip() + "/" if galaxy_tool_path is None: galaxy_tool_path = "" for category, file_names in categories_to_tools.iteritems(): section_node = add_child_node(toolbox_node, "section") section_node.attrib["id"] = "section-id-" + "".join(category.split()) section_node.attrib["name"] = category for filename in file_names: tool_node = add_child_node(section_node, "tool") tool_node.attrib["file"] = galaxy_tool_path + filename toolconf_tree = ElementTree(toolbox_node) toolconf_tree.write(open(tool_conf_destination,'w'), encoding="UTF-8", xml_declaration=True, pretty_print=True) logger.info("Generated Galaxy tool_conf.xml in %s" % tool_conf_destination, 0)
def convert_models(args, parsed_ctds): # go through each ctd model and perform the conversion, easy as pie! for parsed_ctd in parsed_ctds: model = parsed_ctd.ctd_model origin_file = parsed_ctd.input_file output_file = parsed_ctd.suggested_output_file logger.info("Converting %s (source %s)" % (model.name, utils.get_filename(origin_file))) cwl_tool = convert_to_cwl(model, args) logger.info("Writing to %s" % utils.get_filename(output_file), 1) stream = file(output_file, 'w') stream.write(CWL_SHEBANG + '\n\n') stream.write("# This CWL file was automatically generated using CTDConverter.\n") stream.write("# Visit https://github.com/WorkflowConversion/CTDConverter for more information.\n\n") yaml.dump(cwl_tool, stream, default_flow_style=False) stream.close()
def convert_models(args, parsed_ctds): # go through each ctd model and perform the conversion, easy as pie! for parsed_ctd in parsed_ctds: model = parsed_ctd.ctd_model origin_file = parsed_ctd.input_file output_file = parsed_ctd.suggested_output_file logger.info("Converting %s (source %s)" % (model.name, utils.get_filename(origin_file))) cwl_tool = convert_to_cwl(model, args) logger.info("Writing to %s" % utils.get_filename(output_file), 1) stream = open(output_file, 'w') stream.write(CWL_SHEBANG + '\n\n') stream.write( "# This CWL file was automatically generated using CTDConverter.\n" ) stream.write( "# Visit https://github.com/WorkflowConversion/CTDConverter for more information.\n\n" ) yaml.dump(cwl_tool, stream, default_flow_style=False) stream.close()