Skip to content

Commit 12066ef

Browse files
fishidahoclaude
andcommitted
Import the split-out names from where they are defined
The split left `factorization` re-exporting `export_factors`/`load_factors` purely so old import paths kept resolving, which meant two places to look for one function. Every call site now names the module that defines what it wants, and the shim is gone rather than papered over. scrise/__init__.py factor_io, alignment_stats scrise/tests/test_contracts.py factor_io scrise/tests/test_annotation_alignment.py alignment_stats docs/api.md both, under their own headings `factorization.__all__` and `annotation_alignment.__all__` now list only what those modules define. `annotation_alignment` still imports the statistics helpers, because `cell_type_alignment` and `score_cell_type_alignment` call them -- that is a real dependency, not a re-export, and they are no longer advertised as part of that module's surface. `scrise/__init__.py` keeps aggregating the whole public API, so `from scrise import export_factors` and `from scrise import compute_tau` are unchanged for callers; they now resolve to the defining module, and `scrise.export_factors is factor_io.export_factors`. Also carries the docstring trims made directly to `factor_io` and `alignment_stats`. Verified: the 69-key golden harness is still bit-identical, 90 passed / 1 skipped, ruff and C901 clean, `ty` clean over `scrise/`, every `analysis/` module imports, and `mkdocs build --strict` resolves both new `:::` module references. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016VJRB1RMUAb1id11XZ6KWS
1 parent 73df7bb commit 12066ef

8 files changed

Lines changed: 24 additions & 34 deletions

File tree

‎docs/api.md‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
options:
77
members:
88
- pf2
9-
- export_factors
10-
- load_factors
119
- correct_conditions
1210
- order_components_by_energy
1311
- canonical_component_signs
1412
- match_components_across_ranks
1513

14+
## Factor Import/Export
15+
16+
::: scrise.factor_io
17+
options:
18+
members:
19+
- export_factors
20+
- load_factors
21+
1622
## Rank Selection
1723

1824
::: scrise.rank_selection
@@ -24,6 +30,16 @@
2430

2531
::: scrise.annotation_alignment
2632

33+
### Alignment Statistics
34+
35+
::: scrise.alignment_stats
36+
options:
37+
members:
38+
- compute_auroc_per_cell_type
39+
- compute_tau
40+
- compute_eta_squared
41+
- compute_kruskal_epsilon_squared
42+
2743
## Quantization & Compression
2844

2945
::: scrise.opq

‎scrise/__init__.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
from parafac2.normalize import prepare_dataset
22

33
from . import plotting
4+
from .alignment_stats import compute_tau
45
from .annotation_alignment import (
56
CellTypeAlignmentResults,
67
ComponentAlignmentResult,
78
cell_type_alignment,
8-
compute_tau,
99
score_cell_type_alignment,
1010
)
11+
from .factor_io import export_factors, load_factors
1112
from .factorization import (
1213
canonical_component_signs,
1314
correct_conditions,
14-
export_factors,
15-
load_factors,
1615
match_components_across_ranks,
1716
order_components_by_energy,
1817
pf2,

‎scrise/alignment_stats.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
"""Statistics behind cell-type alignment scoring.
2-
3-
Pure numeric routines -- AUROC enrichment, uniqueness (tau), effect sizes,
4-
and the two p-value nulls -- with no AnnData dependency, so they can be
5-
tested and reused on plain arrays. :mod:`scrise.annotation_alignment` adds
6-
the AnnData plumbing and assembles the results.
7-
"""
8-
91
from __future__ import annotations
102

113
import numpy as np

‎scrise/annotation_alignment.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,5 @@ def score_cell_type_alignment(
431431
"CellTypeAlignmentResults",
432432
"ComponentAlignmentResult",
433433
"cell_type_alignment",
434-
"compute_auroc_per_cell_type",
435-
"compute_eta_squared",
436-
"compute_kruskal_epsilon_squared",
437-
"compute_tau",
438434
"score_cell_type_alignment",
439435
]

‎scrise/factor_io.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
33
Factors are exported to h5ad with the projection matrix OPQ-quantized and
44
the cell barcodes packed into a uint8 matrix, both of which have to be
5-
undone on load. Kept apart from :mod:`scrise.factorization`, which is
6-
concerned with computing a decomposition rather than moving one to and from
7-
disk.
5+
undone on load.
86
"""
97

108
import os
@@ -33,12 +31,7 @@ def _floats_to_float32(mapping) -> dict:
3331

3432

3533
def _pack_obs_names(obs: pd.DataFrame) -> np.ndarray | None:
36-
"""Replace a string barcode index with a RangeIndex, returning the bytes.
37-
38-
h5ad stores an object-dtype index far less compactly than a fixed-width
39-
uint8 matrix, so the barcodes travel in ``uns`` and are rebuilt by
40-
:func:`_restore_obs_names` on load.
41-
"""
34+
"""Replace a string barcode index with a RangeIndex, returning the bytes."""
4235
orig_index = obs.index.to_numpy(dtype=str)
4336
max_len = max((len(s) for s in orig_index), default=0)
4437
if max_len == 0:

‎scrise/factorization.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,9 @@ def rise_pca_r2x(
401401
return r2x_rise, r2x_pca[np.array(ranks) - 1]
402402

403403

404-
# Factor import/export lives in `factor_io`; re-exported here so the
405-
# long-standing `scrise.factorization.export_factors` path keeps working.
406-
from .factor_io import export_factors, load_factors # noqa: E402
407-
408404
__all__ = [
409405
"canonical_component_signs",
410406
"correct_conditions",
411-
"export_factors",
412-
"load_factors",
413407
"match_components_across_ranks",
414408
"order_components_by_energy",
415409
"pf2",

‎scrise/tests/test_annotation_alignment.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
compute_tau,
1919
score_cell_type_alignment,
2020
)
21-
from scrise.annotation_alignment import (
21+
from scrise.alignment_stats import (
2222
compute_auroc_per_cell_type,
2323
compute_eta_squared,
2424
compute_kruskal_epsilon_squared,

‎scrise/tests/test_contracts.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import pandas as pd
1818
import pytest
1919

20+
from ..factor_io import export_factors
2021
from ..factorization import (
2122
correct_conditions,
22-
export_factors,
2323
order_components_by_energy,
2424
pf2,
2525
)

0 commit comments

Comments
 (0)