Example #1
0
File: _trees.py Project: jhill1/stk
 def test_permute_trees_2(self):
     XML = etree.tostring(etree.parse('data/input/permute_trees.phyml',
                                      parser),
                          pretty_print=True)
     trees = obtain_trees(XML)
     output = permute_tree(trees['Davis_2011_1'], treefile="newick")
     temp_file_handle, temp_file = tempfile.mkstemp(suffix=".new")
     f = open(temp_file, "w")
     f.write(output)
     f.close()
     output_trees = import_trees(temp_file)
     expected_trees = import_trees("data/output/permute_trees_2.nex")
     os.remove(temp_file)
     self.assert_(len(output_trees) == len(expected_trees))
     for i in range(0, len(output_trees)):
         self.assert_(_trees_equal(output_trees[i], expected_trees[i]))
Example #2
0
File: _trees.py Project: jhill1/stk
 def test_import_trees(self):
     """ Test reading all trees from a file """
     test_file = "data/input/multiple_trees.tre"
     tree = import_tree(test_file, tree_no=0)
     expected_tree = "(Coracias_caudata, (Gallus_gallus, Apus_affinis), (Acanthisitta_chloris, ((Formicarius_colma, Thamnophilus_nigrocinereus, Furnarius_rufus), (Tyrannus_tyrannus, (Pipra_coronata, Rupicola_rupicola)), (Pitta_guajana, (Smithornis_rufolateralis, (Philepitta_castanea, Psarisomus_dalhousiae)))), (Menura_novaehollandiae, (Climacteris_picumnus, Ptilonorhynchus_violaceus), (Aegithalos_iouschensis, Callaeas_cinerea, Notiomystis_cincta, Tregellasia_leucops, Troglodytes_aedon, Regulus_calendula, Sitta_pygmaea, Pycnonotus_barbatus, Picathartes_gymnocephalus, Parus_inornatus, Orthonyx_spaldingii, Petrochelidon_pyrrhonota, Cisticola_anonymus, Certhia_familiaris, Bombycilla_garrulus, Alauda_arvensis, (Ficedula_strophiata, Turdus_falklandii), (Meliphaga_analoga, Pardalotus_striatus), (Malurus_melanocephalus, Pomatostomus_isidorei), (Dicaeum_melanoxanthum, Nectarinia_olivacea), (Toxorhamphus_novaeguineae, (Melanocharis_nigra, Oedistoma_iliolophum)), (Sylvia_nana, (Garrulax_milleti, Zosterops_senegalensis)), (Cinclus_cinclus, (Mimus_patagonicus, Sturnus_vulgaris)), (Chloropsis_cochinchinensis, Irena_cyanogaster, (Cardinalis_cardinalis, Passer_montanus, Fringilla_montifringilla, (Motacilla_cinerea, Ploceus_cucullatus, Prunella_collaris), (Emberiza_schoeniclus, Thraupis_cyanocephala, Parula_americana, Icterus_parisorum))), ((Artamus_leucorynchus, (Aegithina_tiphia, Vanga_curvirostris)), ((Oriolus_larvatus, (Pachycephala_soror, Vireo_philadelphicus)), (Corvus_corone, Paradisaea_raggiana, (Monarcha_axillaris, Dicrurus_adsimilis), (Coracina_lineata, Lanius_ludovicianus))))))));"
     self.assert_(expected_tree == tree)
     tree = import_tree(test_file, tree_no=1)
     expected_tree2 = "(Coracias_caudata, Gallus_gallus, Apus_affinis, (Acanthisitta_chloris, ((Formicarius_colma, Thamnophilus_nigrocinereus, Furnarius_rufus), (Tyrannus_tyrannus, (Pipra_coronata, Rupicola_rupicola)), (Pitta_guajana, (Smithornis_rufolateralis, (Philepitta_castanea, Psarisomus_dalhousiae)))), (Menura_novaehollandiae, (Climacteris_picumnus, Ptilonorhynchus_violaceus), (Aegithalos_iouschensis, Callaeas_cinerea, Notiomystis_cincta, Tregellasia_leucops, Troglodytes_aedon, Regulus_calendula, Sitta_pygmaea, Pycnonotus_barbatus, Picathartes_gymnocephalus, Parus_inornatus, Orthonyx_spaldingii, Petrochelidon_pyrrhonota, Cisticola_anonymus, Certhia_familiaris, Bombycilla_garrulus, Alauda_arvensis, (Ficedula_strophiata, Turdus_falklandii), (Meliphaga_analoga, Pardalotus_striatus), (Malurus_melanocephalus, Pomatostomus_isidorei), (Dicaeum_melanoxanthum, Nectarinia_olivacea), (Toxorhamphus_novaeguineae, (Melanocharis_nigra, Oedistoma_iliolophum)), (Sylvia_nana, (Garrulax_milleti, Zosterops_senegalensis)), (Cinclus_cinclus, (Mimus_patagonicus, Sturnus_vulgaris)), (Chloropsis_cochinchinensis, Irena_cyanogaster, (Cardinalis_cardinalis, Passer_montanus, Fringilla_montifringilla, (Motacilla_cinerea, Ploceus_cucullatus, Prunella_collaris), (Emberiza_schoeniclus, Thraupis_cyanocephala, Parula_americana, Icterus_parisorum))), ((Artamus_leucorynchus, (Aegithina_tiphia, Vanga_curvirostris)), ((Oriolus_larvatus, (Pachycephala_soror, Vireo_philadelphicus)), (Corvus_corone, Paradisaea_raggiana, (Monarcha_axillaris, Dicrurus_adsimilis), (Coracina_lineata, Lanius_ludovicianus))))))));"
     self.assert_(expected_tree2 == tree)
     trees = import_trees(test_file)
     self.assert_(expected_tree == trees[0])
     self.assert_(expected_tree2 == trees[1])
