Skip to content

Commit

Permalink
name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hesspnnl committed Jan 31, 2025
1 parent 9c9c6e0 commit 1aaa9e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
31 changes: 18 additions & 13 deletions nmdc_notebook_tools/functional_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ class FunctionalSearch:
def __init__(self):
self.collectioninstance = CollectionSearch("functional_annotation_agg")

def get_functional_annotation_id(
self, id: str, id_type: str, page_size=25, fields="", all_pages=False
def get_functional_annotations(
self,
annotation: str,
annotation_type: str,
page_size=25,
fields="",
all_pages=False,
):
"""
Get a record from the NMDC API by id. ID types can be KEGG, COG, or PFAM.
params:
id: str
annotation: str
The data base id to query the function annotations.
id_type:
annotation_type:
The type of id to query. MUST be one of the following:
KEGG
COG
Expand All @@ -32,23 +37,23 @@ def get_functional_annotation_id(
all_pages: bool
True to return all pages. False to return the first page. Default is False.
"""
if id_type not in ["KEGG", "COG", "PFAM"]:
if annotation_type not in ["KEGG", "COG", "PFAM"]:
raise ValueError("id_type must be one of the following: KEGG, COG, PFAM")
if id_type == "KEGG":
formatted_id_type = f"KEGG.ORTHOLOGY:{id}"
elif id_type == "COG":
formatted_id_type = f"COG:{id}"
elif id_type == "PFAM":
formatted_id_type = f"PFAM:{id}"
if annotation_type == "KEGG":
formatted_annotation_type = f"KEGG.ORTHOLOGY:{annotation}"
elif annotation_type == "COG":
formatted_annotation_type = f"COG:{annotation}"
elif annotation_type == "PFAM":
formatted_annotation_type = f"PFAM:{annotation}"

filter = f'{{"gene_function_id": "{formatted_id_type}"}}'
filter = f'{{"gene_function_id": "{formatted_annotation_type}"}}'

result = self.collectioninstance.get_record_by_filter(
filter, page_size, fields, all_pages
)
return result

def get_records_by_id(
def get_records(
self,
filter: str = "",
max_page_size: int = 100,
Expand Down
4 changes: 2 additions & 2 deletions nmdc_notebook_tools/test/test_func_ann_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
class TestFunctionalAnnotation(unittest.TestCase):
def test_func_ann_id(self):
fannagg = FunctionalAnnotationAggSearch()
results = fannagg.get_functional_annotation_id("K01426", "KEGG")
results = fannagg.get_functional_annotations("K01426", "KEGG")
self.assertGreater(len(results), 0)
self.assertEqual(results[0]["gene_function_id"], "KEGG.ORTHOLOGY:K01426")

def test_func_ann_id_fail(self):
fannagg = FunctionalAnnotationAggSearch()
with self.assertRaises(ValueError):
fannagg.get_functional_annotation_id("K01426", "nfjbg")
fannagg.get_functional_annotations("K01426", "nfjbg")

0 comments on commit 1aaa9e8

Please sign in to comment.