# Review of `old/`

## Main Problems Found

- Package import is fragile: `old/__init__.py` imports R-related modules when
  `rpy2` is present, and `old/utils/rtools.py` imports `rpy2`, `muon`, Seurat
  helpers, and R packages at module import time.
- R environment configuration is hard to reproduce because Python functions
  directly call `importr()` and inline R code without a central dependency check.
- Argument names are inconsistent: `counts_key`, `layer`, `condition_key`,
  `treatment_key`, `control_key`, `cell_type_key`, `group_key`, `key`, and
  `uns` sometimes mean related concepts.
- Several functions mutate `.X` temporarily, for example pseudobulk and memento
  workflows. This can silently corrupt downstream analysis state.
- decoupler usage is based on older helpers such as `get_ora_df` and
  `get_gsea_df`. Current decoupler exposes methods under `dc.mt.*` and
  pseudobulk under `dc.pp.pseudobulk`.
- `utils` mixes unrelated domains: gene conversion, R bridge, memento,
  ORA/GSEA, generic file prompts, and survival analysis.
- `__pycache__` files are stored in `old/`, adding noise and making review harder.
- Some implementations duplicate Scanpy/scverse behavior that should be wrapped
  instead of reimplemented, especially pseudobulk aggregation.

## Module Decisions

- Keep and rewrite: preprocessing, clustering, pseudobulk differential
  expression, enrichment, marker utilities, cell-cycle gene loading, and core
  plotting helpers.
- Keep but isolate now: R-backed scDblFinder and SoupX.
- Defer heavy R wrappers: clustree, CellChat, NicheNet, inferCNV,
  clusterProfiler, AUCell/UCell. A lightweight, optional LIANA workflow now
  covers the core ligand–receptor use case without restoring those wrappers.
- Extract from core: survival analysis.
- Revisit later: large plotting classes and geneNMF. They can be ported after
  the data APIs are stable.

## References Checked

- decoupler latest API lists enrichment methods under `decoupler.mt.*`, including
  `mt.ora` and `mt.gsea`.
- decoupler latest API provides `decoupler.pp.pseudobulk(adata, sample_col,
  groups_col, layer=None, mode="sum", ...)` and records pseudobulk QC metrics.
