Metadata-Version: 2.4
Name: bullkpy
Version: 0.2.0
Summary: Scanpy-like pipeline for bulk RNA-seq in Python
Author-email: Marcos Malumbres <mmalumbres@vhio.net>
License: BSD 3-Clause License
        
        Copyright (c) 2025, Marcos Malumbres
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/malumbres/BULLKpy
Project-URL: Repository, https://github.com/malumbres/BULLKpy
Project-URL: Issues, https://github.com/malumbres/BULLKpy/issues
Project-URL: Documentation, https://bullkpy.readthedocs.io/en/latest/index.html
Project-URL: Changelog, https://github.com/malumbres/BULLKpy/blob/main/CHANGELOG.md
Keywords: bulk-rnaseq,tcga,anndata,scanpy,bioinformatics
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: scipy
Requires-Dist: matplotlib
Requires-Dist: anndata
Requires-Dist: seaborn
Requires-Dist: scikit-learn
Requires-Dist: statsmodels
Requires-Dist: gseapy
Requires-Dist: lifelines
Requires-Dist: openpyxl
Provides-Extra: umap
Requires-Dist: umap-learn>=0.5.7; extra == "umap"
Requires-Dist: numba>=0.60; extra == "umap"
Provides-Extra: leiden
Requires-Dist: igraph; extra == "leiden"
Requires-Dist: leidenalg; extra == "leiden"
Provides-Extra: network
Requires-Dist: networkx; extra == "network"
Provides-Extra: notebook
Requires-Dist: ipykernel; extra == "notebook"
Requires-Dist: jupyterlab; extra == "notebook"
Requires-Dist: networkx; extra == "notebook"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx<8,>=7; extra == "docs"
Requires-Dist: pydata-sphinx-theme>=0.15; extra == "docs"
Requires-Dist: myst-parser<4,>=2; extra == "docs"
Requires-Dist: myst-nb<1.3,>=1.1; extra == "docs"
Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
Requires-Dist: sphinx-copybutton>=0.5; extra == "docs"
Requires-Dist: sphinx-design>=0.6; extra == "docs"
Requires-Dist: ipython; extra == "docs"
Dynamic: license-file

# BULLKpy 🧬
<img src="https://raw.githubusercontent.com/malumbres/BULLKpy/main/docs/images/BULLKpy_logo.png" width="300">

**BULLKpy** is a Python pipeline for **bulk OMICs analysis**, based on AnnData objects and inspired by Scanpy/scverse but adapted for bulk transcriptomics. It integrates QC, normalization, clustering, correlation and association utilities, differential expression, gene set enrichment analysis (GSEA), metaprograms, and rich visualization utilities (oncoprints, etc.).  

---

## 📄 Documentation

BULLKpy documentation in Read The Docs:

https://bullkpy.readthedocs.io/en/latest/    

--- 

## 🚀 Installation

Clone the repository:

```bash
git clone https://github.com/malumbres/BULLKpy.git
cd BULLKpy
```

Install from Pypi:  
https://pypi.org/project/bullkpy/  

```bash
pip install bullkpy
```

BULLKpy requires **Python 3.10 or newer**.

Optional extras:

```bash
pip install "bullkpy[umap]"      # bk.tl.umap / bk.pl.umap
pip install "bullkpy[leiden]"    # bk.tl.cluster(method="leiden")
```

--- 

## 🛠️ Development

```bash
git clone https://github.com/malumbres/BULLKpy.git
cd BULLKpy
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev,docs,umap,leiden]"

pytest                                  # run the test suite
ruff check src/                         # lint
python -m sphinx -b html docs docs/_build/html   # build the docs
```

--- 

## 🚀 Tutorials

Use this initial Jupyter notebook for a practical presentation of BULLKpy functions:  

https://bullkpy.readthedocs.io/en/latest/notebooks/BULLKpy_TCGA_example_notebook.html

More functions and field-specific tutorials to come...

--- 
## 📦 Project structure

```bash
bullkpy-skeleton/
├── src/                # BULLKpy Python package
│   └── bullkpy/
|       ├── io.py.      # input/output tools
│       ├── pp/         # preprocessing
│       ├── tl/         # tools (DE, clustering, GSEA, associations)
│       ├── pl/         # plotting
│       └── settings.py
│
├── notebooks/          # analysis notebooks (examples, use cases)
├── data/               # large input datasets (NOT tracked by git)
├── docs/		# Read the Docs at `https://bullkpy.readthedocs.io/en/latest/` 
├── results/            # analysis outputs (NOT tracked by git)
│
├── pyproject.toml      # package configuration
├── README.md
├── CHANGELOG.md
├── LICENSE
├── .gitignore
└── .readthedocs.yaml

