Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions src/_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,87 +380,6 @@ macro_rules! handle_metadata_return {
};
}

macro_rules! mutation_table_add_row_details {
($site: ident, $node: ident, $parent: ident,
$time: ident, $derived_state: ident,
$metadata: expr,
$metadata_len: expr,
$table: expr) => {{
let dstate = process_state_input!($derived_state);
let rv = unsafe {
$crate::bindings::tsk_mutation_table_add_row(
$table,
$site.into().into(),
$node.into().into(),
$parent.into().into(),
$time.into().into(),
dstate.0,
dstate.1,
$metadata,
$metadata_len,
)
};
handle_tsk_return_value!(rv, rv.into())
}};
}

macro_rules! mutation_table_add_row {
($(#[$attr:meta])* => $name: ident, $self: ident, $table: expr) => {
$(#[$attr])*
pub fn $name<S,N,P,T>(&mut $self,
site: S,
node: N,
parent: P,
time: T,
derived_state: Option<&[u8]>) -> Result<$crate::MutationId, $crate::TskitError>
where
S: Into<$crate::SiteId>,
N: Into<$crate::NodeId>,
P: Into<$crate::MutationId>,
T: Into<$crate::Time>,
{
mutation_table_add_row_details!(site,
node,
parent,
time,
derived_state,
std::ptr::null(),
0,
$table)
}
};
}

macro_rules! mutation_table_add_row_with_metadata {
($(#[$attr:meta])* => $name: ident, $self: ident, $table: expr) => {
$(#[$attr])*
pub fn $name<S,N,P,T,M>(&mut $self,
site: S,
node: N,
parent: P,
time: T,
derived_state: Option<&[u8]>,
metadata: &M) -> Result<$crate::MutationId, $crate::TskitError>
where
S: Into<$crate::SiteId>,
N: Into<$crate::NodeId>,
P: Into<$crate::MutationId>,
T: Into<$crate::Time>,
M: $crate::metadata::MutationMetadata
{
let md = $crate::metadata::EncodedMetadata::new(metadata)?;
mutation_table_add_row_details!(site,
node,
parent,
time,
derived_state,
md.as_ptr(),
md.len()?.into(),
$table)
}
};
}

macro_rules! site_table_add_row_details {
($position: ident,
$ancestral_state: ident,
Expand Down
80 changes: 78 additions & 2 deletions src/mutation_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,84 @@ impl MutationTable {
self.table_.clear().map_err(|e| e.into())
}

mutation_table_add_row!(=> add_row, self, self.as_mut_ptr());
mutation_table_add_row_with_metadata!(=> add_row_with_metadata, self, self.as_mut_ptr());
#[allow(clippy::too_many_arguments)]
fn add_row_details<S, N, P, T>(
&mut self,
site: S,
node: N,
parent: P,
time: T,
derived_state: Option<&[u8]>,
metadata: *const i8,
metadata_length: u64,
) -> Result<crate::MutationId, crate::TskitError>
where
S: Into<crate::SiteId>,
N: Into<crate::NodeId>,
P: Into<crate::MutationId>,
T: Into<crate::Time>,
{
let dstate = process_state_input!(derived_state);
let rv = unsafe {
ll_bindings::tsk_mutation_table_add_row(
self.as_mut_ptr(),
site.into().into(),
node.into().into(),
parent.into().into(),
time.into().into(),
dstate.0,
dstate.1,
metadata,
metadata_length,
)
};
handle_tsk_return_value!(rv, rv.into())
}

pub fn add_row<S, N, P, T>(
&mut self,
site: S,
node: N,
parent: P,
time: T,
derived_state: Option<&[u8]>,
) -> Result<crate::MutationId, crate::TskitError>
where
S: Into<crate::SiteId>,
N: Into<crate::NodeId>,
P: Into<crate::MutationId>,
T: Into<crate::Time>,
{
self.add_row_details(site, node, parent, time, derived_state, std::ptr::null(), 0)
}

pub fn add_row_with_metadata<S, N, P, T, M>(
&mut self,
site: S,
node: N,
parent: P,
time: T,
derived_state: Option<&[u8]>,
metadata: &M,
) -> Result<crate::MutationId, crate::TskitError>
where
S: Into<crate::SiteId>,
N: Into<crate::NodeId>,
P: Into<crate::MutationId>,
T: Into<crate::Time>,
M: crate::metadata::MutationMetadata,
{
let md = crate::metadata::EncodedMetadata::new(metadata)?;
self.add_row_details(
site,
node,
parent,
time,
derived_state,
md.as_ptr(),
md.len()?.into(),
)
}

build_table_column_slice_getter!(
/// Get the node column as a slice
Expand Down
46 changes: 42 additions & 4 deletions src/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,25 @@ impl TableCollection {
/// ```
=> add_site_with_metadata, self, &mut (*self.as_mut_ptr()).sites);

mutation_table_add_row!(
/// Add a row to the mutation table.
=> add_mutation, self, &mut (*self.as_mut_ptr()).mutations);
pub fn add_mutation<S, N, P, T>(
&mut self,
site: S,
node: N,
parent: P,
time: T,
derived_state: Option<&[u8]>,
) -> Result<crate::MutationId, crate::TskitError>
where
S: Into<crate::SiteId>,
N: Into<crate::NodeId>,
P: Into<crate::MutationId>,
T: Into<crate::Time>,
{
self.mutations_mut()
.add_row(site, node, parent, time, derived_state)
}

mutation_table_add_row_with_metadata!(
/// Add a row with optional metadata to the mutation table.
///
/// # Examples
Expand All @@ -567,7 +581,31 @@ impl TableCollection {
/// &metadata).is_ok());
/// # }
/// ```
=> add_mutation_with_metadata, self, &mut (*self.as_mut_ptr()).mutations);
pub fn add_mutation_with_metadata<S, N, P, T, M>(
&mut self,
site: S,
node: N,
parent: P,
time: T,
derived_state: Option<&[u8]>,
metadata: &M,
) -> Result<crate::MutationId, crate::TskitError>
where
S: Into<crate::SiteId>,
N: Into<crate::NodeId>,
P: Into<crate::MutationId>,
T: Into<crate::Time>,
M: crate::metadata::MutationMetadata,
{
self.mutations_mut().add_row_with_metadata(
site,
node,
parent,
time,
derived_state,
metadata,
)
}

/// Add a row to the population_table
///
Expand Down