Пример #1
0
def _move_label_properties_for_otu(otu, syntax_version):
    ol = find_val_literal_meta_first(otu, 'ot:originalLabel', syntax_version)
    assert ol is not None
    label_att = otu.get('@label')
    if label_att is not None:
        del otu['@label']
        if label_att != ol:
            ml = find_val_literal_meta_first(otu, 'ot:ottTaxonName', syntax_version)
            if (not ml) or (ml != label_att):
                add_literal_meta(otu, 'ot:altLabel', label_att, syntax_version)
Пример #2
0
 def testExternalURL(self):
     pa = PhylesystemAPI(self.domains, get_from='api')
     u = pa.get_external_url('pg_10')
     re = requests.get(u).json()
     sid = find_val_literal_meta_first(re['nexml'], 'ot:studyId',
                                       detect_nexson_version(re))
     self.assertTrue(sid in ['10', 'pg_10'])
Пример #3
0
 def _do_sugar_tests(self, pa):
     x = pa.get('pg_10')['data']
     sid = find_val_literal_meta_first(x['nexml'], 'ot:studyId',
                                       detect_nexson_version(x))
     self.assertTrue(sid in ['10', 'pg_10'])
     y = pa.get('pg_10', tree_id='tree3', format='newick')
     self.assertTrue(y.startswith('('))
Пример #4
0
def test_phylesystem_api_for_study(test_case_instance, phylesystem_wrapper, study_id='pg_10'):
    from peyotl.nexson_syntax.helper import detect_nexson_version, find_val_literal_meta_first
    x = phylesystem_wrapper.get(study_id)['data']
    sid = find_val_literal_meta_first(x['nexml'], 'ot:studyId', detect_nexson_version(x))
    test_case_instance.assertTrue(sid in [study_id])
    y = phylesystem_wrapper.get(study_id, tree_id='tree3', format='newick')
    test_case_instance.assertTrue(y.startswith('('))
Пример #5
0
 def add_or_replace_annotation(
         self,  #pylint: disable=R0201
         obj,
         annotation,
         agent,
         add_agent_only=False):
     '''Takes an `annotation` dictionary which is
     expected to have a string as the value of annotation['author']['name']
     This function will remove all annotations from obj that:
         1. have the same author/name, and
         2. have no messages that are flagged as messages to be preserved (values for 'preserve'
             that evaluate to true)
     '''
     nex = get_nexml_el(obj)
     nvers = detect_nexson_version(obj)
     _LOG.debug('detected version as ' + nvers)
     agents_obj = find_val_literal_meta_first(nex, 'ot:agents', nvers)
     if not agents_obj:
         agents_obj = add_literal_meta(nex, 'ot:agents', {'agent': []},
                                       nvers)
     agents_list = agents_obj.setdefault('agent', [])
     found_agent = False
     aid = agent['@id']
     for a in agents_list:
         if a.get('@id') == aid:
             found_agent = True
             break
     if not found_agent:
         agents_list.append(agent)
     if add_agent_only:
         delete_same_agent_annotation(obj, annotation)
     else:
         replace_same_agent_annotation(obj, annotation)
Пример #6
0
 def add_or_replace_annotation(self,  # pylint: disable=R0201
                               obj,
                               annotation,
                               agent,
                               add_agent_only=False):
     """Takes an `annotation` dictionary which is
     expected to have a string as the value of annotation['author']['name']
     This function will remove all annotations from obj that:
         1. have the same author/name, and
         2. have no messages that are flagged as messages to be preserved (values for 'preserve'
             that evaluate to true)
     """
     nex = get_nexml_el(obj)
     nvers = detect_nexson_version(obj)
     _LOG.debug('detected version as ' + nvers)
     agents_obj = find_val_literal_meta_first(nex, 'ot:agents', nvers)
     if not agents_obj:
         agents_obj = add_literal_meta(nex, 'ot:agents', {'agent': []}, nvers)
     agents_list = agents_obj.setdefault('agent', [])
     found_agent = False
     aid = agent['@id']
     for a in agents_list:
         if a.get('@id') == aid:
             found_agent = True
             break
     if not found_agent:
         agents_list.append(agent)
     if add_agent_only:
         delete_same_agent_annotation(obj, annotation)
     else:
         replace_same_agent_annotation(obj, annotation)
Пример #7
0
 def testFetchStudy(self):
     try:
         x = self.phylografter.fetch_study('252')
     except:
         _LOG.exception('GET from phylografter failed!')
     else:
         sid = find_val_literal_meta_first(x['nexml'], 'ot:studyId', detect_nexson_version(x))
         self.assertTrue(sid in ['252', 'pg_252'])
Пример #8
0
 def testExternalURL(self):
     # N.B. that the URL for this API call is an odd one, e.g.
     #    http://devapi.opentreeoflife.org/phylesystem/external_url/pg_10
     pa = PhylesystemAPI(self.domains, get_from='api')
     u = pa.get_external_url('pg_10')
     re = requests.get(u).json()
     sid = find_val_literal_meta_first(re['nexml'], 'ot:studyId', detect_nexson_version(re))
     self.assertTrue(sid in ['10', 'pg_10'])
