Skip to content

Commit c1639ce

Browse files
committed
Fixes #262
1 parent 509636f commit c1639ce

File tree

8 files changed

+67
-47
lines changed

8 files changed

+67
-47
lines changed

c/tests/test_tables.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ test_provenance_table(void)
19861986
}
19871987

19881988
static void
1989-
test_map_ancestors_input_errors(void)
1989+
test_link_ancestors_input_errors(void)
19901990
{
19911991
int ret;
19921992
tsk_treeseq_t ts;
@@ -2002,30 +2002,30 @@ test_map_ancestors_input_errors(void)
20022002
ret = tsk_edge_table_init(&result, 0);
20032003
CU_ASSERT_EQUAL_FATAL(ret, 0);
20042004

2005-
ret = tsk_table_collection_map_ancestors(&tables, NULL, 2, ancestors, 2, 0, &result);
2005+
ret = tsk_table_collection_link_ancestors(&tables, NULL, 2, ancestors, 2, 0, &result);
20062006
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_PARAM_VALUE);
20072007

20082008
/* Bad sample IDs */
20092009
samples[0] = -1;
2010-
ret = tsk_table_collection_map_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
2010+
ret = tsk_table_collection_link_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
20112011
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_NODE_OUT_OF_BOUNDS);
20122012

20132013
/* Bad ancestor IDs */
20142014
samples[0] = 0;
20152015
ancestors[0] = -1;
2016-
ret = tsk_table_collection_map_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
2016+
ret = tsk_table_collection_link_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
20172017
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_NODE_OUT_OF_BOUNDS);
20182018

20192019
/* Duplicate sample IDs */
20202020
ancestors[0] = 4;
20212021
samples[0] = 1;
2022-
ret = tsk_table_collection_map_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
2022+
ret = tsk_table_collection_link_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
20232023
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_DUPLICATE_SAMPLE);
20242024

20252025
/* Duplicate sample IDs */
20262026
ancestors[0] = 6;
20272027
samples[0] = 0;
2028-
ret = tsk_table_collection_map_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
2028+
ret = tsk_table_collection_link_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
20292029
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_DUPLICATE_SAMPLE);
20302030

20312031
/* TODO more tests! */
@@ -2036,7 +2036,7 @@ test_map_ancestors_input_errors(void)
20362036
}
20372037

20382038
static void
2039-
test_map_ancestors_single_tree(void)
2039+
test_link_ancestors_single_tree(void)
20402040
{
20412041
int ret;
20422042
tsk_treeseq_t ts;
@@ -2055,7 +2055,7 @@ test_map_ancestors_single_tree(void)
20552055
ret = tsk_edge_table_init(&result, 0);
20562056
CU_ASSERT_EQUAL_FATAL(ret, 0);
20572057

2058-
ret = tsk_table_collection_map_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
2058+
ret = tsk_table_collection_link_ancestors(&tables, samples, 2, ancestors, 2, 0, &result);
20592059
CU_ASSERT_EQUAL_FATAL(ret, 0);
20602060

20612061
// Check we get the right result.
@@ -2076,7 +2076,7 @@ test_map_ancestors_single_tree(void)
20762076
}
20772077

20782078
static void
2079-
test_map_ancestors_no_edges(void)
2079+
test_link_ancestors_no_edges(void)
20802080
{
20812081
int ret;
20822082
tsk_treeseq_t ts;
@@ -2092,7 +2092,7 @@ test_map_ancestors_no_edges(void)
20922092
ret = tsk_edge_table_init(&result, 0);
20932093
CU_ASSERT_EQUAL_FATAL(ret, 0);
20942094

2095-
ret = tsk_table_collection_map_ancestors(&tables, samples, 1, ancestors, 1, 0, &result);
2095+
ret = tsk_table_collection_link_ancestors(&tables, samples, 1, ancestors, 1, 0, &result);
20962096
CU_ASSERT_EQUAL_FATAL(ret, 0);
20972097

20982098
tsk_table_collection_free(&tables);
@@ -2102,7 +2102,7 @@ test_map_ancestors_no_edges(void)
21022102
}
21032103

21042104
static void
2105-
test_map_ancestors_samples_and_ancestors_overlap(void)
2105+
test_link_ancestors_samples_and_ancestors_overlap(void)
21062106
{
21072107
int ret;
21082108
tsk_treeseq_t ts;
@@ -2118,7 +2118,7 @@ test_map_ancestors_samples_and_ancestors_overlap(void)
21182118
ret = tsk_edge_table_init(&result, 0);
21192119
CU_ASSERT_EQUAL_FATAL(ret, 0);
21202120

2121-
ret = tsk_table_collection_map_ancestors(&tables, samples, 4, ancestors, 1, 0, &result);
2121+
ret = tsk_table_collection_link_ancestors(&tables, samples, 4, ancestors, 1, 0, &result);
21222122

21232123
// tsk_edge_table_print_state(&result, stdout);
21242124

@@ -2143,7 +2143,7 @@ test_map_ancestors_samples_and_ancestors_overlap(void)
21432143
}
21442144

21452145
static void
2146-
test_map_ancestors_paper(void)
2146+
test_link_ancestors_paper(void)
21472147
{
21482148
int ret;
21492149
tsk_treeseq_t ts;
@@ -2159,7 +2159,7 @@ test_map_ancestors_paper(void)
21592159
ret = tsk_edge_table_init(&result, 0);
21602160
CU_ASSERT_EQUAL_FATAL(ret, 0);
21612161

2162-
ret = tsk_table_collection_map_ancestors(&tables, samples, 3, ancestors, 3, 0, &result);
2162+
ret = tsk_table_collection_link_ancestors(&tables, samples, 3, ancestors, 3, 0, &result);
21632163

21642164
// tsk_edge_table_print_state(&result, stdout);
21652165

@@ -2183,7 +2183,7 @@ test_map_ancestors_paper(void)
21832183
}
21842184

21852185
static void
2186-
test_map_ancestors_multiple_to_single_tree(void)
2186+
test_link_ancestors_multiple_to_single_tree(void)
21872187
{
21882188
int ret;
21892189
tsk_treeseq_t ts;
@@ -2199,7 +2199,7 @@ test_map_ancestors_multiple_to_single_tree(void)
21992199
ret = tsk_edge_table_init(&result, 0);
22002200
CU_ASSERT_EQUAL_FATAL(ret, 0);
22012201

2202-
ret = tsk_table_collection_map_ancestors(&tables, samples, 2, ancestors, 1, 0, &result);
2202+
ret = tsk_table_collection_link_ancestors(&tables, samples, 2, ancestors, 1, 0, &result);
22032203

22042204
// tsk_edge_table_print_state(&result, stdout);
22052205

@@ -2651,14 +2651,14 @@ main(int argc, char **argv)
26512651
{"test_load_tsk_node_table_errors", test_load_tsk_node_table_errors},
26522652
{"test_simplify_tables_drops_indexes", test_simplify_tables_drops_indexes},
26532653
{"test_simplify_empty_tables", test_simplify_empty_tables},
2654-
{"test_map_ancestors_no_edges", test_map_ancestors_no_edges},
2655-
{"test_map_ancestors_input_errors", test_map_ancestors_input_errors},
2656-
{"test_map_ancestors_single_tree", test_map_ancestors_single_tree},
2657-
{"test_map_ancestors_paper", test_map_ancestors_paper},
2658-
{"test_map_ancestors_samples_and_ancestors_overlap",
2659-
test_map_ancestors_samples_and_ancestors_overlap},
2660-
{"test_map_ancestors_multiple_to_single_tree",
2661-
test_map_ancestors_multiple_to_single_tree},
2654+
{"test_link_ancestors_no_edges", test_link_ancestors_no_edges},
2655+
{"test_link_ancestors_input_errors", test_link_ancestors_input_errors},
2656+
{"test_link_ancestors_single_tree", test_link_ancestors_single_tree},
2657+
{"test_link_ancestors_paper", test_link_ancestors_paper},
2658+
{"test_link_ancestors_samples_and_ancestors_overlap",
2659+
test_link_ancestors_samples_and_ancestors_overlap},
2660+
{"test_link_ancestors_multiple_to_single_tree",
2661+
test_link_ancestors_multiple_to_single_tree},
26622662
{"test_sort_tables_drops_indexes", test_sort_tables_drops_indexes},
26632663
{"test_copy_table_collection", test_copy_table_collection},
26642664
{"test_sort_tables_errors", test_sort_tables_errors},

c/tskit/tables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6496,7 +6496,7 @@ tsk_table_collection_simplify(tsk_table_collection_t *self,
64966496
}
64976497

64986498
int TSK_WARN_UNUSED
6499-
tsk_table_collection_map_ancestors(tsk_table_collection_t *self, tsk_id_t *samples,
6499+
tsk_table_collection_link_ancestors(tsk_table_collection_t *self, tsk_id_t *samples,
65006500
tsk_size_t num_samples, tsk_id_t *ancestors, tsk_size_t num_ancestors,
65016501
tsk_flags_t TSK_UNUSED(options), tsk_edge_table_t *result)
65026502
{

c/tskit/tables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ int tsk_table_collection_build_index(tsk_table_collection_t *self, tsk_flags_t o
22112211

22122212
/* Undocumented methods */
22132213

2214-
int tsk_table_collection_map_ancestors(tsk_table_collection_t *self,
2214+
int tsk_table_collection_link_ancestors(tsk_table_collection_t *self,
22152215
tsk_id_t *samples, tsk_size_t num_samples,
22162216
tsk_id_t *ancestors, tsk_size_t num_ancestors, tsk_flags_t options,
22172217
tsk_edge_table_t *result);

python/_tskitmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5468,7 +5468,7 @@ TableCollection_simplify(TableCollection *self, PyObject *args, PyObject *kwds)
54685468

54695469

54705470
static PyObject *
5471-
TableCollection_map_ancestors(TableCollection *self, PyObject *args, PyObject *kwds)
5471+
TableCollection_link_ancestors(TableCollection *self, PyObject *args, PyObject *kwds)
54725472
{
54735473
int err;
54745474
PyObject *ret = NULL;
@@ -5510,7 +5510,7 @@ TableCollection_map_ancestors(TableCollection *self, PyObject *args, PyObject *k
55105510
if (result == NULL) {
55115511
goto out;
55125512
}
5513-
err = tsk_table_collection_map_ancestors(self->tables,
5513+
err = tsk_table_collection_link_ancestors(self->tables,
55145514
PyArray_DATA(samples_array), num_samples,
55155515
PyArray_DATA(ancestors_array), num_ancestors, 0,
55165516
result->table);
@@ -5660,7 +5660,7 @@ static PyGetSetDef TableCollection_getsetters[] = {
56605660
static PyMethodDef TableCollection_methods[] = {
56615661
{"simplify", (PyCFunction) TableCollection_simplify, METH_VARARGS|METH_KEYWORDS,
56625662
"Simplifies for a given sample subset." },
5663-
{"map_ancestors", (PyCFunction) TableCollection_map_ancestors,
5663+
{"link_ancestors", (PyCFunction) TableCollection_link_ancestors,
56645664
METH_VARARGS|METH_KEYWORDS,
56655665
"Returns an edge table linking samples to a set of specified ancestors." },
56665666
{"sort", (PyCFunction) TableCollection_sort, METH_VARARGS|METH_KEYWORDS,

python/tests/simplify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def __init__(self, ts, sample, ancestors):
469469
self.add_ancestry(0, self.sequence_length, sample_id, sample_id)
470470
self.edge_buffer = {}
471471

472-
def map_ancestors(self):
472+
def link_ancestors(self):
473473
if self.ts.num_edges > 0:
474474
all_edges = list(self.ts.edges())
475475
edges = all_edges[:1]
@@ -659,7 +659,7 @@ def print_state(self):
659659
ancestors = list(map(int, ancestors))
660660

661661
s = AncestorMap(ts, samples, ancestors)
662-
tss = s.map_ancestors()
662+
tss = s.link_ancestors()
663663
# tables = tss.dump_tables()
664664
# print(tables.nodes)
665665
print(tss)

python/tests/test_lowlevel.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,26 @@ def test_simplify_bad_args(self):
182182
with self.assertRaises(_tskit.LibraryError):
183183
tc.simplify([0, -1])
184184

185-
def test_map_ancestors_bad_args(self):
185+
def test_link_ancestors_bad_args(self):
186186
ts = msprime.simulate(10, random_seed=1)
187187
tc = ts.tables.ll_tables
188188
with self.assertRaises(TypeError):
189-
tc.map_ancestors()
189+
tc.link_ancestors()
190190
with self.assertRaises(TypeError):
191-
tc.map_ancestors([0, 1])
191+
tc.link_ancestors([0, 1])
192192
with self.assertRaises(ValueError):
193-
tc.map_ancestors(samples=[0, 1], ancestors="sdf")
193+
tc.link_ancestors(samples=[0, 1], ancestors="sdf")
194194
with self.assertRaises(ValueError):
195-
tc.map_ancestors(samples="sdf", ancestors=[0, 1])
195+
tc.link_ancestors(samples="sdf", ancestors=[0, 1])
196196
with self.assertRaises(_tskit.LibraryError):
197-
tc.map_ancestors(samples=[0, 1], ancestors=[11, -1])
197+
tc.link_ancestors(samples=[0, 1], ancestors=[11, -1])
198198
with self.assertRaises(_tskit.LibraryError):
199-
tc.map_ancestors(samples=[0, -1], ancestors=[11])
199+
tc.link_ancestors(samples=[0, -1], ancestors=[11])
200200

201-
def test_map_ancestors(self):
201+
def test_link_ancestors(self):
202202
ts = msprime.simulate(2, random_seed=1)
203203
tc = ts.tables.ll_tables
204-
edges = tc.map_ancestors([0, 1], [3])
204+
edges = tc.link_ancestors([0, 1], [3])
205205
self.assertIsInstance(edges, _tskit.EdgeTable)
206206
del edges
207207
self.assertEqual(tc.edges.num_rows, 2)

python/tests/test_topology.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,17 +3551,33 @@ class TestMapToAncestors(unittest.TestCase):
35513551

35523552
def do_map(self, ts, ancestors, samples=None, compare_lib=True):
35533553
"""
3554-
Runs the Python test implementation of map_ancestors.
3554+
Runs the Python test implementation of link_ancestors.
35553555
"""
35563556
if samples is None:
35573557
samples = ts.samples()
35583558
s = tests.AncestorMap(ts, samples, ancestors)
3559-
ancestor_table = s.map_ancestors()
3559+
ancestor_table = s.link_ancestors()
35603560
if compare_lib:
3561-
lib_result = ts.tables.map_ancestors(samples, ancestors)
3561+
lib_result = ts.tables.link_ancestors(samples, ancestors)
35623562
self.assertEqual(ancestor_table, lib_result)
35633563
return ancestor_table
35643564

3565+
def test_deprecated_name(self):
3566+
# copied from test_single_tree_one_ancestor below
3567+
nodes = io.StringIO(self.nodes)
3568+
edges = io.StringIO(self.edges)
3569+
ts = tskit.load_text(nodes=nodes, edges=edges, strict=False)
3570+
samples = ts.samples()
3571+
ancestors = [8]
3572+
s = tests.AncestorMap(ts, samples, ancestors)
3573+
tss = s.link_ancestors()
3574+
lib_result = ts.tables.map_ancestors(samples, ancestors)
3575+
self.assertEqual(tss, lib_result)
3576+
self.assertEqual(list(tss.parent), [8, 8, 8, 8, 8])
3577+
self.assertEqual(list(tss.child), [0, 1, 2, 3, 4])
3578+
self.assertEqual(all(tss.left), 0)
3579+
self.assertEqual(all(tss.right), 1)
3580+
35653581
def test_single_tree_one_ancestor(self):
35663582
nodes = io.StringIO(self.nodes)
35673583
edges = io.StringIO(self.edges)

python/tskit/tables.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ def simplify(
16091609
reduce_to_site_topology=reduce_to_site_topology,
16101610
keep_unary=keep_unary)
16111611

1612-
def map_ancestors(self, samples, ancestors):
1612+
def link_ancestors(self, samples, ancestors):
16131613
"""
16141614
Returns an :class:`EdgeTable` instance describing a subset of the genealogical
16151615
relationships between the nodes in``samples`` and ``ancestors``.
@@ -1627,12 +1627,12 @@ def map_ancestors(self, samples, ancestors):
16271627
``ancestors``.
16281628
16291629
The following table shows which ``parent->child`` pairs will be shown in the
1630-
output of ``map_ancestors``.
1630+
output of ``link_ancestors``.
16311631
A node is a relevant descendant on a given interval if it also appears somewhere
16321632
in the ``parent`` column of the outputted table.
16331633
16341634
======================== ===============================================
1635-
Type of relationship Shown in output of ``map_ancestors``
1635+
Type of relationship Shown in output of ``link_ancestors``
16361636
------------------------ -----------------------------------------------
16371637
``ancestor->sample`` Always
16381638
``ancestor1->ancestor2`` Only if ``ancestor2`` has a relevant descendant
@@ -1664,9 +1664,13 @@ def map_ancestors(self, samples, ancestors):
16641664
"""
16651665
samples = util.safe_np_int_cast(samples, np.int32)
16661666
ancestors = util.safe_np_int_cast(ancestors, np.int32)
1667-
ll_edge_table = self.ll_tables.map_ancestors(samples, ancestors)
1667+
ll_edge_table = self.ll_tables.link_ancestors(samples, ancestors)
16681668
return EdgeTable(ll_table=ll_edge_table)
16691669

1670+
def map_ancestors(self, *args, **kwargs):
1671+
# A deprecated alias for link_ancestors()
1672+
return self.link_ancestors(*args, **kwargs)
1673+
16701674
def sort(self, edge_start=0):
16711675
"""
16721676
Sorts the tables in place. This ensures that all tree sequence ordering

0 commit comments

Comments
 (0)