TODO
Project description
OpenTAK Clustering
OpenTAK is a python package for clustering and visualizing treatment sequences in a cohort. It aims to identify, cluster, and represent the different treatment sequences used, while quantifying the number of patients involved in each of these sequences.
Under the hood, it runs on a Hierarchical Clustering Algorithm.
📖 Documentation: https://heva-io.github.io/opentak/latest/
📝 Blog (methodology + real use cases):
https://hevaweb.com/en/articles/tak-r-celebrates-its-4th-anniversary/120
Installation
To get started with the package, run one of the following command:
pip install opentak
or:
poetry add opentak
or:
uv add opentak
Quick Start
Starting from an event log with 3 columns — ID_PATIENT, EVT, and TIMESTAMP (int) — you can easily plot treatment sequences for each patient.
The sequences are automatically ordered and clustered by similarity.
👉 Check out the full documentation for more details.
from opentak import TakBuilder, TakVisualizer
from opentak.generation_cohort_tak import GenerateCohortTAK
NB_PATIENTS = 400
NB_JOURS_END = 370
n_clusters = 3
# Event log generation
evtlog = GenerateCohortTAK(
nb_patients=NB_PATIENTS, nb_days_end=NB_JOURS_END, random_state=42
)
evtlog.initialisation_dataframe(
treatment_name="Treatment A",
dose_mean=int(NB_JOURS_END / 10),
dose_std=int(NB_JOURS_END / 25),
)
evtlog.add_switch_gaussien("Treatment B")
evtlog = evtlog.add_in_out()
evtlog = evtlog.sort_values(by=["ID_PATIENT", "TIMESTAMP"])
# TAK builder
tak = TakBuilder(evtlog).build()
tak.fit(n_clusters=n_clusters)
# TAK visualizer
tak_viz = TakVisualizer(tak)
tak_viz.process_visualization()
figplotly = tak_viz.get_plot(add_sep=True, unit_as_months=True, nb_months=2)
figplotly.update_layout(height=500, width=700)
figplotly.show()
You should obtain the following visualization.
You can explore the examples folder to see additional applications on various event logs.
Contributing
Contributions are welcome! To contribute:
-
Fork the repository and create a new branch for your changes.
-
Install the package dependencies using uv.
First install uv by following the official documentation guide. Then run:uv sync --all-groups -
Ensure your code is well-documented and includes relevant tests.
-
Checklist before submitting a pull request:
- All tests pass with pytest
- Ruff reports no linting errors when you run:
uv run ruff format . uv run ruff check . - Mypy reports no type errors when you run:
uv run mypy opentak
-
Open a pull request with a clear description of your changes and reference any related issues when possible.
Acknowledgements
- Big thanks to Marie Laurent for kicking off the idea and building the first version of the package.
- Shout-out to Alexandre Batisse, Martin Prodel, Hugo de Oliveira, and all former contributors from the Heva Data Science team for their feedback, refactoring, and feature enhancements.
- And of course, cheers to all future contributors who will keep pushing this project forward.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opentak-0.1.0.tar.gz.
File metadata
- Download URL: opentak-0.1.0.tar.gz
- Upload date:
- Size: 1.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3f2d43bb6a1f4bcf41dddbfb2e125fd72a6c6a9912cfdb57f1640278255dfaa
|
|
| MD5 |
dca4db845d214e9a67764f4b7bd2b9e5
|
|
| BLAKE2b-256 |
9e078d82d2aa9a60e91dfb4766577418c411675d3fe716512f8dd349443df309
|
File details
Details for the file opentak-0.1.0-py3-none-any.whl.
File metadata
- Download URL: opentak-0.1.0-py3-none-any.whl
- Upload date:
- Size: 55.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23d7cf5f04e3cb88cb123eb745c3d02c681a15a82ba14cfd8d1d34ba9ae2dfee
|
|
| MD5 |
4ce88978a18f03bb1e8325f29ddfe2ea
|
|
| BLAKE2b-256 |
6d102cff57d6040ede3b2ac44a0edeafc77173e619b68f45a3757670f541205c
|