Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list_files returns inappropriate fov files #41

Closed
bryjcannon opened this issue Jan 3, 2024 · 1 comment · Fixed by #42
Closed

list_files returns inappropriate fov files #41

bryjcannon opened this issue Jan 3, 2024 · 1 comment · Fixed by #42
Assignees
Labels
bug Something isn't working

Comments

@bryjcannon
Copy link
Collaborator

bryjcannon commented Jan 3, 2024

Please refer to our FAQ and look at our known issues before opening a bug report.

Describe the bug
Screenshot 2024-01-03 at 3 17 03 PM
When trying to run segmentation, an error propped up where a mask file that didn't exist was being loaded for csv writing. After troubleshooting, the problem occurs in alpineer's io_utils.list_files code. In this example, while only file names with 'R6C1' were desired, files with R6C10' were also being extracted due to the way io_utils.list_files` matches substrings in file names.

Expected behavior
io_utils.list_files currently finds files using the code below based on a matching substring (substr)
matches = [file for file in files if any([substr in file for substr in substrs])] -> will return files with both 'R6C1' and 'R6C10'

To Reproduce
Ping me for access to my mask files.

@bryjcannon bryjcannon added the bug Something isn't working label Jan 3, 2024
@bryjcannon
Copy link
Collaborator Author

bryjcannon commented Jan 3, 2024

Proposed solution below:
Change the current list comprehension in io_utils.list_files from the below:
matches = [file for file in files if any([substr in file for substr in substrs])]
To this regular expression which uses a word boundary instead of string matching alone to find the desired files.

    # Create a regular expression pattern from substrs with word boundaries
    pattern = '|'.join(re.escape(substr) + r'\b' for substr in substrs)

    # Use re.search to check if any of the substrings exactly match in the file names
    matches = [file for file in files if re.search(pattern, file)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant