Struct tskit::TableCollection [−][src]
pub struct TableCollection { /* fields omitted */ }
Expand description
A table collection.
This is a thin wrapper around the C type tsk_table_collection_t
.
Current limitations
Examples
use tskit::TableAccess; let mut tables = tskit::TableCollection::new(100.).unwrap(); assert_eq!(tables.sequence_length(), 100.); // Adding edges: let rv = tables.add_edge(0., 53., 1, 11).unwrap(); // Add node: let rv = tables.add_node(0, 3.2, tskit::TSK_NULL, tskit::TSK_NULL).unwrap(); // Get immutable reference to edge table let edges = tables.edges(); assert_eq!(edges.num_rows(), 1); // Get immutable reference to node table let nodes = tables.nodes(); assert_eq!(nodes.num_rows(), 1);
Metadata round trips and table iteration
use tskit; use tskit::TableAccess; use tskit::metadata::MetadataRoundtrip; // Define a type for metadata struct F { x: i32, } // Implement our metadata trait for type F. // NOTE: this is hard because we are only using the // rust standard library here. See the examples/ // directory of the repository for examples using // other, more convenient, crates. impl tskit::metadata::MetadataRoundtrip for F { fn encode(&self) -> Result<Vec<u8>, tskit::metadata::MetadataError> { let mut rv = vec![]; rv.extend(self.x.to_le_bytes().iter().copied()); Ok(rv) } fn decode(md: &[u8]) -> Result<Self, tskit::metadata::MetadataError> { use std::convert::TryInto; let (x_int_bytes, rest) = md.split_at(std::mem::size_of::<i32>()); Ok(Self { x: i32::from_le_bytes(x_int_bytes.try_into().unwrap()), }) } } // Crate a table and add a mutation with metadata let mut tables = tskit::TableCollection::new(100.).unwrap(); // The metadata takes a reference in the event that it could // be data store in some container somewhere, and you don't want // it moved. tables.add_mutation_with_metadata(0, 0, 0, 0., None, Some(&F{x: -33})).unwrap(); // Iterate over each row in the table. // The "true" means to include (a copy of) the // encoded metadata, if any exist. for row in tables.mutations().iter() { // Decode the metadata if any exists. if !row.metadata.is_none() { let md = F::decode(&row.metadata.unwrap()).unwrap(); assert_eq!(md.x, -33); } }
Future road map
- Support all table types. Currently, we only support those needed for current goals in ongoing projects.
- Strengthen some of the error handling.
Implementations
impl TableCollection
[src]
impl TableCollection
[src]pub fn new(sequence_length: f64) -> Result<Self, TskitError>
[src]
pub fn new(sequence_length: f64) -> Result<Self, TskitError>
[src]Create a new table collection with a sequence length.
pub fn new_from_file(filename: &str) -> Result<Self, TskitError>
[src]
pub fn new_from_file(filename: &str) -> Result<Self, TskitError>
[src]Load a table collection from a file.
pub fn sequence_length(&self) -> f64
[src]
pub fn sequence_length(&self) -> f64
[src]Length of the sequence/“genome”.
pub fn add_edge(
&mut self,
left: f64,
right: f64,
parent: tsk_id_t,
child: tsk_id_t
) -> TskReturnValue
[src]
pub fn add_edge(
&mut self,
left: f64,
right: f64,
parent: tsk_id_t,
child: tsk_id_t
) -> TskReturnValue
[src]Add a row to the edge table
pub fn add_edge_with_metadata(
&mut self,
left: f64,
right: f64,
parent: tsk_id_t,
child: tsk_id_t,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]
pub fn add_edge_with_metadata(
&mut self,
left: f64,
right: f64,
parent: tsk_id_t,
child: tsk_id_t,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]Add a row with metadata to the edge table
pub fn add_individual(
&mut self,
flags: tsk_flags_t,
location: &[f64],
parents: &[tsk_id_t]
) -> TskReturnValue
[src]
pub fn add_individual(
&mut self,
flags: tsk_flags_t,
location: &[f64],
parents: &[tsk_id_t]
) -> TskReturnValue
[src]Add a row to the individual table
pub fn add_individual_with_metadata(
&mut self,
flags: tsk_flags_t,
location: &[f64],
parents: &[tsk_id_t],
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]
pub fn add_individual_with_metadata(
&mut self,
flags: tsk_flags_t,
location: &[f64],
parents: &[tsk_id_t],
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]Add a row with metadata to the individual table
pub fn add_migration(
&mut self,
span: (f64, f64),
node: tsk_id_t,
source_dest: (tsk_id_t, tsk_id_t),
time: f64
) -> TskReturnValue
[src]
pub fn add_migration(
&mut self,
span: (f64, f64),
node: tsk_id_t,
source_dest: (tsk_id_t, tsk_id_t),
time: f64
) -> TskReturnValue
[src]Add a row to the migration table
Warnings
Migration tables are not currently supported by tree sequence simplification.
pub fn add_migration_with_metadata(
&mut self,
span: (f64, f64),
node: tsk_id_t,
source_dest: (tsk_id_t, tsk_id_t),
time: f64,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]
pub fn add_migration_with_metadata(
&mut self,
span: (f64, f64),
node: tsk_id_t,
source_dest: (tsk_id_t, tsk_id_t),
time: f64,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]Add a row with metadata to the migration table
Warnings
Migration tables are not currently supported by tree sequence simplification.
pub fn add_node(
&mut self,
flags: tsk_flags_t,
time: f64,
population: tsk_id_t,
individual: tsk_id_t
) -> TskReturnValue
[src]
pub fn add_node(
&mut self,
flags: tsk_flags_t,
time: f64,
population: tsk_id_t,
individual: tsk_id_t
) -> TskReturnValue
[src]Add a row to the node table
pub fn add_node_with_metadata(
&mut self,
flags: tsk_flags_t,
time: f64,
population: tsk_id_t,
individual: tsk_id_t,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]
pub fn add_node_with_metadata(
&mut self,
flags: tsk_flags_t,
time: f64,
population: tsk_id_t,
individual: tsk_id_t,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]Add a row with metadata to the node table
pub fn add_site(
&mut self,
position: f64,
ancestral_state: Option<&[u8]>
) -> TskReturnValue
[src]
pub fn add_site(
&mut self,
position: f64,
ancestral_state: Option<&[u8]>
) -> TskReturnValue
[src]Add a row to the site table
pub fn add_site_with_metadata(
&mut self,
position: f64,
ancestral_state: Option<&[u8]>,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]
pub fn add_site_with_metadata(
&mut self,
position: f64,
ancestral_state: Option<&[u8]>,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]Add a row with metadata to the site table
pub fn add_mutation(
&mut self,
site: tsk_id_t,
node: tsk_id_t,
parent: tsk_id_t,
time: f64,
derived_state: Option<&[u8]>
) -> TskReturnValue
[src]
pub fn add_mutation(
&mut self,
site: tsk_id_t,
node: tsk_id_t,
parent: tsk_id_t,
time: f64,
derived_state: Option<&[u8]>
) -> TskReturnValue
[src]Add a row to the mutation table.
pub fn add_mutation_with_metadata(
&mut self,
site: tsk_id_t,
node: tsk_id_t,
parent: tsk_id_t,
time: f64,
derived_state: Option<&[u8]>,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]
pub fn add_mutation_with_metadata(
&mut self,
site: tsk_id_t,
node: tsk_id_t,
parent: tsk_id_t,
time: f64,
derived_state: Option<&[u8]>,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]Add a row with metadata to the mutation table.
pub fn add_population(&mut self) -> TskReturnValue
[src]
pub fn add_population(&mut self) -> TskReturnValue
[src]Add a row to the population_table
pub fn add_population_with_metadata(
&mut self,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]
pub fn add_population_with_metadata(
&mut self,
metadata: Option<&dyn MetadataRoundtrip>
) -> TskReturnValue
[src]Add a row with metadata to the population_table
pub fn build_index(&mut self) -> TskReturnValue
[src]
pub fn build_index(&mut self) -> TskReturnValue
[src]Build the “input” and “output” indexes for the edge table.
Note
The C API
call behind this takes a flags
argument
that is currently unused. A future release may break API
here if the C
library is updated to use flags.
pub fn is_indexed(&self) -> bool
[src]
pub fn is_indexed(&self) -> bool
[src]Return true
if tables are indexed.
pub fn edge_insertion_order(&self) -> Option<&[tsk_id_t]>
[src]
pub fn edge_insertion_order(&self) -> Option<&[tsk_id_t]>
[src]If self.is_indexed()
is true
, return a non-owning
slice containing the edge insertion order.
Otherwise, return None
.
pub fn edge_removal_order(&self) -> Option<&[tsk_id_t]>
[src]
pub fn edge_removal_order(&self) -> Option<&[tsk_id_t]>
[src]If self.is_indexed()
is true
, return a non-owning
slice containing the edge removal order.
Otherwise, return None
.
pub fn sort(
&mut self,
start: &Bookmark,
options: TableSortOptions
) -> TskReturnValue
[src]
pub fn sort(
&mut self,
start: &Bookmark,
options: TableSortOptions
) -> TskReturnValue
[src]Sort the tables.
The bookmark
can
be used to affect where sorting starts from for each table.
pub fn full_sort(&mut self, options: TableSortOptions) -> TskReturnValue
[src]
pub fn full_sort(&mut self, options: TableSortOptions) -> TskReturnValue
[src]Fully sort all functions.
Implemented via a call to sort
.
pub fn dump(
&self,
filename: &str,
options: TableOutputOptions
) -> TskReturnValue
[src]
pub fn dump(
&self,
filename: &str,
options: TableOutputOptions
) -> TskReturnValue
[src]Dump the table collection to file.
pub fn clear(&mut self, options: TableClearOptions) -> TskReturnValue
[src]
pub fn clear(&mut self, options: TableClearOptions) -> TskReturnValue
[src]Clear the contents of all tables. Does not release memory. Memory will be released when the object goes out of scope.
pub fn equals(
&self,
other: &TableCollection,
options: TableEqualityOptions
) -> bool
[src]
pub fn equals(
&self,
other: &TableCollection,
options: TableEqualityOptions
) -> bool
[src]Return true
if self
contains the same
data as other
, and false
otherwise.
pub fn deepcopy(&self) -> Result<TableCollection, TskitError>
[src]
pub fn deepcopy(&self) -> Result<TableCollection, TskitError>
[src]Return a “deep” copy of the tables.
pub fn tree_sequence(
self,
flags: TreeSequenceFlags
) -> Result<TreeSequence, TskitError>
[src]
pub fn tree_sequence(
self,
flags: TreeSequenceFlags
) -> Result<TreeSequence, TskitError>
[src]Return a crate::TreeSequence
based on the tables.
This function will raise errors if tables are not sorted,
not indexed, or invalid in any way.
pub fn simplify(
&mut self,
samples: &[tsk_id_t],
options: SimplificationOptions,
idmap: bool
) -> Result<Option<Vec<tsk_id_t>>, TskitError>
[src]
pub fn simplify(
&mut self,
samples: &[tsk_id_t],
options: SimplificationOptions,
idmap: bool
) -> Result<Option<Vec<tsk_id_t>>, TskitError>
[src]Simplify tables in place.
Parameters
samples
: a slice containing non-null node ids. The tables are simplified with respect to the ancestry of these nodes.options
: ASimplificationOptions
bit field controlling the behavior of simplification.idmap
: iftrue
, 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 orTSK_NULL
if the input node is not part of the simplified history.
Trait Implementations
impl Drop for TableCollection
[src]
impl Drop for TableCollection
[src]impl NodeListGenerator for TableCollection
[src]
impl NodeListGenerator for TableCollection
[src]fn samples_as_vector(&self) -> Vec<tsk_id_t>
[src]
fn samples_as_vector(&self) -> Vec<tsk_id_t>
[src]Obtain a vector containing the indexes (“ids”)
of all nodes for which crate::TSK_NODE_IS_SAMPLE
is true
. Read more
fn create_node_id_vector(
&self,
f: impl FnMut(&NodeTableRow) -> bool
) -> Vec<tsk_id_t>
[src]
fn create_node_id_vector(
&self,
f: impl FnMut(&NodeTableRow) -> bool
) -> Vec<tsk_id_t>
[src]Obtain a vector containing the indexes (“ids”) of all nodes satisfying a certain criterion. Read more
impl Provenance for TableCollection
[src]
impl Provenance for TableCollection
[src]fn add_provenance(&mut self, record: &str) -> TskReturnValue
[src]
fn add_provenance(&mut self, record: &str) -> TskReturnValue
[src]Add provenance record with a time stamp. Read more
fn provenances(&self) -> ProvenanceTable<'_>
[src]
fn provenances(&self) -> ProvenanceTable<'_>
[src]Return an immutable reference to the table, type ProvenanceTable
fn provenances_iter(&self) -> TableIterator<ProvenanceTable<'_>>
[src]
fn provenances_iter(&self) -> TableIterator<ProvenanceTable<'_>>
[src]Return an iterator over the rows of the ProvenanceTable
.
See ProvenanceTable::iter
for details. Read more
impl TableAccess for TableCollection
[src]
impl TableAccess for TableCollection
[src]fn individuals(&self) -> IndividualTable<'_>
[src]
fn individuals(&self) -> IndividualTable<'_>
[src]Get reference to the IndividualTable
.
fn migrations(&self) -> MigrationTable<'_>
[src]
fn migrations(&self) -> MigrationTable<'_>
[src]Get reference to the MigrationTable
.
fn mutations(&self) -> MutationTable<'_>
[src]
fn mutations(&self) -> MutationTable<'_>
[src]Get reference to the MutationTable
.
fn populations(&self) -> PopulationTable<'_>
[src]
fn populations(&self) -> PopulationTable<'_>
[src]Get reference to the PopulationTable
.
fn edges_iter(&self) -> TableIterator<EdgeTable<'_>>
[src]
fn edges_iter(&self) -> TableIterator<EdgeTable<'_>>
[src]Return an iterator over the edges.
See EdgeTable::iter
for details. Read more
fn nodes_iter(&self) -> TableIterator<NodeTable<'_>>
[src]
fn nodes_iter(&self) -> TableIterator<NodeTable<'_>>
[src]Return an iterator over the nodes.
See NodeTable::iter
for details. Read more
fn mutations_iter(&self) -> TableIterator<MutationTable<'_>>
[src]
fn mutations_iter(&self) -> TableIterator<MutationTable<'_>>
[src]Return an iterator over the mutations.
See MutationTable::iter
for details. Read more
fn sites_iter(&self) -> TableIterator<SiteTable<'_>>
[src]
fn sites_iter(&self) -> TableIterator<SiteTable<'_>>
[src]Return an iterator over the sites.
See SiteTable::iter
for details. Read more
fn populations_iter(&self) -> TableIterator<PopulationTable<'_>>
[src]
fn populations_iter(&self) -> TableIterator<PopulationTable<'_>>
[src]Return an iterator over the populations.
See PopulationTable::iter
for details. Read more
fn migrations_iter(&self) -> TableIterator<MigrationTable<'_>>
[src]
fn migrations_iter(&self) -> TableIterator<MigrationTable<'_>>
[src]Return an iterator over the migration events.
See MigrationTable::iter
for details. Read more
fn individuals_iter(&self) -> TableIterator<IndividualTable<'_>>
[src]
fn individuals_iter(&self) -> TableIterator<IndividualTable<'_>>
[src]Return an iterator over the individuals.
See IndividualTable::iter
for details. Read more
impl TskitTypeAccess<tsk_table_collection_t> for TableCollection
[src]
impl TskitTypeAccess<tsk_table_collection_t> for TableCollection
[src]fn as_ptr(&self) -> *const tsk_table_collection_t
[src]
fn as_ptr(&self) -> *const tsk_table_collection_t
[src]Return const pointer
fn as_mut_ptr(&mut self) -> *mut tsk_table_collection_t
[src]
fn as_mut_ptr(&mut self) -> *mut tsk_table_collection_t
[src]Return mutable pointer