pub struct Tree { /* private fields */ }
Expand description
A Tree.
Wrapper around tsk_tree_t
.
Methods from Deref<Target = TreeInterface>
pub fn flags(&self) -> TreeFlags
sourcepub fn parent_array(&self) -> &[NodeId]
pub fn parent_array(&self) -> &[NodeId]
Failing examples
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap();
while let Some(tree) = tree_iter.next() {
let p = tree.parent_array();
drop(tree_iter);
for _ in p {} // ERROR
}
sourcepub fn samples_array(&self) -> Result<&[NodeId], TskitError>
pub fn samples_array(&self) -> Result<&[NodeId], TskitError>
Failing examples
An error will be returned if [’crate::TreeFlags::SAMPLE_LISTS`] is not used:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap(); // ERROR
while let Some(tree) = tree_iter.next() {
let s = tree.samples_array().unwrap();
for _ in s {}
}
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::SAMPLE_LISTS).unwrap();
while let Some(tree) = tree_iter.next() {
let s = tree.samples_array().unwrap();
drop(tree_iter);
for _ in s {} // ERROR
}
sourcepub fn next_sample_array(&self) -> Result<&[NodeId], TskitError>
pub fn next_sample_array(&self) -> Result<&[NodeId], TskitError>
Failing examples
An error will be returned if [’crate::TreeFlags::SAMPLE_LISTS`] is not used:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap(); // ERROR
while let Some(tree) = tree_iter.next() {
let n = tree.next_sample_array().unwrap();
for _ in n {}
}
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::SAMPLE_LISTS).unwrap();
while let Some(tree) = tree_iter.next() {
let n = tree.next_sample_array().unwrap();
drop(tree_iter);
for _ in n {} // ERROR
}
sourcepub fn left_sample_array(&self) -> Result<&[NodeId], TskitError>
pub fn left_sample_array(&self) -> Result<&[NodeId], TskitError>
Failing examples
An error will be returned if [’crate::TreeFlags::SAMPLE_LISTS`] is not used:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap(); // Error
while let Some(tree) = tree_iter.next() {
let l = tree.left_sample_array().unwrap();
for _ in l {}
}
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::SAMPLE_LISTS).unwrap();
while let Some(tree) = tree_iter.next() {
let l = tree.left_sample_array().unwrap();
drop(tree_iter);
for _ in l {} // Error
}
sourcepub fn right_sample_array(&self) -> Result<&[NodeId], TskitError>
pub fn right_sample_array(&self) -> Result<&[NodeId], TskitError>
Failing examples
An error will be returned if [’crate::TreeFlags::SAMPLE_LISTS`] is not used:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap(); // ERROR
while let Some(tree) = tree_iter.next() {
let r = tree.right_sample_array().unwrap();
for _ in r {}
}
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::SAMPLE_LISTS).unwrap();
while let Some(tree) = tree_iter.next() {
let r = tree.right_sample_array().unwrap();
drop(tree_iter);
for _ in r {} // ERROR
}
sourcepub fn left_sib_array(&self) -> &[NodeId]
pub fn left_sib_array(&self) -> &[NodeId]
Failing examples
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap();
while let Some(tree) = tree_iter.next() {
let r = tree.left_sib_array();
drop(tree_iter);
for _ in r {} // ERROR
}
sourcepub fn right_sib_array(&self) -> &[NodeId]
pub fn right_sib_array(&self) -> &[NodeId]
Failing examples
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap();
while let Some(tree) = tree_iter.next() {
let r = tree.right_sib_array();
drop(tree_iter);
for _ in r {} // ERROR
}
sourcepub fn left_child_array(&self) -> &[NodeId]
pub fn left_child_array(&self) -> &[NodeId]
Failing examples
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap();
while let Some(tree) = tree_iter.next() {
let l = tree.left_child_array();
drop(tree_iter);
for _ in l {} // ERROR
}
sourcepub fn right_child_array(&self) -> &[NodeId]
pub fn right_child_array(&self) -> &[NodeId]
Failing examples
The lifetime of the slice is tied to the parent object:
use streaming_iterator::StreamingIterator;
let tables = tskit::TableCollection::new(1.).unwrap();
let treeseq =
tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
let mut tree_iter = treeseq.tree_iterator(tskit::TreeFlags::default()).unwrap();
while let Some(tree) = tree_iter.next() {
let r = tree.right_child_array();
drop(tree_iter);
for _ in r {} // ERROR
}
sourcepub fn interval(&self) -> (Position, Position)
pub fn interval(&self) -> (Position, Position)
Return the [left, right)
coordinates of the tree.
sourcepub fn span(&self) -> Position
pub fn span(&self) -> Position
Return the length of the genome for which this tree is the ancestry.
sourcepub fn parent<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
pub fn parent<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
Get the parent of node u
.
Returns None
if u
is out of range.
sourcepub fn left_child<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
pub fn left_child<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
Get the left child of node u
.
Returns None
if u
is out of range.
sourcepub fn right_child<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
pub fn right_child<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
Get the right child of node u
.
Returns None
if u
is out of range.
sourcepub fn left_sib<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
pub fn left_sib<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
Get the left sib of node u
.
Returns None
if u
is out of range.
sourcepub fn right_sib<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
pub fn right_sib<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId>
Get the right sib of node u
.
Returns None
if u
is out of range.
sourcepub fn samples_to_vec(&self) -> Vec<NodeId>
👎Deprecated since 0.2.3: Please use Tree::sample_nodes instead
pub fn samples_to_vec(&self) -> Vec<NodeId>
Obtain the list of samples for the current tree/tree sequence as a vector.
Panics
Will panic if the number of samples is too large to cast to a valid id.
sourcepub fn sample_nodes(&self) -> &[NodeId]
pub fn sample_nodes(&self) -> &[NodeId]
Get the list of sample nodes as a slice.
sourcepub fn samples<N: Into<NodeId> + Copy>(
&self,
u: N
) -> Result<impl Iterator<Item = NodeId> + '_, TskitError>
pub fn samples<N: Into<NodeId> + Copy>(
&self,
u: N
) -> Result<impl Iterator<Item = NodeId> + '_, TskitError>
Return an Iterator
over the sample nodes descending from node u
.
Note
If u
is itself a sample, then it is included in the values returned.
Returns
- Some(Ok(iterator)) if
TreeFlags::SAMPLE_LISTS
is inTreeInterface::flags
- Some(Err(_)) if
TreeFlags::SAMPLE_LISTS
is not inTreeInterface::flags
- None if
u
is not valid.
sourcepub fn roots_to_vec(&self) -> Vec<NodeId>
pub fn roots_to_vec(&self) -> Vec<NodeId>
Return all roots as a vector.
sourcepub fn traverse_nodes(
&self,
order: NodeTraversalOrder
) -> Box<dyn Iterator<Item = NodeId> + '_>
pub fn traverse_nodes(
&self,
order: NodeTraversalOrder
) -> Box<dyn Iterator<Item = NodeId> + '_>
Return an Iterator
over all nodes in the tree.
Parameters
order
: A value fromNodeTraversalOrder
specifying the iteration order.
sourcepub fn node_table(&self) -> NodeTable
pub fn node_table(&self) -> NodeTable
Return the crate::NodeTable
for this current tree
(and the tree sequence from which it came).
This is a convenience function for accessing node times, etc..
sourcepub fn total_branch_length(&self, by_span: bool) -> Result<Time, TskitError>
pub fn total_branch_length(&self, by_span: bool) -> Result<Time, TskitError>
Calculate the total length of the tree via a preorder traversal.
Parameters
by_span
: iftrue
, multiply the return value byTreeInterface::span
.
Errors
TskitError
may be returned if a node index is out of range.
sourcepub fn num_tracked_samples<N: Into<NodeId> + Copy>(
&self,
u: N
) -> Result<SizeType, TskitError>
pub fn num_tracked_samples<N: Into<NodeId> + Copy>(
&self,
u: N
) -> Result<SizeType, TskitError>
sourcepub fn kc_distance(
&self,
other: &TreeInterface,
lambda: f64
) -> Result<f64, TskitError>
pub fn kc_distance(
&self,
other: &TreeInterface,
lambda: f64
) -> Result<f64, TskitError>
Calculate the average Kendall-Colijn (K-C
) distance between
pairs of trees whose intervals overlap.
Note
Parameters
lambda
specifies the relative weight of topology and branch length. Iflambda
is 0, we only consider topology. Iflambda
is 1, we only consider branch lengths.
sourcepub fn virtual_root(&self) -> NodeId
pub fn virtual_root(&self) -> NodeId
Return the virtual root of the tree.
Trait Implementations
sourceimpl Deref for Tree
impl Deref for Tree
type Target = TreeInterface
type Target = TreeInterface
sourceimpl DoubleEndedStreamingIterator for Tree
impl DoubleEndedStreamingIterator for Tree
sourceimpl StreamingIterator for Tree
impl StreamingIterator for Tree
sourcefn get(&self) -> Option<&Tree>
fn get(&self) -> Option<&Tree>
sourcefn next(&mut self) -> Option<&Self::Item>
fn next(&mut self) -> Option<&Self::Item>
sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
sourcefn all<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item) -> bool,
sourcefn any<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item) -> bool,
sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
sourcefn chain<I>(self, other: I) -> Chain<Self, I>where
Self: Sized,
I: StreamingIterator<Item = Self::Item>,
fn chain<I>(self, other: I) -> Chain<Self, I>where
Self: Sized,
I: StreamingIterator<Item = Self::Item>,
sourcefn count(self) -> usizewhere
Self: Sized,
fn count(self) -> usizewhere
Self: Sized,
sourcefn filter<F>(self, f: F) -> Filter<Self, F>where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
fn filter<F>(self, f: F) -> Filter<Self, F>where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
sourcefn filter_map<B, F>(self, f: F) -> FilterMap<Self, B, F>where
Self: Sized,
F: FnMut(&Self::Item) -> Option<B>,
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, B, F>where
Self: Sized,
F: FnMut(&Self::Item) -> Option<B>,
sourcefn flat_map<J, F>(self, f: F) -> FlatMap<Self, J, F>where
Self: Sized,
J: StreamingIterator,
F: FnMut(&Self::Item) -> J,
fn flat_map<J, F>(self, f: F) -> FlatMap<Self, J, F>where
Self: Sized,
J: StreamingIterator,
F: FnMut(&Self::Item) -> J,
sourcefn filter_map_deref<B, F>(self, f: F) -> FilterMapDeref<Self, F>where
Self: Sized,
F: FnMut(&Self::Item) -> Option<B>,
fn filter_map_deref<B, F>(self, f: F) -> FilterMapDeref<Self, F>where
Self: Sized,
F: FnMut(&Self::Item) -> Option<B>,
sourcefn find<F>(&mut self, f: F) -> Option<&Self::Item>where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
fn find<F>(&mut self, f: F) -> Option<&Self::Item>where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
sourcefn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
sourcefn inspect<F>(self, f: F) -> Inspect<Self, F>where
F: FnMut(&Self::Item),
Self: Sized,
fn inspect<F>(self, f: F) -> Inspect<Self, F>where
F: FnMut(&Self::Item),
Self: Sized,
advance
or advance_back
, and exactly once per element
regardless of how many times (if any) get
is called. Read moresourcefn map<B, F>(self, f: F) -> Map<Self, B, F>where
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn map<B, F>(self, f: F) -> Map<Self, B, F>where
Self: Sized,
F: FnMut(&Self::Item) -> B,
sourcefn map_deref<B, F>(self, f: F) -> MapDeref<Self, F>where
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn map_deref<B, F>(self, f: F) -> MapDeref<Self, F>where
Self: Sized,
F: FnMut(&Self::Item) -> B,
sourcefn map_ref<B, F>(self, f: F) -> MapRef<Self, F>where
Self: Sized,
F: Fn(&Self::Item) -> &B,
B: ?Sized,
fn map_ref<B, F>(self, f: F) -> MapRef<Self, F>where
Self: Sized,
F: Fn(&Self::Item) -> &B,
B: ?Sized,
sourcefn nth(&mut self, n: usize) -> Option<&Self::Item>
fn nth(&mut self, n: usize) -> Option<&Self::Item>
n
elements of the iterator, returning the next one.sourcefn position<F>(&mut self, f: F) -> Option<usize>where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
fn position<F>(&mut self, f: F) -> Option<usize>where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
sourcefn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n
elements.sourcefn skip_while<F>(self, f: F) -> SkipWhile<Self, F>where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
sourcefn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n
elements.