Trait tskit::NodeListGenerator [−][src]
pub trait NodeListGenerator: TableAccess { fn samples_as_vector(&self) -> Vec<tsk_id_t> { ... } fn create_node_id_vector(
&self,
f: impl FnMut(&NodeTableRow) -> bool
) -> Vec<tsk_id_t> { ... } }
Interface for returning lists of node ids from
types implementing TableAccess
.
Provided methods
fn samples_as_vector(&self) -> Vec<tsk_id_t>
[src]
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
.
fn create_node_id_vector(
&self,
f: impl FnMut(&NodeTableRow) -> bool
) -> Vec<tsk_id_t>
[src]
&self,
f: impl FnMut(&NodeTableRow) -> bool
) -> Vec<tsk_id_t>
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::TSK_NULL; use tskit::tsk_id_t; use tskit::TableAccess; use tskit::NodeListGenerator; let mut tables = tskit::TableCollection::new(100.).unwrap(); tables .add_node(tskit::TSK_NODE_IS_SAMPLE, 0.0, TSK_NULL, TSK_NULL) .unwrap(); tables .add_node(tskit::TSK_NODE_IS_SAMPLE, 1.0, TSK_NULL, TSK_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. tabled_type: &dyn tskit::TableAccess, row: &tskit::NodeTableRow, ) -> bool { for mrow in tabled_type.mutations_iter(false) { if mrow.node == row.id { return true; } } false } // Get all nodes that have a mutation: tables.add_mutation(0, 0, TSK_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);