Skip to content

Commit 33c2794

Browse files
Ben Jefferymergify[bot]
Ben Jeffery
authored andcommitted
Remove git submodule
1 parent 9fa382b commit 33c2794

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+59054
-8
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

MANIFEST.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include lib/*.h
2-
include git-submodules/tskit/c/*.h
3-
include git-submodules/tskit/c/tskit/*.h
4-
include git-submodules/tskit/c/subprojects/kastore/*.h
2+
include lib/subprojects/tskit/c/*.h
3+
include lib/subprojects/tskit/c/tskit/*.h
4+
include lib/subprojects/tskit/c/subprojects/kastore/*.h
55
include README.txt
66
include LICENSE
77
recursive-include tests *.py

git-submodules/tskit

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/subprojects/tskit/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

lib/subprojects/tskit/CHANGELOG.rst

Lines changed: 498 additions & 0 deletions
Large diffs are not rendered by default.

lib/subprojects/tskit/VERSION.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.1.1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Simple Makefile for building examples.
2+
# This will build the examples in the current directory by compiling in the
3+
# full tskit source into each of the examples. This is *not* recommended for
4+
# real projects!
5+
#
6+
# To use, type "make" in the this directory. If you have GSL installed you
7+
# should then get two example programs built.
8+
#
9+
# **Note**: This repo uses git submodules, and these must be checked out
10+
# correctly for this makefile to work, e.g.:
11+
#
12+
# $ git clone [email protected]:tskit-dev/tskit.git --recurse-submodules
13+
#
14+
# See the documentation (https://tskit.dev/tskit/docs/stable/c-api.html)
15+
# for more details on how to use the C API, and the tskit build examples
16+
# repo (https://github.com/tskit-dev/tskit-build-examples) for examples
17+
# of how to set up a production-ready build with tskit.
18+
#
19+
20+
CFLAGS=-I../ -I../subprojects/kastore
21+
TSKIT_SOURCE=../tskit/*.c ../subprojects/kastore/kastore.c
22+
23+
targets = api_structure error_handling \
24+
haploid_wright_fisher streaming \
25+
tree_iteration tree_traversal \
26+
take_ownership
27+
28+
all: $(targets)
29+
30+
$(targets): %: %.c
31+
${CC} ${CFLAGS} -o $@ $< ${TSKIT_SOURCE} -lm
32+
33+
clean:
34+
rm -f $(targets)
35+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <tskit/tables.h>
4+
5+
#define check_tsk_error(val) \
6+
if (val < 0) { \
7+
fprintf(stderr, "line %d: %s", __LINE__, tsk_strerror(val)); \
8+
exit(EXIT_FAILURE); \
9+
}
10+
11+
int
12+
main(int argc, char **argv)
13+
{
14+
int j, ret;
15+
tsk_edge_table_t edges;
16+
17+
ret = tsk_edge_table_init(&edges, 0);
18+
check_tsk_error(ret);
19+
for (j = 0; j < 5; j++) {
20+
ret = tsk_edge_table_add_row(&edges, 0, 1, j + 1, j, NULL, 0);
21+
check_tsk_error(ret);
22+
}
23+
tsk_edge_table_print_state(&edges, stdout);
24+
tsk_edge_table_free(&edges);
25+
26+
return EXIT_SUCCESS;
27+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include <cstddef>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <stdexcept>
5+
#include <sstream>
6+
#include <iostream>
7+
#include <type_traits>
8+
#include <tskit.h>
9+
10+
static void
11+
handle_tskit_return_code(int code)
12+
{
13+
if (code != 0) {
14+
std::ostringstream o;
15+
o << tsk_strerror(code);
16+
throw std::runtime_error(o.str());
17+
}
18+
}
19+
20+
struct edge_plus_time {
21+
double time;
22+
tsk_id_t parent, child;
23+
double left, right;
24+
};
25+
26+
int
27+
sort_edges(tsk_table_sorter_t *sorter, tsk_size_t start)
28+
{
29+
if (sorter->tables->edges.metadata_length != 0) {
30+
throw std::invalid_argument(
31+
"the sorter does not currently handle edge metadata");
32+
}
33+
if (start != 0) {
34+
throw std::invalid_argument("the sorter requires start==0");
35+
}
36+
37+
std::vector<edge_plus_time> temp;
38+
temp.reserve(static_cast<std::size_t>(sorter->tables->edges.num_rows));
39+
40+
auto edges = &sorter->tables->edges;
41+
auto nodes = &sorter->tables->nodes;
42+
43+
for (tsk_size_t i = 0; i < sorter->tables->edges.num_rows; ++i) {
44+
temp.push_back(edge_plus_time{ nodes->time[edges->parent[i]], edges->parent[i],
45+
edges->child[i], edges->left[i], edges->right[i] });
46+
}
47+
48+
std::sort(begin(temp), end(temp),
49+
[](const edge_plus_time &lhs, const edge_plus_time &rhs) {
50+
if (lhs.time == rhs.time) {
51+
if (lhs.parent == rhs.parent) {
52+
if (lhs.child == rhs.child) {
53+
return lhs.left < rhs.left;
54+
}
55+
return lhs.child < rhs.child;
56+
}
57+
return lhs.parent < rhs.parent;
58+
}
59+
return lhs.time < rhs.time;
60+
});
61+
62+
for (std::size_t i = 0; i < temp.size(); ++i) {
63+
edges->left[i] = temp[i].left;
64+
edges->right[i] = temp[i].right;
65+
edges->parent[i] = temp[i].parent;
66+
edges->child[i] = temp[i].child;
67+
}
68+
69+
return 0;
70+
}
71+
72+
int
73+
main(int argc, char **argv)
74+
{
75+
if (argc != 3) {
76+
std::cerr << "Usage: " << argv[0] << " input.trees output.trees\n";
77+
std::exit(0);
78+
}
79+
const char *infile = argv[1];
80+
const char *outfile = argv[2];
81+
82+
tsk_table_collection_t tables;
83+
auto ret = tsk_table_collection_load(&tables, infile, 0);
84+
handle_tskit_return_code(ret);
85+
86+
tsk_table_sorter_t sorter;
87+
ret = tsk_table_sorter_init(&sorter, &tables, 0);
88+
handle_tskit_return_code(ret);
89+
sorter.sort_edges = sort_edges;
90+
try {
91+
ret = tsk_table_sorter_run(&sorter, NULL);
92+
} catch (std::exception &e) {
93+
std::cerr << e.what() << '\n';
94+
std::exit(1);
95+
}
96+
handle_tskit_return_code(ret);
97+
ret = tsk_table_collection_dump(&tables, outfile, 0);
98+
handle_tskit_return_code(ret);
99+
ret = tsk_table_collection_free(&tables);
100+
handle_tskit_return_code(ret);
101+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <tskit.h>
4+
5+
int
6+
main(int argc, char **argv)
7+
{
8+
int ret;
9+
tsk_treeseq_t ts;
10+
11+
if (argc != 2) {
12+
fprintf(stderr, "usage: <tree sequence file>");
13+
exit(EXIT_FAILURE);
14+
}
15+
ret = tsk_treeseq_load(&ts, argv[1], 0);
16+
if (ret < 0) {
17+
/* Error condition. Free and exit */
18+
tsk_treeseq_free(&ts);
19+
fprintf(stderr, "%s", tsk_strerror(ret));
20+
exit(EXIT_FAILURE);
21+
}
22+
printf("Loaded tree sequence with %lld nodes and %lld edges from %s\n",
23+
(long long) tsk_treeseq_get_num_nodes(&ts),
24+
(long long) tsk_treeseq_get_num_edges(&ts), argv[1]);
25+
tsk_treeseq_free(&ts);
26+
27+
return EXIT_SUCCESS;
28+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <assert.h>
4+
#include <err.h>
5+
6+
#include <tskit/tables.h>
7+
8+
#define check_tsk_error(val) \
9+
if (val < 0) { \
10+
errx(EXIT_FAILURE, "line %d: %s", __LINE__, tsk_strerror(val)); \
11+
}
12+
13+
void
14+
simulate(tsk_table_collection_t *tables, int N, int T, int simplify_interval)
15+
{
16+
tsk_id_t *buffer, *parents, *children, child, left_parent, right_parent;
17+
double breakpoint;
18+
int ret, j, t, b;
19+
20+
assert(simplify_interval != 0); // leads to division by zero
21+
buffer = malloc(2 * N * sizeof(tsk_id_t));
22+
if (buffer == NULL) {
23+
errx(EXIT_FAILURE, "Out of memory");
24+
}
25+
tables->sequence_length = 1.0;
26+
parents = buffer;
27+
for (j = 0; j < N; j++) {
28+
parents[j]
29+
= tsk_node_table_add_row(&tables->nodes, 0, T, TSK_NULL, TSK_NULL, NULL, 0);
30+
check_tsk_error(parents[j]);
31+
}
32+
b = 0;
33+
for (t = T - 1; t >= 0; t--) {
34+
/* Alternate between using the first and last N values in the buffer */
35+
parents = buffer + (b * N);
36+
b = (b + 1) % 2;
37+
children = buffer + (b * N);
38+
for (j = 0; j < N; j++) {
39+
child = tsk_node_table_add_row(
40+
&tables->nodes, 0, t, TSK_NULL, TSK_NULL, NULL, 0);
41+
check_tsk_error(child);
42+
/* NOTE: the use of rand() is discouraged for
43+
* research code and proper random number generator
44+
* libraries should be preferred.
45+
*/
46+
left_parent = parents[(size_t)((rand() / (1. + RAND_MAX)) * N)];
47+
right_parent = parents[(size_t)((rand() / (1. + RAND_MAX)) * N)];
48+
do {
49+
breakpoint = rand() / (1. + RAND_MAX);
50+
} while (breakpoint == 0); /* tiny proba of breakpoint being 0 */
51+
ret = tsk_edge_table_add_row(
52+
&tables->edges, 0, breakpoint, left_parent, child, NULL, 0);
53+
check_tsk_error(ret);
54+
ret = tsk_edge_table_add_row(
55+
&tables->edges, breakpoint, 1, right_parent, child, NULL, 0);
56+
check_tsk_error(ret);
57+
children[j] = child;
58+
}
59+
if (t % simplify_interval == 0) {
60+
printf("Simplify at generation %lld: (%lld nodes %lld edges)", (long long) t,
61+
(long long) tables->nodes.num_rows, (long long) tables->edges.num_rows);
62+
/* Note: Edges must be sorted for simplify to work, and we use a brute force
63+
* approach of sorting each time here for simplicity. This is inefficient. */
64+
ret = tsk_table_collection_sort(tables, NULL, 0);
65+
check_tsk_error(ret);
66+
ret = tsk_table_collection_simplify(tables, children, N, 0, NULL);
67+
check_tsk_error(ret);
68+
printf(" -> (%lld nodes %lld edges)\n", (long long) tables->nodes.num_rows,
69+
(long long) tables->edges.num_rows);
70+
for (j = 0; j < N; j++) {
71+
children[j] = j;
72+
}
73+
}
74+
}
75+
free(buffer);
76+
}
77+
78+
int
79+
main(int argc, char **argv)
80+
{
81+
int ret;
82+
tsk_table_collection_t tables;
83+
84+
if (argc != 6) {
85+
errx(EXIT_FAILURE, "usage: N T simplify-interval output-file seed");
86+
}
87+
ret = tsk_table_collection_init(&tables, 0);
88+
check_tsk_error(ret);
89+
srand((unsigned) atoi(argv[5]));
90+
simulate(&tables, atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
91+
ret = tsk_table_collection_dump(&tables, argv[4], 0);
92+
check_tsk_error(ret);
93+
94+
tsk_table_collection_free(&tables);
95+
return 0;
96+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <tskit/tables.h>
4+
5+
#define check_tsk_error(val) \
6+
if (val < 0) { \
7+
fprintf(stderr, "Error: line %d: %s\n", __LINE__, tsk_strerror(val)); \
8+
exit(EXIT_FAILURE); \
9+
}
10+
11+
int
12+
main(int argc, char **argv)
13+
{
14+
int ret;
15+
int j = 0;
16+
tsk_table_collection_t tables;
17+
18+
ret = tsk_table_collection_init(&tables, 0);
19+
check_tsk_error(ret);
20+
21+
while (true) {
22+
ret = tsk_table_collection_loadf(&tables, stdin, TSK_NO_INIT);
23+
if (ret == TSK_ERR_EOF) {
24+
break;
25+
}
26+
check_tsk_error(ret);
27+
fprintf(stderr, "Tree sequence %d had %lld mutations\n", j,
28+
(long long) tables.mutations.num_rows);
29+
ret = tsk_mutation_table_truncate(&tables.mutations, 0);
30+
check_tsk_error(ret);
31+
ret = tsk_table_collection_dumpf(&tables, stdout, 0);
32+
check_tsk_error(ret);
33+
j++;
34+
}
35+
tsk_table_collection_free(&tables);
36+
return EXIT_SUCCESS;
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <err.h>
2+
#include <stdlib.h>
3+
#include <tskit/tables.h>
4+
#include <tskit/trees.h>
5+
6+
#define check_tsk_error(val) \
7+
if (val < 0) { \
8+
errx(EXIT_FAILURE, "line %d: %s", __LINE__, tsk_strerror(val)); \
9+
}
10+
11+
int
12+
main(int argc, char **argv)
13+
{
14+
tsk_table_collection_t *tables;
15+
tsk_treeseq_t treeseq;
16+
int rv;
17+
18+
tables = malloc(sizeof(*tables));
19+
rv = tsk_table_collection_init(tables, 0);
20+
check_tsk_error(rv);
21+
22+
/* NOTE: you must set sequence length AFTER initialization */
23+
tables->sequence_length = 1.0;
24+
25+
/* Do your regular table operations */
26+
rv = tsk_node_table_add_row(&tables->nodes, 0, 0.0, -1, -1, NULL, 0);
27+
check_tsk_error(rv);
28+
29+
/* Initalize the tree sequence, transferring all responsibility
30+
* for the table collection's memory managment
31+
*/
32+
rv = tsk_treeseq_init(
33+
&treeseq, tables, TSK_TS_INIT_BUILD_INDEXES | TSK_TAKE_OWNERSHIP);
34+
check_tsk_error(rv);
35+
36+
/* WARNING: calling tsk_table_collection_free is now a memory error! */
37+
tsk_treeseq_free(&treeseq);
38+
}

0 commit comments

Comments
 (0)