def _teardown(self, config, temp): # Picard creates a folder named after the user in the temp-root try_rmtree(os.path.join(temp, getpass.getuser())) # Some JREs may create a folder for temporary performance counters try_rmtree(os.path.join(temp, "hsperfdata_" + getpass.getuser())) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): # Picard creates a folder named after the user in the temp-root try_rmtree(os.path.join(temp, getpass.getuser())) # Some JREs may create a folder for temporary performance counters try_rmtree(os.path.join(temp, "hsperfdata_" + getpass.getuser())) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): os.remove(os.path.join(temp, self.PIPE_FILE)) if self._index_format: os.remove(os.path.join(temp, swap_ext(self.PIPE_FILE, self._index_format))) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): # Validate output from MAFFT output_file = reroot_path(temp, self._output_file) try: MSA.from_file(output_file) except MSAError as error: raise NodeError("Invalid MSA produced by MAFFT:\n%s" % (error, )) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): os.remove(os.path.join(temp, "RAxML_info.output")) source = os.path.join(temp, "RAxML_parsimonyTree.output.0") destination = fileutils.reroot_path(temp, self._output_tree) fileutils.move_file(source, destination) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): os.remove(os.path.join(temp, self.PIPE_FILE)) if self._index_format: os.remove( os.path.join(temp, swap_ext(self.PIPE_FILE, self._index_format))) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): for ext in ("log", "nosex"): os.rename( os.path.join(temp, self._basename + "." + ext), os.path.join(temp, self._basename + ".frq.strat." + ext), ) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): basename = os.path.basename(self._output_tree) os.rename( os.path.join(temp, "RAxML_parsimonyTree.Pypeline"), os.path.join(temp, basename), ) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): os.remove(os.path.join(temp, "RAxML_info.output")) source = os.path.join(temp, "RAxML_parsimonyTree.output.0") destination = fileutils.reroot_path(temp, self._output_tree) fileutils.move_file(source, destination) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): with open(fileutils.reroot_path(temp, self._params_file), "w") as out: out.write("k: %i\n" % (self._param_k, )) out.write("m: %i\n" % (self._param_m, )) out.write("outgroup: %r\n" % (list(self._param_outgroup), )) open(fileutils.reroot_path(temp, self._parameters_hash), "w").close() CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): template = self._output_template bootstraps = self._bootstrap_num start = self._bootstrap_start for (src_file, dst_file) in self._bootstraps(template, bootstraps, start): src_file = os.path.join(temp, src_file) dst_file = fileutils.reroot_path(temp, dst_file) fileutils.move_file(src_file, dst_file) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): with open(fileutils.reroot_path(temp, self._params_file), "w") as out: out.write("k: %i\n" % (self._param_k,)) out.write("m: %i\n" % (self._param_m,)) out.write("outgroup: %r\n" % (list(self._param_outgroup),)) open(fileutils.reroot_path(temp, self._parameters_hash), "w").close() CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): for filename in os.listdir(temp): match = re.match("RAxML_(.*).PALEOMIX", filename) if match: source = os.path.join(temp, filename) destination = os.path.join(temp, self._template % match.groups()) fileutils.move_file(source, destination) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): for filename in os.listdir(temp): match = re.match("RAxML_(.*).PALEOMIX", filename) if match: source = os.path.join(temp, filename) destination = os.path.join(temp, self._template % match.groups()) fileutils.move_file(source, destination) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): # No Length_plot.pdf file is written if there are no SE reads in the # input_file. In that case, we write a dummy PDF to ensure that all # expected files exist. err_message = "No length distributions are available" with open(os.path.join(temp, "pipe_mapDamage.stderr")) as in_handle: if any(line.startswith(err_message) for line in in_handle): fpath = os.path.join(temp, "Length_plot.pdf") with open(fpath, "w") as out_handle: out_handle.write(_DUMMY_LENGTH_PLOT_PDF) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): for filename in os.listdir(temp): match = re.match("ExaML_(.*).Pypeline", filename) if match: if "binaryCheckpoint" in match.groups(): os.remove(os.path.join(temp, filename)) else: source = os.path.join(temp, filename) destination = os.path.join(temp, self._template % match.groups()) fileutils.move_file(source, destination) CommandNode._teardown(self, config, temp)
def test_commandnode_teardown__missing_optional_files(temp_folder): destination, temp_folder = _setup_temp_folders(temp_folder) cmd = AtomicCmd(("echo", "-n", "1 2 3"), IN_DUMMY=_EMPTY_FILE, TEMP_OUT_BAR="bar.txt", OUT_STDOUT=os.path.join(destination, "foo.txt")) cmd.run(temp_folder) assert_equal(cmd.join(), [0]) node = CommandNode(cmd) node._teardown(None, temp_folder) assert_equal(os.listdir(temp_folder), []) assert_equal(os.listdir(destination), ["foo.txt"])
def test_commandnode_teardown(temp_folder): destination, temp_folder = _setup_temp_folders(temp_folder) cmd = AtomicCmd(("echo", "-n", "1 2 3"), IN_DUMMY=_EMPTY_FILE, OUT_STDOUT=os.path.join(destination, "foo.txt")) cmd.run(temp_folder) assert_equal(cmd.join(), [0]) node = CommandNode(cmd) assert os.path.exists(os.path.join(temp_folder, "foo.txt")) assert not os.path.exists(os.path.join(destination, "foo.txt")) node._teardown(None, temp_folder) assert not os.path.exists(os.path.join(temp_folder, "foo.txt")) assert os.path.exists(os.path.join(destination, "foo.txt"))
def _teardown(self, config, temp): for filename in os.listdir(temp): match = re.match("ExaML_(.*).Pypeline", filename) if match: if "binaryCheckpoint" in match.groups(): os.remove(os.path.join(temp, filename)) else: source = os.path.join(temp, filename) destination = os.path.join(temp, self._template % match.groups()) fileutils.move_file(source, destination) CommandNode._teardown(self, config, temp)
def test_commandnode_teardown__missing_optional_files(tmp_path): destination, tmp_path = _setup_temp_folders(tmp_path) cmd = AtomicCmd( ("echo", "-n", "1 2 3"), IN_DUMMY=_EMPTY_FILE, TEMP_OUT_BAR="bar.txt", OUT_STDOUT=os.path.join(destination, "foo.txt"), ) cmd.run(tmp_path) assert cmd.join() == [0] node = CommandNode(cmd) node._teardown(None, tmp_path) assert os.listdir(tmp_path) == [] assert os.listdir(destination) == ["foo.txt"]
def _teardown(self, config, temp): for postfix in ("ALIGNMENT", "PARTITION"): filenames = [self._kwargs["TEMP_IN_" + postfix], self._kwargs["TEMP_IN_" + postfix] + ".reduced", self._kwargs["OUT_" + postfix]] for (source, destination) in zip(filenames, filenames[1:]): source = fileutils.reroot_path(temp, source) destination = fileutils.reroot_path(temp, destination) if not os.path.exists(destination): fileutils.copy_file(source, destination) os.remove(source) CommandNode._teardown(self, config, temp)
class MAFFTNode(CommandNode): @create_customizable_cli_parameters def customize(cls, input_file, output_file, algorithm = "auto", dependencies = ()): command = AtomicCmdBuilder(_PRESETS[algorithm.lower()]) command.add_value("%(IN_FASTA)s") command.set_kwargs(IN_FASTA = input_file, OUT_STDOUT = output_file, CHECK_VERSION = MAFFT_VERSION) return {"command" : command, "dependencies" : dependencies} @use_customizable_cli_parameters def __init__(self, parameters): self._output_file = parameters.output_file description = "<MAFFTNode (%s): '%s' -> '%s'>" \ % (parameters.algorithm, parameters.input_file, parameters.output_file) CommandNode.__init__(self, command = parameters.command.finalize(), description = description, dependencies = parameters.dependencies) def _teardown(self, config, temp): # Validate output from MAFFT output_file = reroot_path(temp, self._output_file) try: MSA.from_file(output_file) except MSAError, error: raise NodeError("Invalid MSA produced by MAFFT:\n%s" % (error,)) CommandNode._teardown(self, config, temp)
def test_commandnode_teardown(tmp_path): destination, tmp_path = _setup_temp_folders(tmp_path) cmd = AtomicCmd( ("echo", "-n", "1 2 3"), IN_DUMMY=_EMPTY_FILE, OUT_STDOUT=os.path.join(destination, "foo.txt"), ) cmd.run(tmp_path) assert cmd.join() == [0] node = CommandNode(cmd) assert os.path.exists(os.path.join(tmp_path, "foo.txt")) assert not os.path.exists(os.path.join(destination, "foo.txt")) node._teardown(None, tmp_path) assert not os.path.exists(os.path.join(tmp_path, "foo.txt")) assert os.path.exists(os.path.join(destination, "foo.txt"))
def test_commandnode_teardown__missing_files_in_dest(tmp_path): destination, tmp_path = _setup_temp_folders(tmp_path) class _CmdMock(AtomicCmd): def commit(self, temp): AtomicCmd.commit(self, temp) os.remove(os.path.join(destination, "foo.txt")) cmd = _CmdMock( ("touch", "%(OUT_FOO)s", "%(OUT_BAR)s"), IN_DUMMY=_EMPTY_FILE, OUT_FOO=os.path.join(destination, "foo.txt"), OUT_BAR=os.path.join(destination, "bar.txt"), ) cmd.run(tmp_path) assert cmd.join() == [0] node = CommandNode(cmd) with pytest.raises(NodeError): node._teardown(None, tmp_path)
def test_commandnode_teardown__extra_files_in_temp(tmp_path): destination, tmp_path = _setup_temp_folders(tmp_path) cmd = AtomicCmd( ("echo", "-n", "1 2 3"), IN_DUMMY=_EMPTY_FILE, OUT_STDOUT=os.path.join(destination, "foo.txt"), ) cmd.run(tmp_path) assert cmd.join() == [0] node = CommandNode(cmd) (tmp_path / "bar.txt").write_text("1 2 3") temp_files_before = set(os.listdir(tmp_path)) dest_files_before = set(os.listdir(destination)) with pytest.raises(CmdNodeError): node._teardown(None, tmp_path) assert temp_files_before == set(os.listdir(tmp_path)) assert dest_files_before == set(os.listdir(destination))
def test_command_node__run(): cfg_mock = Mock(temp_root=_DUMMY_TEMP_ROOT) mock = _build_cmd_mock() node_mock = CommandNode(mock) node_mock._create_temp_dir = mock._test_node_._create_temp_dir node_mock._create_temp_dir.return_value = _DUMMY_TEMP node_mock._setup = mock._test_node_._setup node_mock._teardown = mock._test_node_._teardown node_mock._remove_temp_dir = mock._test_node_._remove_temp_dir node_mock.run(cfg_mock) assert mock.mock_calls == [ call._test_node_._create_temp_dir(cfg_mock), call._test_node_._setup(cfg_mock, _DUMMY_TEMP), call.run(_DUMMY_TEMP), call.join(), call._test_node_._teardown(cfg_mock, _DUMMY_TEMP), call._test_node_._remove_temp_dir(_DUMMY_TEMP), ]
def _teardown(self, config, temp): os.rename(os.path.join(temp, self._basename) + ".calmd", os.path.join(temp, self._basename)) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): # Ensure that this file exists even when no filtered SNPs deleted_snps = os.path.basename(self._output_prefix) + ".deleted_snps" open(os.path.join(temp, deleted_snps), "a").close() CommandNode._teardown(self, config, temp)
def test_commandnode_teardown__commit(temp_folder): cmd_mock = _build_cmd_mock() cmd_mock.should_receive("commit").with_args(temp_folder).once node = CommandNode(cmd_mock) node._teardown(None, temp_folder)
def _teardown(self, config, temp): for ext in ("log", "nosex"): os.rename(os.path.join(temp, self._basename + "." + ext), os.path.join(temp, self._basename + ".frq.strat." + ext)) CommandNode._teardown(self, config, temp)
def test_commandnode_teardown__commit(tmp_path): cmd_mock = _build_cmd_mock() node = CommandNode(cmd_mock) node._teardown(None, tmp_path) assert cmd_mock.mock_calls == [call.commit(tmp_path)]
def _teardown(self, config, temp): """See CommandNode._teardown.""" os.remove(reroot_path(temp, self._infile)) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): """See CommandNode._teardown.""" os.remove(reroot_path(temp, self._infile)) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): basename = os.path.basename(self._output_tree) os.rename(os.path.join(temp, "RAxML_parsimonyTree.Pypeline"), os.path.join(temp, basename)) CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp): # Ensure that this file exists even when no filtered SNPs deleted_snps = os.path.basename(self._output_prefix) + ".deleted_snps" open(os.path.join(temp, deleted_snps), "a").close() CommandNode._teardown(self, config, temp)
def _teardown(self, config, temp_root): pipe_fname = os.path.join(temp_root, self._bam_input.pipe) os.remove(pipe_fname) try_remove(pipe_fname + ".bai") CommandNode._teardown(self, config, temp_root)