How to use the newick.read function in newick

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 lmaurits / BEASTling / tests / configuration_tests.py View on Github external
def test_get_glottolog_newick(tmppath, mocker):
    tmppath.joinpath('glottolog-2.5.newick').write_text(
        '(B [abcd1234],C [abcd1234])A [abcd1234];', encoding='utf8')
    mocker.patch(
        'beastling.configuration.user_data_dir',
        new=mocker.Mock(return_value=str(tmppath)))
    trees = newick.read(get_glottolog_data('newick', '2.5'))
    assert trees[0].name == 'A [abcd1234]'
github glottobank / python-newick / tests / test_newick.py View on Github external
def test_read_write(tmpdir):
    trees = read(pathlib.Path(__file__).parent / 'fixtures' / 'tree-glottolog-newick.txt')
    descs = [len(tree.descendants) for tree in trees]
    # The bookkeeping family has 391 languages
    assert descs[0] == 391
    tmp = str(tmpdir.join('test.txt'))
    write(trees, tmp)
    assert pathlib.Path(tmp).exists()
    assert [len(tree.descendants) for tree in read(tmp)] == descs
github glottobank / python-newick / tests / test_newick.py View on Github external
def test_read_write(tmpdir):
    trees = read(pathlib.Path(__file__).parent / 'fixtures' / 'tree-glottolog-newick.txt')
    descs = [len(tree.descendants) for tree in trees]
    # The bookkeeping family has 391 languages
    assert descs[0] == 391
    tmp = str(tmpdir.join('test.txt'))
    write(trees, tmp)
    assert pathlib.Path(tmp).exists()
    assert [len(tree.descendants) for tree in read(tmp)] == descs
github lmaurits / BEASTling / beastling / configuration.py View on Github external
match.group('glottocode'),
                match.group('isocode'))

        def get_classification(node):
            ancestor = node.ancestor
            if not ancestor:
                # Node is root of some family
                return [label2name[node.name]]
            res = []
            while ancestor:
                res.append(label2name[ancestor.name])
                ancestor = ancestor.ancestor
            return list(reversed(res))

        # Walk the tree and build the classifications dictionary
        glottolog_trees = newick.read(get_glottolog_data('newick', self.admin.glottolog_release))
        for tree in glottolog_trees:
            for node in tree.walk():
                name, glottocode, isocode = parse_label(node.name)
                classification = get_classification(node)
                self.classifications[glottocode] = classification
                if isocode:
                    self.classifications[isocode] = classification
                glottocode2node[glottocode] = node

        # Load geographic metadata
        for t in reader(
                get_glottolog_data('geo', self.admin.glottolog_release), namedtuples=True):
            if t.macroarea:
                self.glotto_macroareas[t.glottocode] = t.macroarea
                for isocode in t.isocodes.split():
                    self.glotto_macroareas[isocode] = t.macroarea

newick

A python module to read and write the Newick format

Apache-2.0
Latest version published 1 year ago

Package Health Score

53 / 100
Full package analysis

Similar packages