Skip to main content

ExpressionMatrix

Struct ExpressionMatrix 

Source
pub struct ExpressionMatrix { /* private fields */ }
Expand description

A dense, row-major expression matrix (features × samples).

Implementations§

Source§

impl ExpressionMatrix

Source

pub fn new( data: Vec<Vec<f64>>, feature_names: Vec<String>, sample_names: Vec<String>, ) -> Result<Self>

Create a matrix from row-major 2D data.

Each inner Vec is one feature (row) with n_samples values.

Source

pub fn zeros( n_features: usize, n_samples: usize, feature_names: Vec<String>, sample_names: Vec<String>, ) -> Result<Self>

Create a zero-filled matrix.

Source

pub fn shape(&self) -> (usize, usize)

(n_features, n_samples).

Source

pub fn get(&self, feature_idx: usize, sample_idx: usize) -> Option<f64>

Get a single value by feature and sample index.

Source

pub fn set( &mut self, feature_idx: usize, sample_idx: usize, value: f64, ) -> Result<()>

Set a single value. Returns an error if indices are out of bounds.

Source

pub fn row(&self, feature_idx: usize) -> Option<&[f64]>

A slice of one feature’s expression across all samples.

Source

pub fn column(&self, sample_idx: usize) -> Option<Vec<f64>>

All feature values for a single sample (column copy, since data is row-major).

Source

pub fn row_mean(&self, feature_idx: usize) -> Option<f64>

Mean expression of a feature across all samples.

Source

pub fn column_mean(&self, sample_idx: usize) -> Option<f64>

Mean expression across all features for a sample.

Source

pub fn transpose(&self) -> ExpressionMatrix

Transpose the matrix, swapping features and samples.

Source

pub fn filter_features(&self, indices: &[usize]) -> Result<ExpressionMatrix>

Subset the matrix to the given feature (row) indices.

Source

pub fn filter_samples(&self, indices: &[usize]) -> Result<ExpressionMatrix>

Subset the matrix to the given sample (column) indices.

Source

pub fn as_slice(&self) -> &[f64]

The underlying flat data as a slice (row-major, n_features × n_samples).

Source

pub fn feature_names(&self) -> &[String]

Feature (gene/protein) names.

Source

pub fn sample_names(&self) -> &[String]

Sample names.

Source

pub fn log_transform(&self, pseudocount: f64) -> ExpressionMatrix

Log2-transform all values: log2(x + pseudocount).

Commonly used to normalize RNA-seq count data.

Trait Implementations§

Source§

impl Clone for ExpressionMatrix

Source§

fn clone(&self) -> ExpressionMatrix

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExpressionMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Summarizable for ExpressionMatrix

Source§

fn summary(&self) -> String

A one-line summary suitable for display.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.