Skip to content

Commit b63c451

Browse files
author
oerc0042
committed
fix to get_ols_ontology
1 parent 8976a8e commit b63c451

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

isatools/net/ols.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
def get_ols_ontologies():
2525
"""Returns a list of OntologySource objects according to what's in OLS"""
26-
ontologiesUri = OLS_API_BASE_URI + "/ontologies?size=" + str(OLS_PAGINATION_SIZE)
26+
ontologiesUri = OLS_API_BASE_URI + "/ontologies?" + str(OLS_PAGINATION_SIZE)
2727
log.debug(ontologiesUri)
2828
J = json.loads(urlopen(ontologiesUri).read().decode("utf-8"))
2929
ontology_sources = []
@@ -43,9 +43,9 @@ def get_ols_ontologies():
4343
return ontology_sources
4444

4545

46-
def get_ols_ontology(ontology_name):
46+
def get_ols_ontology(ontology_name, page: int):
4747
"""Returns a single OntologySource objects according to what's in OLS"""
48-
ontologiesUri = OLS_API_BASE_URI + "/ontologies?size=" + str(OLS_PAGINATION_SIZE)
48+
ontologiesUri = OLS_API_BASE_URI + "/ontologies?page=" + str(page) + "&size=" + str(OLS_PAGINATION_SIZE)
4949
log.debug(ontologiesUri)
5050
J = json.loads(urlopen(ontologiesUri).read().decode("utf-8"))
5151
print("EMBEDDED: ", J["_embedded"]["ontologies"])
@@ -80,6 +80,8 @@ def search_ols(term, ontology_source):
8080

8181
query = "{0}&queryFields=label&ontology={1}&exact=True".format(term, os_search)
8282
url += "?q={}".format(query)
83+
84+
print("OLS_URL", url)
8385
log.debug(url)
8486
import requests
8587

tests/convert/test_isatab2sra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_isatab2sra_dump_submission_xml_biis7(self):
114114
actual_submission_xml_biis7 = etree.fromstring(submission_xml)
115115
self.assertTrue(utils.assert_xml_equal(self._expected_submission_xml_biis7, actual_submission_xml_biis7))
116116

117-
@unittest.skip("Not working yet")
117+
# @unittest.skip("Not working yet")
118118
def test_isatab2sra_dump_project_set_xml_biis7(self):
119119
isatab2sra.convert(self._biis7_dir, self._tmp_dir, validate_first=False)
120120
with open(os.path.join(self._tmp_dir, "project_set.xml"), "rb") as ps_fp:

tests/isatab/test_isatab.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,9 +2005,7 @@ def test_isatab_protocol_chain_parsing(self):
20052005
for proc in nucleotide_sequencing_assay.process_sequence
20062006
if proc.executes_protocol.name == "genomic DNA extraction - standard procedure 4"
20072007
)
2008-
extract = next(
2009-
mat for mat in nucleotide_sequencing_assay.other_material if mat.name == "GSM255770.e1"
2010-
)
2008+
extract = next(mat for mat in nucleotide_sequencing_assay.other_material if mat.name == "GSM255770.e1")
20112009
self.assertTrue(nucl_ac_extraction_process.next_process is gen_dna_extraction_process)
20122010
self.assertEqual(len(gen_dna_extraction_process.outputs), 1)
20132011
self.assertFalse(nucl_ac_extraction_process.outputs)

tests/utils/test_isatools_utils.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,55 @@ def test_get_ontologies(self):
139139
self.assertIsInstance(ontology_sources, list)
140140
self.assertIsInstance(ontology_sources[0], OntologySource)
141141

