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
36 changes: 22 additions & 14 deletions src/test_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ pub mod simulation {

// state variables for site/mutation tables
let num_sites = f64::from(seqlen.into()) as usize;
let mut site_last_mutation_order = vec![0usize; num_sites];

let mut site_last_mutation_tables = vec![MutationId::NULL; num_sites];
let mut site_last_mutation_tr_tbls = vec![MutationId::NULL; num_sites];
let site_last_mutation_order = vec![0usize; num_sites];

let mut site_id_map_tables = vec![SiteId::NULL; num_sites];
let mut site_id_map_tr_tbls = vec![SiteId::NULL; num_sites];
Expand Down Expand Up @@ -387,14 +384,10 @@ pub mod simulation {
tables.add_site(mut_pos as f64, Some(b"a")).unwrap();
}
// add mutation
let parent_mut = site_last_mutation_tables[mut_pos];
let site = site_id_map_tables[mut_pos];
let new_mutation = tables
.add_mutation(site, c, parent_mut, t, Some(derived_state))
let _ = tables
.add_mutation(site, c, MutationId::NULL, t, Some(derived_state))
.unwrap();

site_last_mutation_tables[mut_pos] = new_mutation;
site_last_mutation_order[mut_pos] += 1;
}

find_overlaps(s, e, &intervals, &mut buffer);
Expand All @@ -410,12 +403,10 @@ pub mod simulation {
tr_tbls.add_site(mut_pos as f64, Some(b"a")).unwrap();
}
// add mutation
let parent_mut = site_last_mutation_tr_tbls[mut_pos];
let site = site_id_map_tr_tbls[mut_pos];
let new_mutation = tr_tbls
.add_mutation(site, c, parent_mut, t, Some(derived_state))
let _ = tr_tbls
.add_mutation(site, c, MutationId::NULL, t, Some(derived_state))
.unwrap();
site_last_mutation_tr_tbls[mut_pos] = new_mutation;
}
}
}
Expand Down Expand Up @@ -448,6 +439,23 @@ pub mod simulation {
tables.build_index().unwrap();
tr_tbls.build_index().unwrap();

// Calculate mutation parents
// TODO: need safe API for this.
let code = unsafe {
crate::sys::bindings::tsk_table_collection_compute_mutation_parents(
tables.as_mut_ptr(),
0,
)
};
assert_eq!(code, 0);
let code = unsafe {
crate::sys::bindings::tsk_table_collection_compute_mutation_parents(
tr_tbls.as_mut_ptr(),
0,
)
};
assert_eq!(code, 0);

// to tree sequences
let treeseq_opts = TreeSequenceFlags::default();
let full_trees = TreeSequence::new(tables, treeseq_opts).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion subprojects/tskit/tskit.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019 Tskit Developers
* Copyright (c) 2019-2024 Tskit Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 11 additions & 11 deletions subprojects/tskit/tskit/convert.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2018-2021 Tskit Developers
* Copyright (c) 2018-2025 Tskit Developers
* Copyright (c) 2015-2017 University of Oxford
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -68,11 +68,11 @@ tsk_newick_converter_run(
const char *label_format = ms_labels ? "%d" : "n%d";

if (root < 0 || root >= (tsk_id_t) self->tree->num_nodes) {
ret = TSK_ERR_NODE_OUT_OF_BOUNDS;
ret = tsk_trace_error(TSK_ERR_NODE_OUT_OF_BOUNDS);
goto out;
}
if (buffer == NULL) {
ret = TSK_ERR_BAD_PARAM_VALUE;
ret = tsk_trace_error(TSK_ERR_BAD_PARAM_VALUE);
goto out;
}
root_parent = tree->parent[root];
Expand All @@ -82,7 +82,7 @@ tsk_newick_converter_run(
v = stack[stack_top];
if (tree->left_child[v] != TSK_NULL && v != u) {
if (s >= buffer_size) {
ret = TSK_ERR_BUFFER_OVERFLOW;
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
goto out;
}
buffer[s] = '(';
Expand All @@ -104,17 +104,17 @@ tsk_newick_converter_run(
}
if (label != -1) {
if (s >= buffer_size) {
ret = TSK_ERR_BUFFER_OVERFLOW;
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
goto out;
}
r = snprintf(buffer + s, buffer_size - s, label_format, label);
if (r < 0) {
ret = TSK_ERR_IO;
ret = tsk_trace_error(TSK_ERR_IO);
goto out;
}
s += (size_t) r;
if (s >= buffer_size) {
ret = TSK_ERR_BUFFER_OVERFLOW;
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
goto out;
}
}
Expand All @@ -123,12 +123,12 @@ tsk_newick_converter_run(
r = snprintf(buffer + s, buffer_size - s, ":%.*f", (int) self->precision,
branch_length);
if (r < 0) {
ret = TSK_ERR_IO;
ret = tsk_trace_error(TSK_ERR_IO);
goto out;
}
s += (size_t) r;
if (s >= buffer_size) {
ret = TSK_ERR_BUFFER_OVERFLOW;
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
goto out;
}
if (v == tree->right_child[u]) {
Expand All @@ -141,7 +141,7 @@ tsk_newick_converter_run(
}
}
if ((s + 1) >= buffer_size) {
ret = TSK_ERR_BUFFER_OVERFLOW;
ret = tsk_trace_error(TSK_ERR_BUFFER_OVERFLOW);
goto out;
}
buffer[s] = ';';
Expand All @@ -164,7 +164,7 @@ tsk_newick_converter_init(tsk_newick_converter_t *self, const tsk_tree_t *tree,
self->traversal_stack
= tsk_malloc(tsk_tree_get_size_bound(tree) * sizeof(*self->traversal_stack));
if (self->traversal_stack == NULL) {
ret = TSK_ERR_NO_MEMORY;
ret = tsk_trace_error(TSK_ERR_NO_MEMORY);
goto out;
}
out:
Expand Down
Loading
Loading