Пример #1
0
    def test_good_gbif_ids(self):
        """Tests that tree can be retrieved when input is set of GBIF ids
        """
        gbif_ids = GBIF_ID_MAP.keys()
        id_map = open_tree.get_ottids_from_gbifids(gbif_ids)
        # Make sure we haven't lost any ids
        assert len(gbif_ids) == len(id_map.keys())

        resp = open_tree.induced_subtree(
            id_map.keys(), label_format=open_tree.LABEL_FORMAT.ID)

        newick = resp['newick']

        tree = dendropy.Tree.get(data=newick, schema='newick')

        # Number of labels in the tree plus the number of unmatched should
        #     be less than or equal the number of keys in id_map.  Less than if
        #     one of the ids matches somewhere other than a tiop

        assert len(tree.taxon_namespace) + len(
            resp['unmatched_ott_ids']) <= len(id_map.keys())

        for taxon in tree.taxon_namespace:
            # Id map contains integers as of now, check to make sure each tip
            #     is in mapping
            # Taxon labels look like 'ott{ottid}'
            search_label = taxon.label.strip('ott')
            assert search_label in id_map.keys()

        # Make sure any unmatched ids are in mapping
        for unmatched in resp['unmatched_ott_ids']:
            assert str(unmatched) in id_map.keys()
Пример #2
0
 def test_all_good_ottids(self):
     """Test that the service responds correctly when only good ids are used
     """
     resp = open_tree.induced_subtree(
         GOOD_OTT_IDS, label_format=open_tree.LABEL_FORMAT.ID)
     newick = resp['newick']
     # Should fail if bad newick
     tree = dendropy.Tree.get(data=newick, schema='newick')
     # Make sure tree is not None
     assert tree is not None
Пример #3
0
 def test_all_bad_ottids(self):
     """Test that the service responds appropriately when given bad data
     """
     resp = open_tree.induced_subtree(
         BAD_OTT_IDS, label_format=open_tree.LABEL_FORMAT.ID)
     newick = resp['newick']
     # Should fail if bad newick
     tree = dendropy.Tree.get(data=newick, schema='newick')
     # Make sure tree is not None
     assert tree is not None
Пример #4
0
    def test_some_bad_ottids(self):
        """Test that the service handles a mix of good and bad ott ids
        """
        test_ids = GOOD_OTT_IDS
        test_ids.extend(BAD_OTT_IDS)

        resp = open_tree.induced_subtree(
            test_ids, label_format=open_tree.LABEL_FORMAT.ID)
        newick = resp['newick']
        # Should fail if bad newick
        tree = dendropy.Tree.get(data=newick, schema='newick')
        # Make sure tree is not None
        assert tree is not None
Пример #5
0
    def test_good_taxa(self):
        """Tests that a tree can be retrieved starting with good taxon names."""
        taxa_info, unmatched_names = open_tree.get_info_for_names(TAXON_NAMES)
        assert len(unmatched_names) == 0
        ott_ids = [tax['ott_id'] for tax in taxa_info.values()]
        assert len(ott_ids) == len(TAXON_NAMES)
        resp = open_tree.induced_subtree(
            ott_ids, label_format=open_tree.LABEL_FORMAT.ID
        )
        newick = resp['newick']

        tree = dendropy.Tree.get(data=newick, schema='newick')

        assert len(tree.taxon_namespace) == len(ott_ids)

        for taxon in tree.taxon_namespace:
            # Id map contains integers as of now, check to make sure each tip
            #     is in mapping
            # Taxon labels look like 'ott{ottid}'
            search_label = taxon.label.replace('ott', '')
            assert int(search_label) in ott_ids