def make_tree(*taxa): # We create a dict to lookup Glottolog languoids by name, ISO- or Glottocode. langs = {} for lang in Glottolog().languoids(): if lang.iso: langs[lang.iso] = lang langs[lang.name] = lang langs[lang.id] = lang t = TreeMaker() for taxon in taxa: if taxon not in langs: print('unknown taxon: {0}'.format(taxon)) continue t.add(taxon, ', '.join(l[1] for l in langs[taxon].lineage)) return t
def test_add(self): t = TreeMaker() t.add('A', 'a') t.add('AB1', 'a, b') t.add('AB2', 'a, b') t.add('C', 'c') assert str(t.tree) == "((A,(AB1,AB2)),C)"
def test_add(self): t = TreeMaker() t.add('A', 'a') t.add('AB1', 'a, b') t.add('AB2', 'a, b') t.add('C', 'c') assert str(t.tree) == "((A,(AB1,AB2)),C)"
def test_add_2(self): t = TreeMaker() t.add('A1', 'family a, subgroup 1') t.add('A2', 'family a, subgroup 2') t.add('B1a', 'family b, subgroup 1') t.add('B1b', 'family b, subgroup 1') t.add('B2', 'family b, subgroup 2') assert str(t.tree) == "((A1,A2),((B1a,B1b),B2))"
def test_error_on_bad_taxon(self): t = TreeMaker() with self.assertRaises(ValueError): t.add('A (x)', 'a') with self.assertRaises(ValueError): t.add('A)', 'a') with self.assertRaises(ValueError): t.add('A(', 'a')
def test_add_2(self): t = TreeMaker() t.add('A1', 'family a, subgroup 1') t.add('A2', 'family a, subgroup 2') t.add('B1a', 'family b, subgroup 1') t.add('B1b', 'family b, subgroup 1') t.add('B2', 'family b, subgroup 2') assert str(t.tree) == "((A1,A2),((B1a,B1b),B2))"
def test_error_on_bad_taxon(self): t = TreeMaker() with self.assertRaises(ValueError): t.add('A (x)', 'a') with self.assertRaises(ValueError): t.add('A)', 'a') with self.assertRaises(ValueError): t.add('A(', 'a')
def test_error_on_duplicate(self): t = TreeMaker() t.add('A', 'a') with self.assertRaises(ValueError): t.add('A', 'a')
def test_error_on_duplicate(self): t = TreeMaker() t.add('A', 'a') with self.assertRaises(ValueError): t.add('A', 'a')