File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use super::bindings::tsk_size_t;
55use super :: bindings:: tsk_tree_t;
66use super :: flags:: TreeFlags ;
77use super :: newtypes:: NodeId ;
8+ use super :: newtypes:: SizeType ;
89use super :: tskbox:: TskBox ;
910use super :: TreeSequence ;
1011use super :: TskitError ;
@@ -69,7 +70,7 @@ impl<'treeseq> LLTree<'treeseq> {
6970 self . inner . as_mut ( )
7071 }
7172
72- pub fn as_ptr ( & mut self ) -> * const tsk_tree_t {
73+ pub fn as_ptr ( & self ) -> * const tsk_tree_t {
7374 self . inner . as_ptr ( )
7475 }
7576
@@ -112,6 +113,17 @@ impl<'treeseq> LLTree<'treeseq> {
112113 . num_rows ,
113114 )
114115 }
116+
117+ pub fn num_tracked_samples ( & self , u : NodeId ) -> Result < SizeType , TskitError > {
118+ let mut n = tsk_size_t:: MAX ;
119+ let np: * mut tsk_size_t = & mut n;
120+ assert ! ( !self . as_ptr( ) . is_null( ) ) ;
121+ // SAFETY: internal pointer not null and is initialized.
122+ let code = unsafe {
123+ super :: bindings:: tsk_tree_get_num_tracked_samples ( self . as_ptr ( ) , u. into ( ) , np)
124+ } ;
125+ handle_tsk_return_value ! ( code, n. into( ) )
126+ }
115127}
116128
117129// Trait defining iteration over nodes.
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use crate::sys::bindings as ll_bindings;
22use crate :: sys:: { LLTree , TreeSequence } ;
33use crate :: NodeId ;
44use crate :: Position ;
5+ use crate :: SizeType ;
56use crate :: TreeFlags ;
67use crate :: TskitError ;
78
@@ -115,6 +116,15 @@ impl<'treeseq> Tree<'treeseq> {
115116 pub fn right_child < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
116117 self . inner . left_sib ( u. into ( ) )
117118 }
119+
120+ /// Get the number of samples below node `u`.
121+ ///
122+ /// # Errors
123+ ///
124+ /// * [`TskitError`] if [`TreeFlags::NO_SAMPLE_COUNTS`].
125+ pub fn num_tracked_samples ( & self , u : NodeId ) -> Result < SizeType , TskitError > {
126+ self . inner . num_tracked_samples ( u)
127+ }
118128}
119129
120130impl < ' ts > streaming_iterator:: StreamingIterator for Tree < ' ts > {
You can’t perform that action at this time.
0 commit comments