Permalink
Browse files

Decorator to handle checking for presence of output file

  • Loading branch information...
1 parent 1495abf commit 7e54fb70231b3655468f42c580b841543ff6ede1 @chapmanb committed May 18, 2011
Showing with 24 additions and 0 deletions.
  1. +1 −0 biostar/findorf/src/findorf/core.clj
  2. +23 −0 nextgen/bcbio/utils.py
@@ -36,6 +36,7 @@
(defn tx-sqn-frame [dna frame]
"Longest transcribed region within a given translation frame."
(let [tx-engine (-> (TranscriptionEngine$Builder.)
+ (.translateNCodons true)
(.trimStop false)
(.build))
dna-coords (fn [coords]
View
@@ -60,6 +60,29 @@ def wrapper(*args, **kwargs):
return apply(f, *args, **kwargs)
return wrapper
+def memoize_outfile(ext):
+ """Creates outfile from input file and ext, running if outfile not present.
+
+ This requires a standard function usage. The first arg, or kwarg 'in_file', needs
+ to be the input file that is being processed. The output name is created with the
+ provided ext relative to the input. The function is only run if the created
+ out_file is not present.
+ """
+ def decor(f):
+ @functools.wraps(f)
+ def wrapper(*args, **kwargs):
+ if len(args) > 0:
+ in_file = args[0]
+ else:
+ in_file = kwargs['in_file']
+ out_file = "%s%s" % (os.path.splitext(in_file)[0], ext)
+ if not os.path.exists(out_file) or os.path.getsize(out_file) == 0:
+ kwargs['out_file'] = out_file
+ f(*args, **kwargs)
+ return out_file
+ return wrapper
+ return decor
+
@contextlib.contextmanager
def curdir_tmpdir():
"""Context manager to create and remove a temporary directory.

0 comments on commit 7e54fb7

Please sign in to comment.