Skip to content

Commit 34bc9e7

Browse files
benjefferymergify-bot
authored andcommitted
Add docs for individual parents
1 parent 9fb2bf6 commit 34bc9e7

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

docs/data-model.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ Column Type Description
259259
================ ============== ===========
260260
flags uint32 Bitwise flags.
261261
location double Location in arbitrary dimensions
262+
parents int32 Ids of parent individuals
262263
metadata binary Individual :ref:`sec_metadata_definition`
263264
================ ============== ===========
264265

@@ -281,6 +282,10 @@ so different individuals can have locations with different dimensions (i.e.,
281282
one individual may have location ``[]`` and another ``[0, 1, 0]``. This could
282283
therefore be used to store other quantities (e.g., phenotype).
283284

285+
The ``parents`` column stores the ids of other individuals that are the parents of
286+
an individual. This column is :ref:`ragged <sec_encoding_ragged_columns>` such that an
287+
individual can have any number of parents.
288+
284289
The ``metadata`` column provides a location for client code to store
285290
information about each individual. See the :ref:`sec_metadata_definition` section for
286291
more details on how metadata columns should be used.
@@ -1078,26 +1083,26 @@ Individual text format
10781083
======================
10791084

10801085
The individual text format must contain a ``flags`` column.
1081-
Optionally, there may also be a ``location`` and
1086+
Optionally, there may also be ``location``, ``parents`` and
10821087
``metadata`` columns. See the :ref:`individual table definitions
10831088
<sec_individual_table_definition>` for details on these columns.
10841089

10851090
Note that there are currently no globally defined ``flags``, but the column
10861091
is still required; a value of ``0`` means that there are no flags set.
10871092

1088-
The ``location`` column should be a sequence of comma-separated numeric
1093+
The ``location`` and ``parents`` columns should be a sequence of comma-separated numeric
10891094
values. They do not all have to be the same length.
10901095

10911096
An example individual table::
10921097

1093-
flags location
1094-
0 0.5,1.2
1095-
0 1.0,3.4
1098+
flags location parents
1099+
0 0.5,1.2 -1, -1
1100+
0 1.0,3.4 0, -1
10961101
0
10971102
0 1.2
1098-
0 3.5,6.3
1099-
0 0.5,0.5
1100-
0 0.5
1103+
0 3.5,6.3 1,2
1104+
0 0.5,0.5 3,4
1105+
0 0.5 -1,-1
11011106
0 0.7,0.6,0.0
11021107
0 0.5,0.0
11031108

python/tskit/tables.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ class IndividualTable(BaseTable, MetadataMixin):
457457
:ivar location_offset: The array of offsets into the location column. See
458458
:ref:`sec_encoding_ragged_columns` for more details.
459459
:vartype location_offset: numpy.ndarray, dtype=np.uint32
460+
:ivar parents: The flattened array of parent individual ids. See
461+
:ref:`sec_encoding_ragged_columns` for more details.
462+
:vartype parents: numpy.ndarray, dtype=np.int32
463+
:ivar parents_offset: The array of offsets into the parents column. See
464+
:ref:`sec_encoding_ragged_columns` for more details.
465+
:vartype parents_offset: numpy.ndarray, dtype=np.uint32
460466
:ivar metadata: The flattened array of binary metadata values. See
461467
:ref:`sec_tables_api_binary_columns` for more details.
462468
:vartype metadata: numpy.ndarray, dtype=np.int8
@@ -522,6 +528,8 @@ def add_row(self, flags=0, location=None, parents=None, metadata=None):
522528
:param array-like location: A list of numeric values or one-dimensional numpy
523529
array describing the location of this individual. If not specified
524530
or None, a zero-dimensional location is stored.
531+
:param array-like parents: A list or array of ids of parent individuals. If not
532+
specified an empty array is stored.
525533
:param object metadata: Any object that is valid metadata for the table's schema.
526534
Defaults to the default metadata value for the table's schema. This is
527535
typically ``{}``. For no schema, ``None``.
@@ -555,6 +563,8 @@ def set_columns(
555563
the table will contain.
556564
The ``location`` and ``location_offset`` parameters must be supplied
557565
together, and meet the requirements for :ref:`sec_encoding_ragged_columns`.
566+
The ``parents`` and ``parents_offset`` parameters must be supplied
567+
together, and meet the requirements for :ref:`sec_encoding_ragged_columns`.
558568
The ``metadata`` and ``metadata_offset`` parameters must be supplied
559569
together, and meet the requirements for :ref:`sec_encoding_ragged_columns`.
560570
See :ref:`sec_tables_api_binary_columns` for more information and
@@ -568,6 +578,12 @@ def set_columns(
568578
:type location: numpy.ndarray, dtype=np.float64
569579
:param location_offset: The offsets into the ``location`` array.
570580
:type location_offset: numpy.ndarray, dtype=np.uint32.
581+
:param parents: The flattened parents array. Must be specified along
582+
with ``parents_offset``. If not specified or None, an empty parents array
583+
is stored for each individual.
584+
:type parents: numpy.ndarray, dtype=np.int32
585+
:param parents_offset: The offsets into the ``parents`` array.
586+
:type parents_offset: numpy.ndarray, dtype=np.uint32.
571587
:param metadata: The flattened metadata array. Must be specified along
572588
with ``metadata_offset``. If not specified or None, an empty metadata
573589
value is stored for each individual.
@@ -606,6 +622,8 @@ def append_columns(
606622
607623
The ``flags`` array is mandatory and defines the number of
608624
extra individuals to add to the table.
625+
The ``parents`` and ``parents_offset`` parameters must be supplied
626+
together, and meet the requirements for :ref:`sec_encoding_ragged_columns`.
609627
The ``location`` and ``location_offset`` parameters must be supplied
610628
together, and meet the requirements for :ref:`sec_encoding_ragged_columns`.
611629
The ``metadata`` and ``metadata_offset`` parameters must be supplied
@@ -624,6 +642,11 @@ def append_columns(
624642
:param metadata: The flattened metadata array. Must be specified along
625643
with ``metadata_offset``. If not specified or None, an empty metadata
626644
value is stored for each individual.
645+
:param parents: The flattened parents array. Must be specified along
646+
with ``parents_offset``. If not specified or None, an empty parents array
647+
is stored for each individual.
648+
:type parents: numpy.ndarray, dtype=np.int32
649+
:param parents_offset: The offsets into the ``parents`` array.
627650
:type metadata: numpy.ndarray, dtype=np.int8
628651
:param metadata_offset: The offsets into the ``metadata`` array.
629652
:type metadata_offset: numpy.ndarray, dtype=np.uint32.
@@ -663,7 +686,7 @@ def packset_parents(self, parents):
663686
must be equal to the number of rows in the table.
664687
665688
:param list parents: A list of list of parent ids, interpreted as numpy int32
666-
arrays
689+
arrays.
667690
"""
668691
packed, offset = util.pack_arrays(parents, np.int32)
669692
d = self.asdict()

python/tskit/trees.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ class Individual(SimpleContainerWithMetadata):
147147
:ivar location: The spatial location of this individual as a numpy array. The
148148
location is an empty array if no spatial location is defined.
149149
:vartype location: numpy.ndarray
150+
:ivar parents: The parent individual ids of this individual as a numpy array. The
151+
parents is an empty array if no parents are defined.
152+
:vartype parents: numpy.ndarray
150153
:ivar nodes: The IDs of the nodes that are associated with this individual as
151154
a numpy array (dtype=np.int32). If no nodes are associated with the
152155
individual this array will be empty.
153-
:vartype location: numpy.ndarray
156+
:vartype nodes: numpy.ndarray
154157
:ivar metadata: The decoded :ref:`metadata <sec_metadata_definition>`
155158
for this individual.
156159
:vartype metadata: object

0 commit comments

Comments
 (0)