def action(self, action, inputs, outputs): variables = super().action(action, inputs, outputs) vars_dict = variables._asdict() plugin_name = util.to_cli_name(action.plugin_id) action_name = util.to_cli_name(action.action_id) self.recorder.append('qiime %s %s \\' % (plugin_name, action_name)) action_f = action.get_action() action_state = get_action_state(action_f) ins = inputs.map_variables(lambda v: v.to_interface_name()) outs = {k: v.to_interface_name() for k, v in vars_dict.items()} signature = {s['name']: s for s in action_state['signature']} for param_name, value in ins.items(): self._append_action_line(signature, param_name, value) max_collection_size = self.action_collection_size if max_collection_size is not None and len(outs) > max_collection_size: dir_name = self._build_output_dir_name(plugin_name, action_name) self.recorder.append(self.INDENT + '--output-dir %s \\' % (dir_name)) self._rename_outputs(vars_dict, dir_name) else: for param_name, value in outs.items(): self._append_action_line(signature, param_name, value) self.recorder[-1] = self.recorder[-1][:-2] # remove trailing \ return variables
def action(self, action, inputs, outputs): variables = super().action(action, inputs, outputs) vars_dict = variables._asdict() plugin_name = util.to_cli_name(action.plugin_id) action_name = util.to_cli_name(action.action_id) self.recorder.append("qiime %s %s \\" % (plugin_name, action_name)) action_f = action.get_action() action_state = get_action_state(action_f) ins = inputs.map_variables(lambda v: v.to_interface_name()) outs = {k: v.to_interface_name() for k, v in vars_dict.items()} signature = {s['name']: s for s in action_state['signature']} for param_name, value in {**ins, **outs}.items(): param_state = signature[param_name] if value is not None: for opt, val in self._make_param(value, param_state): line = self.INDENT + opt if val is not None: line += ' ' + val line += ' \\' self.recorder.append(line) self.recorder[-1] = self.recorder[-1][:-2] # remove trailing \ return variables
def to_interface_name(self): if hasattr(self, '_q2cli_ref'): return self._q2cli_ref ext = { 'artifact': 'qza', 'visualization': 'qzv', 'metadata': 'tsv', }[self.var_type] cli_name = util.to_cli_name(self.name) fn = '%s.%s' % (cli_name, ext) return shlex.quote(fn)
def write_example_data(action, output_dir): for example_name, example in action.examples.items(): cli_name = util.to_cli_name(example_name) example_path = os.path.join(output_dir, cli_name) use = CLIUsage() example(use) for fn, val in use.get_example_data(): os.makedirs(example_path, exist_ok=True) path = os.path.join(example_path, fn) val.save(path) try: hint = repr(val.type) except AttributeError: hint = 'Metadata' yield hint, path
def to_cli_name(val): return util.to_cli_name(val)
def write_plugin_example_data(plugin, output_dir): for name, action in plugin.actions.items(): path = os.path.join(output_dir, util.to_cli_name(name)) yield from write_example_data(action, path)