Skip to content

Commit 4f4af53

Browse files
committed
deprecations
update links from readthedocs
1 parent 9bc27db commit 4f4af53

16 files changed

+259
-160
lines changed

CHANGELOG.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@
44

55
**Breaking changes**:
66

7-
-
7+
- `pyslim.recapitate` is updated to use new demography features in msprime 1.0,
8+
and differs from `SlimTreeSequence.recapitate()` (now deprecated). The
9+
argument `Ne` is removed; use `ancestral_Ne`.
10+
11+
- `reference_sequence` is now a tskit attribute, no longer managed by pyslim.
12+
It is no longer mutable on tree sequences (only TableCollections), and
13+
previous calls to `ts.reference_sequence` to get the actual sequence
14+
should be replaced by `ts.reference_sequence.data`.
15+
16+
- Old-style "legacy" metadata (previously deprecated) has been removed.
17+
See `the documentation <https://tskit.dev/pyslim/docs/previous_versions.html>`_
18+
for instructions on migrating your code.
19+
820

921
**New features**:
1022

1123
- Added `pyslim.population_size( )` to compute an array giving numbers of
1224
individuals across a grid of space and time bins. ({user}giliapatterson)
1325

26+
1427
********************
1528
[0.600] - 2021-02-24
1629
********************

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# pySLiM
22

