Skip to content

Commit 29f8a6f

Browse files
committed
feat: TableCollection::compute_mutation_parents
1 parent 0787f9f commit 29f8a6f

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/sys/flags.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::sys::bindings as ll_bindings;
77
use crate::RawFlags;
88
use bitflags::bitflags;
99

10+
use super::bindings::tsk_flags_t;
11+
1012
macro_rules! impl_from_for_flag_types {
1113
($flagstype: ty) => {
1214
impl From<$crate::RawFlags> for $flagstype {
@@ -746,6 +748,15 @@ impl From<RawFlags> for IndividualFlags {
746748
}
747749
}
748750

751+
#[derive(Copy, Clone, Default, Debug)]
752+
pub struct MutationParentsFlags(tsk_flags_t);
753+
754+
impl From<MutationParentsFlags> for tsk_flags_t {
755+
fn from(value: MutationParentsFlags) -> Self {
756+
value.0
757+
}
758+
}
759+
749760
#[cfg(test)]
750761
mod tests {
751762
use super::*;

src/sys/table_collection.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::bindings;
12
use super::bindings::tsk_edge_table_t;
23
use super::bindings::tsk_individual_table_t;
34
use super::bindings::tsk_migration_table_t;
@@ -9,6 +10,7 @@ use super::bindings::tsk_provenance_table_t;
910
use super::bindings::tsk_site_table_t;
1011
use super::bindings::tsk_table_collection_init;
1112
use super::bindings::tsk_table_collection_t;
13+
use super::flags::MutationParentsFlags;
1214
use super::tskbox::TskBox;
1315
use super::TskitError;
1416

@@ -119,6 +121,20 @@ impl TableCollection {
119121
pub fn into_raw(self) -> *mut tsk_table_collection_t {
120122
self.0.into_raw()
121123
}
124+
125+
pub fn compute_mutation_parents(
126+
&mut self,
127+
options: MutationParentsFlags,
128+
) -> Result<(), TskitError> {
129+
// SAFETY: as_mut_ptr is safe because the internal pointer cannot be null
130+
let code = unsafe {
131+
bindings::tsk_table_collection_compute_mutation_parents(
132+
self.as_mut_ptr(),
133+
options.into(),
134+
)
135+
};
136+
handle_tsk_return_value!(code, ())
137+
}
122138
}
123139

124140
#[test]

src/table_collection.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,4 +1564,12 @@ impl TableCollection {
15641564
Ok(Some(tables))
15651565
}
15661566
}
1567+
1568+
/// Compute the parents of each mutation.
1569+
pub fn compute_mutation_parents(
1570+
&mut self,
1571+
options: crate::MutationParentsFlags,
1572+
) -> Result<(), TskitError> {
1573+
self.inner.compute_mutation_parents(options)
1574+
}
15671575
}

0 commit comments

Comments
 (0)