pub struct MigrationTable { /* private fields */ }Expand description
A migration table.
§Examples
use tskit::MigrationTable;
let mut migrations = MigrationTable::default();
let rowid = migrations.add_row((0., 1.), 1, (0, 1), 10.3).unwrap();
assert_eq!(rowid, 0);
assert_eq!(migrations.num_rows(), 1);An example with metadata.
This requires the cargo feature "derive" for tskit.
use tskit::MigrationTable;
#[derive(serde::Serialize,
serde::Deserialize,
tskit::metadata::MigrationMetadata)]
#[serializer("serde_json")]
struct MigrationMetadata {
value: i32,
}
let metadata = MigrationMetadata{value: 42};
let mut migrations = MigrationTable::default();
let rowid = migrations.add_row_with_metadata((0., 1.), 1, (0, 1), 10.3, &metadata).unwrap();
assert_eq!(rowid, 0);
match migrations.metadata::<MigrationMetadata>(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 MigrationTable
impl MigrationTable
Sourcepub fn left<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Position>
pub fn left<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Position>
Return the left coordinate for a given row.
§Returns
Some(position)ifrowis valid.Noneotherwise.
Sourcepub fn right<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Position>
pub fn right<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Position>
Return the right coordinate for a given row.
§Returns
Some(positions)ifrowis valid.Noneotherwise.
Sourcepub fn source<M: Into<MigrationId> + Copy>(
&self,
row: M,
) -> Option<PopulationId>
pub fn source<M: Into<MigrationId> + Copy>( &self, row: M, ) -> Option<PopulationId>
Return the source population for a given row.
§Returns
Some(population)ifrowis valid.Noneotherwise.
Sourcepub fn dest<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<PopulationId>
pub fn dest<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<PopulationId>
Return the destination population for a given row.
§Returns
Some(population)ifrowis valid.Noneotherwise.
Sourcepub fn time<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Time>
pub fn time<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Time>
Return the time of the migration event for a given row.
§Returns
Some(time)ifrowis valid.Noneotherwise.
Sourcepub fn metadata<T: MigrationMetadata>(
&self,
row: impl Into<MigrationId>,
) -> Option<Result<T, TskitError>>
pub fn metadata<T: MigrationMetadata>( &self, row: impl Into<MigrationId>, ) -> 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 or the row has no metadata.
§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 = MigrationTableRow> + '_
pub fn iter(&self) -> impl Iterator<Item = MigrationTableRow> + '_
Return an iterator over rows of the table.
The value of the iterator is MigrationTableRow.
pub fn lending_iter(&self) -> MigrationTableRowView<'_>
Sourcepub fn row<M: Into<MigrationId> + Copy>(
&self,
r: M,
) -> Option<MigrationTableRow>
pub fn row<M: Into<MigrationId> + Copy>( &self, r: M, ) -> Option<MigrationTableRow>
Sourcepub fn row_view<M: Into<MigrationId> + Copy>(
&self,
r: M,
) -> Option<MigrationTableRowView<'_>>
pub fn row_view<M: Into<MigrationId> + Copy>( &self, r: M, ) -> Option<MigrationTableRowView<'_>>
Sourcepub fn left_slice(&self) -> &[Position]
pub fn left_slice(&self) -> &[Position]
Get the left column as a slice
Sourcepub fn left_slice_raw(&self) -> &[f64]
pub fn left_slice_raw(&self) -> &[f64]
Get the left column as a slice
Sourcepub fn right_slice(&self) -> &[Position]
pub fn right_slice(&self) -> &[Position]
Get the right column as a slice
Sourcepub fn right_slice_raw(&self) -> &[f64]
pub fn right_slice_raw(&self) -> &[f64]
Get the right 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 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 source_slice(&self) -> &[PopulationId]
pub fn source_slice(&self) -> &[PopulationId]
Get the source column as a slice
Sourcepub fn source_slice_raw(&self) -> &[tsk_id_t] ⓘ
pub fn source_slice_raw(&self) -> &[tsk_id_t] ⓘ
Get the source column as a slice
Sourcepub fn dest_slice(&self) -> &[PopulationId]
pub fn dest_slice(&self) -> &[PopulationId]
Get the dest column as a slice
Sourcepub fn dest_slice_raw(&self) -> &[tsk_id_t] ⓘ
pub fn dest_slice_raw(&self) -> &[tsk_id_t] ⓘ
Get the dest column as a slice
pub fn left_column(&self) -> impl TableColumn<MigrationId, Position> + '_
pub fn right_column(&self) -> impl TableColumn<MigrationId, Position> + '_
pub fn node_column(&self) -> impl TableColumn<MigrationId, NodeId> + '_
pub fn time_column(&self) -> impl TableColumn<MigrationId, Time> + '_
pub fn source_column(&self) -> impl TableColumn<MigrationId, PopulationId> + '_
pub fn dest_column(&self) -> impl TableColumn<MigrationId, PopulationId> + '_
Sourcepub fn clear(&mut self) -> Result<i32, TskitError>
pub fn clear(&mut self) -> Result<i32, TskitError>
Clear all data from the table