stangene 0.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stangene/__init__.py +92 -0
- stangene/__main__.py +60 -0
- stangene/_logging.py +16 -0
- stangene/biotype.py +204 -0
- stangene/classify.py +65 -0
- stangene/data/refs/c_elegans/build_metadata.json +18 -0
- stangene/data/refs/c_elegans/gene_table.parquet +0 -0
- stangene/data/refs/cynomolgus/build_metadata.json +20 -0
- stangene/data/refs/cynomolgus/gene_table.parquet +0 -0
- stangene/data/refs/fruit_fly/build_metadata.json +18 -0
- stangene/data/refs/fruit_fly/gene_table.parquet +0 -0
- stangene/data/refs/human/build_metadata.json +13 -0
- stangene/data/refs/human/gene_table.parquet +0 -0
- stangene/data/refs/marmoset/build_metadata.json +20 -0
- stangene/data/refs/marmoset/gene_table.parquet +0 -0
- stangene/data/refs/mouse/build_metadata.json +22 -0
- stangene/data/refs/mouse/gene_table.parquet +0 -0
- stangene/data/refs/mouse_lemur/build_metadata.json +20 -0
- stangene/data/refs/mouse_lemur/gene_table.parquet +0 -0
- stangene/data/refs/rat/build_metadata.json +13 -0
- stangene/data/refs/rat/gene_table.parquet +0 -0
- stangene/data/refs/rhesus/build_metadata.json +20 -0
- stangene/data/refs/rhesus/gene_table.parquet +0 -0
- stangene/data/refs/zebrafish/build_metadata.json +23 -0
- stangene/data/refs/zebrafish/gene_table.parquet +0 -0
- stangene/harmonize.py +252 -0
- stangene/hb.py +83 -0
- stangene/infer.py +200 -0
- stangene/io.py +204 -0
- stangene/merge.py +80 -0
- stangene/mito.py +64 -0
- stangene/references.py +893 -0
- stangene/report.py +381 -0
- stangene/species.py +267 -0
- stangene-0.5.1.dist-info/METADATA +569 -0
- stangene-0.5.1.dist-info/RECORD +40 -0
- stangene-0.5.1.dist-info/WHEEL +5 -0
- stangene-0.5.1.dist-info/entry_points.txt +2 -0
- stangene-0.5.1.dist-info/licenses/LICENSE +21 -0
- stangene-0.5.1.dist-info/top_level.txt +1 -0
stangene/__init__.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Stangene: gene identifier harmonization for single-cell transcriptomics."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.5.1"
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from stangene.classify import classify_features
|
|
8
|
+
from stangene.harmonize import HarmonizationResult, harmonize
|
|
9
|
+
from stangene.io import load_features
|
|
10
|
+
from stangene.merge import MergeResult, merge_features
|
|
11
|
+
from stangene.references import (
|
|
12
|
+
ReferenceNotFoundError,
|
|
13
|
+
build_reference,
|
|
14
|
+
load_reference,
|
|
15
|
+
)
|
|
16
|
+
from stangene.report import conflict_report, generate_markdown_report, summary, write_reports
|
|
17
|
+
from stangene.species import resolve_species
|
|
18
|
+
from stangene.infer import infer_species
|
|
19
|
+
from stangene.mito import mito_mask
|
|
20
|
+
from stangene.hb import hb_mask
|
|
21
|
+
from stangene.biotype import CANONICAL_BIOTYPES, normalize_biotype
|
|
22
|
+
from stangene._logging import get_logger
|
|
23
|
+
|
|
24
|
+
_logger = get_logger("run")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def harmonize_anndata(adata, species: str, *, reference_dir: str = None) -> HarmonizationResult:
|
|
28
|
+
"""Harmonize an in-memory AnnData's features without touching the matrix.
|
|
29
|
+
|
|
30
|
+
Builds a FeatureTable from ``adata.var`` (mirroring the h5ad loader:
|
|
31
|
+
``original_feature_name`` from var_names, plus ``gene_ids``/``feature_types``
|
|
32
|
+
columns if present), then runs classify -> load_reference -> harmonize. The
|
|
33
|
+
returned ``HarmonizationResult.mapping_table`` rows are positionally aligned
|
|
34
|
+
with ``adata.var_names``. Does NOT modify ``adata`` or write any file —
|
|
35
|
+
applying the mapping (e.g. renaming var_names) is the caller's policy.
|
|
36
|
+
"""
|
|
37
|
+
from stangene.io import _infer_reference_source, _strip_version
|
|
38
|
+
|
|
39
|
+
var = adata.var
|
|
40
|
+
ft = pd.DataFrame({"original_feature_name": list(var.index)})
|
|
41
|
+
if "gene_ids" in var.columns:
|
|
42
|
+
ft["original_feature_id"] = var["gene_ids"].values
|
|
43
|
+
else:
|
|
44
|
+
# No dedicated ID column: var_names may themselves be Ensembl/stable IDs.
|
|
45
|
+
# Feed them as the ID too so ID tiers can match (a real symbol is not in
|
|
46
|
+
# the Ensembl set, so it simply falls through to the symbol tier — no
|
|
47
|
+
# false ID match), while original_feature_name still drives symbol matching.
|
|
48
|
+
ft["original_feature_id"] = list(var.index)
|
|
49
|
+
if "feature_types" in var.columns:
|
|
50
|
+
ft["original_feature_type"] = var["feature_types"].values
|
|
51
|
+
ft = ft.reset_index(drop=True)
|
|
52
|
+
|
|
53
|
+
# Mirror load_features' column normalization (harmonize() requires these).
|
|
54
|
+
ft["species"] = species
|
|
55
|
+
ft["dataset"] = "anndata"
|
|
56
|
+
if "original_feature_id" in ft.columns:
|
|
57
|
+
ft["feature_id_no_version"] = ft["original_feature_id"].apply(_strip_version)
|
|
58
|
+
ft.loc[ft["feature_id_no_version"] == "", "feature_id_no_version"] = None
|
|
59
|
+
else:
|
|
60
|
+
ft["original_feature_id"] = None
|
|
61
|
+
ft["feature_id_no_version"] = None
|
|
62
|
+
ft["original_feature_id"] = ft["original_feature_id"].replace("", None)
|
|
63
|
+
ft["reference_source"] = _infer_reference_source(ft.get("original_feature_id"))
|
|
64
|
+
ft["reference_release"] = None
|
|
65
|
+
|
|
66
|
+
ft = classify_features(ft)
|
|
67
|
+
ref = load_reference(species, reference_dir=reference_dir)
|
|
68
|
+
return harmonize(ft, ref)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def run(
|
|
72
|
+
path: str,
|
|
73
|
+
species: str,
|
|
74
|
+
output_dir: str = None,
|
|
75
|
+
dataset_name: str = None,
|
|
76
|
+
reference_dir: str = None,
|
|
77
|
+
) -> HarmonizationResult:
|
|
78
|
+
"""Run the full harmonization pipeline on a single dataset."""
|
|
79
|
+
_logger.info("Starting harmonization: path=%s, species=%s", path, species)
|
|
80
|
+
|
|
81
|
+
ft = load_features(path, species=species, dataset_name=dataset_name)
|
|
82
|
+
ft = classify_features(ft)
|
|
83
|
+
ref = load_reference(species, reference_dir=reference_dir)
|
|
84
|
+
result = harmonize(ft, ref)
|
|
85
|
+
|
|
86
|
+
if output_dir:
|
|
87
|
+
from stangene.io import write_results
|
|
88
|
+
write_results(result, output_dir, input_path=path)
|
|
89
|
+
write_reports(result, output_dir)
|
|
90
|
+
|
|
91
|
+
_logger.info("Harmonization complete: %s", result.stats)
|
|
92
|
+
return result
|
stangene/__main__.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""CLI entry point for stangene."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from stangene._logging import get_logger
|
|
7
|
+
|
|
8
|
+
logger = get_logger("cli")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
parser = argparse.ArgumentParser(
|
|
13
|
+
prog="stangene",
|
|
14
|
+
description="Gene identifier harmonization for single-cell transcriptomics",
|
|
15
|
+
)
|
|
16
|
+
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
17
|
+
|
|
18
|
+
harm_parser = subparsers.add_parser("harmonize", help="Harmonize gene identifiers")
|
|
19
|
+
harm_parser.add_argument("--input", required=True, help="Path to input file")
|
|
20
|
+
harm_parser.add_argument("--species", required=True, help="Species name")
|
|
21
|
+
harm_parser.add_argument("--output-dir", required=True, help="Output directory")
|
|
22
|
+
harm_parser.add_argument("--dataset-name", default=None, help="Dataset name")
|
|
23
|
+
harm_parser.add_argument("--reference-dir", default=None, help="Reference directory")
|
|
24
|
+
|
|
25
|
+
build_parser = subparsers.add_parser("build-refs", help="Build reference databases")
|
|
26
|
+
build_parser.add_argument("--species", required=True, help="Species name")
|
|
27
|
+
build_parser.add_argument("--reference-dir", default=None, help="Reference directory")
|
|
28
|
+
build_parser.add_argument("--force", action="store_true", help="Force rebuild")
|
|
29
|
+
|
|
30
|
+
args = parser.parse_args()
|
|
31
|
+
|
|
32
|
+
if args.command == "harmonize":
|
|
33
|
+
from stangene import run
|
|
34
|
+
try:
|
|
35
|
+
result = run(
|
|
36
|
+
path=args.input, species=args.species,
|
|
37
|
+
output_dir=args.output_dir, dataset_name=args.dataset_name,
|
|
38
|
+
reference_dir=args.reference_dir,
|
|
39
|
+
)
|
|
40
|
+
print(f"Harmonization complete. {len(result.mapping_table)} features processed.")
|
|
41
|
+
print(f"Status counts: {result.stats}")
|
|
42
|
+
print(f"Reports written to: {args.output_dir}")
|
|
43
|
+
except Exception as e:
|
|
44
|
+
logger.error("Harmonization failed: %s", e)
|
|
45
|
+
sys.exit(1)
|
|
46
|
+
elif args.command == "build-refs":
|
|
47
|
+
from stangene.references import build_reference
|
|
48
|
+
try:
|
|
49
|
+
build_reference(species=args.species, reference_dir=args.reference_dir, force=args.force)
|
|
50
|
+
print(f"Reference build complete for {args.species}.")
|
|
51
|
+
except Exception as e:
|
|
52
|
+
logger.error("Reference build failed: %s", e)
|
|
53
|
+
sys.exit(1)
|
|
54
|
+
else:
|
|
55
|
+
parser.print_help()
|
|
56
|
+
sys.exit(1)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
main()
|
stangene/_logging.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Structured logging for stangene."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_logger(name: str) -> logging.Logger:
|
|
7
|
+
"""Get a logger under the stangene namespace."""
|
|
8
|
+
logger = logging.getLogger(f"stangene.{name}")
|
|
9
|
+
if not logger.handlers:
|
|
10
|
+
handler = logging.StreamHandler()
|
|
11
|
+
handler.setFormatter(
|
|
12
|
+
logging.Formatter("%(asctime)s [%(name)s] %(levelname)s: %(message)s")
|
|
13
|
+
)
|
|
14
|
+
logger.addHandler(handler)
|
|
15
|
+
logger.setLevel(logging.INFO)
|
|
16
|
+
return logger
|
stangene/biotype.py
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"""Canonical gene biotype vocabulary and per-source normalization."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
CANONICAL_BIOTYPES: frozenset[str] = frozenset({
|
|
6
|
+
"protein_coding",
|
|
7
|
+
"lncRNA",
|
|
8
|
+
"pseudogene",
|
|
9
|
+
"miRNA",
|
|
10
|
+
"snoRNA",
|
|
11
|
+
"snRNA",
|
|
12
|
+
"rRNA",
|
|
13
|
+
"tRNA",
|
|
14
|
+
"IG_gene",
|
|
15
|
+
"TR_gene",
|
|
16
|
+
"other_ncrna",
|
|
17
|
+
"other",
|
|
18
|
+
"unknown",
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
# HGNC: locus_type field (more granular than locus_group)
|
|
22
|
+
_HGNC_MAP: dict[str, str] = {
|
|
23
|
+
"gene with protein product": "protein_coding",
|
|
24
|
+
"rna, micro": "miRNA",
|
|
25
|
+
"rna, small nucleolar": "snoRNA",
|
|
26
|
+
"rna, small nuclear": "snRNA",
|
|
27
|
+
"rna, ribosomal": "rRNA",
|
|
28
|
+
"rna, transfer": "tRNA",
|
|
29
|
+
"rna, long non-coding": "lncRNA",
|
|
30
|
+
"rna, y": "other_ncrna",
|
|
31
|
+
"rna, vault": "other_ncrna",
|
|
32
|
+
"rna, small cytoplasmic": "other_ncrna",
|
|
33
|
+
"immunoglobulin gene": "IG_gene",
|
|
34
|
+
"t cell receptor gene": "TR_gene",
|
|
35
|
+
"pseudogene": "pseudogene",
|
|
36
|
+
"endogenous retrovirus": "other",
|
|
37
|
+
"complex locus constituent": "other",
|
|
38
|
+
"fragile site": "other",
|
|
39
|
+
"readthrough": "other",
|
|
40
|
+
"region": "other",
|
|
41
|
+
"unknown": "unknown",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# MGI: feature_type field
|
|
45
|
+
_MGI_MAP: dict[str, str] = {
|
|
46
|
+
"protein coding gene": "protein_coding",
|
|
47
|
+
"lncrna gene": "lncRNA",
|
|
48
|
+
"pseudogene": "pseudogene",
|
|
49
|
+
"mirna gene": "miRNA",
|
|
50
|
+
"snorna gene": "snoRNA",
|
|
51
|
+
"snrna gene": "snRNA",
|
|
52
|
+
"rrna gene": "rRNA",
|
|
53
|
+
"trna gene": "tRNA",
|
|
54
|
+
"ig gene": "IG_gene",
|
|
55
|
+
"tr gene": "TR_gene",
|
|
56
|
+
"unclassified non-coding rna gene": "other_ncrna",
|
|
57
|
+
"pirna gene": "other_ncrna",
|
|
58
|
+
"scrna gene": "other_ncrna",
|
|
59
|
+
"rnase mrp rna gene": "other_ncrna",
|
|
60
|
+
"rnase p rna gene": "other_ncrna",
|
|
61
|
+
"srp rna gene": "other_ncrna",
|
|
62
|
+
"telomerase rna gene": "other_ncrna",
|
|
63
|
+
"antisense lncrna gene": "lncRNA",
|
|
64
|
+
"bidirectional promoter lncrna": "lncRNA",
|
|
65
|
+
"transgene": "other",
|
|
66
|
+
"unclassified gene": "other",
|
|
67
|
+
"gene segment": "other",
|
|
68
|
+
"other feature types": "other",
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# RGD: GENE_TYPE field (lowercase in data)
|
|
72
|
+
_RGD_MAP: dict[str, str] = {
|
|
73
|
+
"protein-coding": "protein_coding",
|
|
74
|
+
"ncrna": "other_ncrna",
|
|
75
|
+
"lincrna": "lncRNA",
|
|
76
|
+
"lncrna": "lncRNA",
|
|
77
|
+
"mirna": "miRNA",
|
|
78
|
+
"snorna": "snoRNA",
|
|
79
|
+
"snrna": "snRNA",
|
|
80
|
+
"rrna": "rRNA",
|
|
81
|
+
"trna": "tRNA",
|
|
82
|
+
"pseudo": "pseudogene",
|
|
83
|
+
"pseudogene": "pseudogene",
|
|
84
|
+
"gene": "other",
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Ensembl BioMart: gene_biotype field
|
|
88
|
+
# Pseudogene subtypes all end in "pseudogene" — handled by suffix fallback below.
|
|
89
|
+
# IG/TR subtypes all match IG_*_gene / TR_*_gene — handled by prefix fallback.
|
|
90
|
+
_ENSEMBL_MAP: dict[str, str] = {
|
|
91
|
+
"protein_coding": "protein_coding",
|
|
92
|
+
"lincrna": "lncRNA",
|
|
93
|
+
"lncrna": "lncRNA",
|
|
94
|
+
"mirna": "miRNA",
|
|
95
|
+
"snorna": "snoRNA",
|
|
96
|
+
"snrna": "snRNA",
|
|
97
|
+
"rrna": "rRNA",
|
|
98
|
+
"mt_rrna": "rRNA",
|
|
99
|
+
"trna": "tRNA",
|
|
100
|
+
"mt_trna": "tRNA",
|
|
101
|
+
"pseudogene": "pseudogene",
|
|
102
|
+
"misc_rna": "other_ncrna",
|
|
103
|
+
"ribozyme": "other_ncrna",
|
|
104
|
+
"vault_rna": "other_ncrna",
|
|
105
|
+
"scrna": "other_ncrna",
|
|
106
|
+
"pirna": "other_ncrna",
|
|
107
|
+
"scarna": "other_ncrna",
|
|
108
|
+
"known_ncrna": "other_ncrna",
|
|
109
|
+
"processed_transcript": "other_ncrna",
|
|
110
|
+
"tec": "other",
|
|
111
|
+
"artifact": "other",
|
|
112
|
+
"disrupted_domain": "other",
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# WormBase: biotype field
|
|
116
|
+
_WORMBASE_MAP: dict[str, str] = {
|
|
117
|
+
"protein_coding_gene": "protein_coding",
|
|
118
|
+
"pseudogene": "pseudogene",
|
|
119
|
+
"lncrna_gene": "lncRNA",
|
|
120
|
+
"mirna_gene": "miRNA",
|
|
121
|
+
"snorna_gene": "snoRNA",
|
|
122
|
+
"snrna_gene": "snRNA",
|
|
123
|
+
"rrna_gene": "rRNA",
|
|
124
|
+
"trna_gene": "tRNA",
|
|
125
|
+
"ncrna_gene": "other_ncrna",
|
|
126
|
+
"pirna_gene": "other_ncrna",
|
|
127
|
+
"scrna_gene": "other_ncrna",
|
|
128
|
+
"transposable_element_gene": "other",
|
|
129
|
+
"operon": "other",
|
|
130
|
+
"gene": "other", # generic unclassified WormBase gene
|
|
131
|
+
"lincrna_gene": "lncRNA", # long intergenic ncRNA
|
|
132
|
+
"antisense_lncrna_gene": "lncRNA", # antisense lncRNA
|
|
133
|
+
"transcript": "other", # data artifact
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# ZFIN: SO (Sequence Ontology) ID, e.g. "SO:0001217"
|
|
137
|
+
_ZFIN_SO_MAP: dict[str, str] = {
|
|
138
|
+
"so:0001217": "protein_coding", # protein_coding_gene
|
|
139
|
+
"so:0000336": "pseudogene", # pseudogene
|
|
140
|
+
"so:0001263": "miRNA", # miRNA_gene
|
|
141
|
+
"so:0001267": "snoRNA", # snoRNA_gene
|
|
142
|
+
"so:0001268": "snRNA", # snRNA_gene
|
|
143
|
+
"so:0001637": "rRNA", # rRNA_gene
|
|
144
|
+
"so:0001272": "tRNA", # tRNA_gene
|
|
145
|
+
"so:0001877": "lncRNA", # lncRNA_gene
|
|
146
|
+
"so:0001900": "other_ncrna", # ncRNA_gene
|
|
147
|
+
"so:0001265": "other_ncrna", # miRNA_primary_transcript (pre-miRNA)
|
|
148
|
+
"so:0001032": "other_ncrna", # other ncRNA
|
|
149
|
+
"so:0000704": "other", # gene (unspecified)
|
|
150
|
+
"so:0000233": "other", # processed_transcript
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
_SOURCE_MAPS: dict[str, dict[str, str]] = {
|
|
154
|
+
"HGNC": _HGNC_MAP,
|
|
155
|
+
"MGI": _MGI_MAP,
|
|
156
|
+
"RGD": _RGD_MAP,
|
|
157
|
+
"Ensembl": _ENSEMBL_MAP,
|
|
158
|
+
"WormBase": _WORMBASE_MAP,
|
|
159
|
+
"ZFIN": _ZFIN_SO_MAP,
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def normalize_biotype(raw: str, source: str) -> str:
|
|
164
|
+
"""Map a raw gene_type string to a canonical biotype.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
raw: The raw gene_type string from the upstream database.
|
|
168
|
+
source: One of "HGNC", "MGI", "RGD", "Ensembl", "WormBase",
|
|
169
|
+
"ZFIN", or "FlyBase".
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
A member of CANONICAL_BIOTYPES. Unmapped values return "unknown".
|
|
173
|
+
"""
|
|
174
|
+
key = raw.strip().lower()
|
|
175
|
+
if not key:
|
|
176
|
+
return "unknown"
|
|
177
|
+
|
|
178
|
+
# FlyBase uses annotation_id prefix convention (no dict lookup needed)
|
|
179
|
+
if source == "FlyBase":
|
|
180
|
+
if key.startswith("cg"):
|
|
181
|
+
return "protein_coding"
|
|
182
|
+
if key.startswith("cr"):
|
|
183
|
+
return "other_ncrna"
|
|
184
|
+
return "other"
|
|
185
|
+
|
|
186
|
+
source_map = _SOURCE_MAPS.get(source)
|
|
187
|
+
if source_map is None:
|
|
188
|
+
return "unknown"
|
|
189
|
+
|
|
190
|
+
result = source_map.get(key)
|
|
191
|
+
if result is not None:
|
|
192
|
+
return result
|
|
193
|
+
|
|
194
|
+
# Ensembl fallbacks: many pseudogene subtypes end in "pseudogene";
|
|
195
|
+
# IG/TR gene subtypes start with ig_ or tr_ and end with _gene.
|
|
196
|
+
if source == "Ensembl":
|
|
197
|
+
if key.endswith("pseudogene"):
|
|
198
|
+
return "pseudogene"
|
|
199
|
+
if key.startswith("ig_") and key.endswith("_gene"):
|
|
200
|
+
return "IG_gene"
|
|
201
|
+
if key.startswith("tr_") and key.endswith("_gene"):
|
|
202
|
+
return "TR_gene"
|
|
203
|
+
|
|
204
|
+
return "unknown"
|
stangene/classify.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Feature type classification for gene vs non-gene triage."""
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from stangene._logging import get_logger
|
|
6
|
+
from stangene.species import CLASSIFICATION_PATTERNS
|
|
7
|
+
|
|
8
|
+
logger = get_logger("classify")
|
|
9
|
+
|
|
10
|
+
# Map 10x Cell Ranger feature_type labels to our internal types
|
|
11
|
+
_CELLRANGER_TYPE_MAP = {
|
|
12
|
+
"Gene Expression": "gene",
|
|
13
|
+
"Antibody Capture": "antibody_capture",
|
|
14
|
+
"CRISPR Guide Capture": "crispr_guide",
|
|
15
|
+
"Custom": "custom",
|
|
16
|
+
"Peaks": "peak",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_NON_GENE_TYPES = frozenset([
|
|
20
|
+
"transcript", "antibody_capture", "crispr_guide",
|
|
21
|
+
"spike_in", "peak", "custom",
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def classify_features(ft: pd.DataFrame) -> pd.DataFrame:
|
|
26
|
+
"""Classify features as gene or non-gene types.
|
|
27
|
+
|
|
28
|
+
Adds/updates 'original_feature_type' and sets 'mapping_status' to
|
|
29
|
+
'non_gene_feature' for non-gene rows. Returns a copy.
|
|
30
|
+
"""
|
|
31
|
+
result = ft.copy()
|
|
32
|
+
|
|
33
|
+
# Ensure columns exist
|
|
34
|
+
if "original_feature_type" not in result.columns:
|
|
35
|
+
result["original_feature_type"] = None
|
|
36
|
+
if "mapping_status" not in result.columns:
|
|
37
|
+
result["mapping_status"] = None
|
|
38
|
+
if "mapping_notes" not in result.columns:
|
|
39
|
+
result["mapping_notes"] = None
|
|
40
|
+
|
|
41
|
+
for idx in result.index:
|
|
42
|
+
existing_type = result.at[idx, "original_feature_type"]
|
|
43
|
+
|
|
44
|
+
if pd.notna(existing_type) and existing_type in _CELLRANGER_TYPE_MAP:
|
|
45
|
+
result.at[idx, "original_feature_type"] = _CELLRANGER_TYPE_MAP[existing_type]
|
|
46
|
+
elif pd.notna(existing_type) and existing_type in _NON_GENE_TYPES | {"gene"}:
|
|
47
|
+
pass
|
|
48
|
+
else:
|
|
49
|
+
name = result.at[idx, "original_feature_name"]
|
|
50
|
+
matched = False
|
|
51
|
+
for pattern, ftype in CLASSIFICATION_PATTERNS:
|
|
52
|
+
if pattern.match(str(name)):
|
|
53
|
+
result.at[idx, "original_feature_type"] = ftype
|
|
54
|
+
matched = True
|
|
55
|
+
break
|
|
56
|
+
if not matched:
|
|
57
|
+
result.at[idx, "original_feature_type"] = "gene"
|
|
58
|
+
result.at[idx, "mapping_notes"] = "classified as gene by default (no pattern match)"
|
|
59
|
+
|
|
60
|
+
if result.at[idx, "original_feature_type"] in _NON_GENE_TYPES:
|
|
61
|
+
result.at[idx, "mapping_status"] = "non_gene_feature"
|
|
62
|
+
|
|
63
|
+
classified_counts = result["original_feature_type"].value_counts().to_dict()
|
|
64
|
+
logger.info("Feature classification: %s", classified_counts)
|
|
65
|
+
return result
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "c_elegans",
|
|
3
|
+
"download_timestamp": "2026-04-24T02:54:48.517177+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"wormbase_gene_ids": {
|
|
6
|
+
"url": "https://downloads.wormbase.org/releases/current-production-release/species/c_elegans/PRJNA13758/annotation/c_elegans.PRJNA13758.WS298.geneIDs.txt.gz",
|
|
7
|
+
"sha256": "d87c69d1cabc03dc3e0d76b98944fecd952734f1010073b8d84c0970cda19346",
|
|
8
|
+
"rows": 52110
|
|
9
|
+
},
|
|
10
|
+
"wormbase_other_ids": {
|
|
11
|
+
"url": "https://downloads.wormbase.org/releases/current-production-release/species/c_elegans/PRJNA13758/annotation/c_elegans.PRJNA13758.WS298.geneOtherIDs.txt.gz",
|
|
12
|
+
"sha256": "d549f0f41bc8cd301ddac1ac91f96fcdbb3815dc38ae29cce040bd758f447608",
|
|
13
|
+
"rows": 52110
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"gene_count": 49552,
|
|
17
|
+
"lookup_count": 106688
|
|
18
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "cynomolgus",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:20:27.951252+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"ensembl_biomart": {
|
|
6
|
+
"url": "https://www.ensembl.org/biomart/martservice?query=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3C%21DOCTYPE%20Query%3E%3CQuery%20virtualSchemaName%3D%22default%22%20formatter%3D%22TSV%22%20header%3D%221%22%3E%3CDataset%20name%3D%22mfascicularis_gene_ensembl%22%20interface%3D%22default%22%3E%3CAttribute%20name%3D%22ensembl_gene_id%22/%3E%3CAttribute%20name%3D%22external_gene_name%22/%3E%3CAttribute%20name%3D%22external_synonym%22/%3E%3CAttribute%20name%3D%22gene_biotype%22/%3E%3C/Dataset%3E%3C/Query%3E",
|
|
7
|
+
"dataset": "mfascicularis_gene_ensembl",
|
|
8
|
+
"attributes": [
|
|
9
|
+
"ensembl_gene_id",
|
|
10
|
+
"external_gene_name",
|
|
11
|
+
"external_synonym",
|
|
12
|
+
"gene_biotype"
|
|
13
|
+
],
|
|
14
|
+
"sha256": "007c79088bc60dc04280c5affc2e38371c7955b380059f2e237bc5befc12d95a",
|
|
15
|
+
"rows": 38566
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"gene_count": 38550,
|
|
19
|
+
"lookup_count": 23134
|
|
20
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "fruit_fly",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:43:30.043674+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"flybase_gene_map": {
|
|
6
|
+
"url": "https://s3ftp.flybase.org/releases/current/precomputed_files/genes/fbgn_annotation_ID.tsv.gz",
|
|
7
|
+
"sha256": "d48298573536bbd049c082691f6631e732c18d31bc310abd777c0b6996518a17",
|
|
8
|
+
"rows": 17871
|
|
9
|
+
},
|
|
10
|
+
"flybase_synonyms": {
|
|
11
|
+
"url": "https://s3ftp.flybase.org/releases/current/precomputed_files/synonyms/fb_synonym_fb_2026_01.tsv.gz",
|
|
12
|
+
"sha256": "7e5814a4191766c84494dd499fa6b29d87384e3a36add9fed76bd927174107db",
|
|
13
|
+
"rows": 744145
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"gene_count": 17871,
|
|
17
|
+
"lookup_count": 111050
|
|
18
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "human",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:17:45.959244+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"hgnc": {
|
|
6
|
+
"url": "https://storage.googleapis.com/public-download-files/hgnc/tsv/tsv/hgnc_complete_set.txt",
|
|
7
|
+
"sha256": "09bf2241a8506691033f0c54e499b31dccd12a1bdd29c927e5c82b6599e5f56b",
|
|
8
|
+
"rows": 44997
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"gene_count": 44997,
|
|
12
|
+
"lookup_count": 105610
|
|
13
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "marmoset",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:20:49.950375+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"ensembl_biomart": {
|
|
6
|
+
"url": "https://www.ensembl.org/biomart/martservice?query=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3C%21DOCTYPE%20Query%3E%3CQuery%20virtualSchemaName%3D%22default%22%20formatter%3D%22TSV%22%20header%3D%221%22%3E%3CDataset%20name%3D%22cjacchus_gene_ensembl%22%20interface%3D%22default%22%3E%3CAttribute%20name%3D%22ensembl_gene_id%22/%3E%3CAttribute%20name%3D%22external_gene_name%22/%3E%3CAttribute%20name%3D%22external_synonym%22/%3E%3CAttribute%20name%3D%22gene_biotype%22/%3E%3C/Dataset%3E%3C/Query%3E",
|
|
7
|
+
"dataset": "cjacchus_gene_ensembl",
|
|
8
|
+
"attributes": [
|
|
9
|
+
"ensembl_gene_id",
|
|
10
|
+
"external_gene_name",
|
|
11
|
+
"external_synonym",
|
|
12
|
+
"gene_biotype"
|
|
13
|
+
],
|
|
14
|
+
"sha256": "ed0cda0a40d0a796850d96e4194703b15f8d9c31dd0bc196f4be25f6792aa313",
|
|
15
|
+
"rows": 40236
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"gene_count": 40188,
|
|
19
|
+
"lookup_count": 27493
|
|
20
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "mouse",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:18:56.012031+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"mgi_markers": {
|
|
6
|
+
"url": "https://www.informatics.jax.org/downloads/reports/MRK_List2.rpt",
|
|
7
|
+
"sha256": "f086d3c772a504be243d173693df6cfdcf4329f607be101eb5fd7fd790140d16",
|
|
8
|
+
"rows": 656698
|
|
9
|
+
},
|
|
10
|
+
"mgi_ensembl": {
|
|
11
|
+
"url": "https://www.informatics.jax.org/downloads/reports/MRK_ENSEMBL.rpt",
|
|
12
|
+
"sha256": "d6133fb96e07aeeccee86be8545f31c52dfb0dda81d2329b287f90e88fdde756",
|
|
13
|
+
"rows": 77644
|
|
14
|
+
},
|
|
15
|
+
"ensembl_biomart": {
|
|
16
|
+
"url": "https://www.ensembl.org/biomart/martservice?query=",
|
|
17
|
+
"note": "supplementary Ensembl ID gap fill"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"gene_count": 100509,
|
|
21
|
+
"lookup_count": 161293
|
|
22
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "mouse_lemur",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:20:57.096005+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"ensembl_biomart": {
|
|
6
|
+
"url": "https://www.ensembl.org/biomart/martservice?query=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3C%21DOCTYPE%20Query%3E%3CQuery%20virtualSchemaName%3D%22default%22%20formatter%3D%22TSV%22%20header%3D%221%22%3E%3CDataset%20name%3D%22mmurinus_gene_ensembl%22%20interface%3D%22default%22%3E%3CAttribute%20name%3D%22ensembl_gene_id%22/%3E%3CAttribute%20name%3D%22external_gene_name%22/%3E%3CAttribute%20name%3D%22external_synonym%22/%3E%3CAttribute%20name%3D%22gene_biotype%22/%3E%3C/Dataset%3E%3C/Query%3E",
|
|
7
|
+
"dataset": "mmurinus_gene_ensembl",
|
|
8
|
+
"attributes": [
|
|
9
|
+
"ensembl_gene_id",
|
|
10
|
+
"external_gene_name",
|
|
11
|
+
"external_synonym",
|
|
12
|
+
"gene_biotype"
|
|
13
|
+
],
|
|
14
|
+
"sha256": "acfe817264d26d695e5440c56b87c9d67bf3054c0592767ec1f54aa783a4b09a",
|
|
15
|
+
"rows": 26807
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"gene_count": 26798,
|
|
19
|
+
"lookup_count": 22649
|
|
20
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "rat",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:19:10.606022+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"rgd_genes": {
|
|
6
|
+
"url": "https://download.rgd.mcw.edu/data_release/RAT/GENES_RAT.txt",
|
|
7
|
+
"sha256": "632a4adb6feb1532819f3c5067d52c6e3d90a3e596fba9a4450b0738f5db5a59",
|
|
8
|
+
"rows": 61624
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"gene_count": 61624,
|
|
12
|
+
"lookup_count": 116350
|
|
13
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "rhesus",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:20:38.354464+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"ensembl_biomart": {
|
|
6
|
+
"url": "https://www.ensembl.org/biomart/martservice?query=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3C%21DOCTYPE%20Query%3E%3CQuery%20virtualSchemaName%3D%22default%22%20formatter%3D%22TSV%22%20header%3D%221%22%3E%3CDataset%20name%3D%22mmulatta_gene_ensembl%22%20interface%3D%22default%22%3E%3CAttribute%20name%3D%22ensembl_gene_id%22/%3E%3CAttribute%20name%3D%22external_gene_name%22/%3E%3CAttribute%20name%3D%22external_synonym%22/%3E%3CAttribute%20name%3D%22gene_biotype%22/%3E%3C/Dataset%3E%3C/Query%3E",
|
|
7
|
+
"dataset": "mmulatta_gene_ensembl",
|
|
8
|
+
"attributes": [
|
|
9
|
+
"ensembl_gene_id",
|
|
10
|
+
"external_gene_name",
|
|
11
|
+
"external_synonym",
|
|
12
|
+
"gene_biotype"
|
|
13
|
+
],
|
|
14
|
+
"sha256": "b75df4acb81e5780161a9180075cad2821659c1463003f78180aeed5636fcec8",
|
|
15
|
+
"rows": 35575
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"gene_count": 35432,
|
|
19
|
+
"lookup_count": 25834
|
|
20
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"species": "zebrafish",
|
|
3
|
+
"download_timestamp": "2026-06-25T07:34:51.908513+00:00",
|
|
4
|
+
"sources": {
|
|
5
|
+
"zfin_genes": {
|
|
6
|
+
"url": "https://zfin.org/downloads/gene.txt",
|
|
7
|
+
"sha256": "ba4ad5cd0b5e717ec0f9369b35ccccf75b8126c23e1f3a8c23475d7bab39f8b7",
|
|
8
|
+
"rows": 25562
|
|
9
|
+
},
|
|
10
|
+
"zfin_aliases": {
|
|
11
|
+
"url": "https://zfin.org/downloads/aliases.txt",
|
|
12
|
+
"sha256": "3ad97187aaea70cda3f0c87c26d8763e76d40126929a35d5b0cf74d9764d3e03",
|
|
13
|
+
"rows": 197789
|
|
14
|
+
},
|
|
15
|
+
"zfin_ensembl": {
|
|
16
|
+
"url": "https://zfin.org/downloads/ensembl_1_to_1.txt",
|
|
17
|
+
"sha256": "d67028499e204a8af94599745211a14a5791be5a05c472ba6100c43c8547250d",
|
|
18
|
+
"rows": 27195
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"gene_count": 25562,
|
|
22
|
+
"lookup_count": 25562
|
|
23
|
+
}
|