Struct tskit::table_views::TableViews
source · pub struct TableViews { /* private fields */ }
Implementations
sourceimpl TableViews
impl TableViews
sourcepub fn mutations(&self) -> &MutationTable
pub fn mutations(&self) -> &MutationTable
Get reference to the MutationTable
.
sourcepub fn individuals(&self) -> &IndividualTable
pub fn individuals(&self) -> &IndividualTable
Get reference to the IndividualTable
.
sourcepub fn populations(&self) -> &PopulationTable
pub fn populations(&self) -> &PopulationTable
Get reference to the PopulationTable
.
sourcepub fn migrations(&self) -> &MigrationTable
pub fn migrations(&self) -> &MigrationTable
Get reference to the MigrationTable
.
sourcepub fn provenances(&self) -> &ProvenanceTable
Available on crate feature provenance
only.
pub fn provenances(&self) -> &ProvenanceTable
provenance
only.Get reference to the ProvenanceTable
sourcepub fn edges_iter(&self) -> impl Iterator<Item = EdgeTableRow> + '_
pub fn edges_iter(&self) -> impl Iterator<Item = EdgeTableRow> + '_
Return an iterator over the edges.
sourcepub fn nodes_iter(&self) -> impl Iterator<Item = NodeTableRow> + '_
pub fn nodes_iter(&self) -> impl Iterator<Item = NodeTableRow> + '_
Return an iterator over the nodes.
sourcepub fn sites_iter(&self) -> impl Iterator<Item = SiteTableRow> + '_
pub fn sites_iter(&self) -> impl Iterator<Item = SiteTableRow> + '_
Return an iterator over the sites.
sourcepub fn mutations_iter(&self) -> impl Iterator<Item = MutationTableRow> + '_
pub fn mutations_iter(&self) -> impl Iterator<Item = MutationTableRow> + '_
Return an iterator over the mutations.
sourcepub fn individuals_iter(&self) -> impl Iterator<Item = IndividualTableRow> + '_
pub fn individuals_iter(&self) -> impl Iterator<Item = IndividualTableRow> + '_
Return an iterator over the individuals.
sourcepub fn populations_iter(&self) -> impl Iterator<Item = PopulationTableRow> + '_
pub fn populations_iter(&self) -> impl Iterator<Item = PopulationTableRow> + '_
Return an iterator over the populations.
sourcepub fn migrations_iter(&self) -> impl Iterator<Item = MigrationTableRow> + '_
pub fn migrations_iter(&self) -> impl Iterator<Item = MigrationTableRow> + '_
Return an iterator over the migrations.
sourcepub fn provenances_iter(&self) -> impl Iterator<Item = ProvenanceTableRow> + '_
Available on crate feature provenance
only.
pub fn provenances_iter(&self) -> impl Iterator<Item = ProvenanceTableRow> + '_
provenance
only.Return an iterator over provenances
sourcepub fn samples_as_vector(&self) -> Vec<NodeId>
pub fn samples_as_vector(&self) -> Vec<NodeId>
Obtain a vector containing the indexes (“ids”)
of all nodes for which crate::TSK_NODE_IS_SAMPLE
is true
.
The provided implementation dispatches to
crate::NodeTable::samples_as_vector
.
sourcepub fn create_node_id_vector(
&self,
f: impl FnMut(&NodeTableRow) -> bool
) -> Vec<NodeId>
pub fn create_node_id_vector(
&self,
f: impl FnMut(&NodeTableRow) -> bool
) -> Vec<NodeId>
Obtain a vector containing the indexes (“ids”) of all nodes satisfying a certain criterion.
The provided implementation dispatches to
crate::NodeTable::create_node_id_vector
.
Parameters
f
: a function. The function is passed the current table collection and eachcrate::node_table::NodeTableRow
. Iff
returnstrue
, the index of that row is included in the return value.
Examples
Get all nodes with time > 0.0:
use tskit::bindings::tsk_id_t;
let mut tables = tskit::TableCollection::new(100.).unwrap();
tables
.add_node(tskit::TSK_NODE_IS_SAMPLE, 0.0, tskit::PopulationId::NULL,
tskit::IndividualId::NULL)
.unwrap();
tables
.add_node(tskit::TSK_NODE_IS_SAMPLE, 1.0, tskit::PopulationId::NULL,
tskit::IndividualId::NULL)
.unwrap();
let samples = tables.create_node_id_vector(
|row: &tskit::NodeTableRow| row.time > 0.,
);
assert_eq!(samples[0], 1);
// Get all nodes that have a mutation:
fn node_has_mutation(
// dyn trait here means this
// will work with TreeSequence, too.
tables_type: &dyn std::ops::Deref<Target=tskit::table_views::TableViews>,
row: &tskit::NodeTableRow,
) -> bool {
for mrow in tables_type.mutations_iter() {
if mrow.node == row.id {
return true;
}
}
false
}
// Get all nodes that have a mutation:
tables.add_mutation(0, 0, tskit::MutationId::NULL, 0.0, None).unwrap();
let samples_with_mut = tables.create_node_id_vector(
|row: &tskit::NodeTableRow| node_has_mutation(&tables, row));
assert_eq!(samples_with_mut[0], 0);