33
`pyslim` is a python module to allow reading and writing of SLiM-produced tree sequences
4-
as a thin interface to [tskit](https://tskit.readthedocs.io/en/stable).
5-
Please see [our documentation](https://pyslim.readthedocs.io/en/stable/) for more information.
6-
(That link is to documentation for the [last release](https://pyslim.readthedocs.io/en/stable/) release;
7-
instead, [the latest](https://pyslim.readthedocs.io/en/latest/) documentation
4+
as a thin interface to [tskit](https://tskit.dev/tskit).
5+
Please see [our documentation](https://tskit.dev/pyslim/docs/stable/) for more information.
6+
(That link is to documentation for the last release release;
7+
instead, [the latest](https://tskit.dev/pyslim/docs/latest) documentation
88
may have additional examples, but may also describe features you need to install from github to get.)
99

1010
## Installation
@@ -13,8 +13,4 @@ To install `pyslim`, do
1313
```
1414
pip install pyslim
1515
```
16-
or read the documentation for how to [install from source](https://pyslim.readthedocs.io/en/stable/development.html#sec-development).
17-
18-
<a href='https://pyslim.readthedocs.io/en/latest/?badge=latest'>
19-
<img src='https://readthedocs.org/projects/pyslim/badge/?version=latest' alt='Documentation Status' />
20-
</a>
16+
or read the documentation for how to [install from source](https://tskit.dev/pyslim/stable/development.html#sec-development).

docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ sphinx:
4242
tskit: ["https://tskit.dev/tskit/docs/stable", null]
4343
msprime: ["https://tskit.dev/msprime/docs/stable", null]
4444
tutorials: ["https://tskit.dev/tutorials/", null]
45-
stdpopsim: ["https://stdpopsim.readthedocs.io/en/stable", null]
45+
stdpopsim: ["https://popsim-consortium.github.io/stdpopsim-docs/stable", null]
4646
myst_enable_extensions:
4747
- colon_fence
4848
- deflist

docs/_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- file: vignette_coalescent_diversity
1212
- file: vignette_parallel_phylo
1313
- file: metadata
14+
- file: previous_versions
1415

1516
- part: pyslim reference
1617
chapters:

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,6 @@
195195
# Example configuration for intersphinx: refer to the Python standard library.
196196
intersphinx_mapping = {
197197
'python': ('https://docs.python.org/3', None),
198-
'tskit': ('https://tskit.readthedocs.io/en/latest', None),
199-
'msprime': ('https://msprime.readthedocs.io/en/latest', None)
198+
'tskit': ('https://tskit.dev/tskit/docs/stable', None),
199+
'msprime': ('https://tskit.dev/tskit/docs/stable', None)
200200
}

docs/metadata.md

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -243,117 +243,17 @@ mod_ts.dump("modified_ts.trees")
243243

244244
### Metadata entries
245245

246-
SLiM records additional information in the metadata columns of Population, Individual, Node, and Mutation tables,
246+
SLiM records additional information in the metadata columns of Individual, Node, and Mutation tables,
247247
in a binary format using the python ``struct`` module.
248248
See {ref}`tskit's metadata documentation <tskit:sec_metadata>`
249249
for details on how this works.
250250
Nothing besides this binary information can be stored in the metadata of these tables if the tree sequence is to be used by SLiM,
251251
and so when ``pyslim`` annotates an existing tree sequence, anything in those columns is overwritten.
252+
Population metadata is stored as JSON, however, which is more flexible.
252253
For more detailed documentation on the contents and format of the metadata, see the SLiM manual.
253254

254255
Of particular note is that *nodes* and *populations* may have empty metadata.
255256
SLiM will not use the metadata of nodes that are not associated with alive individuals,
256257
so this can safely be omitted (and makes recapitation easier).
257258
And, populations not used by SLiM will have empty metadata.
258259
All remaining metadata are required (besides edges and sites, whose metadata is not used at all).
259-
260-
261-
(sec_legacy_metadata)=
262-
263-
## Legacy metadata
264-
265-
In previous versions of pyslim,
266-
SLiM-specific metadata was provided as customized objects:
267-
for instance, for a node ``n`` provided by a ``SlimTreeSequence``,
268-
we'd have ``n.metadata`` as a ``NodeMetadata`` object,
269-
with attributes ``n.metadata.slim_id`` and ``n.metadata.is_null`` and ``n.metadata.genome_type``.
270-
However, with tskit 0.3,
271-
the capacity to deal with structured metadata
272-
was implemented in {ref}`tskit itself <tskit:sec_metadata>`,
273-
and so pyslim shifted to using the tskit-native metadata tools.
274-
As a result, parsed metadata is provided as a dictionary instead of an object,
275-
so that now ``n.metadata`` would be a dict,
276-
with entries ``n.metadata["slim_id"]`` and ``n.metadata["is_null"]`` and ``n.metadata["genome_type"]``.
277-
Annotation should be done with tskit methods (e.g., ``packset_metadata``).
278-
279-
.. note::
280-
281-
Until pyslim version 0.600, the old-style metadata was still available,
282-
but this functionality has been removed.
283-
284-
Here are more detailed notes on how to migrate a script from the legacy
285-
metadata handling. If you run into issues, please ask (open a discussion on github).
286-
287-
**1.** Use top-level metadata instead of ``slim_provenance``:
288-
previously, information about the model type and the time counter (generation)
289-
in SLiM was provided in the Provenances table, made available through
290-
the ``ts.slim_provenance`` object. This is still available but deprecated,
291-
and should be obtained from the *top-level* metadata object, ``ts.metadata["SLiM"]``.
292-
So, in your scripts ``ts.slim_provenance.model_type`` should be replaced with
293-
``ts.metadata["SLiM"]["model_type"]``,
294-
and (although it's not deprecated), probably ``ts.slim_generation`` should
295-
probably be replaced with
296-
``ts.metadata["SLiM"]["generation"]``.
297-
298-
**2.** Switch metadata objects to dicts:
299-
if ``md`` is the ``metadata`` property of a population, individual, or node,
300-
this means replacing ``md.X`` with ``md["X"]``.
301-
The ``migration_records`` property of population metadata is similarly
302-
a list of dicts rather than a list of objects, so instead of
303-
``ts.population(1).metadata.migration_records[0].source_subpop``
304-
we would write
305-
``ts.population(1).metadata["migration_records"][0]["source_subpop"]``.
306-
307-
Mutations were previously a bit different - if ``mut`` is a mutation
308-
(e.g., ``mut = ts.mutation(0)``)
309-
then ``mut.metadata`` was previously a list of MutationMetadata objects.
310-
Now, ``mut.metadata`` is a dict, with a single entry:
311-
``mut.metadata["mutation_list"]`` is a list of dicts, each containing the information
312-
that was previously in the MutationMetadata objects.
313-
So, for instance, instead of ``mut.metadata[0].selection_coeff``
314-
we would write ``mut.metadata["mutation_list"][0]["selection_coeff"]``.
315-
316-
**3.** The ``decode_X`` and ``encode_X`` methods are now deprecated,
317-
as this is handled by tskit itself.
318-
For instance, ``encode_node`` would take a NodeMetadata object
319-
and produce the raw bytes necessary to encode it in a Node table,
320-
and ``decode_node`` would do the inverse operation.
321-
This is now handled by the relevant MetadataSchema object:
322-
for nodes one can obtain this as ``nms = ts.tables.nodes.metadata_schema``,
323-
which has the methods ``nms.validate_and_encode_row`` and ``nms.decode_row``.
324-
Decoding is for the most part not necessary,
325-
since the metadata is automatically decoded,
326-
but ``pyslim.decode_node(raw_md)`` could be replaced by ``nms.decode_row(raw_md)``.
327-
Encoding is necessary to modify tables,
328-
and ``pyslim.encode_node(md)`` can be replaced by ``nms.validate_and_encode_row(md)``
329-
(where furthermore ``md`` should now be a dict rather than a NodeMetadata object).
330-
331-
**4.** The ``annotate_X_metadata`` methods are deprecated,
332-
as again tskit has tools to do this.
333-
These methods would set the metadata column of a table -
334-
for instance, if ``metadata`` is a list of NodeMetadata objects, then
335-
``annotate_node_metadata(tables, metadata)`` would modify ``tables.nodes`` in place
336-
to contain the (encoded) metadata in the list ``metadata``.
337-
Now, this could be done as follows (where now ``metadata`` is a list of metadata dicts):
338-
339-
```{code-cell}
340-
metadata = [ {'slim_id': k, 'is_null': False, 'genome_type': 0}
341-
for k in range(tables.nodes.num_rows) ]
342-
nms = tables.nodes.metadata_schema
343-
tables.nodes.packset_metadata(
344-
[nms.validate_and_encode_row(r) for r in metadata])
345-
```
346-
347-
If speed is an issue, then ``encode_row`` can be substituted for ``validate_and_encode_row``,
348-
but at the risk of missing errors in metadata.
349-
350-
**5.** the ``extract_X_metadata`` methods are not necessary,
351-
since the metadata in the tables of a TableCollection are automatically decoded.
352-
For instance, ``[ind.metadata["sex"] for ind in tables.individuals]`` will obtain
353-
a list of sexes of the individuals in the IndividualTable.
354-
355-
:::{warning}
356-
It is our intention to remain backwards-compatible for a time.
357-
However, the legacy code will disappear at some point in the future,
358-
so please migrate over scripts you intend to rely on.
359-
:::

docs/previous_versions.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .md
5+
format_name: myst
6+
format_version: 0.12
7+
jupytext_version: 1.9.1
8+
kernelspec:
9+
display_name: Python 3
10+
language: python
11+
name: python3
12+
---
13+
14+
```{code-cell}
15+
:tags: [remove-cell]
16+
import pyslim, tskit, msprime
17+
18+
ts = tskit.load("example_sim.trees")
19+
tables = ts.tables
20+
```
21+
22+
23+
(sec_previous_versions)=
24+
25+
26+
# Migrating from previous versions of pyslim
27+
28+
A number of features that were first introduced in pyslim have been made part of core
29+
tskit functionality. For instance, reference sequence support was provided (although
30+
loosely) inpyslim to support SLiM's nucleotide models, but is now part of a standard
31+
tskit {class}`tskit.TreeSequence`. Similarly, metadata processing in tskit made
32+
code to do this within pyslim obsolete; this "legacy metadata" code has been removed
33+
and instructions for how to migrate your code are {ref}`below <sec_legacy_metadata>`.
34+
35+
In fact, we are now at the (very good) place where we don't really need
36+
the {class}`pyslim.SlimTreeSequence` class any longer,
37+
and it will soon be deprecated.
38+
So, pyslim is migrating to be purely functional: instead of providing the SlimTreeSequence
39+
class with specialized methods, all methods will be functions of TreeSequences,
40+
that take in a tree sequence and return something
41+
(a modified tree sequence or some summary of it).
42+
Backwards compatibility will be maintained for some time, but we request that you
43+
switch over sooner, as your code will be cleaner and faster.
44+
45+
To migrate, you should:
46+
47+
48+
1. Replace `ts.slim_generation` with `ts.metadata['SLiM']['generation']`,
49+
and `ts.model_type` with `ts.metadata['SLiM']['model_type']`.
50+
2. Replace `ts.reference_sequence` with `ts.reference_sequence.data`.
51+
3. Replace calls to `ts.recapitate(...)` with `pyslim.recapitate(ts, ...)`,
52+
and similarly with other SlimTreeSequence methods.
53+
54+
If you encounter difficulties, please post an
55+
[issue](https://github.com/tskit-dev/pyslim/issues)
56+
or [discussion](https://github.com/tskit-dev/pyslim/discussions) on github.
57+
58+
59+
(sec_legacy_metadata)=
60+
61+
## Legacy metadata
62+
63+
In previous versions of pyslim,
64+
SLiM-specific metadata was provided as customized objects:
65+
for instance, for a node ``n`` provided by a ``SlimTreeSequence``,
66+
we'd have ``n.metadata`` as a ``NodeMetadata`` object,
67+
with attributes ``n.metadata.slim_id`` and ``n.metadata.is_null`` and ``n.metadata.genome_type``.
68+
However, with tskit 0.3,
69+
the capacity to deal with structured metadata
70+
was implemented in {ref}`tskit itself <tskit:sec_metadata>`,
71+
and so pyslim shifted to using the tskit-native metadata tools.
72+
As a result, parsed metadata is provided as a dictionary instead of an object,
73+
so that now ``n.metadata`` would be a dict,
74+
with entries ``n.metadata["slim_id"]`` and ``n.metadata["is_null"]`` and ``n.metadata["genome_type"]``.
75+
Annotation should be done with tskit methods (e.g., ``packset_metadata``).
76+
77+
.. note::
78+
79+
Until pyslim version 0.600, the old-style metadata was still available,
80+
but this functionality has been removed.
81+
82+
Here are more detailed notes on how to migrate a script from the legacy
83+
metadata handling. If you run into issues, please ask (open a discussion on github).
84+
85+
**1.** Use top-level metadata instead of ``slim_provenance``:
86+
previously, information about the model type and the time counter (generation)
87+
in SLiM was provided in the Provenances table, made available through
88+
the ``ts.slim_provenance`` object. This is still available but deprecated,
89+
and should be obtained from the *top-level* metadata object, ``ts.metadata["SLiM"]``.
90+
So, in your scripts ``ts.slim_provenance.model_type`` should be replaced with
91+
``ts.metadata["SLiM"]["model_type"]``,
92+
and (although it's not deprecated), probably ``ts.slim_generation`` should
93+
probably be replaced with
94+
``ts.metadata["SLiM"]["generation"]``.
95+
96+
**2.** Switch metadata objects to dicts:
97+
if ``md`` is the ``metadata`` property of a population, individual, or node,
98+
this means replacing ``md.X`` with ``md["X"]``.
99+
The ``migration_records`` property of population metadata is similarly
100+
a list of dicts rather than a list of objects, so instead of
101+
``ts.population(1).metadata.migration_records[0].source_subpop``
102+
we would write
103+
``ts.population(1).metadata["migration_records"][0]["source_subpop"]``.
104+
105+
Mutations were previously a bit different - if ``mut`` is a mutation
106+
(e.g., ``mut = ts.mutation(0)``)
107+
then ``mut.metadata`` was previously a list of MutationMetadata objects.
108+
Now, ``mut.metadata`` is a dict, with a single entry:
109+
``mut.metadata["mutation_list"]`` is a list of dicts, each containing the information
110+
that was previously in the MutationMetadata objects.
111+
So, for instance, instead of ``mut.metadata[0].selection_coeff``
112+
we would write ``mut.metadata["mutation_list"][0]["selection_coeff"]``.
113+
114+
**3.** The ``decode_X`` and ``encode_X`` methods are now deprecated,
115+
as this is handled by tskit itself.
116+
For instance, ``encode_node`` would take a NodeMetadata object
117+
and produce the raw bytes necessary to encode it in a Node table,
118+
and ``decode_node`` would do the inverse operation.
119+
This is now handled by the relevant MetadataSchema object:
120+
for nodes one can obtain this as ``nms = ts.tables.nodes.metadata_schema``,
121+
which has the methods ``nms.validate_and_encode_row`` and ``nms.decode_row``.
122+
Decoding is for the most part not necessary,
123+
since the metadata is automatically decoded,
124+
but ``pyslim.decode_node(raw_md)`` could be replaced by ``nms.decode_row(raw_md)``.
125+
Encoding is necessary to modify tables,
126+
and ``pyslim.encode_node(md)`` can be replaced by ``nms.validate_and_encode_row(md)``
127+
(where furthermore ``md`` should now be a dict rather than a NodeMetadata object).
128+
129+
**4.** The ``annotate_X_metadata`` methods are deprecated,
130+
as again tskit has tools to do this.
131+
These methods would set the metadata column of a table -
132+
for instance, if ``metadata`` is a list of NodeMetadata objects, then
133+
``annotate_node_metadata(tables, metadata)`` would modify ``tables.nodes`` in place
134+
to contain the (encoded) metadata in the list ``metadata``.
135+
Now, this could be done as follows (where now ``metadata`` is a list of metadata dicts):
136+
137+
```{code-cell}
138+
metadata = [ {'slim_id': k, 'is_null': False, 'genome_type': 0}
139+
for k in range(tables.nodes.num_rows) ]
140+
nms = tables.nodes.metadata_schema
141+
tables.nodes.packset_metadata(
142+
[nms.validate_and_encode_row(r) for r in metadata]
143+
)
144+
```
145+
146+
If speed is an issue, then ``encode_row`` can be substituted for ``validate_and_encode_row``,
147+
but at the risk of missing errors in metadata.
148+
149+
**5.** the ``extract_X_metadata`` methods are not necessary,
150+
since the metadata in the tables of a TableCollection are automatically decoded.
151+
For instance, ``[ind.metadata["sex"] for ind in tables.individuals]`` will obtain
152+
a list of sexes of the individuals in the IndividualTable.
153+
154+
:::{warning}
155+
It is our intention to remain backwards-compatible for a time.
156+
However, the legacy code will disappear at some point in the future,
157+
so please migrate over scripts you intend to rely on.
158+
:::
159+
=======
160+
>>>>>>> 483184a (deprecation start)

docs/python_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ available in pyslim.
5151

5252
## Summarizing tree sequences
5353

54-
Additionally, ``pyslim`` contains the following summary methods:
54+
Additionally, ``pyslim`` contains the following methods:
5555

5656
```{eval-rst}
5757
.. autosummary::

docs/tutorial.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,10 @@ demography.add_migration_rate_change(
566566
time=orig_ts.metadata['SLiM']['generation'],
567567
rate=0.1, source="p2", dest="p1",
568568
)
569-
rts = pyslim.recapitate(orig_ts, demography=demography,
570-
recombination_rate=1e-8,
571-
random_seed=4
569+
rts = pyslim.recapitate(
570+
orig_ts, demography=demography,
571+
recombination_rate=1e-8,
572+
random_seed=4
572573
)
573574
ts = pyslim.SlimTreeSequence(
574575
msprime.sim_mutations(
@@ -685,8 +686,9 @@ and {attr}`.SlimTreeSequence.individual_populations` as follows:
685686
```{code-cell}
686687
alive = ts.individuals_alive_at(0)
687688
adults = alive[ts.individual_ages[alive] > 2]
688-
pops = [np.where(
689-
ts.individual_populations[adults] == k)[0] for k in [1, 2]]
689+
pops = [
690+
np.where(ts.individual_populations[adults] == k)[0] for k in [1, 2]
691+
]
690692
sample_inds = [np.random.choice(pop, 10, replace=False) for pop in pops]
691693
sample_nodes = []
692694
for samp in sample_inds:

0 commit comments

Comments
 (0)