Metadata-Version: 2.4
Name: crc-mets-vis
Version: 0.1.4
Summary: CRC metastasis explorer: Streamlit app with a custom D3 component (overview matrix, organ combinations with survival, swimmer plot).
Author: Visual Intelligence Lab, University of Minnesota
License-Expression: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: streamlit>=1.40
Requires-Dist: pandas>=2.0
Requires-Dist: numpy>=1.24

# crc-mets-vis: CRC metastasis explorer

A Streamlit app with a custom D3 component, organized as overview → explore → details:

1. **Who has metastases?** A matrix of any two attributes (default: primary site group × race/ethnicity).
   Each bar shows the share of the cell's patients with metastasis, split into *at diagnosis*
   (first metastasis within N days, set in the sidebar) and *found later*. The whisker is the
   95% CI and the dashed tick is the rate for all patients.
2. **Which organs, and how do patients fare?** A transposed UpSet plot for the selected cell.
   Each row is one organ combination with its patient count (at diagnosis / later) and a
   survival curve measured from the first metastasis, drawn against all metastatic patients.
   The bars above the organ columns show 1-year survival by organ involved.
3. **Patients.** A swimmer plot for the clicked combination: one lane per patient, with
   organ markers at the time of each metastasis and follow-up ending in death (×) or alive (›).

Groups smaller than **Hide counts below** (sidebar; default 11, the SEER-Medicare rule) are hidden in
every view. Lower it only for exploring; anything shared must use at least 11.

## Which data file is used

1. `--data <folder>` / `--file <csv>` given to `crc-mets-vis run` (the launcher does this)
2. otherwise `DATA_FILE` at the top of `src/crc_mets_vis/app.py` (default `None`)

There is no fallback: without a defined file the app shows nothing. The sidebar always
shows which file is loaded.

## Layout

```
crc-mets-vis/                      (same layout as the project folder in the secure environment)
├── final_CRC_mets_full.csv        (the app reads this file)
└── vis-app/
    ├── app.py                     dev entry: streamlit run app.py
    ├── make_synthetic_data.py     writes fake CSVs to ../
    ├── pyproject.toml             package metadata (name on PyPI: crc-mets-vis)
    └── src/crc_mets_vis/
        ├── app.py                 the Streamlit page
        ├── analysis.py            loading, summaries, small-cell rule, Kaplan-Meier
        ├── attributes.py          attribute bins / labels / order  <- edit here
        ├── cli.py                 crc-mets-vis run | make-launcher | demo-data
        ├── synth.py               synthetic data generator
        └── component/frontend/    index.html, main.js, style.css, d3.v7.min.js
```

## Develop locally

```bash
cd vis-app
conda create -y -n crcvis python=3.12 && conda activate crcvis
python -m pip install -e .
python make_synthetic_data.py      # fake data in ../ (no real patients)
python -m streamlit run app.py
```

After editing `analysis.py` or `attributes.py`, press **C** in the app (clear cache) or restart.

## Publish to PyPI (no file transfer needed)

```bash
python -m pip install build twine
# bump __version__ in src/crc_mets_vis/__init__.py first
python -m build                     # -> dist/*.whl, dist/*.tar.gz
python -m twine upload dist/*       # username: __token__, password: your PyPI API token
```

The package contains code only, never data. It's public once uploaded.

## Install in a secure environment (once)

In **Anaconda Prompt** inside the secure environment (set `DATA` to the folder that holds
`final_CRC_mets_full.csv`):

```bat
set DATA=<project folder>
C:\ProgramData\anaconda3\python.exe -m venv "%DATA%\crcvis-env"
"%DATA%\crcvis-env\Scripts\python.exe" -m pip install crc-mets-vis
"%DATA%\crcvis-env\Scripts\python.exe" -m crc_mets_vis make-launcher --data "%DATA%"
```

This writes two files next to the data:

- **Open CRC metastasis explorer.bat**: double-click to start the app. A browser tab opens, and
  closing the black window stops the app.
- **Update CRC metastasis explorer.bat**: double-click to install the newest version from PyPI.

The launcher calls the environment's Python by its full path, so users never activate anything.
Each user gets their own free port, so several people can use it at once on the shared desktop.
If pip can't reach PyPI, set your environment's proxy first (`set HTTPS_PROXY=...` and `HTTP_PROXY`).
