## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Test character generation """ import unittest import subprocess import re import os import sys from dendropy import dataio from dendropy import get_logger _LOG = get_logger("CharacterSimulationAndGeneration") from dendropy.tests import paup, is_test_enabled, TestLevel from dendropy import chargen tree_model_string = """ #NEXUS BEGIN TAXA; DIMENSIONS NTAX=5; TAXLABELS A B C D E ;
#!/usr/bin/env python import sys import shutil import os import re import random from dendropy import get_logger _LOG = get_logger("igarli_master.py") num_bootstrap_reps = 100 script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) if len(sys.argv) < 2: sys.exit("Expecting a data file (NEXUS) as an argument") dataf = open(sys.argv[1], 'rU') dim_pat = re.compile(r'\s*dimensions\s*ntax\s*=\s*(\d+)\s*nchar\s*=\s*(\d+)', re.I) rev_dim_pat = re.compile( r'\s*dimensions\s*nchar\s*=\s*(\d+)\s*ntax\s*=\s*(\d+)', re.I) n_taxa = None n_char = None for line in dataf: m = dim_pat.match(line) if m: n_taxa, n_char = [int(i) for i in m.groups()] break else: m = rev_dim_pat.match(line) if m:
## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ dendropy testing suite """ import unittest import os import re import sys from dendropy import get_logger from dendropy.utils import find_files _LOG = get_logger("tests") class TestLevel: FAST, NORMAL, SLOW, EXHAUSTIVE = 0, 10, 20, 30 def name(i): if i <= TestLevel.FAST: return "FAST" if i <= TestLevel.NORMAL: return "NORMAL" if i <= TestLevel.SLOW: return "SLOW" return "EXHAUSTIVE" name = staticmethod(name) def name_to_int(l): try:
import getpass except: pass import platform import dendropy from dendropy import nexus from dendropy import splits from dendropy import treesum from dendropy import datasets from dendropy import trees from dendropy import treegen from dendropy import get_logger from dendropy.datasets import Dataset from dendropy.dataio import MultiFileTreeIterator _LOG = get_logger("symmdiff_by_split_cutoff") _program_name = 'symmdiff_by_split_cutoff' _program_version = "0.01" _program_author = 'Mark T. Holder' _program_contact = '*****@*****.**' _program_copyright = "Copyright (C) 2008 Mark T. Holder.\n" \ "License GPLv3+: GNU GPL version 3 or later.\n" \ "This is free software: you are free to change\nand redistribute it. " \ "There is NO WARRANTY,\nto the extent permitted by law." def main_cli(): description = '%s %s ' % (_program_name, _program_version) usage = "%prog [options] <TREES FILE> [<TREES FILE> [<TREES FILE> [...]]"
## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tests optional tree modifiers. """ import random import unittest import itertools from dendropy import get_logger from dendropy.datasets import Dataset from dendropy.tests.debugging_random import DebuggingRandom from dendropy.tests.util_for_testing import assert_vec_approx_equal, assert_approx_equal import dendropy.tests _LOG = get_logger("TreeModification") ### MODULE THAT WE ARE TESTING ### from dendropy.treecalc import pybus_harvey_gamma ### MODULE THAT WE ARE TESTING ### class CalcTreeTest(unittest.TestCase): def testPHGamma(self): newick = "((t5:0.161175,t6:0.161175):0.392293,((t4:0.104381,(t2:0.075411,t1:0.075411):0.028969):0.065840,t3:0.170221):0.383247);" d = Dataset() tree = d.trees_from_string(string=newick, format="NEWICK")[0] assert_approx_equal(pybus_harvey_gamma(tree), 0.546276) if __name__ == "__main__":
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tests tree traversal. """ import unittest from dendropy import get_logger from dendropy.datasets import Dataset import dendropy.tests _LOG = get_logger("TreeStructureAndTraversal") ### MODULE THAT WE ARE TESTING ### from dendropy import trees ### MODULE THAT WE ARE TESTING ### class TreeIterTest(unittest.TestCase): def build_fixed_basic_tree1(self): """ Returns a bifurcating basic tree looking like: http://en.wikipedia.org/wiki/Tree_traversal ( ( A, ( C, E
## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ import sys import re import copy from cStringIO import StringIO from dendropy.taxa import TaxaBlock from dendropy.datasets import Dataset from dendropy.splits import encode_splits, is_trivial_split, find_edge_from_split, SplitDistribution from dendropy.treesum import TreeSummarizer from dendropy import get_logger _LOG = get_logger("igarli_neighborhood.py") #garli_dna_model_pattern = r'\[!GarliModel r ([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) e ([.0-9]*) ([.0-9]*) ([.0-9]*) [.0-9]* a ([.0-9]*) p ([.0-9]*) \]' garli_dna_model_pattern = r'\[!GarliModel\s*(r [.0-9]* [.0-9]* [.0-9]* [.0-9]* [.0-9]* e [.0-9]* [.0-9]* [.0-9]* [.0-9]* a [.0-9]* p [.0-9]*)\s*\]' garli_after_name_tm_pattern = r'\s*=\s*\[&U\]\[!GarliScore ([-.0-9]*)\]\s*%s\s*(\(.*\))\s*;' % garli_dna_model_pattern garli_after_name_tree_pattern = r'\s*=\s*\[&U\]\[!GarliScore ([-.0-9]*)\]\s*(\(.*\))\s*;' tree_prefix = r'\[iGarli\s*(\d+)\s*\] tree [a-zA-Z0-9_]+' tm_pat_string = tree_prefix + garli_after_name_tm_pattern tree_pat_string = tree_prefix + garli_after_name_tree_pattern garli_tree_model_pat = re.compile(tm_pat_string) garli_tree_pat = re.compile(tree_pat_string)
""" Various calls to PAUP* to calculate stuff. """ import os import sys import subprocess import tempfile import re import csv import unittest import dendropy.tests from dendropy import get_logger _LOG = get_logger("PAUPWrapper") from dendropy import datasets from dendropy import dataio from dendropy import taxa from dendropy import splits from dendropy import utils if "PAUP_PATH" in os.environ: PAUP_PATH = os.environ["PAUP_PATH"] else: PAUP_PATH = "paup" ###############################################################################
## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tests dataset reading & writing """ import unittest import csv from dendropy import get_logger import dendropy.tests _LOG = get_logger("DatsetReadWrite") from dendropy import datasets class DatasetReadTest(unittest.TestCase): def compare_chars(self, src, format, expected): """Reads 'src', checks against 'expected'""" _LOG.info("Reading %s" % src.name) d = datasets.Dataset() d.read(src, format) taxa_block = d.taxa_blocks[0] char_block = d.char_blocks[0] assert len(expected) == len(char_block)
trees, models etc. """ import os import sys if sys.version_info > (3, ): from io import StringIO else: from cStringIO import StringIO from dendropy import base from dendropy import taxa from dendropy import characters from dendropy import trees from dendropy import get_logger _LOG = get_logger("dendropy.datasets") def cache_reader_state(reader, **kwargs): cache = { "encode_splits": reader.encode_splits, "finish_node_func": reader.finish_node_func, } reader.encode_splits = kwargs.get("encode_splits", False) reader.finish_node_func = kwargs.get("finish_node_func") r = kwargs.get("default_rooting") if r is not None: cache["default_rooting"] = reader.default_rooting reader.default_rooting = r return cache
""" Tests of the strict consensus merger """ import os import sys import unittest import copy from dendropy import get_logger from dendropy.taxa import TaxaBlock from dendropy.splits import encode_splits from dendropy.dataio import trees_from_newick from dendropy.tests import is_test_enabled, TestLevel from dendropy.treedists import symmetric_difference from dendropy.tests.debugging_random import DebuggingRandom from dendropy.treegen import randomly_reorient_tree _LOG = get_logger("StrictConsensusMerger") ### MODULE THAT WE ARE TESTING ### from dendropy.scripts.strict_consensus_merge import strict_consensus_merge ### MODULE THAT WE ARE TESTING ### _counter = 0 class SCMTest(unittest.TestCase): def kernelOfTest(self, trees): expected = trees[-1] input = trees[:-1] output = strict_consensus_merge(input) encode_splits(output) encode_splits(expected)
############################################################################ """ This module handles the core definition of tree data structure class, as well as all the structural classes that make up a tree. """ import sys if sys.version_info > (3, ): from io import StringIO else: from cStringIO import StringIO from dendropy import base from dendropy import taxa import math from dendropy import get_logger _LOG = get_logger('dendropy.trees') ############################################################################## ## TreesBlock class TreesBlock(list, taxa.TaxaLinked): "Tree manager." def __init__(self, *args, **kwargs): "Inits. Handles keyword arguments: `oid`, `label` and `taxa_block`." list.__init__(self, *args) taxa.TaxaLinked.__init__(self, *args, **kwargs) def normalize_taxa(self, taxa_block=None, clear=True): """
#!/usr/bin/env python import sys import copy import logging from dendropy import dataio from dendropy.splits import encode_splits, split_to_list, count_bits, lowest_bit_only from dendropy import get_logger from dendropy.treemanip import collapse_clade, collapse_edge from dendropy.trees import format_split _LOG = get_logger('scripts.strict_consensus_merge') verbose = False IS_DEBUG_LOGGING = _LOG.isEnabledFor(logging.DEBUG) from dendropy.utils import NormalizedBitmaskDict def reroot_on_lowest_common_index_path(t, common_mask): """This operation is only for unrooted trees that are being merged using SCM. The path the separates the lowest index taxon in the leaf set intersection is placed as the first descendant path of the "seed_node" for the tree. This assures that all split representations are oriented in the same way for subsequent operations. The mask most contain more that 2 bits (there must be an internal node in the tree that is has degree > 2 wrt the common leafset). """ l = lowest_bit_only(common_mask) assert (l > 0) assert (count_bits(common_mask) > 2)
## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Split calculation and management. """ import sys from dendropy import taxa from dendropy import trees from dendropy import treegen from dendropy import utils from dendropy import get_logger _LOG = get_logger("dendropy.splits") def lowest_bit_only(s): m = s & (s - 1) return m ^ s __n_bits_set = (0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4) def count_bits(a): '''Returns the number of bits set to one.''' global __n_bits_set if sys.version_info >= (3, ): c = int(a)
""" Test split summarization, consensus tree building etc. """ import unittest import subprocess import re import os import sys from dendropy import nexus from dendropy import get_logger import dendropy.tests from dendropy.tests import paup, is_test_enabled, TestLevel _LOG = get_logger("Splits") from dendropy import nexus from dendropy import treesum from dendropy import taxa from dendropy import splits large_cases = [ #('7180.tre', '7180.tre'), #('terrarana.random.unrooted.100.tre', 'terrarana.random.unrooted.100.tre'), ('terrarana.random.unrooted.30.tre', 'terrarana.random.rooted.30.tre'), ('anolis.mcmct.trees.nexus', 'anolis.chars.nexus'), ] small_cases = [ ('feb032009.tre', 'feb032009.tre'), ('maj-rule-bug1.tre', 'maj-rule-bug1.tre'), ('maj-rule-bug2.tre', 'maj-rule-bug2.tre'),
## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tests character block manipulations. """ import unittest from copy import deepcopy from dendropy import get_logger from dendropy import get_logging_level import dendropy.tests from dendropy import datasets _LOG = get_logger("CharacterBlockStructure") from dendropy import characters class CharStructTest(unittest.TestCase): def testCharBlockMerge(self): ds1 = datasets.Dataset() tb1 = ds1.add_taxa_block(label="Dataset 1, Taxa Block 1") for i in range(1, 11): tb1.add_taxon(label="T%02d" % i) cb1 = ds1.add_char_block(char_block=characters.DnaCharactersBlock( label="Dataset 2, Taxa Block 1")) for t in tb1: cb1.append_taxon_sequence(t, state_symbols="AAAAAAAAAA")
## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ This module provides classes and methods for managing taxa. """ import sys from dendropy import base, get_logger _LOG = get_logger('dendropy.taxa') if sys.version_info[1] > 5 or sys.version_info[0] > 2: def int_to_bitstring(n): assert n >= 0 return bin(n)[2:] else: def int_to_bitstring(n): m = 1 sl = [] while m <= n: if m & n: sl.insert(0, '1') else:
## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tests coalescence calculations. """ import unittest from dendropy import get_logger from dendropy import datasets _LOG = get_logger("TreeCoal") ### MODULE THAT WE ARE TESTING ### from dendropy import coalescent ### MODULE THAT WE ARE TESTING ### class CalcIntervalsTest(unittest.TestCase): def testSimple1(self): d = datasets.Dataset() t = d.trees_from_string( "((((a:1, b:1):1, c:2):1, d:3, e:3):2, (f:4, g:4):1)", "newick")[0] i1 = coalescent.coalescence_intervals(t) assert i1 == [1.0, 1.0, 1.0, 1.0, 1.0], "intervals found = %s" % ", ".join(intervals) i2 = coalescent.num_genes_waiting_times_pairs(t)
## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tests tree distances. """ import random import unittest import math import copy from dendropy import get_logger from dendropy.treedists import symmetric_difference from dendropy.splits import encode_splits, split_to_list, count_bits, lowest_bit_only import dendropy.tests _LOG = get_logger("TreeGenerationAndSimulation") from dendropy import dataio from dendropy.tests.util_for_testing import assert_approx_equal, assert_vec_approx_equal, assert_mat_approx_equal ### MODULE THAT WE ARE TESTING ### from dendropy.treemanip import * ### MODULE THAT WE ARE TESTING ### class TreeManipTest(unittest.TestCase): def testCollapseEdge(self): tree = dataio.trees_from_newick(["((t5,t6),((t4,(t2,t1)),t3));" ]).trees_blocks[0][0] root = tree.seed_node self.assertEqual(str(tree), "((t5,t6),((t4,(t2,t1)),t3))")
## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tests various utilities """ import unittest from dendropy import get_logger import dendropy.tests _LOG = get_logger("Utilities") ### MODULES THAT WE ARE TESTING ### from dendropy import utils ### MODULES THAT WE ARE TESTING ### class NormalizedBitmaskDict(unittest.TestCase): def test_complementing(self): mask = 0xFF # 1111 1111 splits = [ ((0x03, '0000 0011'), (0x03, '0000 0011')), ((0x34, '0011 0100'), (0xCB, '1100 1011')), ((0x44, '0100 0100'), (0xBB, '1011 1011')),
import cStringIO from optparse import OptionParser from subprocess import Popen, PIPE from dendropy import nexus from dendropy.splits import encode_splits, lowest_bit_only, iter_split_indices, find_edge_from_split, collapse_conflicting, is_trivial_split, split_as_string_rev from dendropy.characters import CharactersBlock from dendropy.taxa import TaxaBlock from dendropy.treedists import symmetric_difference from dendropy import treesum from dendropy.trees import format_split, TreesBlock from dendropy import treegen from dendropy import get_logger from dendropy.datasets import Dataset from dendropy.utils import LineReadingThread, Event _LOG = get_logger("incrGarl.py") _program_name = 'incrGarl.py' _program_version = "0.01" _program_author = 'Mark T. Holder' _program_contact = '*****@*****.**' _program_copyright = "Copyright (C) 2008 Mark T. Holder.\n" \ "License GPLv3+: GNU GPL version 3 or later.\n" \ "This is free software: you are free to change\nand redistribute it. " \ "There is NO WARRANTY,\nto the extent permitted by law." TAXON_TO_TRANSLATE = {} GARLI_GENERAL = ( "datafname", "constraintfile",
import os import sys from dendropy import nexus from dendropy import get_logger import dendropy.tests from dendropy.tests import is_test_enabled, TestLevel import itertools from dendropy.treedists import symmetric_difference from dendropy.splits import SplitDistribution from dendropy.treesum import TreeSummarizer from dendropy import dataio from dendropy.nexus import RootingInterpretation from dendropy.splits import encode_splits from dendropy.datasets import Dataset _LOG = get_logger("SumTreesTesting") class SumTreesTest(unittest.TestCase): def setUp(self): self.sumtrees_path = dendropy.tests.scripts_source_path("sumtrees.py") def compose_sumtrees_command(self, args): return "%s %s" % (self.sumtrees_path, " ".join(args)) def runSumTrees(self, args): command = self.compose_sumtrees_command(args) _LOG.debug("Invocation:\n" + command) run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tree summarization. """ import sys from dendropy import splits from dendropy import taxa from dendropy import trees from dendropy import treegen from dendropy import get_logger _LOG = get_logger("dendropy.treesum") def shallowest_containing_node(start_node, split, taxa_mask): """Returns the shallowest node in the tree (the node furthest from `start_node`) that has all of the taxa that are specified in `split` or None if no appropriate node is found. Assumes that edges on tree have been decorated with splits. It is possible that split is not compatible with the subtree that is returned! (compatibility tests are not fully performed). This function is used to find the "insertion point" for a new split via a root to tip search. """
import os import sys import itertools import copy from optparse import OptionParser from dendropy import nexus from dendropy.splits import encode_splits, lowest_bit_only from dendropy import treesum from dendropy import datasets from dendropy.trees import format_split from dendropy import treegen from dendropy import get_logger from dendropy.datasets import Dataset _LOG = get_logger("incrGarl.py") _program_name = 'incrGarl.py' _program_version = "0.01" _program_author = 'Mark T. Holder' _program_contact = '*****@*****.**' _program_copyright = "Copyright (C) 2008 Mark T. Holder.\n" \ "License GPLv3+: GNU GPL version 3 or later.\n" \ "This is free software: you are free to change\nand redistribute it. " \ "There is NO WARRANTY,\nto the extent permitted by law." TAXON_TO_TRANSLATE = {} GARLI_GENERAL = ( "datafname", "constraintfile",
import os from optparse import OptionGroup from optparse import OptionParser import sys if sys.version_info > (3, ): from io import StringIO else: from cStringIO import StringIO from dendropy import get_logger from dendropy.datasets import Dataset from dendropy import get_logging_level import dendropy.tests _LOG = get_logger("TreeParsingAndWriting") from dendropy import taxa from dendropy import trees from dendropy import utils from dendropy.splits import encode_splits from dendropy import treedists from dendropy import datasets ### MODULES THAT WE ARE TESTING ### from dendropy import nexus # from dendropy import nexml ### MODULES THAT WE ARE TESTING ### def iterate_on_trees(tree_files, tf_iterator=nexus.iterate_over_trees):
## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ import sys import re import copy from cStringIO import StringIO from dendropy.taxa import TaxaBlock from dendropy.datasets import Dataset from dendropy.splits import encode_splits, is_trivial_split, find_edge_from_split, SplitDistribution from dendropy.treesum import TreeSummarizer from dendropy import get_logger _LOG = get_logger("igarli_select.py") # this should not be hard coded MAX_TREES_CARRIED_OVER = 1000 SPLIT_DIVERSITY_MULTIPLIER = 1.0 #garli_dna_model_pattern = r'\[!GarliModel r ([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) e ([.0-9]*) ([.0-9]*) ([.0-9]*) [.0-9]* a ([.0-9]*) p ([.0-9]*) \]' garli_dna_model_pattern = r'\[!GarliModel\s*(r [.0-9]* [.0-9]* [.0-9]* [.0-9]* [.0-9]* e [.0-9]* [.0-9]* [.0-9]* [.0-9]* a [.0-9]* p [.0-9]*)\s*\]' garli_after_name_tm_pattern = r'\s*=\s*\[&U\]\[!GarliScore ([-.0-9]*)\]\s*%s\s*(\(.*\))\s*;' % garli_dna_model_pattern garli_after_name_tree_pattern = r'\s*=\s*\[&U\]\[!GarliScore ([-.0-9]*)\]\s*(\(.*\))\s*;' tree_prefix = r'\[iGarli\s*(\d+)\s*\] tree [a-zA-Z0-9_]+' tm_pat_string = tree_prefix + garli_after_name_tm_pattern
## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ import sys import re import copy from cStringIO import StringIO from dendropy.taxa import TaxaBlock from dendropy.datasets import Dataset from dendropy.splits import encode_splits, is_trivial_split, find_edge_from_split, SplitDistribution from dendropy.treesum import TreeSummarizer from dendropy import get_logger _LOG = get_logger("igarli_select.py") # this should not be hard coded MAX_TREES_CARRIED_OVER = 1000 SPLIT_DIVERSITY_MULTIPLIER = 1.0 #garli_dna_model_pattern = r'\[!GarliModel r ([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) e ([.0-9]*) ([.0-9]*) ([.0-9]*) [.0-9]* a ([.0-9]*) p ([.0-9]*) \]' garli_dna_model_pattern = r'\[!GarliModel\s*(r [.0-9]* [.0-9]* [.0-9]* [.0-9]* [.0-9]* e [.0-9]* [.0-9]* [.0-9]* [.0-9]* a [.0-9]* p [.0-9]*)\s*\]' garli_after_name_tm_pattern = r'\s*=\s*\[&U\]\[!GarliScore ([-.0-9]*)\]\s*%s\s*(\(.*\))\s*;' % garli_dna_model_pattern garli_after_name_tree_pattern = r'\s*=\s*\[&U\]\[!GarliScore ([-.0-9]*)\]\s*(\(.*\))\s*;' tree_prefix = r'\[iGarli\s*(\d+)\s*\] tree [a-zA-Z0-9_]+' tm_pat_string = tree_prefix + garli_after_name_tm_pattern tree_pat_string = tree_prefix + garli_after_name_tree_pattern garli_tree_model_pat = re.compile(tm_pat_string) garli_tree_pat = re.compile(tree_pat_string)
## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see <http://www.gnu.org/licenses/>. ## ############################################################################ """ Tests tree distances. """ import random import unittest import math from dendropy import get_logger import dendropy.tests _LOG = get_logger("tree diste ") from dendropy import dataio from dendropy.splits import encode_splits from dendropy.tests.util_for_testing import assert_approx_equal, assert_vec_approx_equal, assert_mat_approx_equal ### MODULE THAT WE ARE TESTING ### from dendropy import treedists ### MODULE THAT WE ARE TESTING ### class TreeDistTest(unittest.TestCase): def testEuclideanDist(self): d = dataio.trees_from_newick([ "((t5:0.161175,t6:0.161175):0.392293,((t4:0.104381,(t2:0.075411,t1:0.075411):1):0.065840,t3:0.170221):0.383247);", "((t5:2.161175,t6:0.161175):0.392293,((t4:0.104381,(t2:0.075411,t1:0.075411):1):0.065840,t3:0.170221):0.383247);",
#!/usr/bin/env python import sys import shutil import os import re import random from dendropy import get_logger _LOG = get_logger("igarli_master.py") num_bootstrap_reps = 100 script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) if len(sys.argv) < 2: sys.exit("Expecting a data file (NEXUS) as an argument") dataf = open(sys.argv[1], 'rU') dim_pat = re.compile(r'\s*dimensions\s*ntax\s*=\s*(\d+)\s*nchar\s*=\s*(\d+)', re.I) rev_dim_pat = re.compile(r'\s*dimensions\s*nchar\s*=\s*(\d+)\s*ntax\s*=\s*(\d+)', re.I) n_taxa = None n_char = None for line in dataf: m = dim_pat.match(line) if m: n_taxa, n_char = [int(i) for i in m.groups()] break else: m = rev_dim_pat.match(line)
import sys if sys.version_info > (3, ): from io import StringIO else: from cStringIO import StringIO from dendropy.datasets import Dataset from dendropy.trees import TreesBlock from dendropy import nexus from dendropy.nexus import RootingInterpretation from dendropy import nexml from dendropy import fasta from dendropy import phylip from dendropy import get_logger, deprecation _LOG = get_logger('dataio') ############################################################################ ## File Formats NEXUS='NEXUS' NEWICK='NEWICK' NEXML='NEXML' FASTA='FASTA' PHYLIP='PHYLIP' FORMATS = [NEXUS, NEXML, NEWICK, FASTA, PHYLIP] READERS = { NEXUS: nexus.NexusReader, NEWICK: nexus.NewickReader, NEXML: nexml.NexmlReader,