Struct tskit::OwnedMutationTable
source · [−]pub struct OwnedMutationTable { /* private fields */ }
Expand description
A standalone mutation table that owns its data.
Examples
use tskit::OwnedMutationTable;
let mut mutations = OwnedMutationTable::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::OwnedMutationTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::MutationMetadata)]
#[serializer("serde_json")]
struct MutationMetadata {
value: i32,
}
let metadata = MutationMetadata{value: 42};
let mut mutations = OwnedMutationTable::default();
let rowid = mutations.add_row_with_metadata(0, 1, 5, 10.0, None, &metadata).unwrap();
assert_eq!(rowid, 0);
if let Some(decoded) = mutations.metadata::<MutationMetadata>(rowid).unwrap() {
assert_eq!(decoded.value, 42);
} else {
panic!("hmm...we expected some metadata!");
}
Implementations
sourceimpl OwnedMutationTable
impl OwnedMutationTable
sourcepub fn clear(&mut self) -> TskReturnValue
pub fn clear(&mut self) -> TskReturnValue
Clear the table.
sourceimpl OwnedMutationTable
impl OwnedMutationTable
pub fn as_ptr(&self) -> *const tsk_mutation_table_t
pub fn as_mut_ptr(&mut self) -> *mut tsk_mutation_table_t
sourceimpl OwnedMutationTable
impl OwnedMutationTable
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>,
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>where
S: Into<SiteId>,
N: Into<NodeId>,
P: Into<MutationId>,
T: Into<Time>,
M: MutationMetadata,
Methods from Deref<Target = MutationTable<'static>>
sourcepub fn site<M: Into<MutationId> + Copy>(
&'a self,
row: M
) -> Result<SiteId, TskitError>
pub fn site<M: Into<MutationId> + Copy>(
&'a self,
row: M
) -> Result<SiteId, TskitError>
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>(
&'a self,
row: M
) -> Result<NodeId, TskitError>
pub fn node<M: Into<MutationId> + Copy>(
&'a self,
row: M
) -> Result<NodeId, TskitError>
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>(
&'a self,
row: M
) -> Result<MutationId, TskitError>
pub fn parent<M: Into<MutationId> + Copy>(
&'a self,
row: M
) -> Result<MutationId, TskitError>
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>(
&'a self,
row: M
) -> Result<Time, TskitError>
pub fn time<M: Into<MutationId> + Copy>(
&'a self,
row: M
) -> Result<Time, TskitError>
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>>(
&'a self,
row: M
) -> Result<Option<&'_ [u8]>, TskitError>
pub fn derived_state<M: Into<MutationId>>(
&'a self,
row: M
) -> Result<Option<&'_ [u8]>, TskitError>
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.
pub fn metadata<T: MetadataRoundtrip>(
&'a self,
row: MutationId
) -> Result<Option<T>, TskitError>
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
.
sourcepub fn row<M: Into<MutationId> + Copy>(
&self,
r: M
) -> Result<MutationTableRow, TskitError>
pub fn row<M: Into<MutationId> + Copy>(
&self,
r: M
) -> Result<MutationTableRow, TskitError>
Return row r
of the table.
Parameters
r
: the row id.
Errors
TskitError::IndexError
if r
is out of range.