Struct tskit::Tree [−][src]
pub struct Tree { /* fields omitted */ }
Expand description
A Tree.
Wrapper around tsk_tree_t
.
Implementations
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
👎 Deprecated since 0.2.3: Please use Tree::sample_nodes instead
Please use Tree::sample_nodes instead
Obtain the list of samples for the current tree/tree sequence as a vector.
Get the list of sample nodes as a slice.
pub 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.
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.
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
.
Return all roots as a vector.
Return an Iterator
over all nodes in the tree.
Parameters
order
: A value fromNodeTraversalOrder
specifying the iteration order.
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..
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.
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.
Trait Implementations
Returns a reference to the current element of the iterator. Read more
Advances the iterator and returns the next value. Read more
Returns the bounds on the remaining length of the iterator.
Determines if all elements of the iterator satisfy a predicate.
Determines if any elements of the iterator satisfy a predicate.
Consumes two iterators and returns a new iterator that iterates over both in sequence.
Produces a normal, non-streaming, iterator by cloning the elements of this iterator.
Consumes the iterator, counting the number of remaining elements and returning it.
Creates an iterator which uses a closure to determine if an element should be yielded.
Creates an iterator which both filters and maps by applying a closure to elements.
Creates an iterator which flattens iterators obtained by applying a closure to elements. Note that the returned iterators must be streaming iterators. Read more
fn 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.
Returns the first element of the iterator that satisfies the predicate.
Creates an iterator which is “well behaved” at the beginning and end of iteration. Read more
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
Creates an iterator which transforms elements of this iterator by passing them to a closure.
Creates a regular, non-streaming iterator which transforms elements of this iterator by passing them to a closure.
Creates an iterator which transforms elements of this iterator by passing them to a closure. Read more
Consumes the first n
elements of the iterator, returning the next one.
Returns the index of the first element of the iterator matching a predicate.
Creates an iterator that skips initial elements matching a predicate.
Creates an iterator which only returns the first n
elements.
Creates an iterator which only returns initial elements matching a predicate.
Creates an iterator which returns elemens in the opposite order.
Reduces the iterator’s elements to a single, final value.
Return const pointer
Return mutable pointer