diff --git a/test/integration/snake.py b/test/integration/snake.py index 698021477..7bc44c3f7 100644 --- a/test/integration/snake.py +++ b/test/integration/snake.py @@ -123,4 +123,4 @@ def run(self, rules=None): cmd = ['snakemake', '--verbose', '--reason', '--printshellcmds'] if rules: cmd.extend(rules) - res = util.misc.run_and_print(cmd, check=True, cwd=self.workdir) + res = util.misc.run(cmd, check=True, cwd=self.workdir) diff --git a/test/unit/test_tools_kraken.py b/test/unit/test_tools_kraken.py index fc30cf951..7a20ee091 100644 --- a/test/unit/test_tools_kraken.py +++ b/test/unit/test_tools_kraken.py @@ -17,9 +17,6 @@ class TestToolKrakenMocked(TestCaseWithTmp): def setUp(self): super().setUp() - patcher = mock.patch('util.misc.run_and_print', autospec=True) - self.addCleanup(patcher.stop) - self.mock_run_and_print = patcher.start() patcher = mock.patch('util.misc.run', autospec=True) self.addCleanup(patcher.stop) self.mock_run = patcher.start() diff --git a/test/unit/test_tools_krona.py b/test/unit/test_tools_krona.py index 6ca87ad7f..c67968964 100644 --- a/test/unit/test_tools_krona.py +++ b/test/unit/test_tools_krona.py @@ -17,7 +17,7 @@ def setUp(self): self.krona = tools.krona.Krona() self.krona.install() - patcher = patch('util.misc.run_and_print', autospec=True) + patcher = patch('subprocess.check_call', autospec=True) self.addCleanup(patcher.stop) self.mock_run = patcher.start() diff --git a/tools/kraken.py b/tools/kraken.py index 8e151a839..8c011baf6 100644 --- a/tools/kraken.py +++ b/tools/kraken.py @@ -53,7 +53,7 @@ def build(self, db, options=None, option_string=None): ''' self.execute('kraken-build', db, db, options=options, option_string=option_string) - + def classify(self, inBam, db, outReads, numThreads=None): """Classify input reads (bam) @@ -88,13 +88,13 @@ def classify(self, inBam, db, outReads, numThreads=None): res = self.execute('kraken', db, outReads, args=[tmp_fastq1, tmp_fastq2], options=opts) os.unlink(tmp_fastq1) os.unlink(tmp_fastq2) - + def filter(self, inReads, db, outReads, filterThreshold): """Filter Kraken hits """ self.execute('kraken-filter', db, outReads, args=[inReads], options={'--threshold': filterThreshold}) - + def report(self, inReads, db, outReport): """Convert Kraken read-based output to summary reports """ @@ -133,13 +133,12 @@ def execute(self, command, db, output, args=None, options=None, elif command == 'kraken-build': jellyfish_path = Jellyfish().install_and_get_path() env = os.environ.copy() - env['PATH'] = ':'.join([os.path.dirname(jellyfish_path), - env['PATH']]) - util.misc.run_and_print(cmd, env=env, check=True, silent=False) + env['PATH'] = ':'.join([os.path.dirname(jellyfish_path), env['PATH']]) + subprocess.check_call(cmd, env=env) else: with util.file.open_or_gzopen(output, 'w') as of: - util.misc.run(cmd, stdout=of, stderr=subprocess.PIPE, - check=True) + util.misc.run(cmd, stdout=of, stderr=subprocess.PIPE, check=True) + @tools.skip_install_test(condition=tools.is_osx()) class Jellyfish(Kraken): diff --git a/tools/krona.py b/tools/krona.py index d39cc82cf..3be4b5727 100644 --- a/tools/krona.py +++ b/tools/krona.py @@ -2,7 +2,6 @@ import os.path import subprocess from os.path import join -import util.misc from builtins import super TOOL_NAME = 'krona' @@ -55,7 +54,7 @@ def import_taxonomy(self, cmd.append('-k') cmd.extend(input_tsvs) - util.misc.run_and_print(cmd, env=env, check=True) + subprocess.check_call(cmd, env=env, check=True) def create_db(self, db_dir): """Caution - this deletes the original .dmp files.""" @@ -65,4 +64,4 @@ def create_db(self, db_dir): sh = join(self.opt, 'updateTaxonomy.sh') cmd = [sh, '--only-build', os.path.abspath(db_dir)] - util.misc.run_and_print(cmd, env=env, check=True) + subprocess.check_call(cmd, env=env, check=True) diff --git a/util/misc.py b/util/misc.py index 3eebf10fd..5a765eec3 100644 --- a/util/misc.py +++ b/util/misc.py @@ -209,9 +209,21 @@ def run_and_print(args, stdout=None, stderr=None, if not buffered: if check and not silent: try: - result = run(args, stdin=stdin, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, env=env, cwd=cwd, - timeout=timeout, check=check) + result = run( + args, + stdin=stdin, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + env=env, + cwd=cwd, + timeout=timeout, + check=check + ) + print(result.stdout.decode('utf-8')) + try: + print(result.stderr.decode('utf-8')) + except AttributeError: + pass except subprocess.CalledProcessError as e: if loglevel: try: