Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,9 @@ jobs:
paths:
- "/home/circleci/.local"

- run:
name: Build docs
command: |
# don't re-generate these which require tricky prerequisites (inkscape, xmlstarlet)
touch docs/_static/{pedigree0.svg,pedigree1.svg,pedigree2.svg,pedigree_recapitate.svg,pedigree_simplify.svg,pedigree_mutate.svg}
touch docs/_static/{pedigree01.png,pedigree0.png,pedigree1.png,pedigree2.png,pedigree_recapitate.png,pedigree_simplify.png,pedigree_mutate.png}
cd docs && make

- run:
name: Run Python tests
command: |
PYTHONPATH=python pytest --cov=pyslim --cov-report=xml --cov-branch \
-n 1 tests

- run:
name: Upload Python coverage
command: |
bash <(curl -s https://codecov.io/bash) -X gcov -n python_tests
# Clean up reports so we don't upload them twice.
rm -f coverage.xml

- run:
name: Build Python package
command: |
rm -fR build
python setup.py sdist
python setup.py check
python -m twine check dist/*.tar.gz
python -m venv venv
source venv/bin/activate
pip install --upgrade setuptools pip wheel
python setup.py build_ext
python setup.py egg_info
python setup.py bdist_wheel
pip install dist/*.tar.gz
python3 -c "import pyslim; print(pyslim.__version__)"
40 changes: 27 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ jobs:
- name: Cache conda and dependancies
id: cache
uses: actions/cache@v2
env:
# Increase this to reset the cache if the key hasn't changed.
CACHE_NUM: 2
with:
path: |
c:\Miniconda\envs\anaconda-client-env
/usr/share/miniconda/envs/anaconda-client-env
~/osx-conda
~/.profile
key: ${{ runner.os }}-${{ matrix.python}}-conda-v10-${{ hashFiles('requirements/CI/pip-requirements.txt') }}-${{ hashFiles('requirements/CI/conda-requirements.txt') }}
${{ steps.find-conda.outputs.CONDA }}/envs/${{ env.CONDA_ENV_NAME }}
~/.bash_profile
key: ${{ runner.os }}-${{ matrix.python}}-conda-v10-${{ hashFiles('requirements/CI/pip-requirements.txt') }}-${{ hashFiles('requirements/CI/conda-requirements.txt') }}-${{ env.CACHE_NUM }}

- name: Install Conda
uses: conda-incubator/setup-miniconda@v2
Expand All @@ -58,7 +59,11 @@ jobs:
- name: Install conda deps
if: steps.cache.outputs.cache-hit != 'true'
shell: bash -l {0} #We need a login shell to get conda
run: conda install --yes --file=requirements/CI/conda-requirements.txt
run: |
if [ "$RUNNER_OS" != "Windows" ]; then
conda install --yes slim
fi
conda install --yes --file=requirements/CI/conda-requirements.txt

- name: Install pip deps
if: steps.cache.outputs.cache-hit != 'true'
Expand All @@ -76,13 +81,14 @@ jobs:
mkdir -p /usr/local/miniconda/envs
sudo cp -r ~/osx-conda /usr/local/miniconda/envs/anaconda-client-env

- name: Build SLiM
run: |
git clone https://github.com/messerlab/SLiM.git
mkdir -p SLiM/Release
cd SLiM/Release
cmake -D CMAKE_BUILD_TYPE=Release ..
make -j 2
# Installing SLiM from conda now.
# - name: Build SLiM
# run: |
# git clone https://github.com/messerlab/SLiM.git
# mkdir -p SLiM/Release
# cd SLiM/Release
# cmake -D CMAKE_BUILD_TYPE=Release ..
# make -j 2

- name: Run tests
run: |
Expand All @@ -91,5 +97,13 @@ jobs:
export PATH=$PATH:$PWD/SLiM/Release
pytest -xv -n2

- name: Build docs
run: |
source ~/.profile
conda activate anaconda-client-env
export PATH=$PATH:$PWD/SLiM/Release
touch docs/_static/{pedigree0.svg,pedigree1.svg,pedigree2.svg,pedigree_recapitate.svg,pedigree_simplify.svg,pedigree_mutate.svg}
touch docs/_static/{pedigree01.png,pedigree0.png,pedigree1.png,pedigree2.png,pedigree_recapitate.png,pedigree_simplify.png,pedigree_mutate.png}
cd docs && make


15 changes: 14 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@

**Breaking changes**:

-
- `pyslim.recapitate` is updated to use new demography features in msprime 1.0,
and differs from `SlimTreeSequence.recapitate()` (now deprecated). The
argument `Ne` is removed; use `ancestral_Ne`.

- `reference_sequence` is now a tskit attribute, no longer managed by pyslim.
It is no longer mutable on tree sequences (only TableCollections), and
previous calls to `ts.reference_sequence` to get the actual sequence
should be replaced by `ts.reference_sequence.data`.

- Old-style "legacy" metadata (previously deprecated) has been removed.
See `the documentation <https://tskit.dev/pyslim/docs/previous_versions.html>`_
for instructions on migrating your code.


**New features**:

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


********************
[0.600] - 2021-02-24
********************
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pySLiM

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

## Installation
Expand All @@ -13,8 +13,4 @@ To install `pyslim`, do
```
pip install pyslim
```
or read the documentation for how to [install from source](https://pyslim.readthedocs.io/en/stable/development.html#sec-development).

<a href='https://pyslim.readthedocs.io/en/latest/?badge=latest'>
<img src='https://readthedocs.org/projects/pyslim/badge/?version=latest' alt='Documentation Status' />
</a>
or read the documentation for how to [install from source](https://tskit.dev/pyslim/stable/development.html#sec-development).
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sphinx:
tskit: ["https://tskit.dev/tskit/docs/stable", null]
msprime: ["https://tskit.dev/msprime/docs/stable", null]
tutorials: ["https://tskit.dev/tutorials/", null]
stdpopsim: ["https://stdpopsim.readthedocs.io/en/stable", null]
stdpopsim: ["https://popsim-consortium.github.io/stdpopsim-docs/stable", null]
myst_enable_extensions:
- colon_fence
- deflist
1 change: 1 addition & 0 deletions docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- file: vignette_coalescent_diversity
- file: vignette_parallel_phylo
- file: metadata
- file: previous_versions

- part: pyslim reference
chapters:
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'tskit': ('https://tskit.readthedocs.io/en/latest', None),
'msprime': ('https://msprime.readthedocs.io/en/latest', None)
'tskit': ('https://tskit.dev/tskit/docs/stable', None),
'msprime': ('https://tskit.dev/tskit/docs/stable', None)
}
104 changes: 2 additions & 102 deletions docs/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,117 +243,17 @@ mod_ts.dump("modified_ts.trees")

### Metadata entries

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

Of particular note is that *nodes* and *populations* may have empty metadata.
SLiM will not use the metadata of nodes that are not associated with alive individuals,
so this can safely be omitted (and makes recapitation easier).
And, populations not used by SLiM will have empty metadata.
All remaining metadata are required (besides edges and sites, whose metadata is not used at all).


(sec_legacy_metadata)=

## Legacy metadata

In previous versions of pyslim,
SLiM-specific metadata was provided as customized objects:
for instance, for a node ``n`` provided by a ``SlimTreeSequence``,
we'd have ``n.metadata`` as a ``NodeMetadata`` object,
with attributes ``n.metadata.slim_id`` and ``n.metadata.is_null`` and ``n.metadata.genome_type``.
However, with tskit 0.3,
the capacity to deal with structured metadata
was implemented in {ref}`tskit itself <tskit:sec_metadata>`,
and so pyslim shifted to using the tskit-native metadata tools.
As a result, parsed metadata is provided as a dictionary instead of an object,
so that now ``n.metadata`` would be a dict,
with entries ``n.metadata["slim_id"]`` and ``n.metadata["is_null"]`` and ``n.metadata["genome_type"]``.
Annotation should be done with tskit methods (e.g., ``packset_metadata``).

.. note::

Until pyslim version 0.600, the old-style metadata was still available,
but this functionality has been removed.

Here are more detailed notes on how to migrate a script from the legacy
metadata handling. If you run into issues, please ask (open a discussion on github).

**1.** Use top-level metadata instead of ``slim_provenance``:
previously, information about the model type and the time counter (generation)
in SLiM was provided in the Provenances table, made available through
the ``ts.slim_provenance`` object. This is still available but deprecated,
and should be obtained from the *top-level* metadata object, ``ts.metadata["SLiM"]``.
So, in your scripts ``ts.slim_provenance.model_type`` should be replaced with
``ts.metadata["SLiM"]["model_type"]``,
and (although it's not deprecated), probably ``ts.slim_generation`` should
probably be replaced with
``ts.metadata["SLiM"]["generation"]``.

**2.** Switch metadata objects to dicts:
if ``md`` is the ``metadata`` property of a population, individual, or node,
this means replacing ``md.X`` with ``md["X"]``.
The ``migration_records`` property of population metadata is similarly
a list of dicts rather than a list of objects, so instead of
``ts.population(1).metadata.migration_records[0].source_subpop``
we would write
``ts.population(1).metadata["migration_records"][0]["source_subpop"]``.

Mutations were previously a bit different - if ``mut`` is a mutation
(e.g., ``mut = ts.mutation(0)``)
then ``mut.metadata`` was previously a list of MutationMetadata objects.
Now, ``mut.metadata`` is a dict, with a single entry:
``mut.metadata["mutation_list"]`` is a list of dicts, each containing the information
that was previously in the MutationMetadata objects.
So, for instance, instead of ``mut.metadata[0].selection_coeff``
we would write ``mut.metadata["mutation_list"][0]["selection_coeff"]``.

**3.** The ``decode_X`` and ``encode_X`` methods are now deprecated,
as this is handled by tskit itself.
For instance, ``encode_node`` would take a NodeMetadata object
and produce the raw bytes necessary to encode it in a Node table,
and ``decode_node`` would do the inverse operation.
This is now handled by the relevant MetadataSchema object:
for nodes one can obtain this as ``nms = ts.tables.nodes.metadata_schema``,
which has the methods ``nms.validate_and_encode_row`` and ``nms.decode_row``.
Decoding is for the most part not necessary,
since the metadata is automatically decoded,
but ``pyslim.decode_node(raw_md)`` could be replaced by ``nms.decode_row(raw_md)``.
Encoding is necessary to modify tables,
and ``pyslim.encode_node(md)`` can be replaced by ``nms.validate_and_encode_row(md)``
(where furthermore ``md`` should now be a dict rather than a NodeMetadata object).

**4.** The ``annotate_X_metadata`` methods are deprecated,
as again tskit has tools to do this.
These methods would set the metadata column of a table -
for instance, if ``metadata`` is a list of NodeMetadata objects, then
``annotate_node_metadata(tables, metadata)`` would modify ``tables.nodes`` in place
to contain the (encoded) metadata in the list ``metadata``.
Now, this could be done as follows (where now ``metadata`` is a list of metadata dicts):

```{code-cell}
metadata = [ {'slim_id': k, 'is_null': False, 'genome_type': 0}
for k in range(tables.nodes.num_rows) ]
nms = tables.nodes.metadata_schema
tables.nodes.packset_metadata(
[nms.validate_and_encode_row(r) for r in metadata])
```

If speed is an issue, then ``encode_row`` can be substituted for ``validate_and_encode_row``,
but at the risk of missing errors in metadata.

**5.** the ``extract_X_metadata`` methods are not necessary,
since the metadata in the tables of a TableCollection are automatically decoded.
For instance, ``[ind.metadata["sex"] for ind in tables.individuals]`` will obtain
a list of sexes of the individuals in the IndividualTable.

:::{warning}
It is our intention to remain backwards-compatible for a time.
However, the legacy code will disappear at some point in the future,
so please migrate over scripts you intend to rely on.
:::
Loading