Skip to content

Commit

Permalink
fix: correctly get the file from endname
Browse files Browse the repository at this point in the history
  • Loading branch information
ElpadoCan committed Apr 25, 2024
1 parent e20e0ed commit 2582947
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cellacdc/__init__.py
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions cellacdc/load.py
Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion cellacdc/myutils.py
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 2582947

Please sign in to comment.