pub struct InMemorySparseReader<'a> { /* private fields */ }Expand description
Gene-major in-memory store behind the SingleCellReading interface.
Reads are slices of the underlying buffers copied into the chunk types the trait hands back, so a full gene sweep costs one copy of the matrix rather than a decompression per chunk.
Implementations§
Source§impl<'a> InMemorySparseReader<'a>
impl<'a> InMemorySparseReader<'a>
Sourcepub fn new(
matrix: &'a CompressedSparseData2<u32, f32>,
target_size: Option<f32>,
) -> Result<Self, ScDataErrors>
pub fn new( matrix: &'a CompressedSparseData2<u32, f32>, target_size: Option<f32>, ) -> Result<Self, ScDataErrors>
Wrap a sparse matrix as a gene-major store.
§Params
matrix- The counts, CSC with shape (cells, genes). Raw counts indata, normalised counts indata_2.target_size- Library sizedata_2was normalised against, if the caller knows it.
§Returns
The reader, or SparseErrors::SparseMatrixMustBeCsc for a CSR input
and SparseErrors::Data2NotAvailable when the normalised layer is
missing.
Sourcepub fn new_cell_major(
matrix: &'a CompressedSparseData2<u32, f32>,
target_size: Option<f32>,
) -> Result<Self, ScDataErrors>
pub fn new_cell_major( matrix: &'a CompressedSparseData2<u32, f32>, target_size: Option<f32>, ) -> Result<Self, ScDataErrors>
Wrap the same matrix as a cell-major store.
Builds and owns a CSR twin, so peak memory is roughly twice the matrix for as long as the reader lives. Use it only where cell chunks are genuinely needed, such as the per-cell totals the analytic Pearson fit sums over each group’s retained genes.
Note this is not CompressedSparseData2::transpose_and_convert, which
relabels a CSC as a CSR and swaps the shape, describing the transpose.
What is wanted here is the same matrix in the other layout, which is a
real scatter.
§Params
matrix- The counts, CSC with shape (cells, genes). Raw counts indata, normalised counts indata_2.target_size- Library sizedata_2was normalised against, if the caller knows it.
§Returns
The reader, or SparseErrors::SparseMatrixMustBeCsc for a CSR input
and SparseErrors::Data2NotAvailable when the normalised layer is
missing.
Trait Implementations§
Source§impl SingleCellReading for InMemorySparseReader<'_>
impl SingleCellReading for InMemorySparseReader<'_>
Source§fn read_cells_parallel(
&self,
indices: &[usize],
) -> Result<Vec<CsrCellChunk>, ScDataErrors>
fn read_cells_parallel( &self, indices: &[usize], ) -> Result<Vec<CsrCellChunk>, ScDataErrors>
Read cells by index in a multi-threaded manner
Only available on a reader built with
InMemorySparseReader::new_cell_major; the default gene-major reader
has no CSR twin to read from.
§Params
indices- Index positions of the cells to retrieve
§Returns
The CsrCellChunks in the order given by indices, or
ScDataErrors::ReaderModeMismatch in gene-major mode.
Source§fn 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 CSR
Slices the CSR twin directly, so no chunk is built and the normalised
layer stays f32 rather than passing through the chunks’ F16.
§Params
indices- Cell indices, in output row orderdata_layer- Which layer(s) to materialise
§Returns
The batch as CSR, or ScDataErrors::ReaderModeMismatch in
gene-major mode.
Source§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 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 CSC, optionally filtering cells
Slices the matrix directly, so no chunk is built and the normalised
layer stays f32 rather than passing through the chunks’ F16.
§Params
indices- Gene indices, in output column ordercells_to_keep- Cells to keep, in output row order, orNonedata_layer- Which layer(s) to materialise
§Returns
The batch as CSC, or ScDataErrors::ReaderModeMismatch in
cell-major mode.
Source§fn read_gene_parallel(
&self,
indices: &[usize],
) -> Result<Vec<CscGeneChunk>, ScDataErrors>
fn read_gene_parallel( &self, indices: &[usize], ) -> Result<Vec<CscGeneChunk>, ScDataErrors>
Read genes by index in a multi-threaded manner
§Params
indices- Index positions of the genes to retrieve
§Returns
The CscGeneChunks in the order given by indices, or
ScDataErrors::ReaderModeMismatch in cell-major mode.
Source§fn get_header(&self) -> SparseDataHeader
fn get_header(&self) -> SparseDataHeader
Source§fn is_cell_based(&self) -> bool
fn is_cell_based(&self) -> bool
Is the store laid out for fast cell retrieval?
§Returns
true when built with InMemorySparseReader::new_cell_major.
Source§fn target_size(&self) -> Option<f32>
fn target_size(&self) -> Option<f32>
Library size the normalised layer was scaled to.
§Returns
Whatever the caller passed to InMemorySparseReader::new.
Source§fn read_cell_library_sizes(
&self,
indices: &[usize],
) -> Result<Vec<usize>, ScDataErrors>
fn read_cell_library_sizes( &self, indices: &[usize], ) -> Result<Vec<usize>, ScDataErrors>
Total raw counts per cell
Served from the sums taken in InMemorySparseReader::new, which is
why a gene-major store can answer a cell-side question at all.
§Params
indices- Cell indices
§Returns
The library sizes in the order given by indices, or
ScDataErrors::ChunkIndexNotFound for an index past the cell axis.
Source§fn read_gene_parallel_raw(
&self,
indices: &[usize],
) -> Result<Vec<CscGeneChunk>, ScDataErrors>
fn read_gene_parallel_raw( &self, indices: &[usize], ) -> Result<Vec<CscGeneChunk>, ScDataErrors>
Source§fn is_gene_based(&self) -> bool
fn is_gene_based(&self) -> bool
Source§fn read_cell(&self, index: usize) -> Result<CsrCellChunk, ScDataErrors>
fn read_cell(&self, index: usize) -> Result<CsrCellChunk, ScDataErrors>
Source§fn read_gene(&self, index: usize) -> Result<CscGeneChunk, ScDataErrors>
fn read_gene(&self, index: usize) -> Result<CscGeneChunk, ScDataErrors>
Source§fn 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>
Source§fn get_all_cells(&self) -> Result<Vec<CsrCellChunk>, ScDataErrors>
fn get_all_cells(&self) -> Result<Vec<CsrCellChunk>, ScDataErrors>
Source§fn get_all_genes(&self) -> Result<Vec<CscGeneChunk>, ScDataErrors>
fn get_all_genes(&self) -> Result<Vec<CscGeneChunk>, ScDataErrors>
Source§fn 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>
Source§fn read_gene_nnz(&self, indices: &[usize]) -> Result<Vec<usize>, ScDataErrors>
fn read_gene_nnz(&self, indices: &[usize]) -> Result<Vec<usize>, ScDataErrors>
Source§fn get_all_gene_nnz(&self) -> Result<Vec<usize>, ScDataErrors>
fn get_all_gene_nnz(&self) -> Result<Vec<usize>, ScDataErrors>
Auto Trait Implementations§
impl<'a> Freeze for InMemorySparseReader<'a>
impl<'a> RefUnwindSafe for InMemorySparseReader<'a>
impl<'a> Send for InMemorySparseReader<'a>
impl<'a> Sync for InMemorySparseReader<'a>
impl<'a> Unpin for InMemorySparseReader<'a>
impl<'a> UnsafeUnpin for InMemorySparseReader<'a>
impl<'a> UnwindSafe for InMemorySparseReader<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.