Skip to content

Commit ba2947d

Browse files
chores: resolve minor suggestions given by GitHub copilot
1 parent 44bdb47 commit ba2947d

5 files changed

Lines changed: 6 additions & 103 deletions

File tree

ontograph/downloader.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -218,44 +218,3 @@ class DownloadManagerAdapter(DownloaderPort):
218218
"""
219219

220220
pass
221-
222-
223-
# -------------------------------------------------------------------------
224-
# ---- MAIN FUNTION (mini-sandbox to try functionalities) ----
225-
# -------------------------------------------------------------------------
226-
if __name__ == '__main__':
227-
# Configure logging
228-
logging.basicConfig(level=logging.DEBUG)
229-
230-
# Define a directory to store all the downloads
231-
cache = Path('./data/in')
232-
233-
# Initialize a downloader object
234-
downloader = PoochDownloaderAdapter(cache_dir=cache)
235-
236-
# Functionality 1. Download from a URL
237-
path_single_download = downloader.fetch_from_url(
238-
url_ontology='https://purl.obolibrary.org/obo/ado.owl',
239-
filename='adosdsdsds.owl',
240-
)
241-
print(f'Path single download: {path_single_download}')
242-
243-
# Functionality 2. Download several resources from a catalog.
244-
from ontograph.models import CatalogOntologies
245-
246-
# Download automatically the catalog
247-
catalog = CatalogOntologies(cache_dir=cache)
248-
resources = [
249-
{'name_id': 'go', 'format': 'obo'},
250-
{'name_id': 'ado', 'format': 'owl'},
251-
]
252-
253-
catalog = CatalogOntologies(cache_dir=cache)
254-
paths_resources = downloader.fetch_from_catalog(
255-
resources=resources, catalog=catalog
256-
)
257-
print(f'\nPaths multiple resources: {paths_resources}')
258-
259-
print('\nPrint all the resources downloaded by the downloader')
260-
for name_id, path_resource in downloader.get_paths().items():
261-
print(f'\t{name_id}: {path_resource}')

ontograph/loader.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -378,45 +378,3 @@ class FastoboAdapter(OntologyLoaderPort):
378378
"""
379379

380380
pass
381-
382-
383-
if __name__ == '__main__':
384-
"""Example usage and testing for loader adapters."""
385-
# Configure logging
386-
logging.basicConfig(level=logging.INFO)
387-
388-
# Define a directory to store all the downloads
389-
cache = Path('./data/out')
390-
391-
# Creates an object that will load the ontology
392-
adapter = ProntoLoaderAdapter(cache_dir=cache)
393-
394-
# ---- Functionality 1. load_from_file()
395-
path_test = './data/in/go_version1.obo'
396-
print(f'Testing load_from_file with: {path_test}')
397-
onto_file = adapter.load_from_file(file_path_ontology=path_test)
398-
399-
print(f'Loaded ontology: {onto_file._ontology_id}')
400-
print(f'Number of terms: {len(onto_file._ontology.terms())}')
401-
402-
# ---- Functionality 2. load_from_catalog()
403-
ontology_id = 'ado' # Use a valid ontology ID
404-
format = 'owl'
405-
406-
print(f'Testing load_from_catalog() with: {ontology_id}.{format}')
407-
onto_catalog = adapter.load_from_catalog(ontology_id, format)
408-
print(f'Loaded ontology: {ontology_id}.{format}')
409-
print(f'Number of terms: {len(onto_catalog._ontology.terms())}')
410-
411-
# ---- Functionality 3. load_from_url()
412-
url_chebi_ontology = 'https://purl.obolibrary.org/obo/chebi.owl'
413-
filename = 'chebi.owl'
414-
onto_url = adapter.load_from_url(
415-
url_ontology=url_chebi_ontology,
416-
filename=filename,
417-
downloader=PoochDownloaderAdapter(
418-
cache_dir=cache
419-
), # By Dependency Injection
420-
)
421-
print(f'Loaded ontology: {filename}')
422-
print(f'Number of terms: {len(onto_url._ontology.terms())}')

ontograph/queries/introspection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ def insert_branch(root: Node, branch: list) -> None:
223223
node = node.children[key]
224224

225225
# All branches are sorted from term to root, so reverse to root-to-term
226-
sorted_branches = [list(branch) for branch in trajectories]
227-
root_info = sorted_branches[0][0]
226+
branch_lists = [list(branch) for branch in trajectories]
227+
root_info = branch_lists[0][0]
228228
root = Node(root_info['id'], root_info['name'], root_info['distance'])
229-
for branch in sorted_branches:
229+
for branch in branch_lists:
230230
insert_branch(root, branch[1:]) # skip root itself, already created
231231
return root
232232

ontograph/queries/navigator.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,6 @@ def get_root(self) -> list:
333333
Exception: If an error occurs during root term retrieval.
334334
"""
335335
try:
336-
# root_terms = [
337-
# term
338-
# for term in self.__ontology.terms()
339-
# if not any(term.superclasses(distance=1, with_self=False))
340-
# ]
341336
root_terms = []
342337

343338
for term in self.__ontology.terms():

ontograph/queries/relations.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,9 @@ def is_sibling(self, nodeA: str, nodeB: str) -> bool:
8383
Exception: If an error occurs during parent lookup.
8484
"""
8585
try:
86-
parentsA = {
87-
parent.id
88-
for parent in self.__navigator.get_term(nodeA).superclasses(
89-
distance=1, with_self=False
90-
)
91-
}
92-
parentsB = {
93-
parent.id
94-
for parent in self.__navigator.get_term(nodeB).superclasses(
95-
distance=1, with_self=False
96-
)
97-
}
86+
parentsA = set(self.__navigator.get_parents(term_id=nodeA))
87+
parentsB = set(self.__navigator.get_parents(term_id=nodeB))
88+
9889
# Siblings must not be the same node and must share at least one parent
9990
return nodeA != nodeB and bool(parentsA & parentsB)
10091
except Exception as e:

0 commit comments

Comments
 (0)