pub trait SingleCellReading: Send + Sync {
Show 19 methods
// Required methods
fn read_cells_parallel(
&self,
indices: &[usize],
) -> Result<Vec<CsrCellChunk>, ScDataErrors>;
fn read_gene_parallel(
&self,
indices: &[usize],
) -> Result<Vec<CscGeneChunk>, ScDataErrors>;
fn read_cells_sparse<T>(
&self,
indices: &[usize],
data_layer: &DataLayerReturn,
) -> Result<CompressedSparseData2<T, f32>, ScDataErrors>
where T: BixverseNumeric + FromPrimitive;
fn read_genes_sparse<T>(
&self,
indices: &[usize],
cells_to_keep: Option<&IndexSet<u32>>,
data_layer: &DataLayerReturn,
) -> Result<CompressedSparseData2<T, f32>, ScDataErrors>
where T: BixverseNumeric + FromPrimitive;
fn get_header(&self) -> SparseDataHeader;
fn is_cell_based(&self) -> bool;
// Provided methods
fn read_gene_parallel_raw(
&self,
indices: &[usize],
) -> Result<Vec<CscGeneChunk>, ScDataErrors> { ... }
fn is_gene_based(&self) -> bool { ... }
fn target_size(&self) -> Option<f32> { ... }
fn read_cell(&self, index: usize) -> Result<CsrCellChunk, ScDataErrors> { ... }
fn read_gene(&self, index: usize) -> Result<CscGeneChunk, ScDataErrors> { ... }
fn read_cells_range(
&self,
start: usize,
end: usize,
) -> Result<Vec<CsrCellChunk>, ScDataErrors> { ... }
fn get_all_cells(&self) -> Result<Vec<CsrCellChunk>, ScDataErrors> { ... }
fn get_all_genes(&self) -> Result<Vec<CscGeneChunk>, ScDataErrors> { ... }
fn read_gene_parallel_filtered(
&self,
indices: &[usize],
cells_to_keep: &IndexSet<u32>,
) -> Result<Vec<CscGeneChunk>, ScDataErrors> { ... }
fn read_cell_library_sizes(
&self,
indices: &[usize],
) -> Result<Vec<usize>, ScDataErrors> { ... }
fn read_gene_nnz(
&self,
indices: &[usize],
) -> Result<Vec<usize>, ScDataErrors> { ... }
fn get_all_gene_nnz(&self) -> Result<Vec<usize>, ScDataErrors> { ... }
fn get_clr_offsets(
&self,
indices: &[usize],
batch_size: Option<usize>,
) -> Result<Vec<f64>, ScDataErrors> { ... }
}Expand description
Read access to a chunked single cell count store.
Abstracts over where the data physically lives. The only implementor today
is ParallelSparseReader, which memory-maps the bixverse binary format
from disk, but the trait exposes nothing file-specific so that other
backends can be added later without touching consumers.
Whether a store is cell-based (CSR, fast per-cell access) or gene-based
(CSC, fast per-gene access) is a runtime property of the underlying data,
not of the type. Asking a gene-based store for cells returns
ScDataErrors::ReaderModeMismatch.
Implementors need only supply read_cells_parallel, read_gene_parallel,
get_header and is_cell_based. The rest have default bodies written in
terms of those four. Backends that can do better should override: the
defaults for read_cell_library_sizes and read_gene_nnz parse whole
chunks, whereas a backend able to peek at chunk headers can avoid that.
Send + Sync is required: readers are shared across rayon threads.
Required Methods§
Sourcefn read_cells_parallel(
&self,
indices: &[usize],
) -> Result<Vec<CsrCellChunk>, ScDataErrors>
fn read_cells_parallel( &self, indices: &[usize], ) -> Result<Vec<CsrCellChunk>, ScDataErrors>
Sourcefn read_gene_parallel(
&self,
indices: &[usize],
) -> Result<Vec<CscGeneChunk>, ScDataErrors>
fn read_gene_parallel( &self, indices: &[usize], ) -> Result<Vec<CscGeneChunk>, ScDataErrors>
Sourcefn read_cells_sparse<T>(
&self,
indices: &[usize],
data_layer: &DataLayerReturn,
) -> Result<CompressedSparseData2<T, f32>, ScDataErrors>where
T: BixverseNumeric + FromPrimitive,
fn read_cells_sparse<T>(
&self,
indices: &[usize],
data_layer: &DataLayerReturn,
) -> Result<CompressedSparseData2<T, f32>, ScDataErrors>where
T: BixverseNumeric + FromPrimitive,
Read a batch of cells straight into one CSR matrix.
Same output as Self::read_cells_parallel followed by
from_cell_chunks, without materialising a chunk per cell. Prefer it
whenever the consumer only needs the counts and indices.
§Params
indices- Cell indices, in output row orderdata_layer- Which layer(s) to materialise
§Returns
CSR of shape (indices.len(), total_genes), raw counts in data (empty
when not requested) and normalised counts in data_2, or
ScDataErrors::ReaderModeMismatch on a gene-major store and
ScDataErrors::RawCountOverflow for a count that does not fit T.
Sourcefn read_genes_sparse<T>(
&self,
indices: &[usize],
cells_to_keep: Option<&IndexSet<u32>>,
data_layer: &DataLayerReturn,
) -> Result<CompressedSparseData2<T, f32>, ScDataErrors>where
T: BixverseNumeric + FromPrimitive,
fn read_genes_sparse<T>(
&self,
indices: &[usize],
cells_to_keep: Option<&IndexSet<u32>>,
data_layer: &DataLayerReturn,
) -> Result<CompressedSparseData2<T, f32>, ScDataErrors>where
T: BixverseNumeric + FromPrimitive,
Read a batch of genes straight into one CSC matrix, optionally keeping only a cell subset.
Same output as Self::read_gene_parallel_filtered (or
Self::read_gene_parallel without a subset) followed by
from_gene_chunks, without materialising a chunk per gene. Kept
cells are renumbered to their position in cells_to_keep.
§Params
indices- Gene indices, in output column ordercells_to_keep- Cells to keep, in output row order, orNonefor all cellsdata_layer- Which layer(s) to materialise
§Returns
CSC of shape (cells, indices.len()), raw counts in data (empty when
not requested) and normalised counts in data_2, or
ScDataErrors::ReaderModeMismatch on a cell-major store and
ScDataErrors::RawCountOverflow for a count that does not fit T.
Sourcefn get_header(&self) -> SparseDataHeader
fn get_header(&self) -> SparseDataHeader
Sourcefn is_cell_based(&self) -> bool
fn is_cell_based(&self) -> bool
Provided Methods§
Sourcefn read_gene_parallel_raw(
&self,
indices: &[usize],
) -> Result<Vec<CscGeneChunk>, ScDataErrors>
fn read_gene_parallel_raw( &self, indices: &[usize], ) -> Result<Vec<CscGeneChunk>, ScDataErrors>
Sourcefn is_gene_based(&self) -> bool
fn is_gene_based(&self) -> bool
Sourcefn target_size(&self) -> Option<f32>
fn target_size(&self) -> Option<f32>
Library size the data_norm layer of this store was scaled to.
Needed by anything that has to undo the ln1p(count / lib_size * target_size) normalisation, such as CscGeneChunk::transform_to_clr.
Defaults to None for stores that do not record it.
§Returns
Some(target_size), or None when the store cannot report one.
Sourcefn read_cell(&self, index: usize) -> Result<CsrCellChunk, ScDataErrors>
fn read_cell(&self, index: usize) -> Result<CsrCellChunk, ScDataErrors>
Sourcefn read_gene(&self, index: usize) -> Result<CscGeneChunk, ScDataErrors>
fn read_gene(&self, index: usize) -> Result<CscGeneChunk, ScDataErrors>
Sourcefn read_cells_range(
&self,
start: usize,
end: usize,
) -> Result<Vec<CsrCellChunk>, ScDataErrors>
fn read_cells_range( &self, start: usize, end: usize, ) -> Result<Vec<CsrCellChunk>, ScDataErrors>
Sourcefn get_all_cells(&self) -> Result<Vec<CsrCellChunk>, ScDataErrors>
fn get_all_cells(&self) -> Result<Vec<CsrCellChunk>, ScDataErrors>
Sourcefn get_all_genes(&self) -> Result<Vec<CscGeneChunk>, ScDataErrors>
fn get_all_genes(&self) -> Result<Vec<CscGeneChunk>, ScDataErrors>
Sourcefn read_gene_parallel_filtered(
&self,
indices: &[usize],
cells_to_keep: &IndexSet<u32>,
) -> Result<Vec<CscGeneChunk>, ScDataErrors>
fn read_gene_parallel_filtered( &self, indices: &[usize], cells_to_keep: &IndexSet<u32>, ) -> Result<Vec<CscGeneChunk>, ScDataErrors>
Sourcefn read_cell_library_sizes(
&self,
indices: &[usize],
) -> Result<Vec<usize>, ScDataErrors>
fn read_cell_library_sizes( &self, indices: &[usize], ) -> Result<Vec<usize>, ScDataErrors>
Sourcefn read_gene_nnz(&self, indices: &[usize]) -> Result<Vec<usize>, ScDataErrors>
fn read_gene_nnz(&self, indices: &[usize]) -> Result<Vec<usize>, ScDataErrors>
Sourcefn get_all_gene_nnz(&self) -> Result<Vec<usize>, ScDataErrors>
fn get_all_gene_nnz(&self) -> Result<Vec<usize>, ScDataErrors>
Sourcefn get_clr_offsets(
&self,
indices: &[usize],
batch_size: Option<usize>,
) -> Result<Vec<f64>, ScDataErrors>
fn get_clr_offsets( &self, indices: &[usize], batch_size: Option<usize>, ) -> Result<Vec<f64>, ScDataErrors>
Compute the shifted CLR per-cell offsets freshly from raw counts.
The offset for cell i is m_i = (1/D) * sum_j log1p(x_ij / s_i), where
D is the total gene count and s_i is the cell’s library size. Size
factor is fixed at 1, independent of any size factor used during the
original normalisation. Cells are read in batches to bound peak memory.
§Params
indices- Cell indices to compute offsets forbatch_size- Number of cells to load per batch (defaults toCELL_BATCH_SIZE)
§Returns
Vector of CLR offsets in the same order as indices.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".