Skip to content

Commit d332213

Browse files
Merge pull request #412 from hyanwong/sphinx-attr-warnings
Use Sphinx currentmodule to rationalise & allow :attr: refs
2 parents c13fc01 + 2679a3d commit d332213

File tree

8 files changed

+240
-233
lines changed

8 files changed

+240
-233
lines changed

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33

44
# You can set these variables from the command line.
5-
SPHINXOPTS = #-W
5+
SPHINXOPTS = -W
66
SPHINXBUILD = python3 -m sphinx
77
SOURCEDIR = .
88
BUILDDIR = _build

docs/data-model.rst

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.. currentmodule:: tskit
12
.. _sec_data_model:
23

34
##########
@@ -21,6 +22,8 @@ store tree sequences on disk in the `Tree sequence file format`_ section.
2122

2223
.. _sec_data_model_definitions:
2324

25+
26+
2427
***********
2528
Definitions
2629
***********
@@ -50,17 +53,17 @@ node
5053
individual
5154
In certain situations we are interested in how nodes (representing
5255
individual homologous genomes) are grouped together into individuals
53-
(e.g., two nodes per diploid individual). For example, when we are working
56+
(e.g. two nodes per diploid individual). For example, when we are working
5457
with polyploid samples it is useful to associate metadata with a specific
5558
individual rather than duplicate this information on the constituent nodes.
5659
See :ref:`sec_nodes_or_individuals` for more discussion on this point.
5760

5861
sample
5962
The focal nodes of a tree sequence, usually thought of as those that we
6063
have obtained data from. The specification of these affects various
61-
methods: (1) :meth:`.TreeSequence.variants` and
62-
:meth:`.TreeSequence.haplotypes` will output the genotypes of the samples,
63-
and :attr:`.Tree.roots` only return roots ancestral to at least one
64+
methods: (1) :meth:`TreeSequence.variants` and
65+
:meth:`TreeSequence.haplotypes` will output the genotypes of the samples,
66+
and :attr:`Tree.roots` only return roots ancestral to at least one
6467
sample. (See the :ref:`node table definitions <sec_node_table_definition>`
6568
for information on how the sample
6669
status a node is encoded in the ``flags`` column.)
@@ -214,7 +217,7 @@ is composed of 32 bitwise boolean values. Currently, the only flag defined
214217
is ``IS_SAMPLE = 1``, which defines the *sample* status of nodes. Marking
215218
a particular node as a "sample" means, for example, that the mutational state
216219
of the node will be included in the genotypes produced by
217-
:meth:`.TreeSequence.variants`.
220+
:meth:`TreeSequence.variants`.
218221

219222
Bits 0-15 (inclusive) of the ``flags`` column are reserved for internal use by
220223
``tskit`` and should not be used by applications for anything other
@@ -511,14 +514,14 @@ Valid tree sequence requirements
511514
================================
512515

513516
Arbitrary data can be stored in tables using the classes in the
514-
:ref:`sec_tables_api`. However, only a :class:`.TableCollection`
517+
:ref:`sec_tables_api`. However, only a :class:`TableCollection`
515518
that fulfils a set of requirements represents
516-
a valid :class:`.TreeSequence` object which can be obtained
517-
using the :meth:`.TableCollection.tree_sequence` method. In this
519+
a valid :class:`TreeSequence` object which can be obtained
520+
using the :meth:`TableCollection.tree_sequence` method. In this
518521
section we list these requirements, and explain their rationale.
519522
Violations of most of these requirements are detected when the
520-
user attempts to load a tree sequence via :func:`.load` or
521-
:meth:`.TableCollection.tree_sequence`, raising an informative
523+
user attempts to load a tree sequence via :func:`tskit.load` or
524+
:meth:`TableCollection.tree_sequence`, raising an informative
522525
error message. Some more complex requirements may not be detectable at load-time,
523526
and errors may not occur until certain operations are attempted.
524527
These are documented below.
@@ -536,7 +539,7 @@ respect to any other tables. Therefore, there are no requirements on
536539
individuals.
537540

538541
There are no requirements regarding the ordering of individuals.
539-
Sorting a set of tables using :meth:`.TableCollection.sort` has
542+
Sorting a set of tables using :meth:`TableCollection.sort` has
540543
no effect on the individuals.
541544

542545
.. _sec_node_requirements:
@@ -558,7 +561,7 @@ There are no requirements regarding the ordering of nodes with respect to time.
558561
For simplicity and algorithmic efficiency, all nodes referring to the same
559562
(non-null) individual must be contiguous.
560563

561-
Sorting a set of tables using :meth:`.TableCollection.sort`
564+
Sorting a set of tables using :meth:`TableCollection.sort`
562565
has no effect on nodes.
563566

