pub struct Tree { /* private fields */ }
Expand description
A Tree.
Wrapper around tsk_tree_t
.
Implementations
sourceimpl Tree
impl Tree
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 left_child(&self, u: NodeId) -> Result<NodeId, TskitError>
pub fn left_child(&self, u: NodeId) -> Result<NodeId, TskitError>
sourcepub fn right_child(&self, u: NodeId) -> Result<NodeId, TskitError>
pub fn right_child(&self, u: NodeId) -> Result<NodeId, TskitError>
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>
Please use Tree::sample_nodes instead
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 path_to_root(
&self,
u: NodeId
) -> Result<impl Iterator<Item = NodeId> + '_, TskitError>
👎 Deprecated since 0.2.3: Please use Tree::parents instead
pub fn path_to_root(
&self,
u: NodeId
) -> Result<impl Iterator<Item = NodeId> + '_, TskitError>
Please use Tree::parents instead
Return an Iterator
from the node u
to the root of the tree.
Errors
TskitError::IndexError
if u
is out of range.
sourcepub fn parents(
&self,
u: NodeId
) -> Result<impl Iterator<Item = NodeId> + '_, TskitError>
pub fn parents(
&self,
u: NodeId
) -> Result<impl Iterator<Item = NodeId> + '_, TskitError>
Return an Iterator
from the node u
to the root of the tree,
travering all parent nodes.
Errors
TskitError::IndexError
if u
is out of range.
sourcepub fn samples(
&self,
u: NodeId
) -> Result<impl Iterator<Item = NodeId> + '_, TskitError>
pub fn samples(
&self,
u: NodeId
) -> 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.
Errors
TskitError::IndexError
if u
is out of range.
TskitError::NotTrackingSamples
if TreeFlags::SAMPLE_LISTS
was not used
to initialize self
.
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<'a>(&'a self) -> NodeTable<'a>
pub fn node_table<'a>(&'a self) -> NodeTable<'a>
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 byTree::span
.
Errors
TskitError
may be returned if a node index is out of range.
sourcepub fn num_tracked_samples(&self, u: NodeId) -> Result<SizeType, TskitError>
pub fn num_tracked_samples(&self, u: NodeId) -> Result<SizeType, TskitError>
sourcepub fn kc_distance(&self, other: &Tree, lambda: f64) -> Result<f64, TskitError>
pub fn kc_distance(&self, other: &Tree, 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 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>
Returns a reference to the current element of the iterator. Read more
sourcefn next(&mut self) -> Option<&Self::Item>
fn next(&mut self) -> Option<&Self::Item>
Advances the iterator and returns the next value. Read more
sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator.
sourcefn all<F>(&mut self, f: F) -> bool where
F: FnMut(&Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> bool where
F: FnMut(&Self::Item) -> bool,
Determines if all elements of the iterator satisfy a predicate.
sourcefn any<F>(&mut self, f: F) -> bool where
F: FnMut(&Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> bool where
F: FnMut(&Self::Item) -> bool,
Determines if any elements of the iterator satisfy a predicate.
sourcefn chain<I>(self, other: I) -> Chain<Self, I> where
I: StreamingIterator<Item = Self::Item>,
fn chain<I>(self, other: I) -> Chain<Self, I> where
I: StreamingIterator<Item = Self::Item>,
Consumes two iterators and returns a new iterator that iterates over both in sequence.
sourcefn cloned(self) -> Cloned<Self> where
Self::Item: Clone,
fn cloned(self) -> Cloned<Self> where
Self::Item: Clone,
Produces a normal, non-streaming, iterator by cloning the elements of this iterator.
sourcefn count(self) -> usize
fn count(self) -> usize
Consumes the iterator, counting the number of remaining elements and returning it.
sourcefn filter<F>(self, f: F) -> Filter<Self, F> where
F: FnMut(&Self::Item) -> bool,
fn filter<F>(self, f: F) -> Filter<Self, F> where
F: FnMut(&Self::Item) -> bool,
Creates an iterator which uses a closure to determine if an element should be yielded.
sourcefn filter_map<B, F>(self, f: F) -> FilterMap<Self, B, F> where
F: FnMut(&Self::Item) -> Option<B>,
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, B, F> where
F: FnMut(&Self::Item) -> Option<B>,
Creates an iterator which both filters and maps by applying a closure to elements.
sourcefn flat_map<J, F>(self, f: F) -> FlatMap<Self, J, F> where
J: StreamingIterator,
F: FnMut(&Self::Item) -> J,
fn flat_map<J, F>(self, f: F) -> FlatMap<Self, J, F> where
J: StreamingIterator,
F: FnMut(&Self::Item) -> J,
Creates an iterator which flattens iterators obtained by applying a closure to elements. Note that the returned iterators must be streaming iterators. Read more
sourcefn filter_map_deref<B, F>(self, f: F) -> FilterMapDeref<Self, F> where
F: FnMut(&Self::Item) -> Option<B>,
fn filter_map_deref<B, F>(self, f: F) -> FilterMapDeref<Self, F> where
F: FnMut(&Self::Item) -> Option<B>,
Creates a regular, non-streaming iterator which both filters and maps by applying a closure to elements.
sourcefn find<F>(&mut self, f: F) -> Option<&Self::Item> where
F: FnMut(&Self::Item) -> bool,
fn find<F>(&mut self, f: F) -> Option<&Self::Item> where
F: FnMut(&Self::Item) -> bool,
Returns the first element of the iterator that satisfies the predicate.
sourcefn fuse(self) -> Fuse<Self>
fn fuse(self) -> Fuse<Self>
Creates an iterator which is “well behaved” at the beginning and end of iteration. Read more
sourcefn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
Call a closure on each element, passing the element on.
The closure is called upon calls to advance
or advance_back
, and exactly once per element
regardless of how many times (if any) get
is called. Read more
sourcefn map<B, F>(self, f: F) -> Map<Self, B, F> where
F: FnMut(&Self::Item) -> B,
fn map<B, F>(self, f: F) -> Map<Self, B, F> where
F: FnMut(&Self::Item) -> B,
Creates an iterator which transforms elements of this iterator by passing them to a closure.
sourcefn map_deref<B, F>(self, f: F) -> MapDeref<Self, F> where
F: FnMut(&Self::Item) -> B,
fn map_deref<B, F>(self, f: F) -> MapDeref<Self, F> where
F: FnMut(&Self::Item) -> B,
Creates a regular, non-streaming iterator which transforms elements of this iterator by passing them to a closure.
sourcefn map_ref<B, F>(self, f: F) -> MapRef<Self, F> where
F: Fn(&Self::Item) -> &B,
B: ?Sized,
fn map_ref<B, F>(self, f: F) -> MapRef<Self, F> where
F: Fn(&Self::Item) -> &B,
B: ?Sized,
Creates an iterator which transforms elements of this iterator by passing them to a closure. Read more
sourcefn nth(&mut self, n: usize) -> Option<&Self::Item>
fn nth(&mut self, n: usize) -> Option<&Self::Item>
Consumes the first n
elements of the iterator, returning the next one.
sourcefn position<F>(&mut self, f: F) -> Option<usize> where
F: FnMut(&Self::Item) -> bool,
fn position<F>(&mut self, f: F) -> Option<usize> where
F: FnMut(&Self::Item) -> bool,
Returns the index of the first element of the iterator matching a predicate.
sourcefn skip_while<F>(self, f: F) -> SkipWhile<Self, F> where
F: FnMut(&Self::Item) -> bool,
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F> where
F: FnMut(&Self::Item) -> bool,
Creates an iterator that skips initial elements matching a predicate.
sourcefn take(self, n: usize) -> Take<Self>
fn take(self, n: usize) -> Take<Self>
Creates an iterator which only returns the first n
elements.
sourcefn take_while<F>(self, f: F) -> TakeWhile<Self, F> where
F: FnMut(&Self::Item) -> bool,
fn take_while<F>(self, f: F) -> TakeWhile<Self, F> where
F: FnMut(&Self::Item) -> bool,
Creates an iterator which only returns initial elements matching a predicate.
sourcefn rev(self) -> Rev<Self> where
Self: DoubleEndedStreamingIterator,
fn rev(self) -> Rev<Self> where
Self: DoubleEndedStreamingIterator,
Creates an iterator which returns elemens in the opposite order.
sourceimpl TskitTypeAccess<tsk_tree_t> for Tree
impl TskitTypeAccess<tsk_tree_t> for Tree
sourcefn as_ptr(&self) -> *const tsk_tree_t
fn as_ptr(&self) -> *const tsk_tree_t
Return const pointer
sourcefn as_mut_ptr(&mut self) -> *mut tsk_tree_t
fn as_mut_ptr(&mut self) -> *mut tsk_tree_t
Return mutable pointer
Auto Trait Implementations
impl RefUnwindSafe for Tree
impl !Send for Tree
impl !Sync for Tree
impl Unpin for Tree
impl UnwindSafe for Tree
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more