ShapG2P
ShapG2P: a strategy for biomarker pathway enrichment with PPI network topology and SHAP analysis.
输入一个基因符号列表(文件或直接传 list),输出 {通路名: SHAP 分数} 字典,按分数从大到小排序。
方法
- 每个基因以其到各通路基因的 PPI 网络距离(
exp(-d/2)相似度)为特征; - XGBoost 分类器区分 biomarker 与背景基因(全局 1:1 欠采样,SEED=42);
- 用 SHAP(
pred_contribs)计算每条通路特征的平均绝对贡献 = 通路 SHAP 分数。
内置数据:STRING 人类 PPI 网络(17613 基因)、KEGG / Hallmark / WikiPathway 通路。
安装
pip install shapg2p
或本地开发安装:
cd shapg2p_pkg
pip install -e .
用法
from shapg2p import score_pathways
# 方式 1: 直接传基因符号列表
scores = score_pathways(['TP53', 'ATM', 'APOE', 'SOD1', 'CDKN2A'])
# 方式 2: 传文件路径 (CSV/TSV/TXT, 含常见基因列如 gene symbol / gene / symbol)
scores = score_pathways('my_biomarkers.csv')
# 方式 3: 传逗号/空格/换行分隔的字符串
scores = score_pathways('TP53, ATM, APOE')
# 输出: 字典, 按 SHAP 分数从大到小
print(scores)
# {'p53 signaling pathway': 0.42, 'Alzheimer disease': 0.31, ...}
运行约需 1–3 分钟(一次 XGBoost 训练 + 全基因 SHAP 计算)。
输出说明
返回 dict[str, float]:key 为通路名,value 为该通路的 mean |SHAP| 分数,按分数降序;
仅包含分数 > 0 的通路(无关通路不返回)。同名通路(出现在多个数据库中)取最大分数。
上传到 PyPI(供他人 pip install)
1. 注册账号并创建 API token
- 注册:https://pypi.org/account/register/
- 创建 token:https://pypi.org/manage/account/token/ (Scope 选整个账号即可)
- token 形如
pypi-AgEIcHlwaS5vcmcC...,只显示一次,保存好
2. 构建
pip install --upgrade build twine
cd shapg2p_pkg
python -m build
生成 dist/shapg2p-0.1.0.tar.gz 和 dist/shapg2p-0.1.0-py3-none-any.whl。
3. 先传 TestPyPI 验证(可选但推荐)
python -m twine upload --repository testpypi dist/*
# 用户名输入: __token__ 密码输入: pypi-xxx (你的 API token)
# 验证安装
pip install --index-url https://test.pypi.org/simple/ shapg2p
4. 上传正式 PyPI
python -m twine upload dist/*
同样输入 __token__ + API token。上传成功后即可:
pip install shapg2p
5. 更新版本
修改 pyproject.toml 的 version(如 0.1.1),重新 python -m build 并 twine upload dist/*。
PyPI 不允许重复上传相同版本号。
依赖
numpy / pandas / scipy / scikit-learn / xgboost(pip install shapg2p 时自动安装)。
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 shapg2p-0.1.0.tar.gz.
File metadata
- Download URL: shapg2p-0.1.0.tar.gz
- Upload date:
- Size: 22.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e89d72dff2b64a28927ff6f8b97283373ef016f14d00b76630f8bdcb0cfd66a
|
|
| MD5 |
c4800531f5095d44c39156f77a92bab3
|
|
| BLAKE2b-256 |
ec2805988b7a133cd2daa4ead905e64278e58b34a2502bcd342b8e2c83a28aca
|
File details
Details for the file shapg2p-0.1.0-py3-none-any.whl.
File metadata
- Download URL: shapg2p-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07fa275f1f636927b20e7dc7a38fd2cb0fd2413b5da12098762a275b2dabd0d0
|
|
| MD5 |
d11a7a521a7fcbb3cd4adb4303b0e113
|
|
| BLAKE2b-256 |
9343508de13255ef67b9e7300c934d01c3d8f61cf772aa466469e188ab5bc838
|