-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update baseimage to 0.1.17; move some code from assembly.py and inter…
…host.py into util.file and util.misc
- Loading branch information
Showing
5 changed files
with
64 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM quay.io/broadinstitute/viral-baseimage:0.1.16 | ||
FROM quay.io/broadinstitute/viral-baseimage:0.1.17 | ||
|
||
LABEL maintainer "[email protected]" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,18 @@ | |
import time | ||
|
||
import util.file | ||
from subprocess import run | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
__author__ = "[email protected]" | ||
|
||
MAX_INT32 = (2 ** 31)-1 | ||
|
||
def unambig_count(seq): | ||
unambig = set(('A', 'T', 'C', 'G')) | ||
return sum(1 for s in seq if s.upper() in unambig) | ||
|
||
@contextlib.contextmanager | ||
def timer(prefix): | ||
start = time.time() | ||
|
@@ -144,84 +149,6 @@ def list_contains(sublist, list_): | |
return False | ||
|
||
|
||
try: | ||
from subprocess import run | ||
except ImportError: | ||
CompletedProcess = collections.namedtuple( | ||
'CompletedProcess', ['args', 'returncode', 'stdout', 'stderr']) | ||
|
||
def run(args, stdin=None, stdout=None, stderr=None, shell=False, | ||
env=None, cwd=None, timeout=None, check=False, executable=None): | ||
'''A poor man's substitute of python 3.5's subprocess.run(). | ||
Should only be used for capturing stdout. If stdout is unneeded, a | ||
simple subprocess.call should suffice. | ||
''' | ||
assert stdout is not None, ( | ||
'Why are you using this util function if not capturing stdout?') | ||
|
||
stdout_pipe = stdout == subprocess.PIPE | ||
stderr_pipe = stderr == subprocess.PIPE | ||
# A little optimization when we don't need temporary files. | ||
if stdout_pipe and ( | ||
stderr == subprocess.STDOUT or stderr is None): | ||
try: | ||
output = subprocess.check_output( | ||
args, stdin=stdin, stderr=stderr, shell=shell, | ||
env=env, cwd=cwd, executable=executable) | ||
return CompletedProcess(args, 0, output, b'') | ||
# Py3.4 doesn't have stderr attribute | ||
except subprocess.CalledProcessError as e: | ||
if check: | ||
raise | ||
returncode = e.returncode | ||
stderr_text = getattr(e, 'stderr', b'') | ||
return CompletedProcess(args, e.returncode, e.output, stderr_text) | ||
|
||
# Otherwise use temporary files as buffers, since subprocess.call | ||
# cannot use PIPE. | ||
if stdout_pipe: | ||
stdout_fn = util.file.mkstempfname('.stdout') | ||
stdout = open(stdout_fn, 'wb') | ||
if stderr_pipe: | ||
stderr_fn = util.file.mkstempfname('.stderr') | ||
stderr = open(stderr_fn, 'wb') | ||
try: | ||
returncode = subprocess.call( | ||
args, stdin=stdin, stdout=stdout, | ||
stderr=stderr, shell=shell, env=env, cwd=cwd, | ||
executable=executable) | ||
if stdout_pipe: | ||
stdout.close() | ||
with open(stdout_fn, 'rb') as f: | ||
output = f.read() | ||
else: | ||
output = '' | ||
if stderr_pipe: | ||
stderr.close() | ||
with open(stderr_fn, 'rb') as f: | ||
error = f.read() | ||
else: | ||
error = '' | ||
if check and returncode != 0: | ||
print(output.decode("utf-8")) | ||
print(error.decode("utf-8")) | ||
try: | ||
raise subprocess.CalledProcessError( | ||
returncode, args, output, error) #pylint: disable-msg=E1121 | ||
except TypeError: # py2 CalledProcessError does not accept error | ||
raise subprocess.CalledProcessError( | ||
returncode, args, output) | ||
return CompletedProcess(args, returncode, output, error) | ||
finally: | ||
if stdout_pipe: | ||
stdout.close() | ||
os.remove(stdout_fn) | ||
if stderr_pipe: | ||
stderr.close() | ||
os.remove(stderr_fn) | ||
|
||
|
||
def run_and_print(args, stdout=None, stderr=subprocess.STDOUT, | ||
stdin=None, shell=False, env=None, cwd=None, | ||
timeout=None, silent=False, buffered=False, check=False, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,27 +5,7 @@ | |
|
||
__author__ = "[email protected], [email protected]" | ||
|
||
try: | ||
# Python 3.4 | ||
from statistics import mean, median | ||
except ImportError: | ||
# Python <3.4, avoid numpy if these two methods are all we really need | ||
def mean(l): | ||
if len(l) > 0: | ||
return float(sum(l)) / len(l) | ||
else: | ||
raise Exception("empty list for mean") | ||
|
||
def median(l): | ||
if len(l) > 0: | ||
half = len(l) // 2 | ||
l.sort() | ||
if len(l) % 2 == 0: | ||
return (l[half - 1] + l[half]) / 2.0 | ||
else: | ||
return l[half] | ||
else: | ||
raise Exception("empty list for median") | ||
from statistics import mean, median | ||
|
||
|
||
def product(iterable): | ||
|