Skip to content

Commit 83e759c

Browse files
Merge pull request #159 from jeromekelleher/v0.1.5-changes
V0.1.5 changes
2 parents ed2cc1f + 0aeef44 commit 83e759c

File tree

7 files changed

+80
-18
lines changed

7 files changed

+80
-18
lines changed

docs/conf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def __getattr__(cls, name):
4646
copyright = '2018-2019, Tskit developers'
4747
author = 'Tskit developers'
4848

49-
# The short X.Y version
50-
version = ''
51-
# The full version, including alpha/beta/rc tags
52-
release = ''
49+
# Following https://github.com/pypa/setuptools_scm#usage-from-sphinx
50+
from pkg_resources import get_distribution
51+
release = get_distribution(project).version
52+
version = '.'.join(release.split('.')[:2])
5353

5454
###################################################################
5555
#

python/CHANGELOG.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
--------------------
2-
[0.1.5] - 2019-XX-XX
2+
[0.1.5] - 2019-03-27
33
--------------------
44

5-
Under development.
6-
7-
This release removes support for Python 2.
5+
This release removes support for Python 2, adds more flexible tree access and a
6+
new ``tskit`` command line interface.
87

98
**New features**
109

1110
- Remove support for Python 2 (:user:`hugovk`). See :issue:`137` and :pr:`140`.
11+
- More flexible tree API (:pr:`121`). Adds ``TreeSequence.at`` and
12+
``TreeSequence.at_index`` methods to find specific trees, and efficient support
13+
for backwards traversal using ``reversed(ts.trees())``.
14+
- Add initial ``tskit`` CLI (:issue:`80`)
15+
- Add ``tskit info`` CLI command (:issue:`66`)
16+
- Enable drawing SVG trees with coloured edges (:user:`hyanwong`; :issue:`149`).
17+
- Add ``Tree.is_descendant`` method (:issue:`120`)
18+
- Add ``Tree.copy`` method (:issue:`122`)
19+
20+
**Bugfixes**
21+
22+
- Fixes to the low-level C API (:issue:`132` and :issue:`157`)
1223

1324
--------------------
1425
[0.1.4] - 2019-02-01

python/tests/test_highlevel.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import unittest
3636
import warnings
3737
import uuid as _uuid
38+
import pathlib
3839

3940
import numpy as np
4041
import msprime
@@ -1482,6 +1483,15 @@ def test_removed_methods(self):
14821483
self.assertRaises(NotImplementedError, ts.diffs)
14831484
self.assertRaises(NotImplementedError, ts.newick_trees)
14841485

1486+
def test_dump_pathlib(self):
1487+
ts = msprime.simulate(5, random_seed=1)
1488+
path = pathlib.Path(self.temp_dir) / "tmp.trees"
1489+
self.assertTrue(path.exists)
1490+
self.assertTrue(path.is_file)
1491+
ts.dump(path)
1492+
other_ts = tskit.load(path)
1493+
self.assertEqual(ts.tables, other_ts.tables)
1494+
14851495
def test_zlib_compression_warning(self):
14861496
ts = msprime.simulate(5, random_seed=1)
14871497
with warnings.catch_warnings(record=True) as w:

python/tskit/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Definitive location for the version number.
2-
tskit_version = "0.1.5.dev0"
2+
tskit_version = "0.1.5"

python/tskit/formats.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ def raise_hdf5_format_error(filename, original_exception):
255255
"File format {} is too old. Please use the ``tskit upgrade`` command "
256256
"to upgrade this file to the latest version".format(version))
257257
except (IOError, OSError, KeyError):
258-
raise exceptions.FileFormatError(str(original_exception))
258+
# We want to keep a useful error message here as well as the chaining history.
259+
raise exceptions.FileFormatError(str(original_exception)) from original_exception
259260

260261

261262
def _dump_legacy_hdf5_v2(tree_sequence, root):

python/tskit/provenance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ def validate_provenance(provenance):
131131
try:
132132
jsonschema.validate(provenance, schema)
133133
except jsonschema.exceptions.ValidationError as ve:
134-
raise exceptions.ProvenanceValidationError(str(ve))
134+
raise exceptions.ProvenanceValidationError from ve

python/tskit/trees.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ def aslist(self):
18911891
@classmethod
18921892
def load(cls, path):
18931893
ts = _tskit.TreeSequence()
1894-
ts.load(path)
1894+
ts.load(str(path))
18951895
return TreeSequence(ts)
18961896

18971897
@classmethod
@@ -1911,7 +1911,8 @@ def dump(self, path, zlib_compression=False):
19111911
warnings.warn(
19121912
"The zlib_compression option is no longer supported and is ignored",
19131913
RuntimeWarning)
1914-
self._ll_tree_sequence.dump(path)
1914+
# Convert the path to str to allow us use Pathlib inputs
1915+
self._ll_tree_sequence.dump(str(path))
19151916

19161917
@property
19171918
def tables(self):
@@ -2774,17 +2775,56 @@ def write_vcf(self, output, ploidy=1, contig_id="1"):
27742775
to the prefix ``msp_`` such that we would have the sample names
27752776
``msp_0``, ``msp_1`` and ``msp_2`` in the running example.
27762777
2777-
Example usage:
2778-
2779-
>>> with open("output.vcf", "w") as vcf_file:
2780-
>>> tree_sequence.write_vcf(vcf_file, 2)
2781-
27822778
.. warning::
27832779
This output function does not currently use information in the
27842780
:class:`IndividualTable`, and so will only correctly produce
27852781
non-haploid output if the nodes corresponding to each individual
27862782
are contiguous as described above.
27872783
2784+
Example usage:
2785+
2786+
.. code-block:: python
2787+
2788+
with open("output.vcf", "w") as vcf_file:
2789+
tree_sequence.write_vcf(vcf_file, 2)
2790+
2791+
The VCF output can also be compressed using the :mod:`gzip` module, if you wish:
2792+
2793+
.. code-block:: python
2794+
2795+
import gzip
2796+
with gzip.open("output.vcf.gz", "wt") as f:
2797+
ts.write_vcf(f)
2798+
2799+
However, this gzipped VCF may not be fully compatible with downstream tools
2800+
such as tabix, which may require the VCF use the specialised bgzip format.
2801+
A general way to convert VCF data to various formats is to pipe the text
2802+
produced by ``tskit`` into ``bcftools``, as done here:
2803+
2804+
.. code-block:: python
2805+
2806+
import os
2807+
import subprocess
2808+
2809+
read_fd, write_fd = os.pipe()
2810+
write_pipe = os.fdopen(write_fd, "w")
2811+
with open("output.bcf", "w") as bcf_file:
2812+
proc = subprocess.Popen(
2813+
["bcftools", "view", "-O", "b"], stdin=read_fd, stdout=bcf_file)
2814+
ts.write_vcf(write_pipe)
2815+
write_pipe.close()
2816+
os.close(read_fd)
2817+
proc.wait()
2818+
if proc.returncode != 0:
2819+
raise RuntimeError("bcftools failed with status:", proc.returncode)
2820+
2821+
This can also be achieved on the command line use the ``tskit vcf`` command,
2822+
e.g.:
2823+
2824+
.. code-block:: bash
2825+
2826+
$ tskit vcf example.trees | bcftools view -O b > example.bcf
2827+
27882828
:param File output: The file-like object to write the VCF output.
27892829
:param int ploidy: The ploidy of the individuals to be written to
27902830
VCF. This sample size must be evenly divisible by ploidy.

0 commit comments

Comments
 (0)