Skip to content
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
2 changes: 2 additions & 0 deletions .github/scripts/check_heavy_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
"pytorch_lightning",
"segmentation_models_pytorch",
"streamlit",
"czifile",
# project modules that need the above
"src.lightning_module",
"src.unet_dataset",
"src.augmentation",
"src.czi_convert",
]

failures = []
Expand Down
100 changes: 98 additions & 2 deletions GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
load_channel_aliases_file,
set_channel_aliases,
)
from src.czi_convert import (
convert_all,
find_czi_files,
is_converted,
plan_sample,
)
from src.intensity_quant import (
BARRIER_TISSUES,
compute_threshold_percentile_suggestions,
Expand Down Expand Up @@ -526,11 +532,101 @@ def suggestions_panel(region, threshold_mode):
# -------------------------
# TABS
# -------------------------
tab_seg, tab_tune, tab_batch = st.tabs(
["1 · Segmentation", "2 · Threshold tuning", "3 · Batch & export"]
tab_files, tab_seg, tab_tune, tab_batch = st.tabs(
["0 · Get the right files", "1 · Segmentation", "2 · Threshold tuning", "3 · Batch & export"]
)


# =========================
# TAB 0: GET THE RIGHT FILES (.czi -> per-channel TIFFs)
# =========================
with tab_files:
st.markdown("### Get the right files")
st.caption(
"RADIX reads one TIFF per channel. If your images are Zeiss `.czi` files, this "
"finds them in the image folder (at its root or inside sample folders) and splits "
"them into DAPI / FITC / TRITC TIFFs. Your `.czi` files are never modified. "
"Pixel size and the original metadata are kept."
)

for _msg in st.session_state.pop("czi_flash", []):
_kind, _text = _msg
getattr(st, _kind)(_text)

_czis = find_czi_files(DATA_DIR)
if not _czis:
st.info(
f"No `.czi` files found in `{DATA_DIR}`. If your images are already TIFFs, skip to tab 1."
)
else:
_rows = []
for _c in _czis:
_out, _name = plan_sample(_c, DATA_DIR, _czis)
_rows.append(
{
".czi file": str(_c.relative_to(DATA_DIR)),
"Sample folder": _out.name,
"Status": "already converted" if is_converted(_out, _name) else "to convert",
}
)
_todo = sum(r["Status"] == "to convert" for r in _rows)
st.caption(f"{len(_czis)} `.czi` file(s) found, {_todo} still to convert.")
st.dataframe(pd.DataFrame(_rows), hide_index=True, width="stretch")

_zc, _oc = st.columns(2)
with _zc:
_z_mode = st.radio(
"Z-stacks",
["max", "keep"],
format_func=lambda m: (
"Max projection (recommended)" if m == "max" else "Keep every plane (3D)"
),
key="czi_z_mode",
help="The model works on flat 2D images, so z-stacks are flattened by default.",
)
with _oc:
_overwrite = st.checkbox(
"Redo files that are already converted",
value=False,
key="czi_overwrite",
)
st.caption(
"Channels are identified with the DAPI / FITC / TRITC names (including any you "
'added under "Channel file names" in the sidebar), then by emission wavelength.'
)

if st.button("Convert .czi files", type="primary", disabled=not (_todo or _overwrite)):
_bar = st.progress(0.0, text="Starting...")

def _progress(done, total, czi):
_bar.progress(
done / max(total, 1),
text=f"Converting {czi.name}..." if czi else "Done",
)

_results = convert_all(DATA_DIR, _z_mode, _overwrite, _progress)
_bar.empty()

_msgs = []
_ok = [r for r in _results if r.outputs]
if _ok:
_msgs.append(
(
"success",
f"Converted {len(_ok)} file(s) into "
f"{sum(len(r.outputs) for r in _ok)} channel TIFF(s).",
)
)
for _r in _results:
if _r.error:
_msgs.append(("error", f"`{_r.czi.name}` failed: {_r.error}"))
for _w in _r.warnings:
_msgs.append(("warning", f"`{_r.czi.name}`: {_w}"))
st.session_state["czi_flash"] = _msgs
scan_image_folders.clear()
st.rerun()


# =========================
# TAB 1: SEGMENTATION
# =========================
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ alternate names are also recognized:
| FITC | `FITC`, `GFP` |
| TRITC | `TRITC`, `RFP` |

**Have Zeiss `.czi` files instead?** Put them in the `data` folder (directly,
or inside a subfolder) and open the **0 · Get the right files** tab, then click
*Convert .czi files*. Each one is split into DAPI / FITC / TRITC TIFFs in its
own sample folder, with pixel size kept in the TIFFs and the full CZI metadata
saved next to them as `<sample>_czi_metadata.xml`. Your `.czi` files are not
changed. Z-stacks are flattened by max projection. The same conversion is
available from a terminal: `python czi_to_tiff.py data`.

A sample is skipped if all 3 channels aren't found — the app will tell you
which ones are missing. If your imaging setup produces a different channel
(e.g. brightfield) instead of one of the three above, contact Stefan before
Expand Down
57 changes: 57 additions & 0 deletions czi_to_tiff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Split Zeiss .czi files into per-channel TIFFs in the layout RADIX expects.

python czi_to_tiff.py data # every .czi under data/
python czi_to_tiff.py data --z keep --overwrite

Same conversion as the app's "0 · Get the right files" tab (see src/czi_convert.py).
Needs: pip install czifile
"""

import argparse
import sys
from pathlib import Path

from src.config import load_channel_aliases_file, set_channel_aliases
from src.czi_convert import convert_all, find_czi_files


def main():
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
p.add_argument("data_dir", type=Path, help="Folder with .czi files (root or in subfolders)")
p.add_argument("--z", choices=["max", "keep"], default="max", help="Z-stack handling")
p.add_argument("--overwrite", action="store_true", help="Redo files already converted")
for ch in ("dapi", "fitc", "tritc"):
p.add_argument(
f"--{ch}-name",
default=None,
help=f"Extra name(s) a CZI channel may have for {ch.upper()}, comma-separated.",
)
args = p.parse_args()

data_dir = args.data_dir.resolve()
aliases = load_channel_aliases_file(data_dir)
for ch in ("DAPI", "FITC", "TRITC"):
cli = getattr(args, f"{ch.lower()}_name")
if cli:
aliases[ch] = [s.strip() for s in cli.split(",") if s.strip()] + aliases.get(ch, [])
set_channel_aliases(aliases)

if not find_czi_files(data_dir):
sys.exit(f"No .czi files found under {data_dir}")

failed = 0
for r in convert_all(data_dir, args.z, args.overwrite):
if r.error:
failed += 1
print(f"FAILED {r.czi.name}: {r.error}")
elif r.skipped:
print(f"skipped {r.czi.name} ({r.skipped})")
else:
print(f"ok {r.czi.name} -> {len(r.outputs)} TIFF(s) in {r.outputs[0].parent}")
for w in r.warnings:
print(f" warning: {w}")
sys.exit(1 if failed else 0)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ click==8.5.1
colorama==0.4.6
contourpy==1.4.0
cycler==0.12.1
czifile==2026.11.26
fastremap==1.21.0
filelock==4.3.2
fill_voids==2.1.2
Expand Down
Loading
Loading