Struct tskit::TreeSequence[][src]

pub struct TreeSequence { /* fields omitted */ }

A tree sequence.

This is a thin wrapper around the C type tsk_treeseq_t.

When created from a TableCollection, the input tables are moved into the TreeSequence object.

Examples

let mut tables = tskit::TableCollection::new(1000.).unwrap();
tables.add_node(0, 1.0, tskit::TSK_NULL, tskit::TSK_NULL).unwrap();
tables.add_node(0, 0.0, tskit::TSK_NULL, tskit::TSK_NULL).unwrap();
tables.add_node(0, 0.0, tskit::TSK_NULL, tskit::TSK_NULL).unwrap();
tables.add_edge(0., 1000., 0, 1).unwrap();
tables.add_edge(0., 1000., 0, 2).unwrap();

// index
tables.build_index(0);

// tables gets moved into our treeseq variable:
let treeseq = tables.tree_sequence().unwrap();

Implementations

impl TreeSequence[src]

pub fn new(tables: TableCollection) -> Result<Self, TskitError>[src]

Create a tree sequence from a TableCollection. In general, TableCollection::tree_sequence may be preferred. The table collection is moved/consumed.

Parameters

Errors

Examples

let mut tables = tskit::TableCollection::new(1000.).unwrap();
tables.build_index(0);
let tree_sequence = tskit::TreeSequence::new(tables).unwrap();

The following may be preferred to the previous example, and more closely mimics the Python tskit interface:

let mut tables = tskit::TableCollection::new(1000.).unwrap();
tables.build_index(0);
let tree_sequence = tables.tree_sequence().unwrap();

The following raises an error because the tables are not indexed:

let mut tables = tskit::TableCollection::new(1000.).unwrap();
let tree_sequence = tskit::TreeSequence::new(tables).unwrap();

pub fn load(filename: &str) -> Result<Self, TskitError>[src]

Load from a file.

pub fn dump_tables(&self) -> Result<TableCollection, TskitError>[src]

Obtain a copy of the TableCollection. The result is a “deep” copy of the tables.

Errors

TskitError will be raised if the underlying C library returns an error code.

pub fn tree_iterator(&self, flags: TreeFlags) -> Result<Tree, TskitError>[src]

Create an iterator over trees.

Parameters

Errors

Examples

// You must include streaming_iterator as a dependency
// and import this type.
use streaming_iterator::StreamingIterator;

let mut tables = tskit::TableCollection::new(1000.).unwrap();
tables.build_index(0);
let tree_sequence = tables.tree_sequence().unwrap();
let mut tree_iterator = tree_sequence.tree_iterator(tskit::TreeFlags::default()).unwrap();
while let Some(tree) = tree_iterator.next() {
}

Warning

The following code results in an infinite loop. Be sure to note the difference from the previous example.

use streaming_iterator::StreamingIterator;

let mut tables = tskit::TableCollection::new(1000.).unwrap();
tables.build_index(0);
let tree_sequence = tables.tree_sequence().unwrap();
while let Some(tree) = tree_sequence.tree_iterator(tskit::TreeFlags::default()).unwrap().next() {
}

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

Get the list of samples as a vector.

pub fn num_trees(&self) -> tsk_size_t[src]

Get the number of trees.

pub fn kc_distance(
    &self,
    other: &TreeSequence,
    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. See Tree::kc_distance for more details.

pub fn num_samples(&self) -> tsk_size_t[src]

Trait Implementations

impl Drop for TreeSequence[src]

impl TskitTypeAccess<tsk_treeseq_t> for TreeSequence[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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.

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.