Centralize partition metadata access and add layer introspection APIs
Replaced scattered direct metadata loading with centralized instance methods on `KmerPartition` to guarantee consistent error mapping and legacy recovery. Introduced `StorageKind`, `LayerContent`, and `EvidenceKind` enums alongside lightweight disk-probe methods that inspect file presence without opening heavy data structures. Updated callers across the index, partitioner, and phylo modules to use the new partition API, and added unit tests validating the introspection behavior.
This commit is contained in:
1 parent
f7ebc7a1ab
commit
76cbd3a886
23 files changed
+580
-74
No files matched your search
@@ -6,6 +6,7 @@ use ndarray::{Array1, Array2};
|
||||
use crate::bitvec::{PersistentBitVec, PersistentBitVecBuilder};
|
||||
use crate::layer_meta::LayerMeta;
|
||||
use crate::meta::MatrixMeta;
|
||||
use crate::storage_kind::StorageKind;
|
||||
use crate::traits::{BitPartials, ColumnWeights};
|
||||
use crate::views::{nonzero_triples, BitSliceView};
|
||||
|
||||
@@ -63,6 +64,42 @@ impl PersistentBitMatrix {
|
||||
Ok(Self::Implicit { n_rows: meta.n, n_cols: 1 })
|
||||
}
|
||||
|
||||
/// This already-open matrix's storage format — reads the discriminant
|
||||
/// already in memory, no disk access.
|
||||
#[inline]
|
||||
pub fn storage_kind(&self) -> StorageKind {
|
||||
match self {
|
||||
Self::Columnar(_) => StorageKind::Columnar,
|
||||
Self::Packed(_) => StorageKind::Packed,
|
||||
Self::Sparse(_) => StorageKind::Sparse,
|
||||
Self::Implicit { .. } => StorageKind::Implicit,
|
||||
}
|
||||
}
|
||||
|
||||
/// Lightweight disk probe: which format `open` would pick, without
|
||||
/// opening (mmap'ing) anything. Mirrors `open`'s own priority order by
|
||||
/// hand — keep the two in sync if that order ever changes.
|
||||
pub fn detect_storage(layer_dir: &Path) -> io::Result<StorageKind> {
|
||||
let presence_dir = layer_dir.join("presence");
|
||||
|
||||
if presence_dir.join("matrix.pbmx").exists() {
|
||||
return Ok(StorageKind::Packed);
|
||||
}
|
||||
if MatrixMeta::load(&presence_dir).is_ok() {
|
||||
return Ok(StorageKind::Columnar);
|
||||
}
|
||||
if presence_dir.join("sparse_meta.json").exists() {
|
||||
return Ok(StorageKind::Sparse);
|
||||
}
|
||||
if LayerMeta::load(layer_dir).is_ok() {
|
||||
return Ok(StorageKind::Implicit);
|
||||
}
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
format!("cannot detect presence storage format in {}", layer_dir.display()),
|
||||
))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn n(&self) -> usize {
|
||||
match self {
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::colgroup::{chunked_presence_count, ColGroup, MatrixGroupOps};
|
||||
use crate::format::{HEADER_SIZE, OVERFLOW_ENTRY_SIZE};
|
||||
use crate::meta::MatrixMeta;
|
||||
use crate::reader::PersistentCompactIntVec;
|
||||
use crate::storage_kind::StorageKind;
|
||||
use crate::tempbitvec::{TempBitVec, TempBitVecBuilder};
|
||||
use crate::tempintvec::{TempCompactIntVec, TempCompactIntVecBuilder};
|
||||
use crate::views::{nonzero_triples, IntSliceView};
|
||||
@@ -287,6 +288,33 @@ impl PersistentCompactIntMatrix {
|
||||
))
|
||||
}
|
||||
|
||||
/// This already-open matrix's storage format — reads the discriminant
|
||||
/// already in memory, no disk access.
|
||||
#[inline]
|
||||
pub fn storage_kind(&self) -> StorageKind {
|
||||
match self {
|
||||
Self::Columnar(_) => StorageKind::Columnar,
|
||||
Self::Packed(_) => StorageKind::Packed,
|
||||
}
|
||||
}
|
||||
|
||||
/// Lightweight disk probe: which format `open` would pick, without
|
||||
/// opening (mmap'ing) anything. Mirrors `open`'s own priority order by
|
||||
/// hand — keep the two in sync if that order ever changes.
|
||||
pub fn detect_storage(layer_dir: &Path) -> io::Result<StorageKind> {
|
||||
let counts_dir = layer_dir.join("counts");
|
||||
if counts_dir.join("matrix.pcmx").exists() {
|
||||
return Ok(StorageKind::Packed);
|
||||
}
|
||||
if MatrixMeta::load(&counts_dir).is_ok() {
|
||||
return Ok(StorageKind::Columnar);
|
||||
}
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
format!("no count matrix found in {}", layer_dir.display()),
|
||||
))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn n(&self) -> usize {
|
||||
match self { Self::Columnar(m) => m.n(), Self::Packed(m) => m.n_rows }
|
||||
|
||||
@@ -10,6 +10,7 @@ mod intmatrix;
|
||||
mod layer_meta;
|
||||
mod meta;
|
||||
mod reader;
|
||||
mod storage_kind;
|
||||
mod tempbitvec;
|
||||
mod tempintvec;
|
||||
mod views;
|
||||
@@ -25,6 +26,7 @@ pub use colgroup::{ColGroup, FilterMask, MatrixGroupOps, eval_filter_mask};
|
||||
pub use intmatrix::{PersistentCompactIntMatrix, PersistentCompactIntMatrixBuilder, pack_compact_int_matrix};
|
||||
pub use layer_meta::LayerMeta;
|
||||
pub use reader::{PersistentCompactIntVec, Iter as CompactIntVecIter};
|
||||
pub use storage_kind::StorageKind;
|
||||
pub use tempbitvec::{TempBitVec, TempBitVecBuilder};
|
||||
pub use tempintvec::{TempCompactIntVec, TempCompactIntVecBuilder};
|
||||
pub use traits::{BinaryMatrix, BitPartials, ColumnWeights, CountPartials};
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//! How a persistent matrix's data is physically laid out on disk —
|
||||
//! orthogonal to *what* it stores (count vs. presence, `obilayeredmap`'s
|
||||
//! `LayerContent` concern, one crate up). `PersistentCompactIntMatrix` only
|
||||
//! ever reports `Columnar`/`Packed`; `PersistentBitMatrix` is the only type
|
||||
//! that can also report `Sparse`/`Implicit`.
|
||||
|
||||
/// On-disk storage format of a persistent matrix.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum StorageKind {
|
||||
/// Per-column files (`.pbiv`/`.pciv`), the build-time format.
|
||||
Columnar,
|
||||
/// Single mmap'd file (`matrix.pbmx`/`matrix.pcmx`), query-optimised.
|
||||
Packed,
|
||||
/// Row-major deduplicated sparse format (`PersistentBitMatrix` only).
|
||||
Sparse,
|
||||
/// No file at all — mono-genome, all values present
|
||||
/// (`PersistentBitMatrix` only).
|
||||
Implicit,
|
||||
}
|
||||
Reference in new issue
Block a user