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
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
[UPCOMING.X.X] - XXXX-XX-XX
***************************

**Notable changes**:

- Switched to using tskit native encoding/decoding of metadata via schemas.
- added to conda-forge (@winni2k)

**New features**:

- enabled dumping the reference sequence for nucleotide models

********************
[0.403] - 2020-08-27
********************
Expand All @@ -16,8 +25,11 @@ BUGFIX: if a tree had all first generation individuals removed

This is a compatibility release, for the tskit 0.3.0 release.


**New features**:

- added has_individual_parents, a method to find individuals with all parents
are also recorded as individuals
- Provenance handling:
* added the `.slim_provenances` property to return all SLiM provenance entries
* added the `slim_provenance_version` and `parse_provenance` methods to tell if
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# 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/latest).
Please see [our documentation](https://pyslim.readthedocs.io/en/latest/) for more information.
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
may have additional examples, but may also describe features you need to install from github to get.)

## Installation

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' />
Expand Down
9 changes: 8 additions & 1 deletion docs/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ to SLiM time as follows:

def slim_time(ts, time):
slim_time = ts.slim_generation - time
if self.slim_provenance.model_type == "WF":
if self.metadata['model_type'] == "WF":
time_adjust = (self.slim_generation
- self.individual(self.first_generation_individuals()[0]).time)
slim_time -= time_adjust
Expand Down Expand Up @@ -94,3 +94,10 @@ The information is recorded in a binary format, and is extracted and written by
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.
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).
4 changes: 2 additions & 2 deletions docs/vignette_continuing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ below we'll run a simulation in which
3. evolves neutrally for another 1000 generations.

To do this, we'll simulate step (2) first, with SLiM,
then recapitate to add step (1), and then "continue" the simulating using msprime to add in (3).
then recapitate to add step (1), and then "continue" the simulation using msprime to add in (3).


******************
Positive selection
******************

Here's a SLiM script that has rapid, strong selection acting genome-wide for 100 generations.
Here's a SLiM script that has rapid, strong selection acting genome-wide for 20 generations.
It is perhaps not very realistic, but it's dramatic.

.. literalinclude:: rapid_adaptation.slim
Expand Down
1 change: 1 addition & 0 deletions pyslim/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# coding: utf-8
pyslim_version = '0.403'
slim_file_version = '0.5'
30 changes: 21 additions & 9 deletions pyslim/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

@attr.s
class ProvenanceMetadata(object):
"""
DEPRECATED: use the tree sequence metadata (under the 'SLiM' key) instead.
"""
model_type = attr.ib()
slim_generation = attr.ib()
file_version = attr.ib()
Expand Down Expand Up @@ -53,7 +56,7 @@ def slim_provenance_version(provenance):
file_version = record["file_version"]
except:
pass
is_slim = (software_name == "SLiM") and (file_version in ["0.1", "0.2", "0.3", "0.4"])
is_slim = (software_name == "SLiM")
return is_slim, file_version


Expand All @@ -62,6 +65,8 @@ def parse_provenance(provenance):
Parses a SLiM provenance entry, returning a :class:`ProvenanceMetadata`
object, or raising an error if the entry is not a SLiM provenance entry.

DEPRECATED: this method will dissappear at some point in the future.

:param Provenance provenance: The provenance entry, as for instance obtained
from ts.provenance(0).
:rtype ProvenanceMetadata:
Expand All @@ -83,24 +88,26 @@ def parse_provenance(provenance):

def get_provenance(ts, only_last=True):
'''
Extracts model type, slim generation, and remembmered node count from either
the last entry in the provenance table that is tagged with "program"="SLiM"
(if ``only_last=True``) or a list of all of them (otherwise).
Extracts model type and slim generation from either the last entry in the
provenance table that is tagged with "program"="SLiM" (if
``only_last=True``) or a list of all of them (otherwise).

:param SlimTreeSequence ts: The tree sequence.
:param SlimTreeSequence ts: The tree sequence or table collection.
:param bool only_last: Whether to return only the last SLiM provenance entry,
(otherwise, returns a list of all SLiM entries).
:rtype ProvenanceMetadata:
'''
if isinstance(ts, tskit.TreeSequence):
ts = ts.tables
provenances = []
for j, p in enumerate(ts.tables.provenances):
for j, p in enumerate(ts.provenances):
is_slim, _ = slim_provenance_version(p)
if is_slim:
out = parse_provenance(p)
provenances.append(out)

if len(provenances) == 0:
raise ValueError("Tree sequence contains no SLiM provenance entries"
raise ValueError("Tree sequence is not a SLiM tree sequence "
"(or your pyslim is out of date).")
if only_last:
return provenances[-1]
Expand All @@ -113,6 +120,9 @@ def upgrade_slim_provenance(tables):
Copies the last provenance entry from a previous SLiM file version to that
required by the current file version.

DEPRECATED: this method will dissappear at some point in the future,
and this information is now stored in the tree sequence metadata.

:param TableCollection tables: the table collection
"""
prov_info = [(slim_provenance_version(p), json.loads(p.record))
Expand Down Expand Up @@ -141,8 +151,8 @@ def upgrade_slim_provenance(tables):

def get_environment():
"""
Returns a dictionary describing the environment in which msprime
is currently running.
Returns a dictionary describing the environment in which we are
currently running.
"""
env = {
"libraries": {
Expand Down Expand Up @@ -185,6 +195,8 @@ def make_pyslim_provenance_dict():
def make_slim_provenance_dict(model_type, slim_generation):
"""
Returns a dictionary encoding necessary provenance information for a SLiM tree sequence.

DEPRECATED: this will be removed in the future; if you need this, open an issue on github.
"""
document = {
"schema_version": "1.0.0",
Expand Down
Loading