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
impl MutationTable
Sourcepub fn site<M: Into<MutationId> + Copy>(&self, row: M) -> Option<SiteId>
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.
Sourcepub fn node<M: Into<MutationId> + Copy>(&self, row: M) -> Option<NodeId>
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.
Sourcepub fn parent<M: Into<MutationId> + Copy>(&self, row: M) -> Option<MutationId>
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.
Sourcepub fn time<M: Into<MutationId> + Copy>(&self, row: M) -> Option<Time>
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.
Sourcepub fn derived_state<M: Into<MutationId>>(&self, row: M) -> Option<&[u8]>
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.
Sourcepub fn metadata<T: MutationMetadata>(
&self,
row: impl Into<MutationId>,
) -> Option<Result<T, TskitError>>
pub fn metadata<T: MutationMetadata>( &self, row: impl Into<MutationId>, ) -> Option<Result<T, TskitError>>
Retrieve decoded metadata for a row.
§Returns
Some(Ok(T))ifrowis valid and decoding succeeded.Some(Err(_))ifrowis valid and decoding failed.Noneifrowis not valid.
§Errors
TskitError::MetadataErrorif decoding fails.
§Examples.
The big-picture semantics are the same for all table types.
See crate::IndividualTable::metadata for examples.
Sourcepub fn iter(&self) -> impl Iterator<Item = MutationTableRow> + '_
pub fn iter(&self) -> impl Iterator<Item = MutationTableRow> + '_
Return an iterator over rows of the table.
The value of the iterator is MutationTableRow.
pub fn lending_iter(&self) -> MutationTableRowView<'_>
Sourcepub fn row<M: Into<MutationId> + Copy>(&self, r: M) -> Option<MutationTableRow>
pub fn row<M: Into<MutationId> + Copy>(&self, r: M) -> Option<MutationTableRow>
Sourcepub fn row_view<M: Into<MutationId> + Copy>(
&self,
r: M,
) -> Option<MutationTableRowView<'_>>
pub fn row_view<M: Into<MutationId> + Copy>( &self, r: M, ) -> Option<MutationTableRowView<'_>>
Sourcepub fn node_slice(&self) -> &[NodeId]
pub fn node_slice(&self) -> &[NodeId]
Get the node column as a slice
Sourcepub fn node_slice_raw(&self) -> &[tsk_id_t] ⓘ
pub fn node_slice_raw(&self) -> &[tsk_id_t] ⓘ
Get the node column as a slice
Sourcepub fn site_slice(&self) -> &[SiteId]
pub fn site_slice(&self) -> &[SiteId]
Get the site column as a slice
Sourcepub fn site_slice_raw(&self) -> &[tsk_id_t] ⓘ
pub fn site_slice_raw(&self) -> &[tsk_id_t] ⓘ
Get the site column as a slice
Sourcepub fn time_slice(&self) -> &[Time]
pub fn time_slice(&self) -> &[Time]
Get the time column as a slice
Sourcepub fn time_slice_raw(&self) -> &[f64]
pub fn time_slice_raw(&self) -> &[f64]
Get the time column as a slice
Sourcepub fn parent_slice(&self) -> &[MutationId]
pub fn parent_slice(&self) -> &[MutationId]
Get the parent column as a slice
Sourcepub fn parent_slice_raw(&self) -> &[tsk_id_t] ⓘ
pub fn parent_slice_raw(&self) -> &[tsk_id_t] ⓘ
Get the parent column as a slice
pub fn node_column(&self) -> impl TableColumn<MutationId, NodeId> + '_
pub fn site_column(&self) -> impl TableColumn<MutationId, SiteId> + '_
pub fn time_column(&self) -> impl TableColumn<MutationId, Time> + '_
pub fn parent_column(&self) -> impl TableColumn<MutationId, MutationId> + '_
Sourcepub fn clear(&mut self) -> Result<i32, TskitError>
pub fn clear(&mut self) -> Result<i32, TskitError>
Clear all data from the table