Struct tskit::Tree[][src]

pub struct Tree { /* fields omitted */ }
Expand description

A Tree.

Wrapper around tsk_tree_t.

Implementations

impl Tree[src]

pub fn parent_array(&self) -> &[tsk_id_t][src]

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
}

pub fn samples_array(&self) -> Result<&[tsk_id_t], TskitError>[src]

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
}

pub fn next_sample_array(&self) -> Result<&[tsk_id_t], TskitError>[src]

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
}

pub fn left_sample_array(&self) -> Result<&[tsk_id_t], TskitError>[src]

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
}

pub fn right_sample_array(&self) -> Result<&[tsk_id_t], TskitError>[src]

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
}

pub fn left_sib_array(&self) -> &[tsk_id_t][src]

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
}

pub fn right_sib_array(&self) -> &[tsk_id_t][src]

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
}

pub fn left_child_array(&self) -> &[tsk_id_t][src]

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
}

pub fn right_child_array(&self) -> &[tsk_id_t][src]

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
}

pub fn interval(&self) -> (f64, f64)[src]

Return the [left, right) coordinates of the tree.

pub fn span(&self) -> f64[src]

Return the length of the genome for which this tree is the ancestry.

pub fn parent(&self, u: tsk_id_t) -> Result<tsk_id_t, TskitError>[src]

Get the parent of node u.

Errors

TskitError if u is out of range.

pub fn left_child(&self, u: tsk_id_t) -> Result<tsk_id_t, TskitError>[src]

Get the left child of node u.

Errors

TskitError if u is out of range.

pub fn right_child(&self, u: tsk_id_t) -> Result<tsk_id_t, TskitError>[src]

Get the right child of node u.

Errors

TskitError if u is out of range.

pub fn left_sib(&self, u: tsk_id_t) -> Result<tsk_id_t, TskitError>[src]

Get the left sib of node u.

Errors

TskitError if u is out of range.

pub fn right_sib(&self, u: tsk_id_t) -> Result<tsk_id_t, TskitError>[src]

Get the right sib of node u.

Errors

TskitError::IndexError if u is out of range.

pub fn samples_to_vec(&self) -> Vec<tsk_id_t>[src]

👎 Deprecated since 0.2.3:

Please use Tree::sample_nodes instead

Obtain the list of samples for the current tree/tree sequence as a vector.

pub fn sample_nodes(&self) -> &[tsk_id_t][src]

Get the list of sample nodes as a slice.

pub fn path_to_root(
    &self,
    u: tsk_id_t
) -> Result<impl Iterator<Item = tsk_id_t> + '_, TskitError>
[src]

👎 Deprecated since 0.2.3:

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.

pub fn parents(
    &self,
    u: tsk_id_t
) -> Result<impl Iterator<Item = tsk_id_t> + '_, TskitError>
[src]

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.

pub fn children(
    &self,
    u: tsk_id_t
) -> Result<impl Iterator<Item = tsk_id_t> + '_, TskitError>
[src]

Return an Iterator over the children of node u.

Errors

TskitError::IndexError if u is out of range.

pub fn samples(
    &self,
    u: tsk_id_t
) -> Result<impl Iterator<Item = tsk_id_t> + '_, TskitError>
[src]

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.

pub fn roots(&self) -> impl Iterator<Item = tsk_id_t> + '_[src]

Return an Iterator over the roots of the tree.

Note

For a tree with multiple roots, the iteration starts at the left root.

pub fn roots_to_vec(&self) -> Vec<tsk_id_t>[src]

Return all roots as a vector.

pub fn traverse_nodes(
    &self,
    order: NodeTraversalOrder
) -> Box<dyn Iterator<Item = tsk_id_t>>
[src]

Return an Iterator over all nodes in the tree.

Parameters

pub fn node_table<'a>(&'a self) -> NodeTable<'a>[src]

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..

pub fn total_branch_length(&self, by_span: bool) -> Result<f64, TskitError>[src]

Calculate the total length of the tree via a preorder traversal.

Parameters

  • by_span: if true, multiply the return value by Tree::span.

Errors

TskitError may be returned if a node index is out of range.

pub fn num_tracked_samples(&self, u: tsk_id_t) -> Result<u64, TskitError>[src]

Get the number of samples below node u.

Errors

pub fn kc_distance(&self, other: &Tree, lambda: f64) -> Result<f64, TskitError>[src]

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. If lambda is 0, we only consider topology. If lambda is 1, we only consider branch lengths.

Trait Implementations

impl DoubleEndedStreamingIterator for Tree[src]

fn advance_back(&mut self)[src]

Advances the iterator to the next element from the back of the iterator. Read more

fn next_back(&mut self) -> Option<&Self::Item>[src]

Advances the iterator and returns the next value from the back. Read more

fn rfold<B, F>(self, init: B, f: F) -> B where
    F: FnMut(B, &Self::Item) -> B, 
[src]

Reduces the iterator’s elements to a single, final value, starting from the back.