Example #3
0
File: _trees.py Project: jhill1/stk
 def test_amalgamate_trees_tnt(self):
     XML = etree.tostring(etree.parse('data/input/old_stk_input.phyml',
                                      parser),
                          pretty_print=True)
     output_string = amalgamate_trees(XML, format="tnt")
     trees = obtain_trees(XML)
     # save the file and read it back in. Then we check correct format (i.e. readable) and
     # we can check the trees are correct
     temp_file_handle, temp_file = tempfile.mkstemp(suffix=".tre")
     f = open(temp_file, "w")
     f.write(output_string)
     f.close()
     try:
         trees_read = import_trees(temp_file)
     except:
         self.assert_(False)
         # we should get no error
     os.remove(temp_file)
     self.assert_(len(trees) == len(trees_read))
     names = trees.keys()
     for i in range(0, len(trees)):
         self.assert_(_trees_equal(trees_read[i], trees[names[i]]))
Example #4
0
File: _trees.py Project: jhill1/stk
 def test_utf_tree(self):
     test_file = "data/input/utf_tree.tre"
     trees = import_trees(test_file)
     expected_tree = """(Colletes_skinneri, ((((Melitta_eickworti, Hesperapis_larreae), ('Andrena (Callandrena) sp.', (Panurgus_calcaratus, (Calliopsis_fracta, Calliopsis_pugionis)))), ((Svastra_machaerantherae, Svastra_obliqua), ('Tetraloniella_sp.', (Melissodes_rustica, (Melissodes_desponsa, 'Melissodes_sp.'))))), ((((Dieunomia_heteropoda, Dieunomia_nevadensis), ((Ceratina_calcarata, ((Chelostoma_fuliginosum, (Hoplitis_biscutellae, (Hoplitis_albifrons, Hoplitis_pilosifrons))), (Megachile_pugnata, Coelioxys_alternata))), ((Paranthidium_jugatorium, Anthidiellum_notatum), (Anthidium_oblongatum, Anthidium_porterae)))), ((Oreopasites_barbarae, ((Holcopasites_calliopsidis, Holcopasites_ruthae), (Nomada_maculata, (Nomada_imbricata, Nomada_obliterta)))), ((Leiopodus_singularis, (Xeromelecta_californica, Zacosmia_maculata)), ((Paranomada_velutina, Triopasites_penniger), (Epeolus_scutellaris, ('Triepeolus "rozeni"', Triepeolus_verbesinae)))))), ((Anthophora_furcata, (Anthophora_montana, Anthophora_urbana)), (((Exomalopsis_completa, Exomalopsis_rufiventris), ('Ptilothrix_sp.', (Diadasia_bituberculata, Diadasia_nigrifrons, (Diadasia_diminuta, Diadasia_martialis)))), ((Xylocopa_tabaniformis, Xylocopa_virginica), (Centris_hoffmanseggiae, (Apis_dorsata, (Apis_mellifera, Apis_nigrocincta)), ((Euglossa_imperialis, (Eulaema_meriana, (Eufriesea_caerulescens, Exaerete_frontalis))), ((Bombus_avinoviellus, (Bombus_pensylvanicus, Bombus_terrestris)), ('Melipona_sp.', Scaptotrigona_depilis, Lestrimelitta_limao, (Trigona_dorsalis, Trigona_necrophaga)))))))))));"""
     self.assert_(_trees_equal(expected_tree, trees[0]))
Example #5
0
File: _trees.py Project: jhill1/stk
 def test_trees_equal2(self):
     test_file = "data/input/equal_trees.new"
     trees = import_trees(test_file)
     self.assert_(_trees_equal(trees[1], trees[0]) == True)
     self.assert_(_trees_equal(trees[3], trees[2]) == False)
Example #6
0
File: _trees.py Project: jhill1/stk
 def test_trees_not_equal(self):
     test_file = "data/input/multiple_trees.tre"
     trees = import_trees(test_file)
     self.assert_(_trees_equal(trees[1], trees[0]) == False)