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

Fix incomplete_fov_check to not require a channel named Au #474

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/toffy/bin_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ def incomplete_fov_check(
run_file_path = os.path.join(bin_file_dir, run_name + ".json")
run_metadata = read_json_file(run_file_path, encoding="utf-8")

# get fov and channel info
fovs = io_utils.list_folders(extraction_dir, "fov")
# TODO: list_folders does not handle cases such as "fov0" correctly
# need to add a fix in to alpineer to deal with this
fovs = [f for f in os.listdir(extraction_dir) if "fov" in f]

# NOTE: the specifically-named "Au" channel is no longer be assumed to be present
# simply check the first "num_channels" channels found
channels = io_utils.list_files(os.path.join(extraction_dir, fovs[0]), ".tiff")
channels_subset = channels[:num_channels]
if "Au.tiff" not in channels_subset:
channels_subset = channels_subset[:-1] + ["Au.tiff"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noah specifically noted here that Au should always be a default channel when checking for incomplete fovs. So if some panels don't have gold, then we need this if statement to change instead of removing it completely.
if "Au.tiff" in channels and not in channels_subset:

Copy link
Contributor Author

@alex-l-kong alex-l-kong Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camisowers in line with adding an explicit argument to set intensity_channels to the callback creation function, what about adding another explicit argument defining a custom name for the gold channel? By default, it will be set to "Au", and even if the user leaves it as None, it'll still assume an "Au.tiff" is found.

In cases where some channels fail to load, instead of erroring out completely, check if the error is specifically caused by a failure to load in gold, and if so, throw a warning that the specific gold channel could not be located and to ask the user to double-check that this is indeed correct.


incomplete_fovs = {}
for fov in fovs:
Expand Down
14 changes: 13 additions & 1 deletion templates/3a_monitor_MIBI_run.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@
"log_path = os.path.join('C:\\\\Users\\\\Customer.ION\\\\Documents\\\\watcher_logs', run_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# define the specific channels you want to extract as intensity images, leave list empty if there are none\n",
"# NOTE: these must match names found in panel_path\n",
"intensity_channels = [\"Au\", \"chan_39\"]"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -125,6 +136,7 @@
" save_dir=metrics_plot_dir,\n",
" panel=panel,\n",
" warn_overwrite=False,\n",
" intensities=intensity_channels,\n",
")"
]
},
Expand Down Expand Up @@ -154,7 +166,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.9"
},
"vscode": {
"interpreter": {
Expand Down
28 changes: 25 additions & 3 deletions templates/3b_extract_images_from_bin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@
"The function below will skip any previously extracted FOVs and print \"Extraction completed!\" when done. If you receive a warning message stating \"no viable bin files were found\", then all of the necessary FOVs have already been extracted."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27887a2a-3dc7-4c7a-ac44-e404c29ff112",
"metadata": {},
"outputs": [],
"source": [
"# define the specific channels you want to extract as intensity images, leave list empty if there are none\n",
"# NOTE: these must match names found in panel_path\n",
"intensity_channels = [\"Au\", \"chan_39\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -106,11 +118,21 @@
"outputs": [],
"source": [
"# base deficient extraction\n",
"extract_missing_fovs(base_dir, extraction_dir, panel)\n",
"extract_missing_fovs(\n",
" base_dir,\n",
" extraction_dir,\n",
" panel,\n",
" extract_intensities=intensity_channels,\n",
")\n",
"\n",
"# mass proficient extraction (for long-term storage)\n",
"if extract_prof:\n",
" extract_missing_fovs(base_dir, extraction_prof_dir, modify_panel_ranges(panel, start_offset=0.3, stop_offset=0.3))"
" extract_missing_fovs(\n",
" base_dir,\n",
" extraction_prof_dir,\n",
" modify_panel_ranges(panel, start_offset=0.3, stop_offset=0.3),\n",
" extract_intensities=intensity_channels,\n",
" )"
]
},
{
Expand Down Expand Up @@ -149,7 +171,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
14 changes: 12 additions & 2 deletions tests/bin_extraction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,15 @@ def test_incomplete_fov_check():

# change fov-2 to have zero values in the bottom of image
fov2_data = load_utils.load_imgs_from_tree(extraction_dir, fovs=["fov-2-scan-1"])
fov2_data[:, 10:, :, 0] = 0
fov2_data_partial = fov2_data.copy()
fov2_data_partial[:, 10:, :, :] = 0
image_utils.save_image(
os.path.join(extraction_dir, "fov-2-scan-1", "Au.tiff"),
fov2_data.loc["fov-2-scan-1", :, :, "Au"],
fov2_data_partial.loc["fov-2-scan-1", :, :, "Au"],
)
image_utils.save_image(
os.path.join(extraction_dir, "fov-2-scan-1", "chan2.tiff"),
fov2_data_partial.loc["fov-2-scan-1", :, :, "chan2"],
)

# test warning for partial fovs (checking 1 channel img)
Expand All @@ -173,6 +178,11 @@ def test_incomplete_fov_check():
)

# test that increasing the number of channels to check causes no warning
# NOTE: this case specifically tests if only a subset of channels are partially imaged
image_utils.save_image(
os.path.join(extraction_dir, "fov-2-scan-1", "chan2.tiff"),
fov2_data.loc["fov-2-scan-1", :, :, "chan2"],
)
with warnings.catch_warnings():
warnings.simplefilter("error")
bin_extraction.incomplete_fov_check(
Expand Down
Loading