scFair
scFair is drop-in HVG selection for single-cell RNA-seq that targets two everyday pain points:
| Problem | What goes wrong | What scFair does |
|---|---|---|
How many genes (n)? |
Users guess 2000 (or copy a paper). Too short can erase structure; too long adds noise. | n_top_genes="auto" (default) suggests a base size from the data. It is not proven optimal for every dataset — it is a safe default and a prompt so unfamiliar users are less likely to ship a silent bad n. Override with n_top_genes=2000 anytime. |
| Unfair HVG allocation | Global ranking is driven by large populations. Markers for smaller types often sit just below the cutoff. | Keeps that global ranking as the backbone and, by default, appends a small extension from the same ranking so near-miss genes are not discarded. The base top-k is never displaced. |
Docs: Read the Docs.
What you need
- Python 3.10+ (tested 3.10–3.12)
- An AnnData object with raw integer counts in
.Xorlayers["counts"]
Install
pip install scfair
First run
import scanpy as sc
import scfair as scf
# 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.pp.scale(adata, max_value=10)
sc.tl.pca(adata)
sc.pp.neighbors(adata)
sc.tl.leiden(adata)
That is the default path: pick a base size from the data (n_top_genes="auto"),
then append a few more genes from the same ranking. Auto is slower than a fixed
k (extra multi-seed graph builds). Read adata.uns["scfair"]["hvg"]["auto_message"]
for a one-line plain summary of the chosen base size. For a classical fixed list
or a paper protocol:
scf.pp.highly_variable_genes(adata, n_top_genes=2000)
To match scanpy with no extension:
scf.pp.highly_variable_genes(adata, n_top_genes=2000, balance_method="none")
Status
0.7.0 (Beta). Import as import scfair as scf and use names in
scfair.__all__ and scf.pp. See the
API reference.
Next steps
- Installation
- Quickstart
- Tutorial: PBMC 10k misclustered cells vs standard HVG
- FAQ if something looks off
License
Software: Apache License 2.0.
Author
Zhao Li (李钊)
Email: leelieber@gmail.com
Metadata
Release files for scfair 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| scfair-0.7.0.tar.gz | 1.7 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scfair-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.8 MB
Release files / scfair-0.7.0.tar.gz
| Download URL | scfair-0.7.0.tar.gz |
|---|---|
| Size | 1.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52e603c81a6570cc2cfacf62354fb581d041bbc42c058804d519760ee0c88a98
|
|
BLAKE2b-256 checksum How to use checksums |
d36b9613a8fe7397eb2c06f0e24c90faaeb7efc344b73d4d5cfb10cfb6c663fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 4, 2026.
Transparency logRelease files / scfair-0.7.0-py3-none-any.whl
| Download URL | scfair-0.7.0-py3-none-any.whl |
|---|---|
| Size | 82.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67c85eb2ff7b6d681c34223379efde0b0136bdfa8275bb9a94b70fdb0a1b1857
|
|
BLAKE2b-256 checksum How to use checksums |
c3ebcb342eec1798b4078f5543537474542f86a6328ecf43c604ca0e3059aebc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 4, 2026.
Transparency log