Skip to content

Commit

Permalink
ENH Bundle aro.obo with argNorm
Browse files Browse the repository at this point in the history
Previously, it was repeatedly loaded from the internet
  • Loading branch information
luispedro committed May 25, 2024
1 parent feb9e08 commit 8cdf7ab
Show file tree
Hide file tree
Showing 6 changed files with 63,917 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased

- Bundle a specific version of ARO with the package instead of downloading it from the internet (ensures reproducibility)

## 0.3.0 - 27 April 2024

Expand Down
63,885 changes: 63,885 additions & 0 deletions argnorm/data/aro.obo

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions argnorm/drug_categorization.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pronto
from typing import List
from . import lib

# Load the ARO ontology from internet
ARO = pronto.Ontology.from_obo_library('aro.obo')
ARO = lib.get_aro_ontology()
confers_resistance_to_drug_class_rel = ARO.get_relationship('confers_resistance_to_drug_class')
confers_resistance_to_antibiotic_rel = ARO.get_relationship('confers_resistance_to_antibiotic')

Expand Down
24 changes: 20 additions & 4 deletions argnorm/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@
pd.options.mode.copy_on_write = True
except pd.errors.OptionError:
pass
import pronto

ORIGINAL_ID_COL = 'Original ID'
MAPPING_TABLE_ARO_COL = 'ARO'
TARGET_ARO_COL = 'ARO'

_ROOT = os.path.abspath(os.path.dirname(__file__))
_ARO = None

def get_aro_ontology():
"""
The ARO ontology used by (bundled with) argNorm
Returns:
ARO (pronto.Ontology): A pronto ontology object with ARO terms.
"""
import pronto
import importlib.resources
global _ARO
if _ARO is None:
_ARO = pronto.Ontology(
importlib.resources.files('argnorm')
.joinpath('data/aro.obo')
.open('rb'))
return _ARO

def get_aro_mapping_table(database):
"""
Expand Down Expand Up @@ -66,6 +83,5 @@ def map_to_aro(gene, database):
else:
if pd.isna(result):
return None

ARO = pronto.Ontology.from_obo_library('aro.obo')
return ARO.get(result)
ARO = get_aro_ontology()
return ARO.get(result)
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
packages=['argnorm', 'argnorm.data'],
include_package_data=True,
package_dir={'argnorm': 'argnorm' },
package_data={'argnorm': ['data/*.tsv', 'data/manual_curation/*.tsv']},
package_data={'argnorm': [
'data/aro.obo',
'data/*.tsv',
'data/manual_curation/*.tsv'
]},
install_requires=open("./requirements.txt", "r").read().splitlines(),
long_description=open("./README.md", "r").read(),
long_description_content_type='text/markdown',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from argnorm import lib
from argnorm.lib import map_to_aro, get_aro_mapping_table
import pronto

def test_map_to_aro():
test_cases = [
Expand All @@ -11,7 +11,7 @@ def test_map_to_aro():
["(Phe)cpt_strepv:U09991:AAB36569:1412-1948:537", "argannot"]
]

ARO = pronto.Ontology.from_obo_library('aro.obo')
ARO = lib.get_aro_ontology()
expected_output = [
ARO.get_term('ARO:3002563'),
ARO.get_term('ARO:3004623'),
Expand Down

0 comments on commit 8cdf7ab

Please sign in to comment.