Skip to content

Commit f801234

Browse files
committed
add _some_ metadata functions for remaining tables
1 parent afb4696 commit f801234

File tree

1 file changed

+80
-6
lines changed

1 file changed

+80
-6
lines changed

src/table_collection.rs

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl TableCollection {
176176
self.add_edge_with_metadata(left, right, parent, child, None)
177177
}
178178

179-
/// Add a row with metadata to the edge table
179+
/// Add a row with optional metadata to the edge table
180180
pub fn add_edge_with_metadata<P: Into<NodeId>, C: Into<NodeId>>(
181181
&mut self,
182182
left: f64,
@@ -201,6 +201,18 @@ impl TableCollection {
201201
handle_tsk_return_value!(rv, EdgeId::from(rv))
202202
}
203203

204+
/// Add a row with metadata to the edge table
205+
pub fn add_edge_with_some_metadata<P: Into<NodeId>, C: Into<NodeId>>(
206+
&mut self,
207+
left: f64,
208+
right: f64,
209+
parent: P,
210+
child: C,
211+
metadata: &dyn MetadataRoundtrip,
212+
) -> Result<EdgeId, TskitError> {
213+
self.add_edge_with_metadata(left, right, parent, child, Some(metadata))
214+
}
215+
204216
/// Add a row to the individual table
205217
pub fn add_individual<N: Into<NodeId>>(
206218
&mut self,
@@ -211,7 +223,7 @@ impl TableCollection {
211223
self.add_individual_with_metadata(flags, location, parents, None)
212224
}
213225

214-
/// Add a row with metadata to the individual table
226+
/// Add a row with optional metadata to the individual table
215227
pub fn add_individual_with_metadata<N: Into<NodeId>>(
216228
&mut self,
217229
flags: tsk_flags_t,
@@ -235,6 +247,17 @@ impl TableCollection {
235247
handle_tsk_return_value!(rv, IndividualId::from(rv))
236248
}
237249

250+
/// Add a row with metadata to the individual table
251+
pub fn add_individual_with_some_metadata<N: Into<NodeId>>(
252+
&mut self,
253+
flags: tsk_flags_t,
254+
location: &[f64],
255+
parents: &[N],
256+
metadata: &dyn MetadataRoundtrip,
257+
) -> Result<IndividualId, TskitError> {
258+
self.add_individual_with_metadata(flags, location, parents, Some(metadata))
259+
}
260+
238261
/// Add a row to the migration table
239262
///
240263
/// # Warnings
@@ -251,7 +274,7 @@ impl TableCollection {
251274
self.add_migration_with_metadata(span, node, source_dest, time, None)
252275
}
253276

254-
/// Add a row with metadata to the migration table
277+
/// Add a row with optional metadata to the migration table
255278
///
256279
/// # Warnings
257280
///
@@ -286,6 +309,27 @@ impl TableCollection {
286309
handle_tsk_return_value!(rv)
287310
}
288311

312+
/// Add a row with metadata to the migration table
313+
///
314+
/// # Warnings
315+
///
316+
/// Migration tables are not currently supported
317+
/// by tree sequence simplification.
318+
pub fn add_migration_with_some_metadata<
319+
N: Into<NodeId>,
320+
SOURCE: Into<PopulationId>,
321+
DEST: Into<PopulationId>,
322+
>(
323+
&mut self,
324+
span: (f64, f64),
325+
node: N,
326+
source_dest: (SOURCE, DEST),
327+
time: f64,
328+
metadata: &dyn MetadataRoundtrip,
329+
) -> TskReturnValue {
330+
self.add_migration_with_metadata(span, node, source_dest, time, Some(metadata))
331+
}
332+
289333
/// Add a row to the node table
290334
pub fn add_node<I: Into<IndividualId>, POP: Into<PopulationId>>(
291335
&mut self,
@@ -297,7 +341,7 @@ impl TableCollection {
297341
self.add_node_with_metadata(flags, time, population, individual, None)
298342
}
299343

300-
/// Add a row with metadata to the node table
344+
/// Add a row with optional metadata to the node table
301345
pub fn add_node_with_metadata<I: Into<IndividualId>, POP: Into<PopulationId>>(
302346
&mut self,
303347
flags: ll_bindings::tsk_flags_t,
@@ -322,6 +366,18 @@ impl TableCollection {
322366
handle_tsk_return_value!(rv, rv.into())
323367
}
324368

369+
/// Add a row with metadata to the node table
370+
pub fn add_node_with_some_metadata<I: Into<IndividualId>, POP: Into<PopulationId>>(
371+
&mut self,
372+
flags: ll_bindings::tsk_flags_t,
373+
time: f64,
374+
population: POP,
375+
individual: I,
376+
metadata: &dyn MetadataRoundtrip,
377+
) -> Result<NodeId, TskitError> {
378+
self.add_node_with_metadata(flags, time, population, individual, Some(metadata))
379+
}
380+
325381
/// Add a row to the site table
326382
pub fn add_site(
327383
&mut self,
@@ -331,7 +387,7 @@ impl TableCollection {
331387
self.add_site_with_metadata(position, ancestral_state, None)
332388
}
333389

334-
/// Add a row with metadata to the site table
390+
/// Add a row with optional metadata to the site table
335391
pub fn add_site_with_metadata(
336392
&mut self,
337393
position: f64,
@@ -355,6 +411,16 @@ impl TableCollection {
355411
handle_tsk_return_value!(rv, SiteId::from(rv))
356412
}
357413

414+
/// Add a row with metadata to the site table
415+
pub fn add_site_with_some_metadata(
416+
&mut self,
417+
position: f64,
418+
ancestral_state: Option<&[u8]>,
419+
metadata: &dyn MetadataRoundtrip,
420+
) -> Result<SiteId, TskitError> {
421+
self.add_site_with_metadata(position, ancestral_state, Some(metadata))
422+
}
423+
358424
/// Add a row to the mutation table.
359425
pub fn add_mutation<N: Into<NodeId>, M: Into<MutationId>, S: Into<SiteId>>(
360426
&mut self,
@@ -419,7 +485,7 @@ impl TableCollection {
419485
self.add_population_with_metadata(None)
420486
}
421487

422-
/// Add a row with metadata to the population_table
488+
/// Add a row with optional metadata to the population_table
423489
pub fn add_population_with_metadata(
424490
&mut self,
425491
metadata: Option<&dyn MetadataRoundtrip>,
@@ -436,6 +502,14 @@ impl TableCollection {
436502
handle_tsk_return_value!(rv, PopulationId::from(rv))
437503
}
438504

505+
/// Add a row with metadata to the population_table
506+
pub fn add_population_with_some_metadata(
507+
&mut self,
508+
metadata: &dyn MetadataRoundtrip,
509+
) -> Result<PopulationId, TskitError> {
510+
self.add_population_with_metadata(Some(metadata))
511+
}
512+
439513
/// Build the "input" and "output"
440514
/// indexes for the edge table.
441515
///

0 commit comments

Comments
 (0)