@@ -5344,6 +5344,69 @@ TreeSequence_dump_tables(TreeSequence *self, PyObject *args, PyObject *kwds)
53445344 return ret ;
53455345}
53465346
5347+ static PyObject *
5348+ TreeSequence_link_ancestors (TreeSequence * self , PyObject * args , PyObject * kwds )
5349+ {
5350+ int err ;
5351+ PyObject * ret = NULL ;
5352+ PyObject * samples = NULL ;
5353+ PyObject * ancestors = NULL ;
5354+ PyArrayObject * samples_array = NULL ;
5355+ PyArrayObject * ancestors_array = NULL ;
5356+ npy_intp * shape ;
5357+ tsk_size_t num_samples , num_ancestors ;
5358+ EdgeTable * result = NULL ;
5359+ PyObject * result_args = NULL ;
5360+ static char * kwlist [] = { "samples" , "ancestors" , NULL };
5361+
5362+ if (TreeSequence_check_state (self ) != 0 ) {
5363+ goto out ;
5364+ }
5365+ if (!PyArg_ParseTupleAndKeywords (args , kwds , "OO" , kwlist , & samples , & ancestors )) {
5366+ goto out ;
5367+ }
5368+
5369+ samples_array = (PyArrayObject * ) PyArray_FROMANY (
5370+ samples , NPY_INT32 , 1 , 1 , NPY_ARRAY_IN_ARRAY );
5371+ if (samples_array == NULL ) {
5372+ goto out ;
5373+ }
5374+ shape = PyArray_DIMS (samples_array );
5375+ num_samples = (tsk_size_t ) shape [0 ];
5376+
5377+ ancestors_array = (PyArrayObject * ) PyArray_FROMANY (
5378+ ancestors , NPY_INT32 , 1 , 1 , NPY_ARRAY_IN_ARRAY );
5379+ if (ancestors_array == NULL ) {
5380+ goto out ;
5381+ }
5382+ shape = PyArray_DIMS (ancestors_array );
5383+ num_ancestors = (tsk_size_t ) shape [0 ];
5384+
5385+ result_args = PyTuple_New (0 );
5386+ if (result_args == NULL ) {
5387+ goto out ;
5388+ }
5389+ result = (EdgeTable * ) PyObject_CallObject ((PyObject * ) & EdgeTableType , result_args );
5390+ if (result == NULL ) {
5391+ goto out ;
5392+ }
5393+ err = tsk_table_collection_link_ancestors (self -> tree_sequence -> tables ,
5394+ PyArray_DATA (samples_array ), num_samples , PyArray_DATA (ancestors_array ),
5395+ num_ancestors , 0 , result -> table );
5396+ if (err != 0 ) {
5397+ handle_library_error (err );
5398+ goto out ;
5399+ }
5400+ ret = (PyObject * ) result ;
5401+ result = NULL ;
5402+ out :
5403+ Py_XDECREF (samples_array );
5404+ Py_XDECREF (ancestors_array );
5405+ Py_XDECREF (result );
5406+ Py_XDECREF (result_args );
5407+ return ret ;
5408+ }
5409+
53475410static PyObject *
53485411TreeSequence_load (TreeSequence * self , PyObject * args , PyObject * kwds )
53495412{
@@ -8624,6 +8687,10 @@ static PyMethodDef TreeSequence_methods[] = {
86248687 .ml_meth = (PyCFunction ) TreeSequence_dump_tables ,
86258688 .ml_flags = METH_VARARGS | METH_KEYWORDS ,
86268689 .ml_doc = "Dumps the tree sequence to the specified set of tables" },
8690+ { .ml_name = "link_ancestors" ,
8691+ .ml_meth = (PyCFunction ) TreeSequence_link_ancestors ,
8692+ .ml_flags = METH_VARARGS | METH_KEYWORDS ,
8693+ .ml_doc = "Returns an EdgeTable linking the specified samples and ancestors." },
86278694 { .ml_name = "get_node" ,
86288695 .ml_meth = (PyCFunction ) TreeSequence_get_node ,
86298696 .ml_flags = METH_VARARGS ,
0 commit comments