Пример #9
0
 def testFetchStudy(self):
     try:
         x = self.phylografter.fetch_study('252')
     except:
         _LOG.exception('GET from phylografter failed!')
     else:
         sid = find_val_literal_meta_first(x['nexml'], 'ot:studyId',
                                           detect_nexson_version(x))
         self.assertTrue(sid in ['252', 'pg_252'])
Пример #10
0
 def testExternalURL(self):
     # N.B. that the URL for this API call is an odd one, e.g.
     #    http://devapi.opentreeoflife.org/phylesystem/external_url/pg_10
     pa = PhylesystemAPI(self.domains, get_from='api')
     u = pa.get_external_url('pg_10')
     re = requests.get(u).json()
     sid = find_val_literal_meta_first(re['nexml'], 'ot:studyId',
                                       detect_nexson_version(re))
     self.assertTrue(sid in ['10', 'pg_10'])
Пример #11
0
def test_phylesystem_api_for_study(test_case_instance,
                                   phylesystem_wrapper,
                                   study_id='pg_10'):
    from peyotl.nexson_syntax.helper import detect_nexson_version, find_val_literal_meta_first
    x = phylesystem_wrapper.get(study_id)['data']
    sid = find_val_literal_meta_first(x['nexml'], 'ot:studyId',
                                      detect_nexson_version(x))
    test_case_instance.assertTrue(sid in [study_id])
    y = phylesystem_wrapper.get(study_id, tree_id='tree3', format='newick')
    test_case_instance.assertTrue(y.startswith('('))
Пример #12
0
 def _fill_otu_ottid_maps(self, otus_group_id):
     if self._otuid2ottid_byogid.get(otus_group_id) is None:
         otuid2ottid = {}
         ottid2otuid_list = {}
         self._otuid2ottid_byogid[otus_group_id] = otuid2ottid
         self._ottid2otuid_list_byogid[otus_group_id] = ottid2otuid_list
         otu_dict = self._otu_by_otug[otus_group_id]
         for otuid, otu in otu_dict.items():
             ottid = find_val_literal_meta_first(otu, 'ot:ottId', self._nexson_version)
             otuid2ottid[otuid] = ottid
             ottid2otuid_list.setdefault(ottid, []).append(otuid)
         return otuid2ottid, ottid2otuid_list
     return self._otuid2ottid_byogid[otus_group_id], self._ottid2otuid_list_byogid[otus_group_id]
Пример #13
0
 def _fill_otu_ottid_maps(self, otus_group_id):
     if self._otuid2ottid_byogid.get(otus_group_id) is None:
         otuid2ottid = {}
         ottid2otuid_list = {}
         self._otuid2ottid_byogid[otus_group_id] = otuid2ottid
         self._ottid2otuid_list_byogid[otus_group_id] = ottid2otuid_list
         otu_dict = self._otu_by_otug[otus_group_id]
         for otuid, otu in otu_dict.items():
             ottid = find_val_literal_meta_first(otu, 'ot:ottId',
                                                 self._nexson_version)
             otuid2ottid[otuid] = ottid
             ottid2otuid_list.setdefault(ottid, []).append(otuid)
         return otuid2ottid, ottid2otuid_list
     return self._otuid2ottid_byogid[
         otus_group_id], self._ottid2otuid_list_byogid[otus_group_id]
Пример #14
0
 def testStudy(self):
     x = self.ot.study.get('pg_10')['data']
     sid = find_val_literal_meta_first(x['nexml'], 'ot:studyId', detect_nexson_version(x))
     self.assertTrue(sid in ['10', 'pg_10'])
     y = self.ot.study.get('pg_10', tree_id='tree3', format='newick')
     self.assertTrue(y.startswith('('))
Пример #15
0
 def testFetchStudyRemote(self):
     pa = PhylesystemAPI(self.domains, get_from='api')
     x = pa.get_study('pg_10')['data']
     sid = find_val_literal_meta_first(x['nexml'], 'ot:studyId',
                                       detect_nexson_version(x))
     self.assertTrue(sid in ['10', 'pg_10'])
Пример #16
0
 def testExternalURL(self):
     pa = PhylesystemAPI(self.domains, get_from='api')
     u = pa.get_external_url('pg_10')
     re = requests.get(u).json()
     sid = find_val_literal_meta_first(re['nexml'], 'ot:studyId', detect_nexson_version(re))
     self.assertTrue(sid in ['10', 'pg_10'])
Пример #17
0
 def testFetchStudyRemote(self):
     pa = PhylesystemAPI(self.domains, get_from='api')
     x = pa.get_study('pg_10')['data']
     sid = find_val_literal_meta_first(x['nexml'], 'ot:studyId', detect_nexson_version(x))
     self.assertTrue(sid in ['10', 'pg_10'])