```
---

## 🧪 Quick start

```python
import bullkpy as bk

# ---- load -------------------------------------------------------------
adata = bk.io.read_counts("counts.tsv", sep="\t", orientation="genes_by_samples")
bk.io.add_metadata(adata, "metadata.tsv", sep="\t", index_col="sample")

# ---- QC and normalisation --------------------------------------------
bk.pp.set_raw_counts(adata)
bk.pp.qc_metrics(adata)
bk.pl.qc_metrics(adata)
bk.pp.normalize_cpm(adata)
bk.pp.log1p(adata)

# ---- dimensionality reduction and clustering -------------------------
bk.pp.highly_variable_genes(adata, n_top_genes=2000)
bk.tl.pca(adata, n_comps=30, use_highly_variable=True)
bk.pl.pca_scatter(adata, color="Subtype")
bk.tl.neighbors(adata, n_neighbors=15)
bk.tl.cluster(adata, method="leiden", resolution=1.0)   # -> adata.obs["clusters"]
bk.tl.cluster_metrics(adata, true_key="Subtype")

# ---- differential expression -----------------------------------------
bk.tl.de(adata, groupby="Subtype", group="Basal", reference="Luminal")
res = adata.uns["de"]["Subtype_Basal_vs_Luminal"]["results"]
bk.pl.volcano(res)
bk.pl.heatmap_de(adata, contrast="Subtype_Basal_vs_Luminal", groupby="Subtype")

# ---- associations and survival ---------------------------------------
bk.tl.gene_categorical_association(adata, groupby="Subtype", genes=["MKI67", "TP53"])
bk.tl.cox_gene_association(adata, time_col="OS.time", event_col="OS", genes=["MKI67"])