142-
@unittest.skip("efo is not available from https://www.ebi.ac.uk/ols4/api/ontologies")
143-
def test_get_ontology(self):
144-
ontology_source = ols.get_ols_ontology("efo")
142+
# @unittest.skip("efo is not available from https://www.ebi.ac.uk/ols4/api/ontologies")
143+
def test_get_ontology0(self):
144+
ontology_source = ols.get_ols_ontology("ado", 0)
145+
self.assertIsInstance(ontology_source, OntologySource)
146+
self.assertEqual(ontology_source.name, "ado")
147+
self.assertIn("://www.ebi.ac.uk/ols", ontology_source.file)
148+
self.assertIn("/api/ontologies/ado?lang=en", ontology_source.file)
149+
self.assertIsInstance(ontology_source.version, str)
150+
self.assertEqual(ontology_source.description, "Alzheimer's Disease Ontology (ADO)")
151+
152+
def test_get_ontology1(self):
153+
ontology_source = ols.get_ols_ontology("stato", 1)
154+
self.assertIsInstance(ontology_source, OntologySource)
155+
self.assertEqual(ontology_source.name, "stato")
156+
self.assertIn("://www.ebi.ac.uk/ols", ontology_source.file)
157+
self.assertIn("/api/ontologies/stato?lang=en", ontology_source.file)
158+
self.assertIsInstance(ontology_source.version, str)
159+
self.assertEqual(ontology_source.description, "STATO: the statistical methods ontology")
160+
161+
def test_get_ontology2(self):
162+
ontology_source = ols.get_ols_ontology("efo", 2)
145163
self.assertIsInstance(ontology_source, OntologySource)
146164
self.assertEqual(ontology_source.name, "efo")
147165
self.assertIn("://www.ebi.ac.uk/ols", ontology_source.file)
148166
self.assertIn("/api/ontologies/efo?lang=en", ontology_source.file)
149167
self.assertIsInstance(ontology_source.version, str)
150168
self.assertEqual(ontology_source.description, "Experimental Factor Ontology")
151169

152-
@unittest.skip("efo is not available from https://www.ebi.ac.uk/ols4/api/ontologies")
153-
def test_search_for_term(self):
154-
ontology_source = ols.get_ols_ontology("efo")
155-
ontology_annotations = ols.search_ols("cell type", ontology_source)
170+
# @unittest.skip("efo is not available from https://www.ebi.ac.uk/ols4/api/ontologies")
171+
def test_search_for_term_p0(self):
172+
ontology_source = ols.get_ols_ontology("chmo", 0)
173+
ontology_annotations = ols.search_ols("mobile phase", ontology_source)
174+
self.assertIsInstance(ontology_annotations, list)
175+
self.assertGreater(len(ontology_annotations), 0)
176+
ontology_annotations = [oa for oa in ontology_annotations if oa.term == "mobile phase"]
177+
self.assertIsInstance(ontology_annotations[-1], OntologyAnnotation)
178+
self.assertEqual(ontology_annotations[-1].term, "mobile phase")
179+
self.assertIn("http://purl.obolibrary.org/obo/CHMO_0000995", [oa.term_accession for oa in ontology_annotations])
180+
self.assertEqual(ontology_annotations[-1].term_source, ontology_source)
181+
182+
def test_search_for_term_p1(self):
183+
ontology_source = ols.get_ols_ontology("efo", 2)
184+
ontology_annotations = ols.search_ols("time", ontology_source)
156185
self.assertIsInstance(ontology_annotations, list)
157186
self.assertGreater(len(ontology_annotations), 0)
158-
ontology_annotations = [oa for oa in ontology_annotations if oa.term == "cell type"]
187+
ontology_annotations = [oa for oa in ontology_annotations if oa.term == "time"]
159188
self.assertIsInstance(ontology_annotations[-1], OntologyAnnotation)
160-
self.assertEqual(ontology_annotations[-1].term, "cell type")
161-
self.assertIn("http://www.ebi.ac.uk/efo/EFO_0000324", [oa.term_accession for oa in ontology_annotations])
189+
self.assertEqual(ontology_annotations[-1].term, "time")
190+
self.assertIn("http://www.ebi.ac.uk/efo/EFO_0000721", [oa.term_accession for oa in ontology_annotations])
162191
self.assertEqual(ontology_annotations[-1].term_source, ontology_source)
163192

164193

tests/validators/test_validate_test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def test_validate_testdata_treatment_sequence_json(self):
404404
with open(os.path.join(utils.JSON_DATA_DIR, "create", "treatment_sequence_test.json")) as test_case_fp:
405405
with open(os.path.join(self.v2_create_schemas_path, "treatment_sequence_schema.json")) as fp:
406406
treatment_sequence_schema = json.load(fp)
407-
#res_path = pathlib.Path("file://", self.v2_create_schemas_path, "treatment_sequence_schema.json").as_uri()
407+
# res_path = pathlib.Path("file://", self.v2_create_schemas_path, "treatment_sequence_schema.json").as_uri()
408408
# resolver = RefResolver(res_path, treatment_sequence_schema)
409409
# validator = Draft4Validator(treatment_sequence_schema, resolver=resolver)
410410
resources = []

0 commit comments

Comments
 (0)