|
1 | 1 | use crate::error::TskitError; |
2 | 2 | use crate::sys; |
| 3 | +use crate::EdgeTable; |
| 4 | +use crate::IndividualTable; |
| 5 | +use crate::MigrationTable; |
| 6 | +use crate::MutationTable; |
3 | 7 | use crate::NodeId; |
| 8 | +use crate::NodeTable; |
| 9 | +use crate::PopulationTable; |
4 | 10 | use crate::Position; |
5 | 11 | use crate::SimplificationOptions; |
| 12 | +use crate::SiteTable; |
6 | 13 | use crate::SizeType; |
7 | 14 | use crate::TableCollection; |
8 | 15 | use crate::TableOutputOptions; |
@@ -59,7 +66,6 @@ use super::Tree; |
59 | 66 | pub struct TreeSequence { |
60 | 67 | pub(crate) inner: sys::TreeSequence, |
61 | 68 | tables: crate::TableCollection, |
62 | | - views: crate::table_views::TableViews, |
63 | 69 | } |
64 | 70 |
|
65 | 71 | unsafe impl Send for TreeSequence {} |
@@ -115,17 +121,12 @@ impl TreeSequence { |
115 | 121 | ) -> Result<Self, TskitError> { |
116 | 122 | let raw_tables_ptr = tables.into_inner(); |
117 | 123 | let mut inner = sys::TreeSequence::new(raw_tables_ptr, flags.into())?; |
118 | | - let views = crate::table_views::TableViews::new_from_tree_sequence(inner.as_mut())?; |
119 | 124 | let tables = unsafe { |
120 | 125 | TableCollection::new_from_ll(sys::TableCollection::new_borrowed( |
121 | 126 | std::ptr::NonNull::new(inner.as_mut().tables).unwrap(), |
122 | 127 | )) |
123 | 128 | }?; |
124 | | - Ok(Self { |
125 | | - inner, |
126 | | - tables, |
127 | | - views, |
128 | | - }) |
| 129 | + Ok(Self { inner, tables }) |
129 | 130 | } |
130 | 131 |
|
131 | 132 | fn as_ref(&self) -> &ll_bindings::tsk_treeseq_t { |
@@ -346,18 +347,13 @@ impl TreeSequence { |
346 | 347 | false => None, |
347 | 348 | }, |
348 | 349 | )?; |
349 | | - let views = crate::table_views::TableViews::new_from_tree_sequence(inner.as_mut())?; |
350 | 350 | let tables = unsafe { |
351 | 351 | TableCollection::new_from_ll(sys::TableCollection::new_borrowed( |
352 | 352 | std::ptr::NonNull::new(inner.as_mut().tables).unwrap(), |
353 | 353 | )) |
354 | 354 | }?; |
355 | 355 | Ok(( |
356 | | - Self { |
357 | | - inner, |
358 | | - tables, |
359 | | - views, |
360 | | - }, |
| 356 | + Self { inner, tables }, |
361 | 357 | match idmap { |
362 | 358 | true => Some(output_node_map), |
363 | 359 | false => None, |
@@ -481,8 +477,6 @@ impl TreeSequence { |
481 | 477 | handle_tsk_return_value!(rv, crate::ProvenanceId::from(rv)) |
482 | 478 | } |
483 | 479 |
|
484 | | - delegate_table_view_api!(); |
485 | | - |
486 | 480 | /// Build a lending iterator over edge differences. |
487 | 481 | /// |
488 | 482 | /// # Errors |
@@ -510,6 +504,135 @@ impl TreeSequence { |
510 | 504 | pub fn tables(&self) -> &TableCollection { |
511 | 505 | &self.tables |
512 | 506 | } |
| 507 | + |
| 508 | + /// Get reference to the [``EdgeTable``](crate::EdgeTable). |
| 509 | + pub fn edges(&self) -> &EdgeTable { |
| 510 | + self.tables.edges() |
| 511 | + } |
| 512 | + |
| 513 | + /// Get reference to the [``NodeTable``](crate::NodeTable). |
| 514 | + pub fn nodes(&self) -> &NodeTable { |
| 515 | + self.tables.nodes() |
| 516 | + } |
| 517 | + |
| 518 | + /// Get reference to the [``SiteTable``](crate::SiteTable). |
| 519 | + pub fn sites(&self) -> &SiteTable { |
| 520 | + self.tables.sites() |
| 521 | + } |
| 522 | + |
| 523 | + /// Get reference to the [``MigrationTable``](crate::MigrationTable). |
| 524 | + pub fn migrations(&self) -> &MigrationTable { |
| 525 | + self.tables.migrations() |
| 526 | + } |
| 527 | + |
| 528 | + pub fn mutations(&self) -> &MutationTable { |
| 529 | + self.tables.mutations() |
| 530 | + } |
| 531 | + |
| 532 | + /// Get reference to the [``IndividualTable``](crate::IndividualTable). |
| 533 | + pub fn individuals(&self) -> &IndividualTable { |
| 534 | + self.tables.individuals() |
| 535 | + } |
| 536 | + |
| 537 | + /// Get reference to the [``PopulationTable``](crate::PopulationTable). |
| 538 | + pub fn populations(&self) -> &PopulationTable { |
| 539 | + self.tables.populations() |
| 540 | + } |
| 541 | + |
| 542 | + #[cfg(feature = "provenance")] |
| 543 | + #[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))] |
| 544 | + /// Get reference to the [``ProvenanceTable``](crate::provenance::ProvenanceTable) |
| 545 | + pub fn provenances(&self) -> &crate::provenance::ProvenanceTable { |
| 546 | + self.tables.provenances() |
| 547 | + } |
| 548 | + |
| 549 | + /// Return an iterator over the individuals. |
| 550 | + pub fn individuals_iter(&self) -> impl Iterator<Item = crate::IndividualTableRow> + '_ { |
| 551 | + self.individuals().iter() |
| 552 | + } |
| 553 | + |
| 554 | + /// Return an iterator over the nodes. |
| 555 | + pub fn nodes_iter(&self) -> impl Iterator<Item = crate::NodeTableRow> + '_ { |
| 556 | + self.nodes().iter() |
| 557 | + } |
| 558 | + /// Return an iterator over the edges. |
| 559 | + pub fn edges_iter(&self) -> impl Iterator<Item = crate::EdgeTableRow> + '_ { |
| 560 | + self.edges().iter() |
| 561 | + } |
| 562 | + /// Return an iterator over the migrations. |
| 563 | + pub fn migrations_iter(&self) -> impl Iterator<Item = crate::MigrationTableRow> + '_ { |
| 564 | + self.migrations().iter() |
| 565 | + } |
| 566 | + /// Return an iterator over the mutations. |
| 567 | + pub fn mutations_iter(&self) -> impl Iterator<Item = crate::MutationTableRow> + '_ { |
| 568 | + self.mutations().iter() |
| 569 | + } |
| 570 | + /// Return an iterator over the populations. |
| 571 | + pub fn populations_iter(&self) -> impl Iterator<Item = crate::PopulationTableRow> + '_ { |
| 572 | + self.populations().iter() |
| 573 | + } |
| 574 | + /// Return an iterator over the sites. |
| 575 | + pub fn sites_iter(&self) -> impl Iterator<Item = crate::SiteTableRow> + '_ { |
| 576 | + self.sites().iter() |
| 577 | + } |
| 578 | + |
| 579 | + #[cfg(feature = "provenance")] |
| 580 | + #[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))] |
| 581 | + /// Return an iterator over provenances |
| 582 | + pub fn provenances_iter( |
| 583 | + &self, |
| 584 | + ) -> impl Iterator<Item = crate::provenance::ProvenanceTableRow> + '_ { |
| 585 | + self.provenances().iter() |
| 586 | + } |
| 587 | + |
| 588 | + /// Obtain a vector containing the indexes ("ids") |
| 589 | + /// of all nodes for which [`crate::NodeFlags::is_sample`] |
| 590 | + /// is `true`. |
| 591 | + /// |
| 592 | + /// The provided implementation dispatches to |
| 593 | + /// [`crate::NodeTable::samples_as_vector`]. |
| 594 | + pub fn samples_as_vector(&self) -> Vec<crate::NodeId> { |
| 595 | + self.tables.samples_as_vector() |
| 596 | + } |
| 597 | + |
| 598 | + /// Obtain a vector containing the indexes ("ids") of all nodes |
| 599 | + /// satisfying a certain criterion. |
| 600 | + /// |
| 601 | + /// The provided implementation dispatches to |
| 602 | + /// [`crate::NodeTable::create_node_id_vector`]. |
| 603 | + /// |
| 604 | + /// # Parameters |
| 605 | + /// |
| 606 | + /// * `f`: a function. The function is passed the current table |
| 607 | + /// collection and each [`crate::node_table::NodeTableRow`]. |
| 608 | + /// If `f` returns `true`, the index of that row is included |
| 609 | + /// in the return value. |
| 610 | + /// |
| 611 | + /// # Examples |
| 612 | + /// |
| 613 | + /// Get all nodes with time > 0.0: |
| 614 | + /// |
| 615 | + /// ``` |
| 616 | + /// let mut tables = tskit::TableCollection::new(100.).unwrap(); |
| 617 | + /// tables |
| 618 | + /// .add_node(tskit::NodeFlags::new_sample(), 0.0, tskit::PopulationId::NULL, |
| 619 | + /// tskit::IndividualId::NULL) |
| 620 | + /// .unwrap(); |
| 621 | + /// tables |
| 622 | + /// .add_node(tskit::NodeFlags::new_sample(), 1.0, tskit::PopulationId::NULL, |
| 623 | + /// tskit::IndividualId::NULL) |
| 624 | + /// .unwrap(); |
| 625 | + /// let samples = tables.create_node_id_vector( |
| 626 | + /// |row: &tskit::NodeTableRow| row.time > 0., |
| 627 | + /// ); |
| 628 | + /// assert_eq!(samples[0], 1); |
| 629 | + /// ``` |
| 630 | + pub fn create_node_id_vector( |
| 631 | + &self, |
| 632 | + f: impl FnMut(&crate::NodeTableRow) -> bool, |
| 633 | + ) -> Vec<crate::NodeId> { |
| 634 | + self.tables.create_node_id_vector(f) |
| 635 | + } |
513 | 636 | } |
514 | 637 |
|
515 | 638 | impl TryFrom<TableCollection> for TreeSequence { |
|
0 commit comments