How to use newick - 10 common examples

To help you get started, we’ve selected a few newick examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glottobank / python-newick / tests / test_newick.py View on Github external
assert len(root.descendants) == 3

    root = loads('(A,B,(C,D));')[0]
    assert root.name is None
    assert len(root.descendants) == 3

    root = loads('(A,B,(C,D)E)Fäß;')[0]
    assert root.name == 'Fäß'
    assert len(root.descendants) == 3

    root = loads('(:0.1,:0.2,(:0.3,:0.4):0.5);')[0]
    assert root.name is None
    assert root.descendants[0].length == 0.1
    assert len(root.descendants) == 3

    root = loads('((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;')[0]
    assert root.name == 'A'
    assert root.descendants[-1].length == 0.1
    assert len(root.descendants) == 1
github tskit-dev / msprime / tskit_tests / test_newick.py View on Github external
def verify_newick_topology(self, tree, root=None, node_labels=None):
        if root is None:
            root = tree.root
        ns = tree.newick(precision=16, root=root, node_labels=node_labels)
        if node_labels is None:
            leaf_labels = {u: str(u + 1) for u in tree.leaves(root)}
        else:
            leaf_labels = {u: node_labels[u] for u in tree.leaves(root)}
        newick_tree = newick.loads(ns)[0]
        leaf_names = newick_tree.get_leaf_names()
        self.assertEqual(sorted(leaf_names), sorted(leaf_labels.values()))
        for u in tree.leaves(root):
            name = leaf_labels[u]
            node = newick_tree.get_node(name)
            while u != root:
                self.assertAlmostEqual(node.length, tree.branch_length(u))
                node = node.ancestor
                u = tree.parent(u)
            self.assertIsNone(node.ancestor)
github glottobank / python-newick / tests / test_newick.py View on Github external
def test_all_removal():
    tree = loads('((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A;')[0]
    tree.remove_names()
    tree.remove_lengths()
    topology_only = dumps(tree)
    assert topology_only == '((,(,)));'
github glottobank / python-newick / tests / test_newick.py View on Github external
def test_polytomy_resolution():
    tree = loads('(A,B,(C,D,(E,F)))')[0]
    assert not tree.is_binary
    tree.resolve_polytomies()
    assert tree.newick == '(A,((C,((E,F),D):0.0),B):0.0)'
    assert tree.is_binary

    tree = loads('(A,B,C,D,E,F)')[0]
    assert not tree.is_binary
    tree.resolve_polytomies()
    assert tree.newick == '(A,(F,(B,(E,(C,D):0.0):0.0):0.0):0.0)'
    assert tree.is_binary
github glottobank / python-newick / tests / test_newick.py View on Github external
def test_Node():
    with pytest.raises(ValueError):
        Node(name='A)')

    root = loads('(A,B,(C,D)E)F;')[0]
    assert [n.name for n in root.walk()] == ['F', 'A', 'B', 'E', 'C', 'D']
    assert [n.name for n in root.walk() if n.is_leaf] == ['A', 'B', 'C', 'D']
    assert [n.name for n in root.walk(mode='postorder')] == ['A', 'B', 'C', 'D', 'E', 'F']
    assert root.ancestor is None
    assert root.descendants[0].ancestor == root
    root = loads('(((a,b),(c,d)),e);')[0]
    assert [n.ancestor.newick for n in root.walk() if n.ancestor] == \
        [
            '(((a,b),(c,d)),e)',
            '((a,b),(c,d))',
            '(a,b)',
            '(a,b)',
            '((a,b),(c,d))',
            '(c,d)',
github glottobank / python-newick / tests / test_newick.py View on Github external
def setUp(self):
        self.test_obj = Node("A", "1.0")
        self.test_descendant = Node("D", "2.0")
        self.lengths = ["2.0", "3.0", "4.0"]
github glottobank / python-newick / tests / test_newick.py View on Github external
def test_node_parameters_changeability(self):
        test_obj = Node(name="A")
        self.assertEqual("A", test_obj.name)
        test_obj.name = "B"
        self.assertEqual("B", test_obj.name)
github glottobank / python-newick / tests / test_newick.py View on Github external
def test_node_newick_representation_without_length(self):
        test_obj = Node(name="A")
        self.assertEqual("A", test_obj.newick)
github glottobank / python-newick / tests / test_newick.py View on Github external
def test_repr():
    n = Node(name="A")
    assert repr(n) == 'Node("A")'

newick

A python module to read and write the Newick format

Apache-2.0
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages