|
| 1 | +#[test] |
| 2 | +fn initialize_from_table_collection() { |
| 3 | + // ANCHOR: build_tables |
| 4 | + use tskit::prelude::*; |
| 5 | + use tskit::TableCollection; |
| 6 | + use tskit::TableSortOptions; |
| 7 | + use tskit::TreeFlags; |
| 8 | + use tskit::TreeSequenceFlags; |
| 9 | + |
| 10 | + let mut tables = TableCollection::new(1000.).unwrap(); |
| 11 | + tables |
| 12 | + .add_node(0, 2.0, PopulationId::NULL, IndividualId::NULL) |
| 13 | + .unwrap(); |
| 14 | + tables |
| 15 | + .add_node(0, 1.0, PopulationId::NULL, IndividualId::NULL) |
| 16 | + .unwrap(); |
| 17 | + tables |
| 18 | + .add_node( |
| 19 | + TSK_NODE_IS_SAMPLE, |
| 20 | + 0.0, |
| 21 | + PopulationId::NULL, |
| 22 | + IndividualId::NULL, |
| 23 | + ) |
| 24 | + .unwrap(); |
| 25 | + tables |
| 26 | + .add_node( |
| 27 | + TSK_NODE_IS_SAMPLE, |
| 28 | + 0.0, |
| 29 | + PopulationId::NULL, |
| 30 | + IndividualId::NULL, |
| 31 | + ) |
| 32 | + .unwrap(); |
| 33 | + tables |
| 34 | + .add_node( |
| 35 | + TSK_NODE_IS_SAMPLE, |
| 36 | + 0.0, |
| 37 | + PopulationId::NULL, |
| 38 | + IndividualId::NULL, |
| 39 | + ) |
| 40 | + .unwrap(); |
| 41 | + tables |
| 42 | + .add_node( |
| 43 | + TSK_NODE_IS_SAMPLE, |
| 44 | + 0.0, |
| 45 | + PopulationId::NULL, |
| 46 | + IndividualId::NULL, |
| 47 | + ) |
| 48 | + .unwrap(); |
| 49 | + tables.add_edge(500., 1000., 0, 1).unwrap(); |
| 50 | + tables.add_edge(0., 500., 0, 2).unwrap(); |
| 51 | + tables.add_edge(0., 1000., 0, 3).unwrap(); |
| 52 | + tables.add_edge(500., 1000., 1, 2).unwrap(); |
| 53 | + tables.add_edge(0., 1000., 1, 4).unwrap(); |
| 54 | + tables.add_edge(0., 1000., 1, 5).unwrap(); |
| 55 | + // ANCHOR_END: build_tables |
| 56 | + |
| 57 | + // ANCHOR: sort_tables |
| 58 | + tables.full_sort(TableSortOptions::default()).unwrap(); |
| 59 | + // ANCHOR_END: sort_tables |
| 60 | + |
| 61 | + // ANCHOR: index_tables |
| 62 | + tables.build_index().unwrap(); |
| 63 | + // ANCHOR_END: index_tables |
| 64 | + |
| 65 | + // ANCHOR: create_tree_sequence |
| 66 | + let treeseq = tables.tree_sequence(TreeSequenceFlags::default()).unwrap(); |
| 67 | + // ANCHOR_END: create_tree_sequence |
| 68 | + |
| 69 | + // ANCHOR: iterate_trees |
| 70 | + let mut tree_iterator = treeseq.tree_iterator(TreeFlags::default()).unwrap(); |
| 71 | + |
| 72 | + while let Some(_tree) = tree_iterator.next() { |
| 73 | + // _tree is a tskit::Tree |
| 74 | + } |
| 75 | + // ANCHOR_END: iterate_trees |
| 76 | +} |
0 commit comments