Skip to content

Commit e20a859

Browse files
authored
chore: bump to tskit C API 1.2.0 (#789)
BREAKING CHANGE: conversion of table collection to tree sequence will require mutation parents to be computed for cases with multiple mutations at a site.
1 parent 869967d commit e20a859

File tree

13 files changed

+9067
-3776
lines changed

13 files changed

+9067
-3776
lines changed

src/test_fixtures.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ pub mod simulation {
301301

302302
// state variables for site/mutation tables
303303
let num_sites = f64::from(seqlen.into()) as usize;
304-
let mut site_last_mutation_order = vec![0usize; num_sites];
305-
306-
let mut site_last_mutation_tables = vec![MutationId::NULL; num_sites];
307-
let mut site_last_mutation_tr_tbls = vec![MutationId::NULL; num_sites];
304+
let site_last_mutation_order = vec![0usize; num_sites];
308305

309306
let mut site_id_map_tables = vec![SiteId::NULL; num_sites];
310307
let mut site_id_map_tr_tbls = vec![SiteId::NULL; num_sites];
@@ -387,14 +384,10 @@ pub mod simulation {
387384
tables.add_site(mut_pos as f64, Some(b"a")).unwrap();
388385
}
389386
// add mutation
390-
let parent_mut = site_last_mutation_tables[mut_pos];
391387
let site = site_id_map_tables[mut_pos];
392-
let new_mutation = tables
393-
.add_mutation(site, c, parent_mut, t, Some(derived_state))
388+
let _ = tables
389+
.add_mutation(site, c, MutationId::NULL, t, Some(derived_state))
394390
.unwrap();
395-
396-
site_last_mutation_tables[mut_pos] = new_mutation;
397-
site_last_mutation_order[mut_pos] += 1;
398391
}
399392

400393
find_overlaps(s, e, &intervals, &mut buffer);
@@ -410,12 +403,10 @@ pub mod simulation {
410403
tr_tbls.add_site(mut_pos as f64, Some(b"a")).unwrap();
411404
}
412405
// add mutation
413-
let parent_mut = site_last_mutation_tr_tbls[mut_pos];
414406
let site = site_id_map_tr_tbls[mut_pos];
415-
let new_mutation = tr_tbls
416-
.add_mutation(site, c, parent_mut, t, Some(derived_state))
407+
let _ = tr_tbls
408+
.add_mutation(site, c, MutationId::NULL, t, Some(derived_state))
417409
.unwrap();
418-
site_last_mutation_tr_tbls[mut_pos] = new_mutation;
419410
}
420411
}
421412
}
@@ -448,6 +439,23 @@ pub mod simulation {
448439
tables.build_index().unwrap();
449440
tr_tbls.build_index().unwrap();
450441

442+
// Calculate mutation parents
443+
// TODO: need safe API for this.
444+
let code = unsafe {
445+
crate::sys::bindings::tsk_table_collection_compute_mutation_parents(
446+
tables.as_mut_ptr(),
447+
0,
448+
)
449+
};
450+
assert_eq!(code, 0);
451+
let code = unsafe {
452+
crate::sys::bindings::tsk_table_collection_compute_mutation_parents(
453+
tr_tbls.as_mut_ptr(),
454+
0,
455+
)
456+
};
457+
assert_eq!(code, 0);
458+
451459
// to tree sequences
452460
let treeseq_opts = TreeSequenceFlags::default();
453461
let full_trees = TreeSequence::new(tables, treeseq_opts).unwrap();

subprojects/tskit/tskit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MIT License
33
*
4-
* Copyright (c) 2019 Tskit Developers
4+
* Copyright (c) 2019-2024 Tskit Developers
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

subprojects/tskit/tskit/convert.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MIT License
33
*
4-
* Copyright (c) 2018-2021 Tskit Developers
4+
* Copyright (c) 2018-2025 Tskit Developers
55
* Copyright (c) 2015-2017 University of Oxford
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -68,11 +68,11 @@ tsk_newick_converter_run(
6868
const char *label_format = ms_labels ? "%d" : "n%d";
6969

7070
if (root < 0 || root >= (tsk_id_t) self->tree->num_nodes) {
71-
ret = TSK_ERR_NODE_OUT_OF_BOUNDS;
71+
ret = tsk_trace_error(TSK_ERR_NODE_OUT_OF_BOUNDS);
7272
goto out;
7373
}
7474
if (buffer == NULL) {
75-
ret = TSK_ERR_BAD_PARAM_VALUE;
75+
ret = tsk_trace_error(TSK_ERR_BAD_PARAM_VALUE);
7676
goto out;
7777
}
7878
root_parent = tree->parent[root];
@@ -82,7 +82,7 @@ tsk_newick_converter_run(
8282
v = stack[stack_top];
8383
if (tree->left_child[v] != TSK_NULL && v != u) {
8484
if (s >= buffer_size) {
85-
ret = TSK_ERR_BUFFER_OVERFLOW;
85+
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
8686
goto out;
8787
}
8888
buffer[s] = '(';
@@ -104,17 +104,17 @@ tsk_newick_converter_run(
104104
}
105105
if (label != -1) {
106106
if (s >= buffer_size) {
107-
ret = TSK_ERR_BUFFER_OVERFLOW;
107+
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
108108
goto out;
109109
}
110110
r = snprintf(buffer + s, buffer_size - s, label_format, label);
111111
if (r < 0) {
112-
ret = TSK_ERR_IO;
112+
ret = tsk_trace_error(TSK_ERR_IO);
113113
goto out;
114114
}
115115
s += (size_t) r;
116116
if (s >= buffer_size) {
117-
ret = TSK_ERR_BUFFER_OVERFLOW;
117+
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
118118
goto out;
119119
}
120120
}
@@ -123,12 +123,12 @@ tsk_newick_converter_run(
123123
r = snprintf(buffer + s, buffer_size - s, ":%.*f", (int) self->precision,
124124
branch_length);
125125
if (r < 0) {
126-
ret = TSK_ERR_IO;
126+
ret = tsk_trace_error(TSK_ERR_IO);
127127
goto out;
128128
}
129129
s += (size_t) r;
130130
if (s >= buffer_size) {
131-
ret = TSK_ERR_BUFFER_OVERFLOW;
131+
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
132132
goto out;
133133
}
134134
if (v == tree->right_child[u]) {
@@ -141,7 +141,7 @@ tsk_newick_converter_run(
141141
}
142142
}
143143
if ((s + 1) >= buffer_size) {
144-
ret = TSK_ERR_BUFFER_OVERFLOW;
144+
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
145145
goto out;
146146
}
147147
buffer[s] = ';';
@@ -164,7 +164,7 @@ tsk_newick_converter_init(tsk_newick_converter_t *self, const tsk_tree_t *tree,
164164
self->traversal_stack
165165
= tsk_malloc(tsk_tree_get_size_bound(tree) * sizeof(*self->traversal_stack));
166166
if (self->traversal_stack == NULL) {
167-
ret = TSK_ERR_NO_MEMORY;
167+
ret = tsk_trace_error(TSK_ERR_NO_MEMORY);
168168
goto out;
169169
}
170170
out:

0 commit comments

Comments
 (0)