Skip to content
Commits on Source (9)
Release 4.4.0
-------------
- Calculation of birth-death likelihoods.
- Bipartitions inherit rooting state of trees.
- Patristic paths between tips can be tracked in ``PatristicDistanceMatrix``.
- Character column metadata annotations now actually possible.
- Standard character matrix defaults to 0-9 alphabet instead of just 01.
- Reorganization of package directory: from "$HOME/dendropy" and "$HOME/dendropy/test" to more modern "$HOME/src/dendropy" and "$HOME/tests" respectively.
Release 4.3.0
-------------
- [SumTrees]: Important bugfix in tracking splits on consensus tree from rooted trees: previously it was possible for a split on the consensus tree to be ignored, resulting in a null (0) edge length and no (0.0) support.
- Added ``sumlabels.py`` application.
- BD tree (``dendropy.model.birth_death_tree``) now allows for preservation of extinct tips.
- Birth-death tree (``dendropy.model.birth_death_tree``) now allows for preservation of extinct tips.
- Improved performance of character subset export
Release 4.2.0
......
This diff is collapsed.
......@@ -3,7 +3,7 @@ include CHANGES.rst
include LICENSE.rst
include doc/Makefile
recursive-include doc/source *
recursive-include dendropy/test/data *
recursive-include tests/data *
global-exclude .DS_Store
global-exclude *.pyc
global-exclude .gitignore
......
Metadata-Version: 1.1
Name: DendroPy
Version: 4.3.0
Version: 4.4.0
Summary: A Python library for phylogenetics and phylogenetic computing: reading, writing, simulation, processing and manipulation of phylogenetic trees (phylogenies) and characters.
Home-page: http://packages.python.org/DendroPy/
Author: Jeet Sukumaran and Mark T. Holder
Author-email: jeetsukumaran@gmail.com and mtholder@ku.edu
Author-email: jeetsukumaran@gmail.com, mtholder@ku.edu
License: BSD
Description: .. image:: https://raw.githubusercontent.com/jeetsukumaran/DendroPy/DendroPy4/doc/source/_static/dendropy_logo.png
:align: right
......@@ -57,56 +57,6 @@ Description: .. image:: https://raw.githubusercontent.com/jeetsukumaran/DendroPy
and more.
Testing
=======
.. note::
Note that some tests rely on PAUP* being available on your system.
You will need to set the environmental variable ``DENDROPY_PAUP_EXECUTABLE_PATH`` to the path
of the PAUP* executable for these tests to be run, e.g.::
DENDROPY_PAUP_EXECUTABLE_PATH=/usr/local/bin/paup python setup.py test
or::
DENDROPY_PAUP_EXECUTABLE_PATH=/usr/local/bin/paup python -m dendropy.test
If this variable is not set or set to "NONE", then any tests that rely on
PAUP* will NOT be run.
Tests can be run by typing::
$ python -m dendropy.test
By default, all tests are run. You can run specific by providing the
fully-qualified name of the modules, test cases, or specific test methods to
run, e.g.::
$ python -m dendropy.test test_tokenizer
$ python -m dendropy.test test_tokenizer.TestCase
$ python -m dendropy.test test_tokenizer.TestCase.test1
$ python -m dendropy.test test_tokenizer test_datamodel_taxon
Or special pre-defined sub-groups of tests, e.g.::
$ python -m dendropy.test @datamodel
$ python -m dendropy.test @dataio
$ python -m dendropy.test @datamodel @newick
A list of all available sub-groups can be seen by::
$ python -m dendropy.test --help-testgroups
For any tests run, you can set the level at which the test progress is logged
by::
$ python -m dendropy.test -l DEBUG all
For all options, type::
$ python -m dendropy.test --help
License and Warranty
====================
......@@ -115,7 +65,7 @@ Description: .. image:: https://raw.githubusercontent.com/jeetsukumaran/DendroPy
Current Release
===============
The current release of DendroPy is version 4.3.0 (master-e251bcf, 2017-07-06 21:23:19).
The current release of DendroPy is version 4.4.0.
Keywords: phylogenetics phylogeny phylogenies phylogeography evolution evolutionary biology systematics coalescent population genetics phyloinformatics bioinformatics
......
......@@ -49,56 +49,6 @@ This includes:
and more.
Testing
=======
.. note::
Note that some tests rely on PAUP* being available on your system.
You will need to set the environmental variable ``DENDROPY_PAUP_EXECUTABLE_PATH`` to the path
of the PAUP* executable for these tests to be run, e.g.::
DENDROPY_PAUP_EXECUTABLE_PATH=/usr/local/bin/paup python setup.py test
or::
DENDROPY_PAUP_EXECUTABLE_PATH=/usr/local/bin/paup python -m dendropy.test
If this variable is not set or set to "NONE", then any tests that rely on
PAUP* will NOT be run.
Tests can be run by typing::
$ python -m dendropy.test
By default, all tests are run. You can run specific by providing the
fully-qualified name of the modules, test cases, or specific test methods to
run, e.g.::
$ python -m dendropy.test test_tokenizer
$ python -m dendropy.test test_tokenizer.TestCase
$ python -m dendropy.test test_tokenizer.TestCase.test1
$ python -m dendropy.test test_tokenizer test_datamodel_taxon
Or special pre-defined sub-groups of tests, e.g.::
$ python -m dendropy.test @datamodel
$ python -m dendropy.test @dataio
$ python -m dendropy.test @datamodel @newick
A list of all available sub-groups can be seen by::
$ python -m dendropy.test --help-testgroups
For any tests run, you can set the level at which the test progress is logged
by::
$ python -m dendropy.test -l DEBUG all
For all options, type::
$ python -m dendropy.test --help
License and Warranty
====================
......
#! /usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
## DendroPy Phylogenetic Computing Library.
......
#! /usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
## DendroPy Phylogenetic Computing Library.
......
python-dendropy (4.4.0-1) unstable; urgency=medium
* New upstream version
* Point Vcs fields to salsa.debian.org
* Standards-Version: 4.1.4
-- Andreas Tille <tille@debian.org> Tue, 22 May 2018 16:36:45 +0200
python-dendropy (4.3.0+dfsg-1) unstable; urgency=medium
* New upstream version
......
......@@ -10,9 +10,9 @@ Build-Depends: debhelper (>= 11~),
python-setuptools,
python3-all,
python3-setuptools
Standards-Version: 4.1.3
Vcs-Browser: https://anonscm.debian.org/cgit/debian-med/python-dendropy.git
Vcs-Git: https://anonscm.debian.org/git/debian-med/python-dendropy.git
Standards-Version: 4.1.4
Vcs-Browser: https://salsa.debian.org/med-team/python-dendropy
Vcs-Git: https://salsa.debian.org/med-team/python-dendropy.git
Homepage: http://dendropy.org/
Package: python-dendropy
......
From c9c1c097f201f2ab2962ac450938c430b3d3dd2f Mon Sep 17 00:00:00 2001
From: Vachaspati <vachasp2@taubh1.campuscluster.illinois.edu>
Date: Fri, 19 Jun 2015 06:03:16 -0500
Subject: [PATCH] Fix bug where encoding for default locale is None.
---
dendropy/utility/textprocessing.py | 3 +++
1 file changed, 3 insertions(+)
--- a/dendropy/utility/textprocessing.py
+++ b/dendropy/utility/textprocessing.py
@@ -45,6 +45,9 @@ except ValueError:
if ENCODING == None:
ENCODING = 'UTF-8'
+if ENCODING == None:
+ ENCODING = 'UTF-8'
+
def bytes_to_text(s):
"""
Converts a byte string (as read from, e.g., standard input)
From b6b932e5c0bd65384015c759ebf281e561e4da07 Mon Sep 17 00:00:00 2001
From: Jeet Sukumaran <jeetsukumaran@gmail.com>
Date: Tue, 23 Jun 2015 10:04:34 -0400
Subject: [PATCH] Do not run PAUP-based tests unless path to PAUP is provided
---
README.rst | 15 ++
dendropy/interop/paup.py | 2 +-
dendropy/test/test_datamodel_split_bitmasks.py | 221 +++++++++++++------------
3 files changed, 129 insertions(+), 109 deletions(-)
--- a/README.rst
+++ b/README.rst
@@ -67,6 +67,21 @@ Testing
If this variable is not set or set to "NONE", then any tests that rely on
PAUP* will NOT be run.
+.. note::
+
+ Note that some tests rely on PAUP* being available on your system.
+ You will need to set the environmental variable ``DENDROPY_PAUP_EXECUTABLE_PATH`` to the path
+ of the PAUP* executable for these tests to be run, e.g.::
+
+ DENDROPY_PAUP_EXECUTABLE_PATH=/usr/local/bin/paup python setup.py test
+
+ or::
+
+ DENDROPY_PAUP_EXECUTABLE_PATH=/usr/local/bin/paup python -m unittest
+
+ If this variable is not set or set to "NONE", then any tests that rely on
+ PAUP* will NOT be run.
+
Tests can be run by typing::
$ python -m dendropy.test
0001-Fix-bug-where-encoding-for-default-locale-is-None.patch
0002-Do-not-run-PAUP-based-tests-unless-path-to-PAUP-is-p.patch
#! /usr/bin/env python
##############################################################################
## DendroPy Phylogenetic Computing Library.
##
## Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
## All rights reserved.
##
## See "LICENSE.rst" for terms and conditions of usage.
##
## If you use this work or any portion thereof in published work,
## please cite it as:
##
## Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
## for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################
#! /usr/bin/env python
##############################################################################
## DendroPy Phylogenetic Computing Library.
##
## Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
## All rights reserved.
##
## See "LICENSE.rst" for terms and conditions of usage.
##
## If you use this work or any portion thereof in published work,
## please cite it as:
##
## Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
## for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################
"""
DendroPy testing suite.
"""
import unittest
if __name__ == "__main__":
unittest.main()
#! /usr/bin/env python
##############################################################################
## DendroPy Phylogenetic Computing Library.
##
## Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
## All rights reserved.
##
## See "LICENSE.rst" for terms and conditions of usage.
##
## If you use this work or any portion thereof in published work,
## please cite it as:
##
## Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
## for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################
import sys
import os
import argparse
import collections
import unittest
from dendropy.utility import metavar
from dendropy.utility import messaging
sys.path.insert(0, os.path.dirname(__file__))
from dendropy.test.support import dendropytest
def main():
group_names = (
("@all" , ".*"),
("@datamodel" , ".*_datamodel_.*"),
("@dataio" , ".*_dataio_.*"),
("@newick" , ".*_newick_.*"),
("@tree" , ".*_tree_.*"),
)
test_group_patterns = collections.OrderedDict(group_names)
test_group_names = list(test_group_patterns)
parser = argparse.ArgumentParser()
parser.add_argument("test_names",
metavar="TEST",
nargs="*",
help= "Name of test(s) to run. These can be (dot-)qualified module, test"
"case, or test name (e.g., 'test_module', 'test_module.TestCase1',"
"'test_module.TestCase1.test1') or special pre-defined groups of"
"tests (e.g., '@datamodel', '@dataio'). Type '--help-testgroups' for"
"a list of available groups.")
parser.add_argument("--help-testgroups",
action="store_true",
default=False,
help="Show list of available test groups and exit.")
parser.add_argument("--list-only",
action="store_true",
default=False,
help="Do not actually run tests: just print list of test module names and exit.")
parser.add_argument("-v", "--verbosity",
default=3,
type=int,
help="Messaging noisiness (default: %(default)s)")
parser.add_argument("--logging-level",
default=os.environ.get(metavar.LOGGING_LEVEL_ENVAR, "NOTSET"),
choices=["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
help="Test logging level (default: '%(default)s')")
parser.add_argument("-f", "--fail-fast",
action="store_true",
default=False,
help="Stop the test run on the first error or failure.")
parser.add_argument("-I", "--fail-incomplete",
action="store_true",
default=False,
help="Fail incomplete or partially-complete test stubs.")
args = parser.parse_args()
if args.help_testgroups:
out = sys.stdout
out.write("Available special test groups:\n")
for name in test_group_names:
out.write(" - {}\n".format(name))
sys.exit(0)
# Set logging level:
os.environ[metavar.LOGGING_LEVEL_ENVAR] = args.logging_level
_LOG = messaging.get_logger("dendropy")
# Set test specifications
if args.fail_incomplete:
os.environ[metavar.FAIL_INCOMPLETE_TESTS_ENVAR] = "1"
# get test modules
test_names = []
filter_patterns = []
for name in args.test_names:
if name is None:
continue
if name.startswith("@"):
try:
filter_patterns.append(test_group_patterns[name])
except KeyError:
sys.exit("Unrecognized test group name '{}'. Accepted names: {}".format(name, test_group_names))
else:
name = name.replace(os.sep, ".")
if name.endswith(".py"):
name = name[:-3]
if not name.startswith("dendropy.test."):
if name.startswith("test."):
name = "dendropy." + name
else:
name = "dendropy.test." + name
test_names.append(name)
if not test_names and not filter_patterns:
test_names = dendropytest.discover_test_module_paths() # get all
if filter_patterns:
test_names.extend(dendropytest.discover_test_module_paths(filter_patterns))
test_names = sorted(set(test_names))
# 0: nothing
# 1: errors and mishaps only + 0
# 2: warnings + 1
# 3: general messages + 2
if args.verbosity >= 3 or args.list_only:
if args.list_only:
out = sys.stdout
else:
out = sys.stderr
out.write("DendroPy tests to be run:\n")
for mp in test_names:
out.write(" + {}\n".format(mp))
if args.list_only:
sys.exit(0)
tests = unittest.defaultTestLoader.loadTestsFromNames(test_names)
test_suite = unittest.TestSuite(tests)
test_runner = unittest.TextTestRunner(verbosity=args.verbosity, failfast=args.fail_fast)
test_runner.run(test_suite)
if __name__ == '__main__':
main()
#! /usr/bin/env python
##############################################################################
## DendroPy Phylogenetic Computing Library.
##
## Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
## All rights reserved.
##
## See "LICENSE.rst" for terms and conditions of usage.
##
## If you use this work or any portion thereof in published work,
## please cite it as:
##
## Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
## for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################
import dendropy
from dendropy.test.support import standard_file_test_trees
class NewickTreeListReaderTaxaManagementBaseTestCase(standard_file_test_trees.NewickTestTreesChecker):
def test_get(self):
tree_file_title = "dendropy-test-trees-n12-x2"
tree_filepath = self.schema_tree_filepaths[tree_file_title]
kwargs = {
"suppress_internal_node_taxa": self.__class__.suppress_internal_node_taxa,
"suppress_leaf_node_taxa": self.__class__.suppress_leaf_node_taxa,
}
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
(dendropy.TreeList.get_from_path, tree_filepath),
(dendropy.TreeList.get_from_stream, tree_stream),
(dendropy.TreeList.get_from_string, tree_string),
)
for method, src in approaches:
tree_list = method(src,
self.__class__.schema,
**kwargs)
self.verify_standard_trees(
tree_list=tree_list,
tree_file_title=tree_file_title)
def test_selective_taxa_read(self):
tree_file_title = "dendropy-test-trees-n12-x2"
tree_filepath = self.schema_tree_filepaths[tree_file_title]
kwargs = {
"suppress_internal_node_taxa": self.__class__.suppress_internal_node_taxa,
"suppress_leaf_node_taxa": self.__class__.suppress_leaf_node_taxa,
}
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
("read_from_path", tree_filepath),
("read_from_stream", tree_stream),
("read_from_string", tree_string),
)
for method, src in approaches:
tree_list = dendropy.TreeList()
old_id = id(tree_list)
f = getattr(tree_list, method)
f(src, self.__class__.schema, **kwargs)
new_id = id(tree_list)
self.verify_standard_trees(
tree_list=tree_list,
tree_file_title=tree_file_title)
#! /usr/bin/env python
##############################################################################
## DendroPy Phylogenetic Computing Library.
##
## Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
## All rights reserved.
##
## See "LICENSE.rst" for terms and conditions of usage.
##
## If you use this work or any portion thereof in published work,
## please cite it as:
##
## Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
## for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################
import random
import dendropy
from dendropy.test.support import standard_file_test_trees
class StandardTreesParsingTestCase(standard_file_test_trees.StandardTestTreesChecker):
def test_default_get(self):
for tree_file_title in [
"dendropy-test-trees-multifurcating-rooted",
"dendropy-test-trees-multifurcating-unrooted",
"dendropy-test-trees-n10-rooted-treeshapes",
"dendropy-test-trees-n14-unrooted-treeshapes",
]:
tree_filepath = self.schema_tree_filepaths[tree_file_title]
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
{"path": tree_filepath},
{"file": tree_stream},
{"data": tree_string},
)
for approach_kwargs in approaches:
approach_kwargs["schema"] = self.__class__.schema
tree_list = dendropy.TreeList.get(**approach_kwargs)
self.verify_standard_trees(tree_list=tree_list,
tree_file_title=tree_file_title)
def test_default_read(self):
preloaded_tree_file_title = "dendropy-test-trees-n33-unrooted-x10a"
preloaded_tree_reference = self.tree_references[preloaded_tree_file_title]
tree_file_title = "dendropy-test-trees-n33-unrooted-x10a"
tree_reference = self.tree_references[tree_file_title]
tree_filepath = self.schema_tree_filepaths[tree_file_title]
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
{"path": tree_filepath},
{"file": tree_stream},
{"data": tree_string},
)
for approach_kwargs in approaches:
# prepopulate
tree_list = dendropy.TreeList.get(
path=self.schema_tree_filepaths[preloaded_tree_file_title],
schema=self.__class__.schema)
# check to make sure trees were loaded
old_len = len(tree_list)
self.assertEqual(old_len, len(tree_list._trees))
self.assertEqual(old_len, preloaded_tree_reference["num_trees"])
self.verify_standard_trees(tree_list, preloaded_tree_file_title)
# load
old_id = id(tree_list)
approach_kwargs["schema"] = self.__class__.schema
trees_read = tree_list.read(**approach_kwargs)
new_id = id(tree_list)
self.assertEqual(old_id, new_id)
# make sure new trees added
new_len = len(tree_list)
self.assertEqual(new_len, len(tree_list._trees))
expected_number_of_trees = tree_reference["num_trees"]
self.assertEqual(old_len + expected_number_of_trees, new_len)
self.assertEqual(trees_read, expected_number_of_trees)
# check new trees
for tree_idx, tree in enumerate(tree_list[old_len:]):
self.compare_to_reference_by_title_and_index(
tree=tree,
tree_file_title=tree_file_title,
reference_tree_idx=tree_idx)
# make sure old ones still intact
for tree_idx, tree in enumerate(tree_list[:old_len]):
self.compare_to_reference_by_title_and_index(
tree=tree,
tree_file_title=preloaded_tree_file_title,
reference_tree_idx=tree_idx)
def test_tree_offset_get(self):
tree_file_title = "dendropy-test-trees-n33-unrooted-x100a"
tree_reference = self.tree_references[tree_file_title]
expected_number_of_trees = tree_reference["num_trees"]
tree_offsets = set([0, expected_number_of_trees-1, -1, -expected_number_of_trees])
while len(tree_offsets) < 8:
tree_offsets.add(random.randint(1, expected_number_of_trees-2))
while len(tree_offsets) < 12:
tree_offsets.add(random.randint(-expected_number_of_trees-2, -2))
tree_filepath = self.schema_tree_filepaths[tree_file_title]
with open(tree_filepath, "r") as src:
tree_string = src.read()
for tree_offset in tree_offsets:
with open(tree_filepath, "r") as tree_stream:
approaches = (
(dendropy.TreeList.get_from_path, tree_filepath),
(dendropy.TreeList.get_from_stream, tree_stream),
(dendropy.TreeList.get_from_string, tree_string),
)
for method, src in approaches:
tree_list = method(
src,
self.__class__.schema,
collection_offset=0,
tree_offset=tree_offset)
self.verify_standard_trees(
tree_list=tree_list,
tree_file_title=tree_file_title,
tree_offset=tree_offset)
def test_tree_offset_read(self):
tree_file_title = "dendropy-test-trees-n33-unrooted-x100a"
tree_reference = self.tree_references[tree_file_title]
expected_number_of_trees = tree_reference["num_trees"]
tree_offsets = set([0, expected_number_of_trees-1, -1, -expected_number_of_trees])
while len(tree_offsets) < 8:
tree_offsets.add(random.randint(1, expected_number_of_trees-2))
while len(tree_offsets) < 12:
tree_offsets.add(random.randint(-expected_number_of_trees-2, -2))
tree_filepath = self.schema_tree_filepaths[tree_file_title]
with open(tree_filepath, "r") as src:
tree_string = src.read()
for tree_offset in tree_offsets:
with open(tree_filepath, "r") as tree_stream:
approaches = (
("read_from_path", tree_filepath),
("read_from_stream", tree_stream),
("read_from_string", tree_string),
)
for method, src in approaches:
tree_list = dendropy.TreeList()
f = getattr(tree_list, method)
trees_read = f(src,
self.__class__.schema,
# collection_offset=0,
tree_offset=tree_offset)
self.verify_standard_trees(
tree_list=tree_list,
tree_file_title=tree_file_title,
tree_offset=tree_offset)
def test_out_of_range_tree_offset_get(self):
tree_file_title = 'dendropy-test-trees-n33-unrooted-x10a'
tree_filepath = self.schema_tree_filepaths[tree_file_title]
tree_reference = self.tree_references[tree_file_title]
expected_number_of_trees = tree_reference["num_trees"]
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
(dendropy.TreeList.get_from_path, tree_filepath),
(dendropy.TreeList.get_from_stream, tree_stream),
(dendropy.TreeList.get_from_string, tree_string),
)
for method, src in approaches:
with self.assertRaises(IndexError):
method(src, self.__class__.schema, collection_offset=0, tree_offset=expected_number_of_trees)
def test_out_of_range_tree_offset_read(self):
tree_file_title = 'dendropy-test-trees-n33-unrooted-x10a'
tree_filepath = self.schema_tree_filepaths[tree_file_title]
tree_reference = self.tree_references[tree_file_title]
expected_number_of_trees = tree_reference["num_trees"]
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
("read_from_path", tree_filepath),
("read_from_stream", tree_stream),
("read_from_string", tree_string),
)
for method, src in approaches:
tree_list = dendropy.TreeList()
f = getattr(tree_list, method)
with self.assertRaises(IndexError):
f(src, self.__class__.schema, collection_offset=0, tree_offset=expected_number_of_trees)
def test_out_of_range_collection_offset_get(self):
tree_file_title = 'dendropy-test-trees-n33-unrooted-x10a'
tree_filepath = self.schema_tree_filepaths[tree_file_title]
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
(dendropy.TreeList.get_from_path, tree_filepath),
(dendropy.TreeList.get_from_stream, tree_stream),
(dendropy.TreeList.get_from_string, tree_string),
)
for method, src in approaches:
with self.assertRaises(IndexError):
method(src, self.__class__.schema, collection_offset=1, tree_offset=0)
def test_out_of_range_collection_offset_read(self):
tree_file_title = 'dendropy-test-trees-n33-unrooted-x10a'
tree_filepath = self.schema_tree_filepaths[tree_file_title]
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
("read_from_path", tree_filepath),
("read_from_stream", tree_stream),
("read_from_string", tree_string),
)
for method, src in approaches:
tree_list = dendropy.TreeList()
f = getattr(tree_list, method)
with self.assertRaises(IndexError):
f(src, self.__class__.schema, collection_offset=1, tree_offset=0)
def test_unsupported_keyword_arguments_get(self):
tree_file_title = 'dendropy-test-trees-n12-x2'
tree_filepath = self.schema_tree_filepaths[tree_file_title]
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
(dendropy.TreeList.get_from_path, tree_filepath),
(dendropy.TreeList.get_from_stream, tree_stream),
(dendropy.TreeList.get_from_string, tree_string),
)
for method, src in approaches:
with self.assertRaises(TypeError):
method(src,
self.__class__.schema,
suppress_internal_taxa=True, # should be suppress_internal_node_taxa
gobbledegook=False,
)
def test_unsupported_keyword_arguments_read(self):
tree_file_title = 'dendropy-test-trees-n12-x2'
tree_filepath = self.schema_tree_filepaths[tree_file_title]
with open(tree_filepath, "r") as src:
tree_string = src.read()
with open(tree_filepath, "r") as tree_stream:
approaches = (
("read_from_path", tree_filepath),
("read_from_stream", tree_stream),
("read_from_string", tree_string),
)
for method, src in approaches:
tree_list = dendropy.TreeList()
f = getattr(tree_list, method)
with self.assertRaises(TypeError):
f(src,
self.__class__.schema,
suppress_internal_taxa=True, # should be suppress_internal_node_taxa
gobbledegook=False,
)
#! /usr/bin/env python
##############################################################################
## DendroPy Phylogenetic Computing Library.
##
## Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
## All rights reserved.
##
## See "LICENSE.rst" for terms and conditions of usage.
##
## If you use this work or any portion thereof in published work,
## please cite it as:
##
## Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
## for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################
#! /usr/bin/env python
##############################################################################
## DendroPy Phylogenetic Computing Library.
##
## Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
## All rights reserved.
##
## See "LICENSE.rst" for terms and conditions of usage.
##
## If you use this work or any portion thereof in published work,
## please cite it as:
##
## Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
## for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################
"""
Benchmarking NEWICK tree parsing using a light tree data model.
"""
import sys
import os
import timeit
import argparse
from dendropy.utility.textprocessing import StringIO
from dendropy.utility import messaging
from dendropy.test.support import pathmap
from dendropy.dataio import nexusprocessing
from dendropy.dataio import newickreader
TREE_FILENAMES = [
"APG_Angiosperms.newick",
"GEBA.tree.newick",
"feb032009.trees.newick",
"Bininda-emonds_2007_mammals.newick",
"Jetz_et_al_2012_Aves.sample.tree.newick",
"Smith_2001_angiosperms.newick",
]
class Tree(object):
def __init__(self):
self.seed_node = Node()
def node_factory(self):
return Node()
class Node(object):
def __init__(self,
taxon=None,
label=None,
edge=None,
edge_length=None):
self.age = None
self._edge = None
self._child_nodes = []
self._parent_node = None
if edge is not None:
self.edge = edge
else:
self.edge = Edge(head_node=self,
length=edge_length)
self.label = label
def add_child(self, node):
self._child_nodes.append(node)
###########################################################################
## Hacked-in NEWICK representation.
def as_newick_string(self, **kwargs):
"""
This returns the Node as a NEWICK statement according to the given
formatting rules. This should be used for debugging purposes only.
For production purposes, use the the full-fledged 'as_string()'
method of the object.
"""
out = io.StringIO()
self.write_newick(out, **kwargs)
return out.getvalue()
def write_newick(self, out, **kwargs):
"""
This returns the Node as a NEWICK statement according to the given
formatting rules. This should be used for debugging purposes only. For
production purposes, use the the full-fledged 'write_to_stream()'
method of the object.
"""
child_nodes = self._child_nodes
if child_nodes:
out.write('(')
f_child = child_nodes[0]
for child in child_nodes:
if child is not f_child:
out.write(',')
child.write_newick(out, **kwargs)
out.write(')')
if self.label is not None:
out.write(self.label)
if self.edge.length is not None:
out.write(":{}".format(self.edge.length))
class Edge(object):
def __init__(self,
tail_node=None,
head_node=None,
length=None,
rootedge=False,
label=None):
self.tail_node = tail_node
self.head_node = head_node
self.rootedge = rootedge
self.length = length
def tree_parsing_fn_factory(src_paths, verbose=False):
def f():
for src_path in src_paths:
if verbose:
sys.stderr.write(" .. {}\n".format(src_path))
src = open(src_path, "rU")
nt = nexusprocessing.NexusTokenizer(src)
np = newickreader.NewickTreeParser()
while True:
t = np.parse_tree_statement(nt, tree_factory=Tree)
if t is None:
break
return f
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("-f", "--target-file",
type=str,
dest="target_files",
default=[],
action="append",
help="""Path to file to be tokenized; option may be specified multiple times for multiple files. If not specified, default target set will be used.""")
parser.add_argument("-r", "--repeat",
type=int,
default=10,
help="Repeat each tokenization this number of times (default=%(default)s).")
parser.add_argument("--delimited_output",
action="store_true",
default=False,
help="Output in tab-delimited instead of aligned format")
parser.add_argument("--delimited-output",
action="store_true",
default=False,
help="Output in tab-delimited instead of aligned format")
args = parser.parse_args()
messenger = messaging.ConsoleMessenger(name="-benchmark")
src_descs = []
src_paths = []
results = []
if args.target_files:
for f in args.target_files:
ff = os.path.expanduser(os.path.expandvars(f))
src_paths.append(ff)
src_descs.append( ("User", f) )
else:
messenger.info("No sources specified: adding default benchmark target set")
for f in TREE_FILENAMES:
ff = pathmap.tree_source_path(f)
src_paths.append(ff)
src_descs.append( ("Default", f) )
for src_path, src_desc in zip(src_paths, src_descs):
messenger.info("Processing: '{}'".format(src_desc[1]))
t = timeit.Timer(tree_parsing_fn_factory([src_path]))
result = min(t.repeat(args.repeat, 1))
messenger.info("Best time (of {} repetions): {:.10f} seconds".format(args.repeat, result))
results.append(result)
messenger.info("Benchmarking complete: all files processed")
if args.delimited_output:
result_template = "{}\t{}\t{:.10f}\n"
header_template = "{}\t{}\t{}\n"
else:
max_len1 = max(len(r[0]) for r in src_descs)
max_len2 = max(len(r[1]) for r in src_descs)
col1 = "{{:{}}}".format(max_len1)
col2 = "{{:{}}}".format(max_len2)
result_template = "[" + col1 + "] " + col2 + " {:.10f}\n"
header_template = col1 + " " + col2 + " {}\n"
sys.stdout.write(header_template.format("Type", "File", "Seconds"))
for result, src_desc in zip(results, src_descs):
sys.stdout.write(result_template.format(src_desc[0], src_desc[1], result))
if __name__ == "__main__":
main()
#! /usr/bin/env python
##############################################################################
## DendroPy Phylogenetic Computing Library.
##
## Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
## All rights reserved.
##
## See "LICENSE.rst" for terms and conditions of usage.
##
## If you use this work or any portion thereof in published work,
## please cite it as:
##
## Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
## for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################
"""
Benchmarking tree parsing.
"""
import sys
import os
import timeit
import argparse
from dendropy.utility import messaging
from dendropy.test.support import pathmap
import dendropy
TREE_FILENAMES = [
"APG_Angiosperms.newick",
"GEBA.tree.newick",
"feb032009.trees.newick",
"Bininda-emonds_2007_mammals.newick",
"Jetz_et_al_2012_Aves.sample.tree.newick",
"Smith_2001_angiosperms.newick",
]
def tree_parsing_fn_factory(src_paths, verbose=False):
def f():
trees = dendropy.TreeList()
for src_path in src_paths:
if verbose:
sys.stderr.write(" .. {}\n".format(src_path))
trees.read_from_path(src_path, "newick")
return f
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("-f", "--target-file",
type=str,
dest="target_files",
default=[],
action="append",
help="""Path to file to be tokenized; option may be specified multiple times for multiple files. If not specified, default target set will be used.""")
parser.add_argument("-r", "--repeat",
type=int,
default=10,
help="Repeat each tokenization this number of times (default=%(default)s).")
parser.add_argument("--delimited_output",
action="store_true",
default=False,
help="Output in tab-delimited instead of aligned format")
parser.add_argument("--delimited-output",
action="store_true",
default=False,
help="Output in tab-delimited instead of aligned format")
args = parser.parse_args()
messenger = messaging.ConsoleMessenger(name="-benchmark")
src_descs = []
src_paths = []
results = []
if args.target_files:
for f in args.target_files:
ff = os.path.expanduser(os.path.expandvars(f))
src_paths.append(ff)
src_descs.append( ("User", f) )
else:
messenger.info("No sources specified: adding default benchmark target set")
for f in TREE_FILENAMES:
ff = pathmap.tree_source_path(f)
src_paths.append(ff)
src_descs.append( ("Default", f) )
for src_path, src_desc in zip(src_paths, src_descs):
messenger.info("Processing: '{}'".format(src_desc[1]))
t = timeit.Timer(tree_parsing_fn_factory([src_path]))
result = min(t.repeat(args.repeat, 1))
messenger.info("Best time (of {} repetions): {:.10f} seconds".format(args.repeat, result))
results.append(result)
messenger.info("Benchmarking complete: all files processed")
if args.delimited_output:
result_template = "{}\t{}\t{:.10f}\n"
header_template = "{}\t{}\t{}\n"
else:
max_len1 = max(len(r[0]) for r in src_descs)
max_len2 = max(len(r[1]) for r in src_descs)
col1 = "{{:{}}}".format(max_len1)
col2 = "{{:{}}}".format(max_len2)
result_template = "[" + col1 + "] " + col2 + " {:.10f}\n"
header_template = col1 + " " + col2 + " {}\n"
sys.stdout.write(header_template.format("Type", "File", "Seconds"))
for result, src_desc in zip(results, src_descs):
sys.stdout.write(result_template.format(src_desc[0], src_desc[1], result))
if __name__ == "__main__":
main()