Skip to content

Commit f82a135

Browse files
petrelharpjeromekelleher
authored andcommitted
Code suggestions from Ben
docs restore output
1 parent ee696bd commit f82a135

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

c/examples/multichrom_wright_fisher.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ sort_and_simplify_all(tsk_table_collection_t *tcs, int num_chroms, int *samples,
122122
void
123123
simplify_tables(tsk_table_collection_t *tcs, int num_chroms, int *samples, int N)
124124
{
125-
int j, k, ret;
125+
int j, k, num_edges, ret;
126126
const tsk_size_t num_nodes = tcs[0].nodes.num_rows;
127127
tsk_bool_t *keep_nodes = malloc(num_nodes * sizeof(*keep_nodes));
128128
tsk_id_t *node_id_map = malloc(num_nodes * sizeof(*node_id_map));
@@ -137,15 +137,18 @@ simplify_tables(tsk_table_collection_t *tcs, int num_chroms, int *samples, int N
137137

138138
for (j = 0; j < num_nodes; j++) {
139139
keep_nodes[j] = false;
140+
tcs[0].nodes.flags[j] &= (~TSK_NODE_IS_SAMPLE);
140141
}
141142
for (j = 0; j < N; j++) {
142143
keep_nodes[samples[j]] = true;
144+
tcs[0].nodes.flags[samples[j]] |= TSK_NODE_IS_SAMPLE;
143145
}
144146

145147
for (j = 0; j < num_chroms; j++) {
146148
edge_child = tcs[j].edges.child;
147149
edge_parent = tcs[j].edges.parent;
148-
for (k = 0; k < tcs[j].edges.num_rows; k++) {
150+
num_edges = tcs[j].edges.num_rows;
151+
for (k = 0; k < num_edges; k++) {
149152
keep_nodes[edge_child[k]] = true;
150153
keep_nodes[edge_parent[k]] = true;
151154
}
@@ -157,7 +160,8 @@ simplify_tables(tsk_table_collection_t *tcs, int num_chroms, int *samples, int N
157160
for (j = 0; j < num_chroms; j++) {
158161
edge_child = tcs[j].edges.child;
159162
edge_parent = tcs[j].edges.parent;
160-
for (k = 0; k < tcs[j].edges.num_rows; k++) {
163+
num_edges = tcs[j].edges.num_rows;
164+
for (k = 0; k < num_edges; k++) {
161165
edge_child[k] = node_id_map[edge_child[k]];
162166
edge_parent[k] = node_id_map[edge_parent[k]];
163167
}
@@ -243,7 +247,7 @@ simulate(
243247
int
244248
main(int argc, char **argv)
245249
{
246-
// int ret;
250+
int ret;
247251
int num_chroms;
248252

249253
if (argc != 7) {
@@ -257,8 +261,8 @@ main(int argc, char **argv)
257261
init_tables(tcs, num_chroms);
258262
simulate(tcs, num_chroms, atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
259263
join_tables(tcs, num_chroms);
260-
// ret = tsk_table_collection_dump(&tcs[0], argv[4], 0);
261-
// check_tsk_error(ret);
264+
ret = tsk_table_collection_dump(&tcs[0], argv[4], 0);
265+
check_tsk_error(ret);
262266
free_tables(tcs, num_chroms);
263267

264268
return 0;

c/examples/multichrom_wright_fisher_singlethreaded.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ main(int argc, char **argv)
107107
srand((unsigned)atoi(argv[5]));
108108
simulate(&tables, atoi(argv[6]), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
109109

110-
// /* Sort and index so that the result can be opened as a tree sequence */
111-
// ret = tsk_table_collection_sort(&tables, NULL, 0);
112-
// check_tsk_error(ret);
113-
// ret = tsk_table_collection_build_index(&tables, 0);
114-
// check_tsk_error(ret);
115-
// ret = tsk_table_collection_dump(&tables, argv[4], 0);
116-
// check_tsk_error(ret);
110+
/* Sort and index so that the result can be opened as a tree sequence */
111+
ret = tsk_table_collection_sort(&tables, NULL, 0);
112+
check_tsk_error(ret);
113+
ret = tsk_table_collection_build_index(&tables, 0);
114+
check_tsk_error(ret);
115+
ret = tsk_table_collection_dump(&tables, argv[4], 0);
116+
check_tsk_error(ret);
117117

118118
tsk_table_collection_free(&tables);
119119
return 0;

docs/c-api.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,3 +920,31 @@ stored in the file ``no_mutations.trees``::
920920
$ ./build/streaming < no_mutations.trees > /dev/null
921921
Tree sequence 0 had 0 mutations
922922
Tree sequence 1 had 0 mutations
923+
924+
------------------------------------
925+
Parallel, multichromosome simulation
926+
------------------------------------
927+
928+
A substantial bottleneck in forwards simulations using tree sequences
929+
is *simplification*. This is therefore a natural target for parallelization.
930+
The potential for breaking up a chromosome into discrete chunks that
931+
are separately parallelized is limited, however, since any edge
932+
that extends across the boundary between two chunks is split;
933+
thus creating more work.
934+
However, distinct chromosomes provide a natural target:
935+
the edge tables describing inheritance for each chromosome can be
936+
independently simplified, as long as the fact that they all refer to
937+
the same set of nodes.
938+
This simulation keeps each chromosome in a separate tree sequence,
939+
but they essentially share a common node table;
940+
the :c:macro:`TSK_SIMPLIFY_NO_FILTER_NODES` flag is used so that
941+
each call to :c:func:`tsk_table_collection_simplify` does not
942+
change the common node table.
943+
Afterwards, we iterate though the edge tables to determine which
944+
nodes need to be retained, and use
945+
:c:func:`tsk_node_table_keep_rows` to remove unused nodes.
946+
947+
948+
.. literalinclude:: ../c/examples/multichrom_wright_fisher.c
949+
:language: c
950+

0 commit comments

Comments
 (0)