Skip to main content

MutationTable

Struct MutationTable 

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

An immutable view of site table.

§Examples

use tskit::MutationTable;

let mut mutations = MutationTable::default();
let rowid = mutations.add_row(1, 2, 0, 1.0, None).unwrap();
assert_eq!(rowid, 0);
assert_eq!(mutations.num_rows(), 1);

An example with metadata. This requires the cargo feature "derive" for tskit.

use tskit::MutationTable;

#[derive(serde::Serialize,
         serde::Deserialize,
         tskit::metadata::MutationMetadata)]
#[serializer("serde_json")]
struct MutationMetadata {
    value: i32,
}

let metadata = MutationMetadata{value: 42};

let mut mutations = MutationTable::default();

let rowid = mutations.add_row_with_metadata(0, 1, 5, 10.0, None, &metadata).unwrap();
assert_eq!(rowid, 0);

match mutations.metadata::<MutationMetadata>(rowid) {
    // rowid is in range, decoding succeeded
    Some(Ok(decoded)) => assert_eq!(decoded.value, 42),
    // rowid is in range, decoding failed
    Some(Err(e)) => panic!("error decoding metadata: {:?}", e),
    None => panic!("row id out of range")
}

Implementations§

Source§

impl MutationTable

Source

pub fn num_rows(&self) -> SizeType

Return the number of rows.

Source

pub fn site<M: Into<MutationId> + Copy>(&self, row: M) -> Option<SiteId>

Return the site value from row row of the table.

§Errors

Will return IndexError if row is out of range.

Source

pub fn node<M: Into<MutationId> + Copy>(&self, row: M) -> Option<NodeId>

Return the node value from row row of the table.

§Errors

Will return IndexError if row is out of range.

Source

pub fn parent<M: Into<MutationId> + Copy>(&self, row: M) -> Option<MutationId>

Return the parent value from row row of the table.

§Errors

Will return IndexError if row is out of range.

Source

pub fn time<M: Into<MutationId> + Copy>(&self, row: M) -> Option<Time>

Return the time value from row row of the table.

§Errors

Will return IndexError if row is out of range.

Source

pub fn derived_state<M: Into<MutationId>>(&self, row: M) -> Option<&[u8]>

Get the derived_state value from row row of the table.

§Return

Will return None if there is no derived state.

§Errors

Will return IndexError if row is out of range.

Source

pub fn metadata<T: MutationMetadata>( &self, row: impl Into<MutationId>, ) -> Option<Result<T, TskitError>>

Retrieve decoded metadata for a row.

§Returns
  • Some(Ok(T)) if row is valid and decoding succeeded.
  • Some(Err(_)) if row is valid and decoding failed.
  • None if row is not valid.
§Errors
§Examples.

The big-picture semantics are the same for all table types. See crate::IndividualTable::metadata for examples.

Source

pub fn iter(&self) -> impl Iterator<Item = MutationTableRow> + '_

Return an iterator over rows of the table. The value of the iterator is MutationTableRow.

Source

pub fn lending_iter(&self) -> MutationTableRowView<'_>

Source

pub fn row<M: Into<MutationId> + Copy>(&self, r: M) -> Option<MutationTableRow>

Return row r of the table.

§Parameters
  • r: the row id.
§Returns
  • Some(row) if r is valid
  • None otherwise
Source

pub fn row_view<M: Into<MutationId> + Copy>( &self, r: M, ) -> Option<MutationTableRowView<'_>>

Return a view of row r of the table.

§Parameters
  • r: the row id.
§Returns
  • Some(row view) if r is valid
  • None otherwise
Source

pub fn node_slice(&self) -> &[NodeId]

Get the node column as a slice

Source

pub fn node_slice_raw(&self) -> &[tsk_id_t]

Get the node column as a slice

Source

pub fn site_slice(&self) -> &[SiteId]

Get the site column as a slice

Source

pub fn site_slice_raw(&self) -> &[tsk_id_t]

Get the site column as a slice

Source

pub fn time_slice(&self) -> &[Time]

Get the time column as a slice

Source

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

Get the time column as a slice

Source

pub fn parent_slice(&self) -> &[MutationId]

Get the parent column as a slice

Source

pub fn parent_slice_raw(&self) -> &[tsk_id_t]

Get the parent column as a slice

Source

pub fn node_column(&self) -> impl TableColumn<MutationId, NodeId> + '_

Source

pub fn site_column(&self) -> impl TableColumn<MutationId, SiteId> + '_

Source

pub fn time_column(&self) -> impl TableColumn<MutationId, Time> + '_

Source

pub fn parent_column(&self) -> impl TableColumn<MutationId, MutationId> + '_

Source

pub fn clear(&mut self) -> Result<i32, TskitError>

Clear all data from the table

Source

pub fn add_row<S, N, P, T>( &mut self, site: S, node: N, parent: P, time: T, derived_state: Option<&[u8]>, ) -> Result<MutationId, TskitError>
where S: Into<SiteId>, N: Into<NodeId>, P: Into<MutationId>, T: Into<Time>,

Source

pub fn add_row_with_metadata<S, N, P, T, M>( &mut self, site: S, node: N, parent: P, time: T, derived_state: Option<&[u8]>, metadata: &M, ) -> Result<MutationId, TskitError>

Trait Implementations§

Source§

impl Debug for MutationTable

Source§

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

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

impl Default for MutationTable

Source§

fn default() -> MutationTable

Returns the “default value” for a type. 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> 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, 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.