Struct tskit::TreeSequence[][src]

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

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::PopulationId::NULL, tskit::IndividualId::NULL).unwrap();
tables.add_node(0, 0.0, tskit::PopulationId::NULL, tskit::IndividualId::NULL).unwrap();
tables.add_node(0, 0.0, tskit::PopulationId::NULL, tskit::IndividualId::NULL).unwrap();
tables.add_edge(0., 1000., 0, 1).unwrap();
tables.add_edge(0., 1000., 0, 2).unwrap();

// index
tables.build_index();

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

Implementations

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();
let tree_sequence = tskit::TreeSequence::new(tables, tskit::TreeSequenceFlags::default()).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();
let tree_sequence = tables.tree_sequence(tskit::TreeSequenceFlags::default()).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,
tskit::TreeSequenceFlags::default()).unwrap();

Dump the tree sequence to file.

Note

  • options is currently not used. Set to default value. This behavior may change in a future release, which could break API.

Load from a file.

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.

Create an iterator over trees.

Parameters

Errors

Examples

// You must include streaming_iterator as a dependency
// and import this type.
use streaming_iterator::StreamingIterator;
// Import this to allow .next_back() for reverse
// iteration over trees.
use streaming_iterator::DoubleEndedStreamingIterator;

let mut tables = tskit::TableCollection::new(1000.).unwrap();
tables.build_index();
let tree_sequence = tables.tree_sequence(tskit::TreeSequenceFlags::default()).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();
let tree_sequence = tables.tree_sequence(tskit::TreeSequenceFlags::default()).unwrap();
while let Some(tree) = tree_sequence.tree_iterator(tskit::TreeFlags::default()).unwrap().next() {
}
👎 Deprecated since 0.2.3:

Please use TreeSequence::sample_nodes instead

Get the list of samples as a vector.

Get the list of sample nodes as a slice.

Get the number of trees.

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.

Simplify tables and return a new tree sequence.

Parameters

  • samples: a slice containing non-null node ids. The tables are simplified with respect to the ancestry of these nodes.
  • options: A SimplificationOptions bit field controlling the behavior of simplification.
  • idmap: if true, the return value contains a vector equal in length to the input node table. For each input node, this vector either contains the node’s new index or NodeId::NULL if the input node is not part of the simplified history.

Trait Implementations

Executes the destructor for this type. Read more

Obtain a vector containing the indexes (“ids”) of all nodes for which crate::TSK_NODE_IS_SAMPLE is true. Read more

Obtain a vector containing the indexes (“ids”) of all nodes satisfying a certain criterion. Read more

Add provenance record with a time stamp. Read more

Return an immutable reference to the table, type ProvenanceTable

Return an iterator over the rows of the ProvenanceTable. See ProvenanceTable::iter for details. Read more

Get reference to the EdgeTable.

Get reference to the IndividualTable.

Get reference to the MigrationTable.

Get reference to the NodeTable.

Get reference to the SiteTable.

Get reference to the MutationTable.

Get reference to the PopulationTable.

Return an iterator over the edges. See EdgeTable::iter for details. Read more

Return an iterator over the nodes. See NodeTable::iter for details. Read more

Return an iterator over the mutations. See MutationTable::iter for details. Read more

Return an iterator over the sites. See SiteTable::iter for details. Read more

Return an iterator over the populations. See PopulationTable::iter for details. Read more

Return an iterator over the migration events. See MigrationTable::iter for details. Read more

Return an iterator over the individuals. See IndividualTable::iter for details. Read more

Return const pointer

Return mutable pointer

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.