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)
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'])
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('('))
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('('))
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)
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)
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'])
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'])
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]
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]
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('('))
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'])