From 468b7953570d75c1de5a8d7c575eca180edf723f Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Wed, 9 Jan 2019 11:12:05 +0100
Subject: [PATCH] Add gen_name_from_orig() to pathtools

---
 src/imcflibs/imagej/bioformats.py |  4 ++--
 src/imcflibs/pathtools.py         | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/imcflibs/imagej/bioformats.py b/src/imcflibs/imagej/bioformats.py
index 9ec73e5..1a9d125 100644
--- a/src/imcflibs/imagej/bioformats.py
+++ b/src/imcflibs/imagej/bioformats.py
@@ -13,7 +13,7 @@ from ij import IJ
 from loci.plugins import BF
 from loci.plugins.in import ImporterOptions
 
-from ..pathtools import image_basename
+from ..pathtools import gen_name_from_orig
 from ..log import LOG as log
 
 
@@ -110,6 +110,6 @@ def export_using_orig_name(imp, path, orig_name, tag, suffix, overwrite=False):
     out_file : str
         The full name of the exported file.
     """
-    out_file = os.path.join(path, image_basename(orig_name) + tag + suffix)
+    out_file = gen_name_from_orig(path, orig_name, tag, suffix)
     export(imp, out_file, overwrite)
     return out_file
diff --git a/src/imcflibs/pathtools.py b/src/imcflibs/pathtools.py
index b9a5ce9..943157f 100644
--- a/src/imcflibs/pathtools.py
+++ b/src/imcflibs/pathtools.py
@@ -126,6 +126,30 @@ def image_basename(orig_name):
     return base
 
 
+def gen_name_from_orig(path, orig_name, tag, suffix):
+    """Derive a file name from a given input file, an optional tag and a suffix.
+
+    Parameters
+    ----------
+    path : str or object that can be cast to a str
+        The output path.
+    orig_name : str or object that can be cast to a str
+        The input file name, may contain arbitrary path components.
+    tag : str
+        An optional tag to be added at the end of the new file name, can be used
+        to denote information like "-avg" for an average projection image.
+    suffix : str
+        The new file name suffix, which also sets the file format for BF.
+
+    Returns
+    -------
+    out_file : str
+        The newly generated file name with its full path.
+    """
+    name = os.path.join(path, image_basename(orig_name) + tag + suffix)
+    return name
+
+
 # pylint: disable-msg=C0103
 #   we use the variable name 'exists' in its common spelling (lowercase), so
 #   removing this workaround will be straightforward at a later point
-- 
GitLab