Metadata-Version: 2.4
Name: mirpredictor
Version: 0.1.2
Summary: miRNA inference from single-cell RNA-seq with cached ensemble models
Project-URL: Upstream, https://github.com/neuropromotion/miRNA-prediction-in-single-cell-RNA-seq-data
Project-URL: Models, https://huggingface.co/neuropromotion/miRPredictor
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: THIRD_PARTY_NOTICES.md
Requires-Dist: numpy<3,>=1.26
Requires-Dist: pandas<3,>=2
Requires-Dist: scipy<2,>=1.11
Requires-Dist: scikit-learn<2,>=1.5
Requires-Dist: pyarrow>=14
Requires-Dist: anndata>=0.10
Requires-Dist: joblib>=1.3
Requires-Dist: tqdm>=4.66
Requires-Dist: huggingface-hub<2,>=0.25
Requires-Dist: platformdirs>=4
Requires-Dist: filelock>=3.13
Requires-Dist: torch<3,>=2.4
Requires-Dist: tabm<0.1,>=0.0.3
Requires-Dist: xgboost<4,>=2
Requires-Dist: rtdl-num-embeddings<0.1,>=0.0.11
Provides-Extra: models
Requires-Dist: torch<3,>=2.4; extra == "models"
Requires-Dist: tabm<0.1,>=0.0.3; extra == "models"
Requires-Dist: xgboost<4,>=2; extra == "models"
Requires-Dist: rtdl-num-embeddings<0.1,>=0.0.11; extra == "models"
Provides-Extra: tabpack
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: build>=1; extra == "test"
Dynamic: license-file

# miRPredictor

Predict miRNA expression from single-cell RNA-seq counts using neuropromotion's
TabPack, TabM and XGBoost ensembles, with optimized preprocessing and cached
model runners. Python 3.12+.

```bash
pip install mirpredictor==0.1.2
```

From source:

```bash
pip install .
```

The compatible TabPack inference layers are included privately in the package.
The default installation includes the model dependencies. No Git clone,
external TabPack installation, or PYTHONPATH editing is needed. The model
architecture is taken from the historical version used to create the weights;
updating the external TabPack repository will not change it.

```python
import anndata as ad
from mirpredictor import miRPredictor

adata = ad.read_h5ad("input.h5ad")  # raw counts in X, layers['counts'], or raw
predictor = miRPredictor(device="cpu")
print(predictor.check_assets())  # reports missing HF files before downloading weights
result = predictor.predict(adata, groupby="CellType", embedding_key="X_pca_harmony")
print(predictor.last_timings)
result.write_h5ad("predicted.h5ad")
predictor.close()
```

`device="cuda"` uses a CUDA GPU when available. Reuse one predictor for multiple
datasets to reuse loaded models. `cache_models=False` avoids keeping all model
weights in RAM. Models are on CPU between predictions by default; GPU residency
can be requested using `keep_models_on_device=True`.

`predict(..., fast=False)` uses the reference preprocessing and uncached model
execution for comparison. `predict_csv` retains the reference CSV/parquet API.
Both paths share upstream gene mapping, robustness thresholds, target panels,
and output conventions. AnnData is copied unless `inplace=True`.

## Model files and offline use

Only stack JSONs and the base models with nonzero stack coefficients (or the
selected fallback model) are downloaded, at a pinned HF revision. Training
datasets/checkpoints/predictions are excluded. HF's `xgb/` maps to local
`xgb_optuna/`. Use `cache_dir=...`, `models_root=...`, `local_files_only=True`,
and `revision=...` as needed. An explicit `models_root` uses the upstream layout:
`tabpack/<miRNA>/`, `tabm/<miRNA>/`, `xgb_optuna/<miRNA>/`, and
`ensemble/tabpack_tabm_xgb_stack/weights/<miRNA>.json`.

`check_assets(mirnas=[...])` inspects the remote manifest and stack weights,
without downloading tensor weights. Missing base models raise an explicit
error; the package does not silently change the ensemble.

The complete paginated HF listing contains XGBoost models for all 312 targets.
All 159 configured inference targets have their required ensemble artifacts.
The K1 reference is distributed separately on Kaggle:
https://www.kaggle.com/datasets/ismailovaly/mirna-prediction-project
under `sc_TRAIN/X_TRAIN_K1.parquet`. It is downloaded automatically on the first
K1 prediction and cached, pinned to Kaggle dataset version 4 (138 MB). K2–K10
never download it. You can supply a local copy with `knn_ref_path`. With
`local_files_only=True`, missing cached files raise a clear error and no
network requests are made. Failed or incomplete reference downloads are not
promoted into the cache.

## Implementation and validation

The package uses private relative imports and does not depend on the training
directory or manipulate global `constants` modules. The bundled model
architecture preserves the original TabPack checkpoint layout.

Version 0.1.2 includes the updated robustness configuration and feature weights
from upstream commit `05a2708fcf4dd6bf07ffd2529f135ff639109bc7`. All data paths
inside the supplied robustness configuration are relative to installed package
resources.

Preprocessing equivalence, robustness filtering, reference caching, and artifact
selection are covered by 22 tests. Model runners have also been checked against
real TabPack, TabM and XGBoost weights on CPU. A full real-data evaluation across
all 159 targets and a CUDA validation remain separate from these checks.

The K1 download endpoint was verified, but full transfer from Google Storage
could not be completed in the validation environment; use `knn_ref_path` when
network policy prevents automatic downloads.

Source provenance is recorded in `provenance.json` and
`THIRD_PARTY_NOTICES.md`. No additional license grant for upstream source is
asserted by this package.

To run tests from a source checkout:

```bash
pip install '.[test]'
python -m pytest
```
