Skip to content

Commit

Permalink
Tidy some docstrings
Browse files Browse the repository at this point in the history
And remove extraneous timedelta param
  • Loading branch information
hyanwong committed Jul 10, 2024
1 parent 32b25a7 commit c41bf23
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ genetic ancestry with structural variation).

The library is a work-in-progress, and is not yet officially released.

Please visit https://github.com/hyanwong/giglib to contribute to development.

The rest of this documentation is organised into the following sections:

```{tableofcontents}
Expand Down
14 changes: 12 additions & 2 deletions giglib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ def to_tree_sequence(self, sequence_length=None):
each iedge has the same child_left as parent_left and the same
child_right as parent_right.
If sequence_length is not None, it will be used as the sequence length,
otherwise the sequence length will be the maximum position of any edge.
:param int sequence_length: The sequence length in the resulting
tree sequence (if ``None``, take the maximum position of any edge).
:return: A tree sequence
:rtype: tskit.TreeSequence
"""
for ie in self.iedges:
if ie.child_left != ie.parent_left or ie.child_right != ie.parent_right:
Expand Down Expand Up @@ -356,6 +359,10 @@ def to_tree_sequence(self, sequence_length=None):
def decapitate(self, time):
"""
Return a new GIG with all nodes older than time removed.
:param float time: The cutoff time
:return: A new GIG object
:rtype: Graph
"""
tables = self.tables.copy() # placeholder for making these editable
tables.decapitate(time)
Expand All @@ -369,6 +376,9 @@ def sample_resolve(self):
counting up the number of samples under each node. This is
identical to the :meth:`Tables.sample_resolve` method, but returns
a new GIG instead.
:return: A new GIG object
:rtype: Graph
"""
new_tables = self.tables.copy()
new_tables.sample_resolve()
Expand Down
25 changes: 17 additions & 8 deletions giglib/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,11 @@ def clear(self):

def copy(self, omit_iedges=None):
"""
Return an unfrozen deep copy of the tables. If omit_iedges is True
do not copy the iedges table but use a blank one
Return an unfrozen deep copy of the tables.
:param bool omit_iedges: If True do not copy the iedges table, use an empty one.
:return: A deep copy of the tables
:rtype: giglib.Tables
"""
copy = self.__class__()
for name, cls in zip(self.table_classes._fields, self.table_classes):
Expand Down Expand Up @@ -1238,6 +1241,9 @@ def graph(self):
.. note::
The nodes are not required to be in any particular order (e.g. by time)
:return: A genetic inheritance graph object
:rtype: giglib.Graph
"""
from .graph import Graph

Expand All @@ -1247,6 +1253,8 @@ def graph(self):
def sample_ids(self):
"""
Return the IDs of all samples in the nodes table
:rtype: numpy.ndarray
"""
if len(self.nodes) == 0:
return np.array([], dtype=np.int32)
Expand All @@ -1262,8 +1270,12 @@ def change_times(self, timedelta):
def decapitate(self, time):
"""
Remove nodes that are older than a certain time, and edges that have those
as parents. Also remove individuals associated with those nodes. Return a
mapping of old node ids to new node ids.
as parents. Also remove individuals associated with those nodes.
:param float time: The time before which nodes should be removed
:return: An array mapping old node ids to new node ids (or -1 if removed)
:rtype: numpy.ndarray
"""
individuals = IndividualTable()
individual_map = {NULL: NULL}
Expand Down Expand Up @@ -1296,16 +1308,14 @@ def decapitate(self, time):
return node_map

@classmethod
def from_tree_sequence(cls, ts, *, chromosome=None, timedelta=0, **kwargs):
def from_tree_sequence(cls, ts, *, chromosome=None, **kwargs):
"""
Create a Tables object from a :class:`tskit:tskit.TreeSequence`. To create a GIG
directly, use :func:`Graph.from_tree_sequence` which simply wraps this method.
:param tskit.TreeSequence ts: The tree sequence on which to base the Tables
object
:param int chromosome: The chromosome number to use for all interval edges
:param float timedelta: A value to add to all node times (this is a hack until
we can set entire columns like in tskit, see #issues/19)
:param kwargs: Other parameters passed to the Tables constructor
:return: A Tables object representing the tree sequence
:rtype: Tables
Expand All @@ -1330,7 +1340,6 @@ def from_tree_sequence(cls, ts, *, chromosome=None, timedelta=0, **kwargs):
raise NotImplementedError
for row in ts_tables.nodes:
obj = dataclasses.asdict(row)
obj["time"] += timedelta
tables.nodes.append(obj)
for row in ts_tables.edges:
obj = dataclasses.asdict(row)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def test_from_tree_sequence_initial_sizes(self, simple_ts):
@pytest.mark.parametrize("time", [0, 1])
def test_simple_from_tree_sequence_with_timedelta(self, simple_ts, time):
assert simple_ts.num_trees > 1
tables = gigl.Tables.from_tree_sequence(simple_ts, timedelta=time)
tables = gigl.Tables.from_tree_sequence(simple_ts)
tables.change_times(timedelta=time)
assert tables.nodes[0].time == simple_ts.node(0).time + time

def test_mutations_not_implemented_error(self, simple_ts_with_mutations):
Expand Down

0 comments on commit c41bf23

Please sign in to comment.