564567
.. _sec_edge_requirements:
@@ -587,7 +590,7 @@ where a node ``a`` is a child of both ``b`` and ``c``), and ensures that
587590
at each point on the sequence we have a well-formed forest of trees.
588591
Because this is a more complex semantic requirement, it is **not** detected
589592
at load time. This error is detected during tree traversal, via, e.g.,
590-
the :meth:`.TreeSequence.trees` iterator.
593+
the :meth:`TreeSequence.trees` iterator.
591594

592595
In the interest of algorithmic efficiency, edges must have the following
593596
sortedness properties:
@@ -598,7 +601,7 @@ sortedness properties:
598601
first by ``child`` ID and then by ``left`` coordinate.
599602

600603
Violations of these requirements are detected at load time.
601-
The :meth:`.TableCollection.sort` method will ensure that these sortedness
604+
The :meth:`TableCollection.sort` method will ensure that these sortedness
602605
properties are fulfilled.
603606

604607
.. _sec_site_requirements:
@@ -617,7 +620,7 @@ For simplicity and algorithmic efficiency, sites must also:
617620
- Be sorted in increasing order of ``position``.
618621

619622
Violations of these requirements are detected at load time.
620-
The :meth:`.TableCollection.sort` method ensures that sites are sorted
623+
The :meth:`TableCollection.sort` method ensures that sites are sorted
621624
according to these criteria.
622625

623626
.. _sec_mutation_requirements:
@@ -646,7 +649,7 @@ For simplicity and algorithmic efficiency, mutations must also:
646649
``parent`` with ID :math:`y`, then we must have :math:`y < x`).
647650

648651
Violations of these sorting requirements are detected at load time.
649-
The :meth:`.TableCollection.sort` method ensures that mutations are sorted
652+
The :meth:`TableCollection.sort` method ensures that mutations are sorted
650653
according site ID, but does not at present enforce that mutations occur
651654
after their parent mutations.
652655

@@ -655,7 +658,7 @@ change of state. For example, if we have a site with ancestral state
655658
of "A" and a single mutation with derived state "A", then this
656659
mutation does not result in any change of state. This error is
657660
raised at run-time when we reconstruct sample genotypes, for example
658-
in the :meth:`.TreeSequence.variants` iterator.
661+
in the :meth:`TreeSequence.variants` iterator.
659662

660663
.. _sec_migration_requirements:
661664

@@ -708,7 +711,7 @@ Schema section (TODO).
708711
Table transformation methods
709712
============================
710713

711-
In general, table methods operate *in place* on a :class:`.TableCollection`,
714+
In general, table methods operate *in place* on a :class:`TableCollection`,
712715
directly altering the data stored within its constituent tables.
713716

714717
In some applications, tables may most naturally be produced in a way that is
@@ -718,8 +721,8 @@ below (while also having other uses), can be used to make such a set of tables
718721
valid, and thus ready to be loaded into a tree sequence.
719722

720723
Some of the other methods described in this section also have an equivalant
721-
:class:`.TreeSequence` version: an important distinction is that unlike the
722-
methods here, :class:`.TreeSequence` methods do *not* operate in place, but
724+
:class:`TreeSequence` version: an important distinction is that unlike the
725+
methods here, :class:`TreeSequence` methods do *not* operate in place, but
723726
rather act in a functional way, returning a new tree sequence while leaving
724727
the original one unchanged.
725728

@@ -732,8 +735,8 @@ Simplification
732735
--------------
733736

734737
Simplification of a tree sequence is in fact a transformation method applied
735-
to the underlying tables: the method :meth:`.TreeSequence.simplify` calls
736-
:meth:`.TableCollection.simplify` on the tables, and loads a new tree sequence.
738+
to the underlying tables: the method :meth:`TreeSequence.simplify` calls
739+
:meth:`TableCollection.simplify` on the tables, and loads a new tree sequence.
737740
The main purpose of this method is to remove redundant information,
738741
only retaining the minimal tree sequence necessary to describe the genealogical
739742
history of the ``samples`` provided.
@@ -743,7 +746,7 @@ Furthermore, ``simplify`` is guaranteed to:
743746
- preserve relative ordering of any rows in the Site and Mutation tables
744747
that are not discarded.
745748

746-
The :meth:`.TableCollection.simplify` method can be applied to a collection of
749+
The :meth:`TableCollection.simplify` method can be applied to a collection of
747750
tables that does not have the ``mutations.parent`` entries filled in, as long
748751
as all other validity requirements are satisfied.
749752

@@ -754,7 +757,7 @@ Sorting
754757

