diff --git a/cellacdc/__init__.py b/cellacdc/__init__.py index 98fa5184..aa32f5e6 100755 --- a/cellacdc/__init__.py +++ b/cellacdc/__init__.py @@ -7,6 +7,10 @@ import pathlib import numpy as np +KNOWN_EXTENSIONS = ( + '.tif', '.npz', '.npy', '.h5', '.json', '.csv', '.txt' +) + def user_data_dir(): r""" Get OS specific data directory path for Cell-ACDC. diff --git a/cellacdc/load.py b/cellacdc/load.py index da08968a..6e63a5bc 100755 --- a/cellacdc/load.py +++ b/cellacdc/load.py @@ -797,12 +797,23 @@ def get_endnames_from_basename(basename, filenames): return [os.path.splitext(f)[0][len(basename):] for f in filenames] def get_path_from_endname(end_name, images_path): + end_name, ext = myutils.remove_known_extension(end_name) + basename = os.path.commonprefix(myutils.listdir(images_path)) + searched_file = f'{basename}{end_name}{ext}' + for file in myutils.listdir(images_path): + filename, ext = os.path.splitext(file) + if file == searched_file: + return os.path.join(images_path, file), file + elif filename == searched_file: + return os.path.join(images_path, file), file + for file in myutils.listdir(images_path): filename, ext = os.path.splitext(file) if file.endswith(end_name): return os.path.join(images_path, file), file elif filename.endswith(end_name): return os.path.join(images_path, file), file + return '', '' def pd_int_to_bool(acdc_df, colsToCast=None): diff --git a/cellacdc/myutils.py b/cellacdc/myutils.py index 124fa1f8..b4199077 100644 --- a/cellacdc/myutils.py +++ b/cellacdc/myutils.py @@ -32,7 +32,7 @@ import skimage.io import skimage.measure -from . import GUI_INSTALLED +from . import GUI_INSTALLED, KNOWN_EXTENSIONS if GUI_INSTALLED: from qtpy.QtWidgets import QMessageBox @@ -133,6 +133,13 @@ def get_salute_string(): else: return 'Have a good night!' +def remove_known_extension(name): + for ext in KNOWN_EXTENSIONS: + if name.endswith(ext): + return name[:-len(ext)], ext + + return name, '' + def getCustomAnnotTooltip(annotState): toolTip = ( f'Name: {annotState["name"]}\n\n'