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.
Metadata
Release files for opentak 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opentak-0.1.0.tar.gz | 1.5 MB | Without provenance | Details for opentak-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opentak-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for opentak-0.1.0-py3-none-any.whl |
Total release size: 1.6 MB
Release files / opentak-0.1.0.tar.gz
| Download URL | opentak-0.1.0.tar.gz |
|---|---|
| Size | 1.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b3f2d43bb6a1f4bcf41dddbfb2e125fd72a6c6a9912cfdb57f1640278255dfaa
|
|
BLAKE2b-256 checksum How to use checksums |
9e078d82d2aa9a60e91dfb4766577418c411675d3fe716512f8dd349443df309
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / opentak-0.1.0-py3-none-any.whl
| Download URL | opentak-0.1.0-py3-none-any.whl |
|---|---|
| Size | 55.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23d7cf5f04e3cb88cb123eb745c3d02c681a15a82ba14cfd8d1d34ba9ae2dfee
|
|
BLAKE2b-256 checksum How to use checksums |
6d102cff57d6040ede3b2ac44a0edeafc77173e619b68f45a3757670f541205c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Security for opentak 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.