# ---- save -------------------------------------------------------------
bk.pp.make_h5ad_safe(adata)          # rename keys HDF5 cannot represent
adata.write("results.h5ad", compression="gzip")
```

Every call above is checked against the real signatures by the test suite.

---
## 📚 Function index

A map of what is available, grouped by task. See the
[API reference](https://bullkpy.readthedocs.io/en/latest/api/index.html) for the
arguments each one takes.

```text
# Load data
adata = bk.io.read_counts("counts.tsv", sep="\t")
# Load metadata
adata = bk.add_metadata(adata, "metadata.tsv", sep="\t")
# QC
bk.pp.qc_metrics(adata)
bk.pl.qc_metrics(adata)
bk.pp.filter_genes(adata)
bk.pp.filter_samples(adata)
# PCA + UMAP
bk.pp.highly_variable_genes(adata)
bk.tl.pca(adata)
bk.pl.pca_scatter(adata)
bk.pl.pca_variance_ratio(adata)
bk.tl.pca_loadings(adata)
bk.pl.pca_loadings_bar(adata)
bk.pl.pca_loadings_heatmap(adata)
bk.tl.neighbors(adata)
bk.tl.umap(adata)
bk.tl.umap_graph(adata)
bk.pl.umap(adata)
# Clustering
bk.tl.leiden_resolution_scan(adata)
bk.pl.ari_resolution_heatmap(adata)
bk.tl.cluster(adata, method="leiden")
bk.tl.cluster(adata, method="means")
bk.tl.cluster_metrics(adata)
# Genes and gene signatures
bk.tl.score_genes(adata, signature)
bk.tl.score_genes_cell_cycle(adata)
# Correlations and associations
bk.pl.corr_heatmap(adata)
bk.tl.gene_gene_correlations(adata)
bk.tl.gene_gene_correlations(adata)
bk.tl.top_gene_obs_correlations(adata)
bk.tl.obs_obs_corr_matrix(adata)
bk.pl.corrplot(adata)
bk.tl.plot_corr_scatter(adata)
bk.tl.gene_categorical_association(adata)
bk.pl.association_heatmap(dfg)
bk.tl.categorical_association(adata)
bk.pl.boxplot_with_stats(adata)
bk.pl.categorical_confusion(adata)
bk.pl.gene_association(adata)
bk.pl.gene_association_volcano(adata)
bk.tl.pairwise_posthoc(y, method="mwu")
bk.pl.dotplot_association(df_all)
bk.pl.heatmap_association(df_all)
bk.tl.rank_genes_groups_fast(adata)
bk.pl.rankplot_association(dfo)
bk.pl.volcano_categorical(res)
bk.tl.posthoc_per_gene(adata)
# Marker genes and Differential expression
bk.tl.de(adata)
bk.tl.de_glm(adata)  # DESeq-like   
bk.pl.volcano(res)
bk.pl.rankplot(res)
bk.pl.ma(res)
# GSEA, genesets and pathway analysis
bk.tl.gsea_preranked(adata)
bk.pl.gsea_bubbleplot(df_gsea)
bk.pl.gsea_leading_edge_heatmap(adata)
bk.pl.leading_edge_jaccard_heatmap(pre_res)
bk.pl.leading_edge_overlap_matrix(pre_res)
bk.tl.list_enrichr_libraries()
# Metaprograms
bk.tl.score_metaprograms(adata)
bk.tl.metaprogram_heterogeneity(adata)
bk.pl.metaprogram_corr(adata)
bk.pl.metaprogram_heatmap(adata)
bk.tl.metaprogram_sample_metrics(adata)
bk.tl.metaprogram_dispersion_by_group(adata)
bk.tl.metaprogram_ne_enrichment(adata)
bk.tl.metaprogram_topk_contribution(adata)
bk.pl.metaprogram_dispersion_heatmap(adata)
bk.pl.metaprogram_metrics_summary(adata)
bk.pl.metaprogram_ne_scatter(adata)
bk.pl.metaprogram_dominance_ridgeplot_like(adata)
bk.pl.metaprogram_rank1_composition_stackedbar(adata)
# Survival analysis
bk.tl.cox_univariate(adata)
bk.pl.cox_forest_from_uns(adata)
bk.pl.run_cox_per_group(adata)
bk.tl.cox_interaction(adata)
bk.pl.km_univariate(adata)
bk.pl.km_2x2_interaction(adata)
# Plots
bk.pl.violin(adata)
bk.pl.dotplot(adata)
bk.pl.heatmap_de(adata)
bk.pl.sample_distances(adata)
bk.pl.sample_correlation_clustergram(adata)
bk.pl.gene_plot(adata)
bk.pl.oncoprint(adata)
# Other Utilities
bk.pp.make_h5ad_safe(adata)
bk.pp.find_bad_obs_cols_by_write(adata)
bk.pp.find_bad_var_cols_by_write(adata)
bk.pp.make_obs_h5ad_safe_strict(adata)
bk.pp.make_var_h5ad_safe_strict(adata)
bk.pp.batch_correct_combat(adata)
```

---
## 📊 Features

	•	Bulk RNA-seq, small and large projects. QC & filtering
	•	PCA, UMAP, Leiden, k-means clustering
	•	Gene scores and signatures
	•	Gene–obs and obs–obs associations and correlations
	•	Differential expression from counts or log data
	•	GSEA preranked pipeline (GSEApy)
	•	Leading-edge GSEA analysis
	•	Oncoprint-style mutation plots
	•	Scanpy-like API (pp, tl, pl)
---
## ⚠️ Notes

	•	data/ and results/ are not versioned
	•	Designed for small or large datasets (TCGA-scale)
	•	Requires Python ≥ 3.10

---
## Upgrading to 0.2.0

0.2.0 fixes several defects that silently produced wrong results, so re-running
existing analyses is worthwhile. Two changes affect existing code:

- **`io.read_counts()` no longer casts non-integer matrices to `int64`.** It
  previously truncated them without warning (`10.77` became `10`), which
  corrupts any file distributed as log2(count+1) — UCSC Xena's tables among
  them. Such files are now loaded unchanged, with a warning.
- **Parameters that defaulted to one study's column names are now required.**
  Calls relying on defaults such as `time_key="OS.time"`, `groupby="Project_ID"`
  or `label_col="PFS_6m"` must now name the column explicitly. A missing
  argument raises `TypeError` naming the parameter.

See [CHANGELOG.md](CHANGELOG.md) for the full list.

---
## Changelog

See [CHANGELOG.md](CHANGELOG.md) for a full list of changes.

---
## 📄 Publication & License

BSD 3-Clause License

Please cite:   
Malumbres M. (2026) BULLKpy: An AnnData-Inspired Unified Framework for Comprehensive Bulk OMICs Analysis. BioRxiv 10.64898/2026.01.26.701768v1. doi: https://doi.org/10.64898/2026.01.26.701768. 

https://www.biorxiv.org/content/10.64898/2026.01.26.701768v1. 


