deepaft 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deepaft-0.1.0/LICENSE +21 -0
- deepaft-0.1.0/PKG-INFO +215 -0
- deepaft-0.1.0/README.md +177 -0
- deepaft-0.1.0/pyproject.toml +51 -0
- deepaft-0.1.0/setup.cfg +4 -0
- deepaft-0.1.0/src/deepaft/__init__.py +25 -0
- deepaft-0.1.0/src/deepaft/censoring.py +264 -0
- deepaft-0.1.0/src/deepaft/diagnostics.py +60 -0
- deepaft-0.1.0/src/deepaft/estimator.py +367 -0
- deepaft-0.1.0/src/deepaft/limitations.py +10 -0
- deepaft-0.1.0/src/deepaft/methods.py +76 -0
- deepaft-0.1.0/src/deepaft/metrics.py +80 -0
- deepaft-0.1.0/src/deepaft/model.py +72 -0
- deepaft-0.1.0/src/deepaft/predict.py +114 -0
- deepaft-0.1.0/src/deepaft/simulate.py +146 -0
- deepaft-0.1.0/src/deepaft.egg-info/PKG-INFO +215 -0
- deepaft-0.1.0/src/deepaft.egg-info/SOURCES.txt +21 -0
- deepaft-0.1.0/src/deepaft.egg-info/dependency_links.txt +1 -0
- deepaft-0.1.0/src/deepaft.egg-info/requires.txt +23 -0
- deepaft-0.1.0/src/deepaft.egg-info/top_level.txt +1 -0
- deepaft-0.1.0/tests/test_censoring.py +39 -0
- deepaft-0.1.0/tests/test_estimator.py +73 -0
- deepaft-0.1.0/tests/test_simulate.py +19 -0
deepaft-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Swati
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
deepaft-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deepaft
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python deepAFT: nonlinear accelerated failure time models with neural networks (Norman et al. 2024) and limitation-aware extensions for censored survival data.
|
|
5
|
+
Author: Swati
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/swatipriyadarshini9/deepaft
|
|
8
|
+
Project-URL: Documentation, https://github.com/swatipriyadarshini9/deepaft#readme
|
|
9
|
+
Keywords: survival-analysis,accelerated-failure-time,deep-learning,censoring
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: numpy>=1.24
|
|
18
|
+
Requires-Dist: scipy>=1.11
|
|
19
|
+
Requires-Dist: pandas>=2.0
|
|
20
|
+
Requires-Dist: torch>=2.0
|
|
21
|
+
Requires-Dist: scikit-learn>=1.3
|
|
22
|
+
Provides-Extra: metrics
|
|
23
|
+
Requires-Dist: scikit-survival>=0.22; extra == "metrics"
|
|
24
|
+
Requires-Dist: lifelines>=0.28; extra == "metrics"
|
|
25
|
+
Provides-Extra: experiments
|
|
26
|
+
Requires-Dist: scikit-survival>=0.22; extra == "experiments"
|
|
27
|
+
Requires-Dist: lifelines>=0.28; extra == "experiments"
|
|
28
|
+
Requires-Dist: requests>=2.31; extra == "experiments"
|
|
29
|
+
Requires-Dist: openpyxl>=3.1; extra == "experiments"
|
|
30
|
+
Requires-Dist: matplotlib>=3.7; extra == "experiments"
|
|
31
|
+
Requires-Dist: nibabel>=5.0; extra == "experiments"
|
|
32
|
+
Requires-Dist: pyradiomics>=3.1; extra == "experiments"
|
|
33
|
+
Requires-Dist: synapseclient>=4.0; extra == "experiments"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.1; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# deepaft: Deep Accelerated Failure Time Models for Glioma Survival
|
|
40
|
+
|
|
41
|
+
[](LICENSE)
|
|
42
|
+
[](https://www.python.org/downloads/)
|
|
43
|
+
|
|
44
|
+
MSc dissertation repository: **first Python implementation** of Norman et al. (2024) deepAFT, plus **limitation-aware extensions**, evaluated primarily on **TCGA** adult glioma (GDC survival + Xena gene expression). BraTS 2024 GLI is **optional** imaging context: the public release **does not** ship a BraTS↔TCGA crosswalk, so the **degree results do not depend** on linking BraTS cases to TCGA.
|
|
45
|
+
|
|
46
|
+
**Agent setup:** See [AGENTS.md](AGENTS.md) and [.cursor/LINKS.md](.cursor/LINKS.md) for linked rules, skills, hooks, subagents, MCPs, and [PROJECT_TASKS.md](PROJECT_TASKS.md) for milestones. **Thesis handoff:** [docs/thesis_submission_checklist.md](docs/thesis_submission_checklist.md), optional BraTS imaging notes: [docs/optional_brats_imaging_chapter.md](docs/optional_brats_imaging_chapter.md), gaps/optional work: [docs/project_gaps_and_remaining.md](docs/project_gaps_and_remaining.md).
|
|
47
|
+
|
|
48
|
+
> **Original method (reproduced):** Norman, Li, Jiang, Chen — [*deepAFT: A nonlinear accelerated failure time model with artificial neural network*](https://doi.org/10.1002/sim.10152), *Statistics in Medicine* 2024. Official R code: [`dnn::deepAFT`](https://CRAN.R-project.org/package=dnn).
|
|
49
|
+
>
|
|
50
|
+
> **This repository adds:** Python package, covariate-aware censoring, degeneracy guards, heteroscedastic scale, and a TCGA glioma benchmark pipeline; BraTS radiomics scripts are **optional** (future / supplementary).
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## What is reproduced vs contributed
|
|
55
|
+
|
|
56
|
+
| Component | Status | Notes |
|
|
57
|
+
|-----------|--------|-------|
|
|
58
|
+
| \(\log \tilde T = \mu(z) + \varepsilon\), ReLU network for \(\mu(z)\) | **Reproduced** | Norman Eq. (1), Section 2.1 |
|
|
59
|
+
| Buckley–James imputation + MSE | **Reproduced** | `method="buckley_james"` |
|
|
60
|
+
| IPCW adjusted MSE | **Reproduced** | `method="ipcw"`, Eq. (4) |
|
|
61
|
+
| Fan–Gijbels transform + MSE | **Reproduced** | `method="transform"` |
|
|
62
|
+
| \(S(t\mid z) = \hat S_0(t e^{-\hat\mu})\) | **Reproduced** | Eq. (5) |
|
|
63
|
+
| Covariate-aware \(\hat G(t\mid z)\) | **Contributed** | `censoring="covariate"` |
|
|
64
|
+
| Degeneracy guard for IPCW/Transform | **Contributed** | Auto-fallback to Buckley–James |
|
|
65
|
+
| Group/network residual scale \(\sigma(z)\) | **Contributed** | `scale="group"` / `"network"` |
|
|
66
|
+
| TCGA + GDC / Xena glioma benchmark pipeline | **Contributed** | `experiments/` (not on PyPI) |
|
|
67
|
+
| Optional BraTS radiomics + merge scripts | **Contributed** | Requires imaging + valid crosswalk; not a thesis dependency here |
|
|
68
|
+
|
|
69
|
+
**Results (measured, not fabricated):**
|
|
70
|
+
- Simulation: [results/tables/simulation_chapter_summary.csv](results/tables/simulation_chapter_summary.csv)
|
|
71
|
+
- TCGA glioma (671 cases, IDH1/MGMT/TP53): [results/tables/glioma_benchmark.csv](results/tables/glioma_benchmark.csv) — deepAFT_BJ_group C-index 0.751 ± 0.019
|
|
72
|
+
- Thesis summary: [results/thesis_results.md](results/thesis_results.md)
|
|
73
|
+
- Simulation chapter: R=50 all scenarios in [thesis_results.md](results/thesis_results.md)
|
|
74
|
+
- BraTS radiomics: **optional** — public BraTS 2024 materials lack a TCGA mapping; full zip extract needs ~40+ GB free. Thesis claims rest on **TCGA-only** tables above.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Quick start (Python package)
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
cd "MSc. Dissertation"
|
|
82
|
+
pip install -e ".[dev]"
|
|
83
|
+
pytest
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
import numpy as np
|
|
88
|
+
from deepaft import DeepAFT, scenario_a, harrell_c_index
|
|
89
|
+
|
|
90
|
+
X, time, event = scenario_a(n=300, seed=42)
|
|
91
|
+
|
|
92
|
+
# Norman et al. (2024) — iterative Buckley–James
|
|
93
|
+
model = DeepAFT(method="buckley_james", hidden=(8, 6), epochs=100)
|
|
94
|
+
model.fit(X, time, event)
|
|
95
|
+
|
|
96
|
+
pred_time = model.predict_time(X)
|
|
97
|
+
print("C-index:", harrell_c_index(pred_time, time, event))
|
|
98
|
+
|
|
99
|
+
# Limitation-aware — covariate-dependent censoring + group scale
|
|
100
|
+
from deepaft.simulate import scenario_d
|
|
101
|
+
X, time, event, groups = scenario_d(n=300, seed=0)
|
|
102
|
+
model2 = DeepAFT(
|
|
103
|
+
method="buckley_james",
|
|
104
|
+
censoring="covariate",
|
|
105
|
+
scale="group",
|
|
106
|
+
hidden=(8, 6),
|
|
107
|
+
)
|
|
108
|
+
model2.fit(X, time, event, groups=groups)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### API summary
|
|
112
|
+
|
|
113
|
+
| Parameter | Values | Description |
|
|
114
|
+
|-----------|--------|-------------|
|
|
115
|
+
| `method` | `buckley_james`, `ipcw`, `transform` | Norman (2024) censoring strategies |
|
|
116
|
+
| `censoring` | `marginal`, `covariate` | \(\hat G(t)\) vs \(\hat G(t\mid z)\) |
|
|
117
|
+
| `scale` | `constant`, `group`, `network` | Shared vs heteroscedastic residuals |
|
|
118
|
+
| `auto_fallback` | `True` / `False` | IPCW/Transform → BJ when \(\hat G\) degenerate |
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Repository layout
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
MSc. Dissertation/
|
|
126
|
+
├── src/deepaft/ # Installable PyPI package
|
|
127
|
+
│ ├── estimator.py # DeepAFT class
|
|
128
|
+
│ ├── censoring.py # KM, BJ imputation, IPCW weights
|
|
129
|
+
│ ├── methods.py # Training targets / losses
|
|
130
|
+
│ ├── predict.py # S(t|z), RMST, median
|
|
131
|
+
│ ├── metrics.py # C-index, AMSE, IBS
|
|
132
|
+
│ ├── simulate.py # Scenarios A–D
|
|
133
|
+
│ └── diagnostics.py # PH test, method selection
|
|
134
|
+
├── tests/ # pytest (scenarios A–D)
|
|
135
|
+
├── experiments/ # Dissertation-only (BraTS, OncoLnc, GNN)
|
|
136
|
+
├── pyproject.toml
|
|
137
|
+
├── CITATION.cff
|
|
138
|
+
└── README.md
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Dissertation pipeline (experiments/)
|
|
144
|
+
|
|
145
|
+
### 1. Data (before any model)
|
|
146
|
+
|
|
147
|
+
| Source | Role | Survival labels? |
|
|
148
|
+
|--------|------|------------------|
|
|
149
|
+
| [BraTS 2024 GLI](https://www.synapse.org/Synapse:syn51156910) | MRI + segmentation (T1n, T1c, T2w, T2-FLAIR; ET, NET, ED) | **No OS in release** |
|
|
150
|
+
| [GDC TCGA](https://portal.gdc.cancer.gov/) | LGG + GBM clinical OS / days | **Yes** |
|
|
151
|
+
| [OncoLnc](http://www.oncolnc.org/) | Gene expression (IDH1, MGMT, TP53, …) | Use GDC for vital status (2016 freeze is stale for GBM) |
|
|
152
|
+
|
|
153
|
+
**Thesis analysis set:** TCGA cases with GDC survival + gene expression (`tcga_glioma_cohort.csv`). BraTS nested cohorts apply only if you obtain a valid BraTS↔TCGA table for your imaging year.
|
|
154
|
+
|
|
155
|
+
### 2. Simulation chapter (package `tests/` + notebook)
|
|
156
|
+
|
|
157
|
+
- **A:** Nonlinear AFT, independent censoring (Norman Eq. 6)
|
|
158
|
+
- **B:** Censoring depends on covariate → test `censoring="covariate"`
|
|
159
|
+
- **C:** Administrative censoring → IPCW/Transform fallback
|
|
160
|
+
- **D:** LGG/GBM-like heteroscedastic scale → test `scale="group"`
|
|
161
|
+
|
|
162
|
+
### 3. Real-data models
|
|
163
|
+
|
|
164
|
+
Same folds for all: Cox, log-normal AFT, RSF, DeepSurv, DeepAFT (chosen variant).
|
|
165
|
+
|
|
166
|
+
Features (thesis): pre-specified genes on TCGA. Optional extensions: BraTS radiomics or genes+radiomics **only** with an organizer crosswalk.
|
|
167
|
+
|
|
168
|
+
Metrics: Harrell C, Uno C, IPCW-AMSE, integrated Brier score, calibration slope. Run Grambsch–Therneau PH test before preferring AFT over Cox.
|
|
169
|
+
|
|
170
|
+
### 4. Optional segmentation chapter
|
|
171
|
+
|
|
172
|
+
U-Net / Mask R-CNN on BraTS if required by supervisor — **separate** from survival claim. Do not feed predicted masks into survival until Dice is validated.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Publishing to PyPI
|
|
177
|
+
|
|
178
|
+
Full credential setup (tokens, `%USERPROFILE%\.pypirc`, TestPyPI): [docs/pypi_credentials.md](docs/pypi_credentials.md).
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
pip install build twine
|
|
182
|
+
python -m build
|
|
183
|
+
twine upload --repository testpypi dist/*
|
|
184
|
+
# after verification:
|
|
185
|
+
twine upload dist/*
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Replace **`your-username`** in `pyproject.toml` and `CITATION.cff`: [docs/github_repo_urls.md](docs/github_repo_urls.md).
|
|
189
|
+
|
|
190
|
+
Package name: `deepaft`. BraTS/OncoLnc loaders stay in `experiments/` (CC BY-NC-SA, TCGA publication rules).
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Citing
|
|
195
|
+
|
|
196
|
+
```bibtex
|
|
197
|
+
@article{norman2024deepaft,
|
|
198
|
+
title = {deepAFT: A nonlinear accelerated failure time model with artificial neural network},
|
|
199
|
+
author = {Norman, Patrick A. and Li, Wanlu and Jiang, Wenyu and Chen, Bingshu E.},
|
|
200
|
+
journal = {Statistics in Medicine},
|
|
201
|
+
volume = {43},
|
|
202
|
+
number = {19},
|
|
203
|
+
pages = {3689--3701},
|
|
204
|
+
year = {2024},
|
|
205
|
+
doi = {10.1002/sim.10152}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
If you use this Python package or the glioma extensions, also cite this repository (see `CITATION.cff`).
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
MIT for this Python code. Independent reimplementation — not a port of GPL R `dnn`. BraTS data: Synapse DUA / CC BY-NC-SA. TCGA: [publication guidelines](https://www.cancer.gov/about-nci/organization/ccg/research/structural-genomics/tcga/history/policies).
|
deepaft-0.1.0/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# deepaft: Deep Accelerated Failure Time Models for Glioma Survival
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
|
|
6
|
+
MSc dissertation repository: **first Python implementation** of Norman et al. (2024) deepAFT, plus **limitation-aware extensions**, evaluated primarily on **TCGA** adult glioma (GDC survival + Xena gene expression). BraTS 2024 GLI is **optional** imaging context: the public release **does not** ship a BraTS↔TCGA crosswalk, so the **degree results do not depend** on linking BraTS cases to TCGA.
|
|
7
|
+
|
|
8
|
+
**Agent setup:** See [AGENTS.md](AGENTS.md) and [.cursor/LINKS.md](.cursor/LINKS.md) for linked rules, skills, hooks, subagents, MCPs, and [PROJECT_TASKS.md](PROJECT_TASKS.md) for milestones. **Thesis handoff:** [docs/thesis_submission_checklist.md](docs/thesis_submission_checklist.md), optional BraTS imaging notes: [docs/optional_brats_imaging_chapter.md](docs/optional_brats_imaging_chapter.md), gaps/optional work: [docs/project_gaps_and_remaining.md](docs/project_gaps_and_remaining.md).
|
|
9
|
+
|
|
10
|
+
> **Original method (reproduced):** Norman, Li, Jiang, Chen — [*deepAFT: A nonlinear accelerated failure time model with artificial neural network*](https://doi.org/10.1002/sim.10152), *Statistics in Medicine* 2024. Official R code: [`dnn::deepAFT`](https://CRAN.R-project.org/package=dnn).
|
|
11
|
+
>
|
|
12
|
+
> **This repository adds:** Python package, covariate-aware censoring, degeneracy guards, heteroscedastic scale, and a TCGA glioma benchmark pipeline; BraTS radiomics scripts are **optional** (future / supplementary).
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## What is reproduced vs contributed
|
|
17
|
+
|
|
18
|
+
| Component | Status | Notes |
|
|
19
|
+
|-----------|--------|-------|
|
|
20
|
+
| \(\log \tilde T = \mu(z) + \varepsilon\), ReLU network for \(\mu(z)\) | **Reproduced** | Norman Eq. (1), Section 2.1 |
|
|
21
|
+
| Buckley–James imputation + MSE | **Reproduced** | `method="buckley_james"` |
|
|
22
|
+
| IPCW adjusted MSE | **Reproduced** | `method="ipcw"`, Eq. (4) |
|
|
23
|
+
| Fan–Gijbels transform + MSE | **Reproduced** | `method="transform"` |
|
|
24
|
+
| \(S(t\mid z) = \hat S_0(t e^{-\hat\mu})\) | **Reproduced** | Eq. (5) |
|
|
25
|
+
| Covariate-aware \(\hat G(t\mid z)\) | **Contributed** | `censoring="covariate"` |
|
|
26
|
+
| Degeneracy guard for IPCW/Transform | **Contributed** | Auto-fallback to Buckley–James |
|
|
27
|
+
| Group/network residual scale \(\sigma(z)\) | **Contributed** | `scale="group"` / `"network"` |
|
|
28
|
+
| TCGA + GDC / Xena glioma benchmark pipeline | **Contributed** | `experiments/` (not on PyPI) |
|
|
29
|
+
| Optional BraTS radiomics + merge scripts | **Contributed** | Requires imaging + valid crosswalk; not a thesis dependency here |
|
|
30
|
+
|
|
31
|
+
**Results (measured, not fabricated):**
|
|
32
|
+
- Simulation: [results/tables/simulation_chapter_summary.csv](results/tables/simulation_chapter_summary.csv)
|
|
33
|
+
- TCGA glioma (671 cases, IDH1/MGMT/TP53): [results/tables/glioma_benchmark.csv](results/tables/glioma_benchmark.csv) — deepAFT_BJ_group C-index 0.751 ± 0.019
|
|
34
|
+
- Thesis summary: [results/thesis_results.md](results/thesis_results.md)
|
|
35
|
+
- Simulation chapter: R=50 all scenarios in [thesis_results.md](results/thesis_results.md)
|
|
36
|
+
- BraTS radiomics: **optional** — public BraTS 2024 materials lack a TCGA mapping; full zip extract needs ~40+ GB free. Thesis claims rest on **TCGA-only** tables above.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Quick start (Python package)
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
cd "MSc. Dissertation"
|
|
44
|
+
pip install -e ".[dev]"
|
|
45
|
+
pytest
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import numpy as np
|
|
50
|
+
from deepaft import DeepAFT, scenario_a, harrell_c_index
|
|
51
|
+
|
|
52
|
+
X, time, event = scenario_a(n=300, seed=42)
|
|
53
|
+
|
|
54
|
+
# Norman et al. (2024) — iterative Buckley–James
|
|
55
|
+
model = DeepAFT(method="buckley_james", hidden=(8, 6), epochs=100)
|
|
56
|
+
model.fit(X, time, event)
|
|
57
|
+
|
|
58
|
+
pred_time = model.predict_time(X)
|
|
59
|
+
print("C-index:", harrell_c_index(pred_time, time, event))
|
|
60
|
+
|
|
61
|
+
# Limitation-aware — covariate-dependent censoring + group scale
|
|
62
|
+
from deepaft.simulate import scenario_d
|
|
63
|
+
X, time, event, groups = scenario_d(n=300, seed=0)
|
|
64
|
+
model2 = DeepAFT(
|
|
65
|
+
method="buckley_james",
|
|
66
|
+
censoring="covariate",
|
|
67
|
+
scale="group",
|
|
68
|
+
hidden=(8, 6),
|
|
69
|
+
)
|
|
70
|
+
model2.fit(X, time, event, groups=groups)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### API summary
|
|
74
|
+
|
|
75
|
+
| Parameter | Values | Description |
|
|
76
|
+
|-----------|--------|-------------|
|
|
77
|
+
| `method` | `buckley_james`, `ipcw`, `transform` | Norman (2024) censoring strategies |
|
|
78
|
+
| `censoring` | `marginal`, `covariate` | \(\hat G(t)\) vs \(\hat G(t\mid z)\) |
|
|
79
|
+
| `scale` | `constant`, `group`, `network` | Shared vs heteroscedastic residuals |
|
|
80
|
+
| `auto_fallback` | `True` / `False` | IPCW/Transform → BJ when \(\hat G\) degenerate |
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Repository layout
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
MSc. Dissertation/
|
|
88
|
+
├── src/deepaft/ # Installable PyPI package
|
|
89
|
+
│ ├── estimator.py # DeepAFT class
|
|
90
|
+
│ ├── censoring.py # KM, BJ imputation, IPCW weights
|
|
91
|
+
│ ├── methods.py # Training targets / losses
|
|
92
|
+
│ ├── predict.py # S(t|z), RMST, median
|
|
93
|
+
│ ├── metrics.py # C-index, AMSE, IBS
|
|
94
|
+
│ ├── simulate.py # Scenarios A–D
|
|
95
|
+
│ └── diagnostics.py # PH test, method selection
|
|
96
|
+
├── tests/ # pytest (scenarios A–D)
|
|
97
|
+
├── experiments/ # Dissertation-only (BraTS, OncoLnc, GNN)
|
|
98
|
+
├── pyproject.toml
|
|
99
|
+
├── CITATION.cff
|
|
100
|
+
└── README.md
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Dissertation pipeline (experiments/)
|
|
106
|
+
|
|
107
|
+
### 1. Data (before any model)
|
|
108
|
+
|
|
109
|
+
| Source | Role | Survival labels? |
|
|
110
|
+
|--------|------|------------------|
|
|
111
|
+
| [BraTS 2024 GLI](https://www.synapse.org/Synapse:syn51156910) | MRI + segmentation (T1n, T1c, T2w, T2-FLAIR; ET, NET, ED) | **No OS in release** |
|
|
112
|
+
| [GDC TCGA](https://portal.gdc.cancer.gov/) | LGG + GBM clinical OS / days | **Yes** |
|
|
113
|
+
| [OncoLnc](http://www.oncolnc.org/) | Gene expression (IDH1, MGMT, TP53, …) | Use GDC for vital status (2016 freeze is stale for GBM) |
|
|
114
|
+
|
|
115
|
+
**Thesis analysis set:** TCGA cases with GDC survival + gene expression (`tcga_glioma_cohort.csv`). BraTS nested cohorts apply only if you obtain a valid BraTS↔TCGA table for your imaging year.
|
|
116
|
+
|
|
117
|
+
### 2. Simulation chapter (package `tests/` + notebook)
|
|
118
|
+
|
|
119
|
+
- **A:** Nonlinear AFT, independent censoring (Norman Eq. 6)
|
|
120
|
+
- **B:** Censoring depends on covariate → test `censoring="covariate"`
|
|
121
|
+
- **C:** Administrative censoring → IPCW/Transform fallback
|
|
122
|
+
- **D:** LGG/GBM-like heteroscedastic scale → test `scale="group"`
|
|
123
|
+
|
|
124
|
+
### 3. Real-data models
|
|
125
|
+
|
|
126
|
+
Same folds for all: Cox, log-normal AFT, RSF, DeepSurv, DeepAFT (chosen variant).
|
|
127
|
+
|
|
128
|
+
Features (thesis): pre-specified genes on TCGA. Optional extensions: BraTS radiomics or genes+radiomics **only** with an organizer crosswalk.
|
|
129
|
+
|
|
130
|
+
Metrics: Harrell C, Uno C, IPCW-AMSE, integrated Brier score, calibration slope. Run Grambsch–Therneau PH test before preferring AFT over Cox.
|
|
131
|
+
|
|
132
|
+
### 4. Optional segmentation chapter
|
|
133
|
+
|
|
134
|
+
U-Net / Mask R-CNN on BraTS if required by supervisor — **separate** from survival claim. Do not feed predicted masks into survival until Dice is validated.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Publishing to PyPI
|
|
139
|
+
|
|
140
|
+
Full credential setup (tokens, `%USERPROFILE%\.pypirc`, TestPyPI): [docs/pypi_credentials.md](docs/pypi_credentials.md).
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
pip install build twine
|
|
144
|
+
python -m build
|
|
145
|
+
twine upload --repository testpypi dist/*
|
|
146
|
+
# after verification:
|
|
147
|
+
twine upload dist/*
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Replace **`your-username`** in `pyproject.toml` and `CITATION.cff`: [docs/github_repo_urls.md](docs/github_repo_urls.md).
|
|
151
|
+
|
|
152
|
+
Package name: `deepaft`. BraTS/OncoLnc loaders stay in `experiments/` (CC BY-NC-SA, TCGA publication rules).
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Citing
|
|
157
|
+
|
|
158
|
+
```bibtex
|
|
159
|
+
@article{norman2024deepaft,
|
|
160
|
+
title = {deepAFT: A nonlinear accelerated failure time model with artificial neural network},
|
|
161
|
+
author = {Norman, Patrick A. and Li, Wanlu and Jiang, Wenyu and Chen, Bingshu E.},
|
|
162
|
+
journal = {Statistics in Medicine},
|
|
163
|
+
volume = {43},
|
|
164
|
+
number = {19},
|
|
165
|
+
pages = {3689--3701},
|
|
166
|
+
year = {2024},
|
|
167
|
+
doi = {10.1002/sim.10152}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
If you use this Python package or the glioma extensions, also cite this repository (see `CITATION.cff`).
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT for this Python code. Independent reimplementation — not a port of GPL R `dnn`. BraTS data: Synapse DUA / CC BY-NC-SA. TCGA: [publication guidelines](https://www.cancer.gov/about-nci/organization/ccg/research/structural-genomics/tcga/history/policies).
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "deepaft"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python deepAFT: nonlinear accelerated failure time models with neural networks (Norman et al. 2024) and limitation-aware extensions for censored survival data."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Swati" }]
|
|
13
|
+
keywords = ["survival-analysis", "accelerated-failure-time", "deep-learning", "censoring"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Medical Science Apps.",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"numpy>=1.24",
|
|
22
|
+
"scipy>=1.11",
|
|
23
|
+
"pandas>=2.0",
|
|
24
|
+
"torch>=2.0",
|
|
25
|
+
"scikit-learn>=1.3",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
metrics = ["scikit-survival>=0.22", "lifelines>=0.28"]
|
|
30
|
+
experiments = [
|
|
31
|
+
"scikit-survival>=0.22",
|
|
32
|
+
"lifelines>=0.28",
|
|
33
|
+
"requests>=2.31",
|
|
34
|
+
"openpyxl>=3.1",
|
|
35
|
+
"matplotlib>=3.7",
|
|
36
|
+
"nibabel>=5.0",
|
|
37
|
+
"pyradiomics>=3.1",
|
|
38
|
+
"synapseclient>=4.0",
|
|
39
|
+
]
|
|
40
|
+
dev = ["pytest>=7.4", "pytest-cov>=4.1"]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/swatipriyadarshini9/deepaft"
|
|
44
|
+
Documentation = "https://github.com/swatipriyadarshini9/deepaft#readme"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
51
|
+
pythonpath = ["src"]
|
deepaft-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
deepaft: Python deep accelerated failure time models.
|
|
3
|
+
|
|
4
|
+
Reproduces Norman et al. (2024) Statistics in Medicine methods and adds
|
|
5
|
+
limitation-aware extensions for covariate-dependent censoring and
|
|
6
|
+
heteroscedastic residuals.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from deepaft.estimator import DeepAFT, DeepAFTConfig
|
|
10
|
+
from deepaft.metrics import amse, harrell_c_index, integrated_brier_score
|
|
11
|
+
from deepaft.simulate import scenario_a, scenario_b, scenario_c, scenario_d, scenario_ph
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|
|
14
|
+
__all__ = [
|
|
15
|
+
"DeepAFT",
|
|
16
|
+
"DeepAFTConfig",
|
|
17
|
+
"harrell_c_index",
|
|
18
|
+
"amse",
|
|
19
|
+
"integrated_brier_score",
|
|
20
|
+
"scenario_a",
|
|
21
|
+
"scenario_b",
|
|
22
|
+
"scenario_c",
|
|
23
|
+
"scenario_d",
|
|
24
|
+
"scenario_ph",
|
|
25
|
+
]
|