Skip to main content

InMemorySparseReader

Struct InMemorySparseReader 

Source
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>

Source

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 in data, normalised counts in data_2.
  • target_size - Library size data_2 was 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.

Source

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 in data, normalised counts in data_2.
  • target_size - Library size data_2 was 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<'_>

Source§

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>

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 order
  • data_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>

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 order
  • cells_to_keep - Cells to keep, in output row order, or None
  • data_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>

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

Return the header of the underlying store

§Returns

The SparseDataHeader.

Source§

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>

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>

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>

Read genes for consumers of the raw counts and indices only. Read more
Source§

fn is_gene_based(&self) -> bool

Is the store laid out for fast gene retrieval? Read more
Source§

fn read_cell(&self, index: usize) -> Result<CsrCellChunk, ScDataErrors>

Read a single cell by index Read more
Source§

fn read_gene(&self, index: usize) -> Result<CscGeneChunk, ScDataErrors>

Read a single gene by index Read more
Source§

fn read_cells_range( &self, start: usize, end: usize, ) -> Result<Vec<CsrCellChunk>, ScDataErrors>

Read a contiguous range of cells Read more
Source§

fn get_all_cells(&self) -> Result<Vec<CsrCellChunk>, ScDataErrors>

Return all cells in the store Read more
Source§

fn get_all_genes(&self) -> Result<Vec<CscGeneChunk>, ScDataErrors>

Return all genes in the store Read more
Source§

fn read_gene_parallel_filtered( &self, indices: &[usize], cells_to_keep: &IndexSet<u32>, ) -> Result<Vec<CscGeneChunk>, ScDataErrors>

Read genes by index and filter them to a set of cells Read more
Source§

fn read_gene_nnz(&self, indices: &[usize]) -> Result<Vec<usize>, ScDataErrors>

Read the NNZ for the given genes Read more
Source§

fn get_all_gene_nnz(&self) -> Result<Vec<usize>, ScDataErrors>

Return NNZ for all genes Read more
Source§

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. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V