755758
The validity requirements for a set of tables to be loaded into a tree sequence
756759
listed in :ref:`sec_table_definitions` are of two sorts: logical consistency,
757-
and sortedness. The :meth:`.TableCollection.sort` method can be used to make
760+
and sortedness. The :meth:`TableCollection.sort` method can be used to make
758761
completely valid a set of tables that satisfies all requirements other than
759762
sortedness.
760763

@@ -765,7 +768,7 @@ be sorted. The method has two additional properties:
765768
- it preserves relative ordering between sites at the same position, and
766769
- it preserves relative ordering between mutations at the same site.
767770

768-
:meth:`.TableCollection.sort` does not check the validity of the `parent`
771+
:meth:`TableCollection.sort` does not check the validity of the `parent`
769772
property of the mutation table. However, because the method preserves mutation
770773
order among mutations at the same site, if mutations are already sorted so that
771774
each mutation comes after its parent (e.g., if they are ordered by time of
@@ -786,7 +789,7 @@ the tables must be indexed.
786789
Removing duplicate sites
787790
------------------------
788791

789-
The :meth:`.TableCollection.deduplicate_sites` method can be used to save a tree
792+
The :meth:`TableCollection.deduplicate_sites` method can be used to save a tree
790793
sequence recording method the bother of checking to see if a given site already
791794
exists in the site table. If there is more than one site with the same
792795
position, all but the first is removed, and all mutations referring to the
@@ -802,7 +805,7 @@ of the mutation table would be easily inferred from the tree at that mutation's
802805
site. If mutations are entered into the mutation table ordered by time of
803806
appearance, then this sortedness allows us to infer the parent of each mutation
804807
even for mutations occurring on the same branch. The
805-
:meth:`.TableCollection.compute_mutation_parents` method will take advantage
808+
:meth:`TableCollection.compute_mutation_parents` method will take advantage
806809
of this fact to compute the ``parent`` column of a mutation table, if all
807810
other information is valid.
808811

@@ -982,8 +985,8 @@ Consider the following example:
982985

983986
In this tree, node 4 is isolated, and therefore for any sites that are
984987
on this tree, the state that it is assigned is a special value
985-
``tskit.MISSING_DATA``, or ``-1``. See the :meth:`.TreeSequence.variants`
986-
method and :class:`.Variant` class for more information on how missing
988+
``tskit.MISSING_DATA``, or ``-1``. See the :meth:`TreeSequence.variants`
989+
method and :class:`Variant` class for more information on how missing
987990
data is represented.
988991

989992
.. _sec_text_file_format:

docs/python-api.rst

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.. currentmodule:: tskit
12
.. _sec_python_api:
23

34
==========
@@ -10,14 +11,14 @@ This page provides detailed documentation for the ``tskit`` Python API.
1011
Trees and tree sequences
1112
************************
1213

13-
The :class:`.TreeSequence` class represents a sequence of correlated trees
14-
output by a simulation. The :class:`.Tree` class represents a single
14+
The :class:`TreeSequence` class represents a sequence of correlated trees
15+
output by a simulation. The :class:`Tree` class represents a single
1516
tree in this sequence.
1617
These classes are the interfaces used to interact with the trees
1718
and mutational information stored in a tree sequence returned from a simulation.
1819
There are also methods for loading data into these objects, either from the native
1920
format using :func:`tskit.load`, or from another sources
20-
using :func:`tskit.load_text` or :meth:`.TableCollection.tree_sequence`.
21+
using :func:`tskit.load_text` or :meth:`TableCollection.tree_sequence`.
2122

2223

2324
+++++++++++++++++
@@ -28,7 +29,7 @@ Top level-classes
2829
.. autoclass:: tskit.TreeSequence()
2930
:members:
3031

31-
.. autoclass:: tskit.Tree
32+
.. autoclass:: tskit.Tree()
3233
:members:
3334

3435

@@ -59,7 +60,7 @@ Simple container classes
5960
These classes are simple shallow containers representing the entities defined
6061
in the :ref:`sec_data_model_definitions`. These classes are not intended to be instantiated
6162
directly, but are the return types for the various iterators provided by the
62-
:class:`.TreeSequence` and :class:`.Tree` classes.
63+
:class:`TreeSequence` and :class:`Tree` classes.
6364

6465
.. autoclass:: tskit.Individual()
6566
:members:
@@ -92,13 +93,13 @@ directly, but are the return types for the various iterators provided by the
9293
Loading data
9394
++++++++++++
9495

95-
There are several methods for loading data into a :class:`.TreeSequence`
96+
There are several methods for loading data into a :class:`TreeSequence`
9697
instance. The simplest and most convenient is the use the :func:`tskit.load`
9798
function to load a :ref:`tree sequence file <sec_tree_sequence_file_format>`. For small
9899
scale data and debugging, it is often convenient to use the
99100
:func:`tskit.load_text` to read data in the :ref:`text file format
100-
<sec_text_file_format>`. The :meth:`.TableCollection.tree_sequence` function
101-
efficiently creates a :class:`.TreeSequence` object from a set of tables
101+
<sec_text_file_format>`. The :meth:`TableCollection.tree_sequence` function
102+
efficiently creates a :class:`TreeSequence` object from a set of tables
102103
using the :ref:`Tables API <sec_tables_api>`.
103104

104105

@@ -115,7 +116,7 @@ Tables
115116

116117
The :ref:`tables API <sec_binary_interchange>` provides an efficient way of working
117118
with and interchanging :ref:`tree sequence data <sec_data_model>`. Each table
118-
class (e.g, :class:`.NodeTable`, :class:`.EdgeTable`) has a specific set of
119+
class (e.g, :class:`NodeTable`, :class:`EdgeTable`) has a specific set of
119120
columns with fixed types, and a set of methods for setting and getting the data
120121
in these columns. The number of rows in the table ``t`` is given by ``len(t)``.
121122
Each table supports accessing the data either by row or column. To access the
@@ -214,7 +215,7 @@ Consider the following example::
214215
>>> t[3]
215216
SiteTableRow(position=3.0, ancestral_state='CCC', metadata=b'')
216217

217-
Here we create a :class:`.SiteTable` and add four rows, each with a different
218+
Here we create a :class:`SiteTable` and add four rows, each with a different
218219
``ancestral_state``. We can then access this information from each
219220
row in a straightforward manner. Working with the data in the columns
220221
is a little trickier, however::
@@ -228,9 +229,9 @@ is a little trickier, however::
228229

229230
Here, the ``ancestral_state`` array is the UTF8 encoded bytes of the flattened
230231
strings, and the ``ancestral_state_offset`` is the offset into this array
231-
for each row. The :func:`.unpack_strings` function, however, is a convient
232+
for each row. The :func:`tskit.unpack_strings` function, however, is a convient
232233
way to recover the original strings from this encoding. We can also use the
233-
:func:`.pack_strings` to insert data using this approach::
234+
:func:`tskit.pack_strings` to insert data using this approach::
234235

235236
>>> a, off = tskit.pack_strings(["0", "12", ""])
236237
>>> t.set_columns(position=[0, 1, 2], ancestral_state=a, ancestral_state_offset=off)
@@ -243,7 +244,7 @@ way to recover the original strings from this encoding. We can also use the
243244
When inserting many rows with standard infinite sites mutations (i.e.,
244245
ancestral state is "0"), it is more efficient to construct the
245246
numpy arrays directly than to create a list of strings and use
246-
:func:`.pack_strings`. When doing this, it is important to note that
247+
:func:`pack_strings`. When doing this, it is important to note that
247248
it is the **encoded** byte values that are stored; by default, we
248249
use UTF8 (which corresponds to ASCII for simple printable characters).::
249250

@@ -332,7 +333,7 @@ decoding is done on the data. Consider the following example::
332333
array([ 0, 9, 33], dtype=uint32)
333334

334335

335-
Here we add two rows to a :class:`.NodeTable`, with different
336+
Here we add two rows to a :class:`NodeTable`, with different
336337
:ref:`metadata <sec_metadata_definition>`. The first row contains a simple
337338
byte string, and the second contains a Python dictionary serialised using
338339
:mod:`pickle`. We then show several different (and seemingly incompatible!)
@@ -356,8 +357,8 @@ encoded as signed integers. As for :ref:`sec_tables_api_text_columns`,
356357
the ``metadata_offset`` column encodes the offsets into this array. So, we
357358
see that the first metadata value is 9 bytes long and the second is 24.
358359

359-
The :func:`.pack_bytes` and :func:`.unpack_bytes` functions are also useful
360-
for encoding data in these columns.
360+
The :func:`tskit.pack_bytes` and :func:`tskit.unpack_bytes` functions are
361+
also useful for encoding data in these columns.
361362

362363
+++++++++++++
363364
Table classes
@@ -410,7 +411,7 @@ Each of the table classes defines a different aspect of the structure of
410411
a tree sequence. It is convenient to be able to refer to a set of these
411412
tables which together define a tree sequence. We
412413
refer to this grouping of related tables as a ``TableCollection``.
413-
The :class:`.TableCollection` and :class:`.TreeSequence` classes are
414+
The :class:`TableCollection` and :class:`TreeSequence` classes are
414415
deeply related. A ``TreeSequence`` instance is based on the information
415416
encoded in a ``TableCollection``. Tree sequences are **immutable**, and
416417
provide methods for obtaining trees from the sequence. A ``TableCollection``

0 commit comments

Comments
 (0)