diff --git a/src/imcflibs/imagej/bioformats.py b/src/imcflibs/imagej/bioformats.py index 9ec73e5eb954f253e1c4eaf2ab14fce9118ac81d..1a9d12523d5a34e2fab6d0917a286f705c37b9a2 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 b9a5ce91d2acb79dff0929af5a879720ba51e94e..943157f1c3262b1a175754499db992271791ce67 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