Skip to main content

scFair

PyPI version PyPI downloads Bioconda Bioconda downloads Total downloads Python versions Documentation Status CI License DOI bioRxiv

scFair selects highly variable genes (HVGs) for single-cell RNA-seq. It handles two choices most pipelines already make, plus an optional population count:

Choice Common default What scFair does
How many genes (n)? Fixed 2000 n_top_genes="auto" (default) estimates a base size from multi-seed density structure. Pass an int when a protocol already fixes n. Auto is slower than a fixed k.
Hard top-k cutoff Rank globally and keep top-k Default append keeps the global top-k and adds the next append_budget genes from the same ranking (top-(k+m)). Use balance_method="none" for exact top-k.

append is a longer same-rank list (top-(k+m)), not a rare-subpopulation marker method (unlike GiniClust / CellSIUS). Pass marker_genes if a type is still unresolved.

Optional: estimate_n_populations counts populations from a 3D density field after sc.pp.neighbors. It works best on well-separated data with up to about 20 populations.

Docs: Read the Docs.

What you need

  • Python 3.10+ (tested 3.10–3.12)
  • For the default seurat_v3 flavor, an AnnData object with raw integer counts in .X or layers["counts"]

Install

pip install scfair
# or: conda install -c conda-forge -c bioconda scfair

Details: installation guide.

First run

import scanpy as sc
import scfair as scf

# the default seurat_v3 flavor expects raw integer counts
# in .X or layers["counts"]
scf.pp.highly_variable_genes(adata)
# annotates adata.var["highly_variable"]; keep the full gene matrix
# (scanpy PCA uses that mask by default — no manual subset step)

sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
sc.tl.pca(adata)
sc.pp.neighbors(adata)
sc.tl.leiden(adata, flavor="igraph", n_iterations=2, directed=False)

Default path: structure auto-n + same-rank append. Auto runs extra multi-seed graph builds and is slower than a fixed k. Read adata.uns["scfair"]["hvg"]["auto_message"] for a one-line summary of the chosen base size. Fixed length for a locked protocol:

scf.pp.highly_variable_genes(adata, n_top_genes=2000)

Pure top-k (no append tail):

scf.pp.highly_variable_genes(adata, n_top_genes=2000, balance_method="none")

Population count after neighbors:

sc.pp.neighbors(adata)
est = scf.pp.estimate_n_populations(adata)
print(est.n_populations, est.confidence)

Status

0.10.5 (Beta). Import as import scfair as scf and use names in scfair.__all__ and scf.pp. See the API reference.

Next steps

  1. Installation
  2. Quickstart
  3. Tutorials
  4. FAQ if something looks off

Citation

If you use scFair in published work, please cite the preprint:

Zhao Li, Aaron James, Shengxuan Li.
scFair: Geometry-Aware Gene Budgets and Same-Rank Extension for Highly Variable Gene Selection.
bioRxiv (2026). https://doi.org/10.64898/2026.08.08.743679

@article{li2026scfair,
  title   = {scFair: Geometry-Aware Gene Budgets and Same-Rank Extension for Highly Variable Gene Selection},
  author  = {Li, Zhao and James, Aaron and Li, Shengxuan},
  journal = {bioRxiv},
  year    = {2026},
  doi     = {10.64898/2026.08.08.743679},
  url     = {https://www.biorxiv.org/content/10.64898/2026.08.08.743679v1},
}

For the software record, cite the Zenodo DOI. Pin the package version used in the analysis, for example scfair==0.10.5. See CITATION.cff.

License

Software: Apache License 2.0.

Author

Zhao Li (李钊)
Email: leelieber@gmail.com

Metadata

Release files for scfair 0.10.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scfair 0.10.5
File Size Uploaded Provenance Actions
scfair-0.10.5.tar.gz 116.1 kB With provenance Details for scfair-0.10.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scfair 0.10.5
File Interpreter ABI Platform Actions
scfair-0.10.5-py3-none-any.whl Python 3 none any Details for scfair-0.10.5-py3-none-any.whl

Total release size: 187.9 kB

Release files / scfair-0.10.5.tar.gz

Download URL scfair-0.10.5.tar.gz
Size 116.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9c0378c61bc48b8a74d64c8a6a639038f9a7b55f93a91156ee260afbb7389356
BLAKE2b-256 checksum
How to use checksums
d163fbc1f20166963001995f5302ed178b532f68ee41ec9391c29537e4675be8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / scfair-0.10.5-py3-none-any.whl

Download URL scfair-0.10.5-py3-none-any.whl
Size 71.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5256bfcbc1b4ee10523b5e18eed8d55db7274b463fdd349164d77252cdc665e
BLAKE2b-256 checksum
How to use checksums
d23ab668ee9e1e4c2a8b2012f7467db3f970e245608f4a5d7d51a3646fb361e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for scfair 0.10.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for scfair-0.10.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page