def testSingleTerm(self): self.loader.options['process_relations'] = True self.loader.options['process_parents'] = True with dal.session_scope() as session: m_ontology = self.loader.load_ontology('fypo', session) session.add(m_ontology) term = helpers.Term( ontology_name='fypo', iri='http://purl.obolibrary.org/obo/FYPO_0000257') o_term = self.client.detail(term) m_term = self.loader.load_term(o_term, m_ontology, session) session.commit() self.assertGreaterEqual(len(m_term.parent_terms), 1) self.loader.options['process_relations'] = False self.loader.options['process_parents'] = False o_ontology = self.client.ontology('GO') term = helpers.Term( ontology_name='GO', iri='http://purl.obolibrary.org/obo/GO_0000002') o_term = self.client.detail(term) m_term = self.loader.load_term(o_term, o_ontology, session) self.assertEqual(m_term.ontology.name, 'GO') with self.assertRaises(RuntimeError): self.loader.load_term(o_term, 33, session)
def test_dynamic_links(self): term = helpers.Term(ontology_name='aero', iri='http://purl.obolibrary.org/obo/IAO_0000630') for relation in term.relations_types: related = term.load_relation(relation) if related: self._checkTerms(related) self.assertIn('has_part', term.relations_types) term = helpers.Term(ontology_name='aero', iri='http://purl.obolibrary.org/obo/IAO_0000314') self.assertIn('part_of', term.relations_types)
def test_namespace(self): # retrieved from namespace annotation h_term = helpers.Term(ontology_name='aero', iri='http://purl.obolibrary.org/obo/IAO_0000314') self.client.detail(h_term) self.assertEqual(h_term.namespace, 'aero') # retrieved from obo_name_space annotation h_term = helpers.Term(ontology_name='duo', iri='http://purl.obolibrary.org/obo/DUO_0000017') self.client.detail(h_term) self.assertEqual(h_term.namespace, 'duo')
def testRelationsShips(self): with dal.session_scope() as session: m_ontology = self.loader.load_ontology('bto', session) session.add(m_ontology) term = helpers.Term( ontology_name='bto', iri='http://purl.obolibrary.org/obo/BTO_0000005') o_term = self.client.detail(term) m_term = self.loader.load_term(o_term, m_ontology, session) session.add(m_term) self.assertGreaterEqual(len(m_term.parent_terms), 0)
def test_terms(self): """ Test direct calls to terms entry point. Should warn that test may be long according to the nnumber of terms involved :return: """ term_1 = helpers.Term(ontology_name='duo', iri='http://purl.obolibrary.org/obo/DUO_0000026') ancestors = term_1.load_relation('ancestors') for ancestor in ancestors: self._checkTerm(ancestor) self._checkTerm(term_1)
def testRelationOtherOntology(self): self.loader.options['process_relations'] = True self.loader.options['process_parents'] = True with dal.session_scope() as session: m_ontology = self.loader.load_ontology('efo', session) session.add(m_ontology) term = helpers.Term(ontology_name='efo', iri='http://www.ebi.ac.uk/efo/EFO_0002215') o_term = self.client.detail(term) m_term = self.loader.load_term(o_term, m_ontology, session) session.add(m_term) self.assertGreaterEqual(session.query(Ontology).count(), 2) term = session.query(Term).filter_by(accession='BTO:0000164') self.assertEqual(1, term.count())
def elem_class_instance(self, **kwargs): """ Search OLS api returns mixed types elements, get current element class to return accordingly :param kwargs: type items :return: mixed """ import ebi.ols.api.helpers as helpers type_item = kwargs.pop('type', None) if type_item == 'property': return helpers.Property(**kwargs) elif type_item == 'individual': return helpers.Individual(**kwargs) elif type_item == 'ontology': return helpers.Ontology(**kwargs) else: return helpers.Term(**kwargs)
def test_exception_retry(self): # unknown URI with self.assertRaises(ebi.ols.api.exceptions.NotFoundException): h_term = helpers.Term( ontology_name='so', iri='http://purl.obolibrary.org/obo/SO_99999999') self.client.detail(h_term) with self.assertRaises(ebi.ols.api.exceptions.NotFoundException): self.client.ontology('unexisting_ontology') with self.assertRaises(ebi.ols.api.exceptions.BadFilters): filters = {'accession': 'EFO:0000405'} self.client.terms(filters=filters) with self.assertRaises(ebi.ols.api.exceptions.ObjectNotRetrievedError): prop = helpers.Property( iri= 'http://purl.obolibrary.org/obo/uberon/insect-anatomy#efo_slim', ontology_name='efo') self.client.detail(prop)
def testSubsets(self): self.loader.options['process_relations'] = False self.loader.options['process_parents'] = False with dal.session_scope() as session: term = helpers.Term( ontology_name='go', iri='http://purl.obolibrary.org/obo/GO_0099565') o_term = self.client.detail(term) m_term = self.loader.load_term(o_term, 'go', session) session.add(m_term) subsets = session.query(Subset).all() for subset in subsets: self.assertIsNotNone(subset.definition) subset = helpers.Property( ontology_name='go', iri= 'http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym') details = self.client.detail(subset) self.assertNotEqual(details.definition, '')