impl Drop for Tree[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl StreamingIterator for Tree[src]

type Item = Tree

The type of the elements being iterated over.

fn advance(&mut self)[src]

Advances the iterator to the next element. Read more

fn get(&self) -> Option<&Tree>[src]

Returns a reference to the current element of the iterator. Read more

fn next(&mut self) -> Option<&Self::Item>[src]

Advances the iterator and returns the next value. Read more

fn size_hint(&self) -> (usize, Option<usize>)[src]

Returns the bounds on the remaining length of the iterator.

fn all<F>(&mut self, f: F) -> bool where
    F: FnMut(&Self::Item) -> bool
[src]

Determines if all elements of the iterator satisfy a predicate.

fn any<F>(&mut self, f: F) -> bool where
    F: FnMut(&Self::Item) -> bool
[src]

Determines if any elements of the iterator satisfy a predicate.

fn by_ref(&mut self) -> &mut Self[src]

Borrows an iterator, rather than consuming it. Read more

fn chain<I>(self, other: I) -> Chain<Self, I> where
    I: StreamingIterator<Item = Self::Item>, 
[src]

Consumes two iterators and returns a new iterator that iterates over both in sequence.

fn cloned(self) -> Cloned<Self> where
    Self::Item: Clone
[src]

Produces a normal, non-streaming, iterator by cloning the elements of this iterator.

fn count(self) -> usize[src]

Consumes the iterator, counting the number of remaining elements and returning it.

fn filter<F>(self, f: F) -> Filter<Self, F> where
    F: FnMut(&Self::Item) -> bool
[src]

Creates an iterator which uses a closure to determine if an element should be yielded.

fn filter_map<B, F>(self, f: F) -> FilterMap<Self, B, F> where
    F: FnMut(&Self::Item) -> Option<B>, 
[src]

Creates an iterator which both filters and maps by applying a closure to elements.

fn flat_map<J, F>(self, f: F) -> FlatMap<Self, J, F> where
    F: FnMut(&Self::Item) -> J,
    J: StreamingIterator
[src]

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>, 
[src]

Creates a regular, non-streaming iterator which both filters and maps by applying a closure to elements.

fn find<F>(&mut self, f: F) -> Option<&Self::Item> where
    F: FnMut(&Self::Item) -> bool
[src]

Returns the first element of the iterator that satisfies the predicate.

fn fuse(self) -> Fuse<Self>[src]

Creates an iterator which is “well behaved” at the beginning and end of iteration. Read more

fn inspect<F>(self, f: F) -> Inspect<Self, F> where
    F: FnMut(&Self::Item), 
[src]

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

fn map<B, F>(self, f: F) -> Map<Self, B, F> where
    F: FnMut(&Self::Item) -> B, 
[src]

Creates an iterator which transforms elements of this iterator by passing them to a closure.

fn map_deref<B, F>(self, f: F) -> MapDeref<Self, F> where
    F: FnMut(&Self::Item) -> B, 
[src]

Creates a regular, non-streaming iterator which transforms elements of this iterator by passing them to a closure.

fn map_ref<B, F>(self, f: F) -> MapRef<Self, F> where
    F: Fn(&Self::Item) -> &B,
    B: ?Sized
[src]

Creates an iterator which transforms elements of this iterator by passing them to a closure. Read more

fn nth(&mut self, n: usize) -> Option<&Self::Item>[src]

Consumes the first n elements of the iterator, returning the next one.

fn position<F>(&mut self, f: F) -> Option<usize> where
    F: FnMut(&Self::Item) -> bool
[src]

Returns the index of the first element of the iterator matching a predicate.

fn skip(self, n: usize) -> Skip<Self>[src]

Creates an iterator which skips the first n elements.

fn skip_while<F>(self, f: F) -> SkipWhile<Self, F> where
    F: FnMut(&Self::Item) -> bool
[src]

Creates an iterator that skips initial elements matching a predicate.

fn take(self, n: usize) -> Take<Self>[src]

Creates an iterator which only returns the first n elements.

fn take_while<F>(self, f: F) -> TakeWhile<Self, F> where
    F: FnMut(&Self::Item) -> bool
[src]

Creates an iterator which only returns initial elements matching a predicate.

fn rev(self) -> Rev<Self> where
    Self: DoubleEndedStreamingIterator
[src]

Creates an iterator which returns elemens in the opposite order.

fn fold<B, F>(self, init: B, f: F) -> B where
    F: FnMut(B, &Self::Item) -> B, 
[src]

Reduces the iterator’s elements to a single, final value.

fn for_each<F>(self, f: F) where
    F: FnMut(&Self::Item), 
[src]

Calls a closure on each element of an iterator.

impl TskitTypeAccess<tsk_tree_t> for Tree[src]

fn as_ptr(&self) -> *const tsk_tree_t[src]

Return const pointer

fn as_mut_ptr(&mut self) -> *mut tsk_tree_t[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.