Skip to content

fix(pp): add_tile_matrix shape error when input AnnData has 0 vars - #42

Open
Starlitnightly wants to merge 1 commit into
mainfrom
fix/add-tile-matrix-zero-var
Open

Starlitnightly wants to merge 1 commit into
mainfrom
fix/add-tile-matrix-zero-var

Conversation

@Starlitnightly

Copy link
Copy Markdown
Collaborator

Problem

epione.pp.add_tile_matrix(adata, bin_size=500) crashes (reported as omicverse #840):

building tile matrix: 568 cells × 6,176,584 tiles (500 bp bins, strategy=paired-insertion)
ValueError: Data matrix has wrong shape (568, 6176584), need to be (568, 0).

The AnnData produced by import_fragments has 0 vars. add_tile_matrix assigned the (n_cells, n_tiles) tile matrix to adata.X before replacing var, so AnnData validated the new X against the current (empty) var and rejected it. Assigning var first would fail symmetrically — X and var must become consistent together.

Fix

Rebuild the object in place via AnnData._init_as_actual(...) with the new X + var (preserving obs/uns/obsm/obsp), keeping the original lazy .X assignment as a fallback for backed / AnnDataOOM inputs.

Verification

Minimal repro (0-var AnnData + a tiny fragments.tsv) now succeeds:

building tile matrix: 3 cells × 6 tiles (500 bp bins, strategy=paired-insertion)
tile matrix nnz=12
→ shape (3, 6), var = ['chr1:0-499', 'chr1:500-999', ...], mutated in place, uns preserved

Fixes omicverse/omicverse#840

🤖 Generated with Claude Code

add_tile_matrix assigned the (n_cells, n_tiles) matrix to adata.X before setting
var, but the incoming AnnData (from import_fragments) has 0 vars, so AnnData
rejected it: 'Data matrix has wrong shape (N, n_tiles), need to be (N, 0)'
(omicverse issue #840). X and var must become consistent together — rebuild the
object in place via _init_as_actual (preserving obs/uns/obsm/obsp), keeping the
lazy .X path as a fallback for backed / AnnDataOOM inputs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VVqVNig3oV6wz42YiQ9obZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in ATAC single-cell workflow

1 participant