clinipub 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.
- clinipub-0.1.0/.github/workflows/pypi-publish.yml +41 -0
- clinipub-0.1.0/.github/workflows/tests-suite.yml +38 -0
- clinipub-0.1.0/.gitignore +218 -0
- clinipub-0.1.0/CONTRIBUTING.md +47 -0
- clinipub-0.1.0/LICENSE +21 -0
- clinipub-0.1.0/PKG-INFO +143 -0
- clinipub-0.1.0/README.md +130 -0
- clinipub-0.1.0/examples/pipeline.py +96 -0
- clinipub-0.1.0/pyproject.toml +24 -0
- clinipub-0.1.0/src/clinipub/__init__.py +6 -0
- clinipub-0.1.0/src/clinipub/assembler.py +130 -0
- clinipub-0.1.0/src/clinipub/bivariate_stats.py +78 -0
- clinipub-0.1.0/src/clinipub/missingness.py +83 -0
- clinipub-0.1.0/src/clinipub/stats_engine.py +74 -0
- clinipub-0.1.0/tests/test_assembler.py +26 -0
- clinipub-0.1.0/tests/test_bivariate_stats.py +62 -0
- clinipub-0.1.0/tests/test_missingness.py +57 -0
- clinipub-0.1.0/tests/test_stats_engine.py +60 -0
- clinipub-0.1.0/uv.lock +859 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Publish to `clinipub` on PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*' # Triggers the workflow whenever a tag starting with 'v' is pushed (e.g., v0.1.0)
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
deploy:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
# Required permissions for Trusted Publishing (OIDC) authentication
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write
|
|
15
|
+
contents: read
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout Source Code
|
|
19
|
+
uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
with:
|
|
24
|
+
version: "latest"
|
|
25
|
+
enable-cache: true
|
|
26
|
+
|
|
27
|
+
- name: Set up Python
|
|
28
|
+
uses: actions/setup-python@v5
|
|
29
|
+
with:
|
|
30
|
+
python-version-file: "pyproject.toml"
|
|
31
|
+
|
|
32
|
+
- name: Run Unit Tests
|
|
33
|
+
run: |
|
|
34
|
+
uv sync
|
|
35
|
+
uv run pytest
|
|
36
|
+
|
|
37
|
+
- name: Build Distribution Packages 🏗️
|
|
38
|
+
run: uv build
|
|
39
|
+
|
|
40
|
+
- name: Publish Package to PyPI
|
|
41
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: clinipub Tests Suite
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout repository
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Python
|
|
21
|
+
uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
cache: 'pip'
|
|
25
|
+
|
|
26
|
+
- name: Install uv
|
|
27
|
+
uses: astral-sh/setup-uv@v5
|
|
28
|
+
with:
|
|
29
|
+
version: "latest"
|
|
30
|
+
enable-cache: true
|
|
31
|
+
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: |
|
|
34
|
+
python -m pip install --upgrade pip
|
|
35
|
+
uv sync
|
|
36
|
+
|
|
37
|
+
- name: Run tests
|
|
38
|
+
run: uv run pytest
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Contributing to clinipub
|
|
2
|
+
|
|
3
|
+
Thank you for contributing to `clinipub`.
|
|
4
|
+
This repository is designed for clinical data scientists and authors who need reproducible, publication-ready tabulation and audit reporting.
|
|
5
|
+
|
|
6
|
+
## How to contribute
|
|
7
|
+
|
|
8
|
+
1. Fork the repository and create a feature branch from `main`.
|
|
9
|
+
- Branch name format: `feature/<short-description>` or `fix/<issue-number>-<short-description>`.
|
|
10
|
+
|
|
11
|
+
2. Keep changes small and focused.
|
|
12
|
+
- One issue per branch.
|
|
13
|
+
- Prefer incremental commits with descriptive messages.
|
|
14
|
+
|
|
15
|
+
3. Run tests locally before submitting a pull request.
|
|
16
|
+
- Use the project development workflow with `uv`.
|
|
17
|
+
- Recommended command:
|
|
18
|
+
```bash
|
|
19
|
+
uv run pytest
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
4. Follow the project style.
|
|
23
|
+
- Keep code readable and consistent with PEP 8.
|
|
24
|
+
- Use clear variable names and concise docstrings.
|
|
25
|
+
|
|
26
|
+
## Reporting issues
|
|
27
|
+
|
|
28
|
+
- Open a GitHub issue for bugs, enhancement requests, or documentation improvements.
|
|
29
|
+
- Provide a minimal reproduction example and expected behavior.
|
|
30
|
+
- Include the Python version and package versions when relevant.
|
|
31
|
+
|
|
32
|
+
## Pull request guidelines
|
|
33
|
+
|
|
34
|
+
- Target the `main` branch.
|
|
35
|
+
- Provide a short summary of the change and the motivation.
|
|
36
|
+
- Mention related issues when applicable.
|
|
37
|
+
- Ensure all tests pass and no new warnings are introduced.
|
|
38
|
+
|
|
39
|
+
## Development notes
|
|
40
|
+
|
|
41
|
+
- `clinipub` is a pandas-centric package. New features should preserve compatibility with typical clinical analysis workflows.
|
|
42
|
+
- Use the existing `src/clinipub` package layout and keep public API changes minimal unless necessary.
|
|
43
|
+
- Update `README.md` or add examples if the change affects usage.
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
By contributing, you agree that your contributions will be licensed under the repository's existing license.
|
clinipub-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arsalan Anwar
|
|
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.
|
clinipub-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: clinipub
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Transform clinical dataframes into publication-ready, beautifully styled tables for medical journals and manuscripts.
|
|
5
|
+
Author-email: Arsalan Anwar <arsalan.anwar.7777@gmail.com>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: jinja2>=3.0.0
|
|
9
|
+
Requires-Dist: numpy>=1.24.0
|
|
10
|
+
Requires-Dist: pandas>=2.0.0
|
|
11
|
+
Requires-Dist: scipy>=1.10.0
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# clinipub
|
|
15
|
+
[](https://pypi.org/project/clinipub/)
|
|
16
|
+
[](https://github.com/arsalananwar11/clinipub/releases)
|
|
17
|
+
[](https://github.com/arsalananwar11/clinipub/actions/workflows/tests-suite.yml)
|
|
18
|
+
|
|
19
|
+
A Python package to transform clinical dataframes into publication-ready, beautifully styled tables for medical journals and manuscripts
|
|
20
|
+
|
|
21
|
+
`clinipub` is a modern Python package designed for data scientists in the life sciences and clinical research fields. It bridges the gap between raw data analysis (`pandas.DataFrame`) and publication-ready medical writing reporting standards (matching *NEJM*, *JAMA*, *The Lancet*, and CDISC/STROBE guidelines).
|
|
22
|
+
|
|
23
|
+
Unlike existing packages, `clinipub` offers autonomous statistical decision-making, impeccable typography, and native exports to formats that medical writers can use out of the box without manual reformatting.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Key Advantages Over Other Packages
|
|
28
|
+
|
|
29
|
+
* **Autonomous Statistics:** Automatically detects variable types and evaluates normality (Shapiro-Wilk) to map the correct parametric or non-parametric test.
|
|
30
|
+
* **Regulatory-Grade Precision:** Automatically falls back to Fisher's Exact test if any contingency cross-tab count drops below 5.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🛠️ Statistical Test Selection Matrix
|
|
35
|
+
|
|
36
|
+
The framework automatically maps and executes your bivariate comparative analytics using the following clinical logic:
|
|
37
|
+
|
|
38
|
+
| Variable Type | Distribution | Group Count | Test Executed |
|
|
39
|
+
| :--- | :--- | :--- | :--- |
|
|
40
|
+
| **Continuous** | Normal (Parametric) | 2 Groups | Independent Welch's $t$-test |
|
|
41
|
+
| **Continuous** | Normal (Parametric) | 3+ Groups | One-way ANOVA |
|
|
42
|
+
| **Continuous** | Skewed (Non-Parametric) | 2 Groups | Mann-Whitney U test |
|
|
43
|
+
| **Continuous** | Skewed (Non-Parametric) | 3+ Groups | Kruskal-Wallis test |
|
|
44
|
+
| **Categorical** | Any | 2x2 with Cell Count < 5 | Fisher's Exact test |
|
|
45
|
+
| **Categorical** | Any | Standard Configurations | Chi-Square ($\chi^2$) Contingency |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Developer Setup & Installation
|
|
50
|
+
|
|
51
|
+
This project is managed efficiently using the **`uv`** package manager.
|
|
52
|
+
|
|
53
|
+
### Prerequisites
|
|
54
|
+
Ensure you have `uv` installed:
|
|
55
|
+
```bash
|
|
56
|
+
pip install uv
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Installation & Environment Setup
|
|
60
|
+
Clone the repository and sync the isolated project development container:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/arsalananwar11/clinipub.git
|
|
64
|
+
|
|
65
|
+
cd clinipub
|
|
66
|
+
uv sync
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Running Unit Tests
|
|
70
|
+
We maintain high test coverage for clinical accuracy using pytest:
|
|
71
|
+
```bash
|
|
72
|
+
uv run pytest
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Pipeline Flow
|
|
76
|
+
1. `MissingDataAuditor` computes raw missingness and validates data completeness.
|
|
77
|
+
2. `ClinicalDataAuditor` classifies variables and checks continuous normality.
|
|
78
|
+
3. `BivariateTestSelector` chooses tests automatically based on group count and distribution.
|
|
79
|
+
4. `TableOneAssembler` builds a stratified Table 1 with descriptive statistics and p-values.
|
|
80
|
+
|
|
81
|
+
## Quick Usage
|
|
82
|
+
```python
|
|
83
|
+
import pandas as pd
|
|
84
|
+
from clinipub import (
|
|
85
|
+
MissingDataAuditor,
|
|
86
|
+
ClinicalDataAuditor,
|
|
87
|
+
BivariateTestSelector,
|
|
88
|
+
TableOneAssembler,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Load your clinical dataset
|
|
92
|
+
df = pd.read_csv("baseline.csv")
|
|
93
|
+
|
|
94
|
+
# 1. Audit missing data and generate an HTML report
|
|
95
|
+
missing_auditor = MissingDataAuditor(df)
|
|
96
|
+
missing_df = missing_auditor.calculate_missingness()
|
|
97
|
+
html_report = missing_auditor.to_html_report(
|
|
98
|
+
audit_df=missing_df,
|
|
99
|
+
thresholds={"low": 1.0, "mid": 20.0},
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# 2. Audit variable types and normality
|
|
103
|
+
auditor = ClinicalDataAuditor(df)
|
|
104
|
+
var_types = auditor.detect_variable_types()
|
|
105
|
+
normality = auditor.test_normality(var_types["continuous"])
|
|
106
|
+
|
|
107
|
+
# 3. Run autonomous bivariate tests
|
|
108
|
+
selector = BivariateTestSelector(df, stratify_by="treatment")
|
|
109
|
+
continuous_result = selector.test_continuous("age", is_normal=normality["age"])
|
|
110
|
+
cat_result = selector.test_categorical("smoker_status")
|
|
111
|
+
|
|
112
|
+
# 4. Build publication-ready Table 1
|
|
113
|
+
assembler = TableOneAssembler(df, stratify_by="treatment")
|
|
114
|
+
table1 = assembler.build()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Core API and Arguments
|
|
118
|
+
- `MissingDataAuditor(data: pd.DataFrame)`
|
|
119
|
+
- `calculate_missingness()`
|
|
120
|
+
- returns a raw `DataFrame` with `missing_count` and `missing_percentage`
|
|
121
|
+
- `to_html_report(audit_df: pd.DataFrame = None, thresholds: dict = {'low': 5.0, 'mid': 30.0})`
|
|
122
|
+
- returns styled HTML for publication-ready missingness reporting
|
|
123
|
+
|
|
124
|
+
- `ClinicalDataAuditor(data: pd.DataFrame)`
|
|
125
|
+
- `detect_variable_types(max_categorical_threshold: int = 10)`
|
|
126
|
+
- returns `{'categorical': [...], 'continuous': [...]}`
|
|
127
|
+
- `test_normality(continuous_cols: list, alpha: float = 0.05)`
|
|
128
|
+
- returns `{column_name: bool}`
|
|
129
|
+
|
|
130
|
+
- `BivariateTestSelector(data: pd.DataFrame, stratify_by: str)`
|
|
131
|
+
- `test_continuous(col: str, is_normal: bool)`
|
|
132
|
+
- returns `{'p_value': float, 'test': str}`
|
|
133
|
+
- `test_categorical(col: str)`
|
|
134
|
+
- returns `{'p_value': float, 'test': str}`
|
|
135
|
+
|
|
136
|
+
- `TableOneAssembler(data: pd.DataFrame, stratify_by: str, columns: list = None)`
|
|
137
|
+
- `build()`
|
|
138
|
+
- returns a styled `pandas.DataFrame` with stratified descriptive statistics and p-values
|
|
139
|
+
|
|
140
|
+
## Contributing
|
|
141
|
+
|
|
142
|
+
Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on issues, pull requests, testing, and repository workflow.
|
|
143
|
+
|
clinipub-0.1.0/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# clinipub
|
|
2
|
+
[](https://pypi.org/project/clinipub/)
|
|
3
|
+
[](https://github.com/arsalananwar11/clinipub/releases)
|
|
4
|
+
[](https://github.com/arsalananwar11/clinipub/actions/workflows/tests-suite.yml)
|
|
5
|
+
|
|
6
|
+
A Python package to transform clinical dataframes into publication-ready, beautifully styled tables for medical journals and manuscripts
|
|
7
|
+
|
|
8
|
+
`clinipub` is a modern Python package designed for data scientists in the life sciences and clinical research fields. It bridges the gap between raw data analysis (`pandas.DataFrame`) and publication-ready medical writing reporting standards (matching *NEJM*, *JAMA*, *The Lancet*, and CDISC/STROBE guidelines).
|
|
9
|
+
|
|
10
|
+
Unlike existing packages, `clinipub` offers autonomous statistical decision-making, impeccable typography, and native exports to formats that medical writers can use out of the box without manual reformatting.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Key Advantages Over Other Packages
|
|
15
|
+
|
|
16
|
+
* **Autonomous Statistics:** Automatically detects variable types and evaluates normality (Shapiro-Wilk) to map the correct parametric or non-parametric test.
|
|
17
|
+
* **Regulatory-Grade Precision:** Automatically falls back to Fisher's Exact test if any contingency cross-tab count drops below 5.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 🛠️ Statistical Test Selection Matrix
|
|
22
|
+
|
|
23
|
+
The framework automatically maps and executes your bivariate comparative analytics using the following clinical logic:
|
|
24
|
+
|
|
25
|
+
| Variable Type | Distribution | Group Count | Test Executed |
|
|
26
|
+
| :--- | :--- | :--- | :--- |
|
|
27
|
+
| **Continuous** | Normal (Parametric) | 2 Groups | Independent Welch's $t$-test |
|
|
28
|
+
| **Continuous** | Normal (Parametric) | 3+ Groups | One-way ANOVA |
|
|
29
|
+
| **Continuous** | Skewed (Non-Parametric) | 2 Groups | Mann-Whitney U test |
|
|
30
|
+
| **Continuous** | Skewed (Non-Parametric) | 3+ Groups | Kruskal-Wallis test |
|
|
31
|
+
| **Categorical** | Any | 2x2 with Cell Count < 5 | Fisher's Exact test |
|
|
32
|
+
| **Categorical** | Any | Standard Configurations | Chi-Square ($\chi^2$) Contingency |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Developer Setup & Installation
|
|
37
|
+
|
|
38
|
+
This project is managed efficiently using the **`uv`** package manager.
|
|
39
|
+
|
|
40
|
+
### Prerequisites
|
|
41
|
+
Ensure you have `uv` installed:
|
|
42
|
+
```bash
|
|
43
|
+
pip install uv
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Installation & Environment Setup
|
|
47
|
+
Clone the repository and sync the isolated project development container:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/arsalananwar11/clinipub.git
|
|
51
|
+
|
|
52
|
+
cd clinipub
|
|
53
|
+
uv sync
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Running Unit Tests
|
|
57
|
+
We maintain high test coverage for clinical accuracy using pytest:
|
|
58
|
+
```bash
|
|
59
|
+
uv run pytest
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Pipeline Flow
|
|
63
|
+
1. `MissingDataAuditor` computes raw missingness and validates data completeness.
|
|
64
|
+
2. `ClinicalDataAuditor` classifies variables and checks continuous normality.
|
|
65
|
+
3. `BivariateTestSelector` chooses tests automatically based on group count and distribution.
|
|
66
|
+
4. `TableOneAssembler` builds a stratified Table 1 with descriptive statistics and p-values.
|
|
67
|
+
|
|
68
|
+
## Quick Usage
|
|
69
|
+
```python
|
|
70
|
+
import pandas as pd
|
|
71
|
+
from clinipub import (
|
|
72
|
+
MissingDataAuditor,
|
|
73
|
+
ClinicalDataAuditor,
|
|
74
|
+
BivariateTestSelector,
|
|
75
|
+
TableOneAssembler,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Load your clinical dataset
|
|
79
|
+
df = pd.read_csv("baseline.csv")
|
|
80
|
+
|
|
81
|
+
# 1. Audit missing data and generate an HTML report
|
|
82
|
+
missing_auditor = MissingDataAuditor(df)
|
|
83
|
+
missing_df = missing_auditor.calculate_missingness()
|
|
84
|
+
html_report = missing_auditor.to_html_report(
|
|
85
|
+
audit_df=missing_df,
|
|
86
|
+
thresholds={"low": 1.0, "mid": 20.0},
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# 2. Audit variable types and normality
|
|
90
|
+
auditor = ClinicalDataAuditor(df)
|
|
91
|
+
var_types = auditor.detect_variable_types()
|
|
92
|
+
normality = auditor.test_normality(var_types["continuous"])
|
|
93
|
+
|
|
94
|
+
# 3. Run autonomous bivariate tests
|
|
95
|
+
selector = BivariateTestSelector(df, stratify_by="treatment")
|
|
96
|
+
continuous_result = selector.test_continuous("age", is_normal=normality["age"])
|
|
97
|
+
cat_result = selector.test_categorical("smoker_status")
|
|
98
|
+
|
|
99
|
+
# 4. Build publication-ready Table 1
|
|
100
|
+
assembler = TableOneAssembler(df, stratify_by="treatment")
|
|
101
|
+
table1 = assembler.build()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Core API and Arguments
|
|
105
|
+
- `MissingDataAuditor(data: pd.DataFrame)`
|
|
106
|
+
- `calculate_missingness()`
|
|
107
|
+
- returns a raw `DataFrame` with `missing_count` and `missing_percentage`
|
|
108
|
+
- `to_html_report(audit_df: pd.DataFrame = None, thresholds: dict = {'low': 5.0, 'mid': 30.0})`
|
|
109
|
+
- returns styled HTML for publication-ready missingness reporting
|
|
110
|
+
|
|
111
|
+
- `ClinicalDataAuditor(data: pd.DataFrame)`
|
|
112
|
+
- `detect_variable_types(max_categorical_threshold: int = 10)`
|
|
113
|
+
- returns `{'categorical': [...], 'continuous': [...]}`
|
|
114
|
+
- `test_normality(continuous_cols: list, alpha: float = 0.05)`
|
|
115
|
+
- returns `{column_name: bool}`
|
|
116
|
+
|
|
117
|
+
- `BivariateTestSelector(data: pd.DataFrame, stratify_by: str)`
|
|
118
|
+
- `test_continuous(col: str, is_normal: bool)`
|
|
119
|
+
- returns `{'p_value': float, 'test': str}`
|
|
120
|
+
- `test_categorical(col: str)`
|
|
121
|
+
- returns `{'p_value': float, 'test': str}`
|
|
122
|
+
|
|
123
|
+
- `TableOneAssembler(data: pd.DataFrame, stratify_by: str, columns: list = None)`
|
|
124
|
+
- `build()`
|
|
125
|
+
- returns a styled `pandas.DataFrame` with stratified descriptive statistics and p-values
|
|
126
|
+
|
|
127
|
+
## Contributing
|
|
128
|
+
|
|
129
|
+
Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on issues, pull requests, testing, and repository workflow.
|
|
130
|
+
|