aiagents4pharma 1.13.1__tar.gz → 1.14.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/PKG-INFO +1 -1
- aiagents4pharma-1.14.1/aiagents4pharma/configs/config.yaml +4 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/configs/talk2biomodels/__init__.py +1 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/default.yaml +2 -3
- aiagents4pharma-1.14.1/aiagents4pharma/configs/talk2biomodels/tools/__init__.py +4 -0
- aiagents4pharma-1.14.1/aiagents4pharma/configs/talk2biomodels/tools/ask_question/__init__.py +3 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/__init__.py +1 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/agents/t2b_agent.py +4 -2
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/api/__init__.py +6 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/api/kegg.py +83 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/api/ols.py +72 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/api/uniprot.py +35 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py +40 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_api.py +57 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_ask_question.py +44 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_get_annotation.py +171 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_getmodelinfo.py +26 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_integration.py +126 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_param_scan.py +68 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_search_models.py +28 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_simulate_model.py +39 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tests/test_steady_state.py +90 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/__init__.py +1 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/ask_question.py +29 -8
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tools/get_annotation.py +304 -0
- aiagents4pharma-1.14.1/aiagents4pharma/talk2biomodels/tools/load_arguments.py +114 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/parameter_scan.py +91 -96
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/simulate_model.py +14 -81
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/steady_state.py +48 -89
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma.egg-info/PKG-INFO +1 -1
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma.egg-info/SOURCES.txt +17 -1
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/pyproject.toml +3 -0
- aiagents4pharma-1.14.1/release_version.txt +1 -0
- aiagents4pharma-1.13.1/aiagents4pharma/configs/config.yaml +0 -3
- aiagents4pharma-1.13.1/aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py +0 -25
- aiagents4pharma-1.13.1/aiagents4pharma/talk2biomodels/tests/test_langgraph.py +0 -384
- aiagents4pharma-1.13.1/release_version.txt +0 -1
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/LICENSE +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/README.md +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/configs/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/configs/talk2biomodels/agents/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/agents/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/models/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/models/basico_model.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/models/sys_bio_model.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/states/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tests/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tests/test_basico_model.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tests/test_sys_bio_model.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/custom_plotter.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/get_modelinfo.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/load_biomodel.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/tools/search_models.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/agents/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/agents/scp_agent.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/states/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/states/state_talk2cells.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/tests/scp_agent/test_scp_agent.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/tools/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/tools/scp_agent/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/tools/scp_agent/display_studies.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2cells/tools/scp_agent/search_studies.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/agents/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/agents/main_agent.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/agents/s2_agent.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/config/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/config/config.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/state/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/state/state_talk2competitors.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/tests/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/tests/test_langgraph.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/tools/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/tools/s2/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/tools/s2/display_results.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/tools/s2/multi_paper_rec.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/tools/s2/search.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2competitors/tools/s2/single_paper_rec.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/datasets/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/datasets/biobridge_primekg.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/datasets/dataset.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/datasets/primekg.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/datasets/starkqa_primekg.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_biobridge_primekg.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_dataset.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_primekg.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_starkqa_primekg.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_embeddings.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_huggingface.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_sentencetransformer.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_enrichments.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_ollama.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/embeddings/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/embeddings/embeddings.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/embeddings/huggingface.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/embeddings/sentence_transformer.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/enrichments/__init__.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/enrichments/enrichments.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/enrichments/ollama.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2knowledgegraphs/utils/kg_utils.py +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma.egg-info/dependency_links.txt +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma.egg-info/requires.txt +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma.egg-info/top_level.txt +0 -0
- {aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: aiagents4pharma
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.14.1
|
4
4
|
Summary: AI Agents for drug discovery, drug development, and other pharmaceutical R&D
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
@@ -4,6 +4,5 @@ state_modifier: >
|
|
4
4
|
If the user asks for the uploaded model,
|
5
5
|
then pass the use_uploaded_model argument
|
6
6
|
as True. If the user asks for simulation
|
7
|
-
or steady state, suggest a
|
8
|
-
|
9
|
-
argument.
|
7
|
+
or param_scan or steady state, suggest a
|
8
|
+
value for the `experiment_name` argument.
|
{aiagents4pharma-1.13.1 → aiagents4pharma-1.14.1}/aiagents4pharma/talk2biomodels/agents/t2b_agent.py
RENAMED
@@ -15,6 +15,7 @@ from ..tools.search_models import SearchModelsTool
|
|
15
15
|
from ..tools.get_modelinfo import GetModelInfoTool
|
16
16
|
from ..tools.simulate_model import SimulateModelTool
|
17
17
|
from ..tools.custom_plotter import CustomPlotterTool
|
18
|
+
from ..tools.get_annotation import GetAnnotationTool
|
18
19
|
from ..tools.ask_question import AskQuestionTool
|
19
20
|
from ..tools.parameter_scan import ParameterScanTool
|
20
21
|
from ..tools.steady_state import SteadyStateTool
|
@@ -44,8 +45,9 @@ def get_app(uniq_id, llm_model='gpt-4o-mini'):
|
|
44
45
|
SearchModelsTool(),
|
45
46
|
GetModelInfoTool(),
|
46
47
|
SteadyStateTool(),
|
47
|
-
ParameterScanTool()
|
48
|
-
|
48
|
+
ParameterScanTool(),
|
49
|
+
GetAnnotationTool()
|
50
|
+
])
|
49
51
|
|
50
52
|
# Define the model
|
51
53
|
llm = ChatOpenAI(model=llm_model, temperature=0)
|
@@ -0,0 +1,83 @@
|
|
1
|
+
"""
|
2
|
+
This module contains the API for fetching Kegg database
|
3
|
+
"""
|
4
|
+
import re
|
5
|
+
from typing import List, Dict
|
6
|
+
import requests
|
7
|
+
|
8
|
+
def fetch_from_api(base_url: str, query: str) -> str:
|
9
|
+
"""Fetch data from the given API endpoint."""
|
10
|
+
try:
|
11
|
+
response = requests.get(base_url + query, timeout=10)
|
12
|
+
response.raise_for_status()
|
13
|
+
return response.text
|
14
|
+
except requests.exceptions.RequestException as e:
|
15
|
+
print(f"Error fetching data for query {query}: {e}")
|
16
|
+
return ""
|
17
|
+
|
18
|
+
def fetch_kegg_names(ids: List[str], batch_size: int = 10) -> Dict[str, str]:
|
19
|
+
"""
|
20
|
+
Fetch the names of multiple KEGG entries using the KEGG REST API in batches.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
ids (List[str]): List of KEGG IDs.
|
24
|
+
batch_size (int): Maximum number of IDs to include in a single request.
|
25
|
+
|
26
|
+
Returns:
|
27
|
+
Dict[str, str]: A mapping of KEGG IDs to their names.
|
28
|
+
"""
|
29
|
+
if not ids:
|
30
|
+
return {}
|
31
|
+
|
32
|
+
base_url = "https://rest.kegg.jp/get/"
|
33
|
+
entry_name_map = {}
|
34
|
+
|
35
|
+
# Process IDs in batches
|
36
|
+
for i in range(0, len(ids), batch_size):
|
37
|
+
batch = ids[i:i + batch_size]
|
38
|
+
query = "+".join(batch)
|
39
|
+
entry_data = fetch_from_api(base_url, query)
|
40
|
+
|
41
|
+
# if not entry_data:
|
42
|
+
# continue
|
43
|
+
entries = entry_data.split("///")
|
44
|
+
for entry in entries:
|
45
|
+
if not entry.strip():
|
46
|
+
continue
|
47
|
+
lines = entry.strip().split("\n")
|
48
|
+
entry_line = next((line for line in lines
|
49
|
+
if line.startswith("ENTRY")), None)
|
50
|
+
name_line = next((line for line in lines
|
51
|
+
if line.startswith("NAME")), None)
|
52
|
+
|
53
|
+
# if not entry_line and not name_line:
|
54
|
+
# continue
|
55
|
+
entry_id = entry_line.split()[1]
|
56
|
+
# Split multiple names in the NAME field and clean them
|
57
|
+
names = [
|
58
|
+
re.sub(r'[^a-zA-Z0-9\s]', '', name).strip()
|
59
|
+
for name in name_line.replace("NAME", "").strip().split(";")
|
60
|
+
]
|
61
|
+
# Join cleaned names into a single string
|
62
|
+
entry_name_map[entry_id] = " ".join(names).strip()
|
63
|
+
|
64
|
+
return entry_name_map
|
65
|
+
|
66
|
+
def fetch_kegg_annotations(data: List[Dict[str, str]],
|
67
|
+
batch_size: int = 10) -> Dict[str, Dict[str, str]]:
|
68
|
+
"""Fetch KEGG entry descriptions grouped by database type."""
|
69
|
+
grouped_data = {}
|
70
|
+
for entry in data:
|
71
|
+
db_type = entry["Database"].lower()
|
72
|
+
grouped_data.setdefault(db_type, []).append(entry["Id"])
|
73
|
+
|
74
|
+
results = {}
|
75
|
+
for db_type, ids in grouped_data.items():
|
76
|
+
results[db_type] = fetch_kegg_names(ids, batch_size=batch_size)
|
77
|
+
|
78
|
+
return results
|
79
|
+
|
80
|
+
# def get_protein_name_or_label(data: List[Dict[str, str]],
|
81
|
+
# batch_size: int = 10) -> Dict[str, Dict[str, str]]:
|
82
|
+
# """Fetch descriptions for KEGG-related identifiers."""
|
83
|
+
# return fetch_kegg_annotations(data, batch_size=batch_size)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"""
|
2
|
+
This module contains the API for fetching ols database
|
3
|
+
"""
|
4
|
+
from typing import List, Dict
|
5
|
+
import requests
|
6
|
+
|
7
|
+
def fetch_from_ols(term: str) -> str:
|
8
|
+
"""
|
9
|
+
Fetch the label for a single term from OLS.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
term (str): The term in the format "ONTOLOGY:TERM_ID".
|
13
|
+
|
14
|
+
Returns:
|
15
|
+
str: The label for the term or an error message.
|
16
|
+
"""
|
17
|
+
try:
|
18
|
+
ontology, _ = term.split(":")
|
19
|
+
base_url = f"https://www.ebi.ac.uk/ols4/api/ontologies/{ontology.lower()}/terms"
|
20
|
+
params = {"obo_id": term}
|
21
|
+
response = requests.get(
|
22
|
+
base_url,
|
23
|
+
params=params,
|
24
|
+
headers={"Accept": "application/json"},
|
25
|
+
timeout=10
|
26
|
+
)
|
27
|
+
response.raise_for_status()
|
28
|
+
data = response.json()
|
29
|
+
label = '-'
|
30
|
+
# Extract and return the label
|
31
|
+
if "_embedded" in data and "terms" in data["_embedded"] \
|
32
|
+
and len(data["_embedded"]["terms"]) > 0:
|
33
|
+
label = data["_embedded"]["terms"][0].get("label", "Label not found")
|
34
|
+
return label
|
35
|
+
except (requests.exceptions.RequestException, KeyError, IndexError) as e:
|
36
|
+
return f"Error: {str(e)}"
|
37
|
+
|
38
|
+
def fetch_ols_labels(terms: List[str]) -> Dict[str, str]:
|
39
|
+
"""
|
40
|
+
Fetch labels for multiple terms from OLS.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
terms (List[str]): A list of terms in the format "ONTOLOGY:TERM_ID".
|
44
|
+
|
45
|
+
Returns:
|
46
|
+
Dict[str, str]: A mapping of term IDs to their labels or error messages.
|
47
|
+
"""
|
48
|
+
results = {}
|
49
|
+
for term in terms:
|
50
|
+
results[term] = fetch_from_ols(term)
|
51
|
+
return results
|
52
|
+
|
53
|
+
def search_ols_labels(data: List[Dict[str, str]]) -> Dict[str, Dict[str, str]]:
|
54
|
+
"""
|
55
|
+
Fetch OLS annotations grouped by ontology type.
|
56
|
+
|
57
|
+
Args:
|
58
|
+
data (List[Dict[str, str]]): A list of dictionaries containing 'Id' and 'Database'.
|
59
|
+
|
60
|
+
Returns:
|
61
|
+
Dict[str, Dict[str, str]]: A mapping of ontology type to term labels.
|
62
|
+
"""
|
63
|
+
grouped_data = {}
|
64
|
+
for entry in data:
|
65
|
+
ontology = entry["Database"].lower()
|
66
|
+
grouped_data.setdefault(ontology, []).append(entry["Id"])
|
67
|
+
|
68
|
+
results = {}
|
69
|
+
for ontology, terms in grouped_data.items():
|
70
|
+
results[ontology] = fetch_ols_labels(terms)
|
71
|
+
|
72
|
+
return results
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"""
|
2
|
+
This module contains the API for fetching uniprot database
|
3
|
+
"""
|
4
|
+
from typing import List, Dict
|
5
|
+
import requests
|
6
|
+
|
7
|
+
def search_uniprot_labels(identifiers: List[str]) -> Dict[str, str]:
|
8
|
+
"""
|
9
|
+
Fetch protein names or labels for a list of UniProt identifiers by making sequential requests.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
identifiers (List[str]): A list of UniProt identifiers.
|
13
|
+
|
14
|
+
Returns:
|
15
|
+
Dict[str, str]: A mapping of UniProt identifiers to their protein names or error messages.
|
16
|
+
"""
|
17
|
+
results = {}
|
18
|
+
base_url = "https://www.uniprot.org/uniprot/"
|
19
|
+
|
20
|
+
for identifier in identifiers:
|
21
|
+
url = f"{base_url}{identifier}.json"
|
22
|
+
try:
|
23
|
+
response = requests.get(url, timeout=10)
|
24
|
+
response.raise_for_status()
|
25
|
+
data = response.json()
|
26
|
+
protein_name = (
|
27
|
+
data.get('proteinDescription', {})
|
28
|
+
.get('recommendedName', {})
|
29
|
+
.get('fullName', {})
|
30
|
+
.get('value', 'Name not found')
|
31
|
+
)
|
32
|
+
results[identifier] = protein_name
|
33
|
+
except requests.exceptions.RequestException as e:
|
34
|
+
results[identifier] = f"Error: {str(e)}"
|
35
|
+
return results
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
|
3
|
+
'''
|
4
|
+
This is the state file for the Talk2BioModels agent.
|
5
|
+
'''
|
6
|
+
|
7
|
+
from typing import Annotated
|
8
|
+
import operator
|
9
|
+
from langgraph.prebuilt.chat_agent_executor import AgentState
|
10
|
+
|
11
|
+
def add_data(data1: dict, data2: dict) -> dict:
|
12
|
+
"""
|
13
|
+
A reducer function to merge two dictionaries.
|
14
|
+
"""
|
15
|
+
left_idx_by_name = {data['name']: idx for idx, data in enumerate(data1)}
|
16
|
+
merged = data1.copy()
|
17
|
+
for data in data2:
|
18
|
+
idx = left_idx_by_name.get(data['name'])
|
19
|
+
if idx is not None:
|
20
|
+
merged[idx] = data
|
21
|
+
else:
|
22
|
+
merged.append(data)
|
23
|
+
return merged
|
24
|
+
|
25
|
+
class Talk2Biomodels(AgentState):
|
26
|
+
"""
|
27
|
+
The state for the Talk2BioModels agent.
|
28
|
+
"""
|
29
|
+
llm_model: str
|
30
|
+
# A StateGraph may receive a concurrent updates
|
31
|
+
# which is not supported by the StateGraph. Hence,
|
32
|
+
# we need to add a reducer function to handle the
|
33
|
+
# concurrent updates.
|
34
|
+
# https://langchain-ai.github.io/langgraph/troubleshooting/errors/INVALID_CONCURRENT_GRAPH_UPDATE/
|
35
|
+
model_id: Annotated[list, operator.add]
|
36
|
+
sbml_file_path: Annotated[list, operator.add]
|
37
|
+
dic_simulated_data: Annotated[list[dict], add_data]
|
38
|
+
dic_scanned_data: Annotated[list[dict], add_data]
|
39
|
+
dic_steady_state_data: Annotated[list[dict], add_data]
|
40
|
+
dic_annotations_data : Annotated[list[dict], add_data]
|
@@ -0,0 +1,57 @@
|
|
1
|
+
'''
|
2
|
+
Test cases for Talk2Biomodels.
|
3
|
+
'''
|
4
|
+
|
5
|
+
from ..api.uniprot import search_uniprot_labels
|
6
|
+
from ..api.ols import fetch_from_ols
|
7
|
+
from ..api.kegg import fetch_kegg_names, fetch_from_api
|
8
|
+
|
9
|
+
def test_search_uniprot_labels():
|
10
|
+
'''
|
11
|
+
Test the search_uniprot_labels function.
|
12
|
+
'''
|
13
|
+
# "P61764" = Positive result, "P0000Q" = negative result
|
14
|
+
identifiers = ["P61764", "P0000Q"]
|
15
|
+
results = search_uniprot_labels(identifiers)
|
16
|
+
assert results["P61764"] == "Syntaxin-binding protein 1"
|
17
|
+
assert results["P0000Q"].startswith("Error: 400")
|
18
|
+
|
19
|
+
def test_fetch_from_ols():
|
20
|
+
'''
|
21
|
+
Test the fetch_from_ols function.
|
22
|
+
'''
|
23
|
+
term_1 = "GO:0005886" #Positive result
|
24
|
+
term_2 = "GO:ABC123" #Negative result
|
25
|
+
label_1 = fetch_from_ols(term_1)
|
26
|
+
label_2 = fetch_from_ols(term_2)
|
27
|
+
assert isinstance(label_1, str), f"Expected string, got {type(label_1)}"
|
28
|
+
assert isinstance(label_2, str), f"Expected string, got {type(label_2)}"
|
29
|
+
assert label_1 == "plasma membrane"
|
30
|
+
assert label_2.startswith("Error: 404")
|
31
|
+
|
32
|
+
def test_fetch_kegg_names():
|
33
|
+
'''
|
34
|
+
Test the fetch_kegg_names function.
|
35
|
+
'''
|
36
|
+
ids = ["C00001", "C00002"]
|
37
|
+
results = fetch_kegg_names(ids)
|
38
|
+
assert results["C00001"] == "H2O"
|
39
|
+
assert results["C00002"] == "ATP"
|
40
|
+
|
41
|
+
# Try with an empty list
|
42
|
+
results = fetch_kegg_names([])
|
43
|
+
assert not results
|
44
|
+
|
45
|
+
def test_fetch_from_api():
|
46
|
+
'''
|
47
|
+
Test the fetch_from_api function.
|
48
|
+
'''
|
49
|
+
base_url = "https://rest.kegg.jp/get/"
|
50
|
+
query = "C00001"
|
51
|
+
entry_data = fetch_from_api(base_url, query)
|
52
|
+
assert entry_data.startswith("ENTRY C00001")
|
53
|
+
|
54
|
+
# Try with an invalid query
|
55
|
+
query = "C0000Q"
|
56
|
+
entry_data = fetch_from_api(base_url, query)
|
57
|
+
assert not entry_data
|
@@ -0,0 +1,44 @@
|
|
1
|
+
'''
|
2
|
+
Test cases for Talk2Biomodels.
|
3
|
+
'''
|
4
|
+
|
5
|
+
from langchain_core.messages import HumanMessage, ToolMessage
|
6
|
+
from ..agents.t2b_agent import get_app
|
7
|
+
|
8
|
+
def test_ask_question_tool():
|
9
|
+
'''
|
10
|
+
Test the ask_question tool without the simulation results.
|
11
|
+
'''
|
12
|
+
unique_id = 12345
|
13
|
+
app = get_app(unique_id, llm_model='gpt-4o-mini')
|
14
|
+
config = {"configurable": {"thread_id": unique_id}}
|
15
|
+
|
16
|
+
##########################################
|
17
|
+
# Test ask_question tool when simulation
|
18
|
+
# results are not available i.e. the
|
19
|
+
# simulation has not been run. In this
|
20
|
+
# case, the tool should return an error
|
21
|
+
##########################################
|
22
|
+
# Update state
|
23
|
+
app.update_state(config, {"llm_model": "gpt-4o-mini"})
|
24
|
+
# Define the prompt
|
25
|
+
prompt = "Call the ask_question tool to answer the "
|
26
|
+
prompt += "question: What is the concentration of CRP "
|
27
|
+
prompt += "in serum at 1000 hours? The simulation name "
|
28
|
+
prompt += "is `simulation_name`."
|
29
|
+
# Invoke the tool
|
30
|
+
app.invoke(
|
31
|
+
{"messages": [HumanMessage(content=prompt)]},
|
32
|
+
config=config
|
33
|
+
)
|
34
|
+
# Get the messages from the current state
|
35
|
+
# and reverse the order
|
36
|
+
current_state = app.get_state(config)
|
37
|
+
reversed_messages = current_state.values["messages"][::-1]
|
38
|
+
# Loop through the reversed messages until a
|
39
|
+
# ToolMessage is found.
|
40
|
+
for msg in reversed_messages:
|
41
|
+
# Assert that the message is a ToolMessage
|
42
|
+
# and its status is "error"
|
43
|
+
if isinstance(msg, ToolMessage):
|
44
|
+
assert msg.status == "error"
|
@@ -0,0 +1,171 @@
|
|
1
|
+
'''
|
2
|
+
Test cases for Talk2Biomodels get_annotation tool.
|
3
|
+
'''
|
4
|
+
|
5
|
+
import random
|
6
|
+
import pytest
|
7
|
+
from langchain_core.messages import HumanMessage, ToolMessage
|
8
|
+
from ..agents.t2b_agent import get_app
|
9
|
+
from ..tools.get_annotation import prepare_content_msg
|
10
|
+
|
11
|
+
@pytest.fixture(name="make_graph")
|
12
|
+
def make_graph_fixture():
|
13
|
+
'''
|
14
|
+
Create an instance of the talk2biomodels agent.
|
15
|
+
'''
|
16
|
+
unique_id = random.randint(1000, 9999)
|
17
|
+
graph = get_app(unique_id)
|
18
|
+
config = {"configurable": {"thread_id": unique_id}}
|
19
|
+
return graph, config
|
20
|
+
|
21
|
+
def test_no_model_provided(make_graph):
|
22
|
+
'''
|
23
|
+
Test the tool by not specifying any model.
|
24
|
+
We are testing a condition where the user
|
25
|
+
asks for annotations of all species without
|
26
|
+
specifying a model.
|
27
|
+
'''
|
28
|
+
app, config = make_graph
|
29
|
+
prompt = "Extract annotations of all species. Call the tool get_annotation."
|
30
|
+
app.invoke({"messages": [HumanMessage(content=prompt)]},
|
31
|
+
config=config
|
32
|
+
)
|
33
|
+
current_state = app.get_state(config)
|
34
|
+
# Assert that the state key model_id is empty.
|
35
|
+
assert current_state.values["model_id"] == []
|
36
|
+
|
37
|
+
def test_specific_species_provided(make_graph):
|
38
|
+
'''
|
39
|
+
Test the tool by providing a specific species name.
|
40
|
+
We are testing a condition where the user asks for annotations
|
41
|
+
of a specific species in a specific model.
|
42
|
+
'''
|
43
|
+
# Test with a valid species name
|
44
|
+
app, config = make_graph
|
45
|
+
prompt = "Extract annotations of species IL6 in model 537."
|
46
|
+
app.invoke(
|
47
|
+
{"messages": [HumanMessage(content=prompt)]},
|
48
|
+
config=config
|
49
|
+
)
|
50
|
+
current_state = app.get_state(config)
|
51
|
+
# print (current_state.values["dic_annotations_data"])
|
52
|
+
dic_annotations_data = current_state.values["dic_annotations_data"]
|
53
|
+
|
54
|
+
# The assert statement checks if IL6 is present in the returned annotations.
|
55
|
+
assert dic_annotations_data[0]['data']["Species Name"][0] == "IL6"
|
56
|
+
|
57
|
+
# Test with an invalid species name
|
58
|
+
app, config = make_graph
|
59
|
+
prompt = "Extract annotations of species NADH in model 537."
|
60
|
+
app.invoke(
|
61
|
+
{"messages": [HumanMessage(content=prompt)]},
|
62
|
+
config=config
|
63
|
+
)
|
64
|
+
current_state = app.get_state(config)
|
65
|
+
reversed_messages = current_state.values["messages"][::-1]
|
66
|
+
# Loop through the reversed messages until a
|
67
|
+
# ToolMessage is found.
|
68
|
+
|
69
|
+
test_condition = False
|
70
|
+
for msg in reversed_messages:
|
71
|
+
# Assert that the one of the messages is a ToolMessage
|
72
|
+
# and its artifact is None.
|
73
|
+
if isinstance(msg, ToolMessage) and msg.name == "get_annotation":
|
74
|
+
#If a ToolMessage exists and artifact is None (meaning no valid annotation was found)
|
75
|
+
#and the rejected species (NADH) is mentioned, the test passes.
|
76
|
+
if msg.artifact is None and 'NADH' in msg.content:
|
77
|
+
#If artifact is None, it means no annotation was found
|
78
|
+
# (likely due to an invalid species).
|
79
|
+
#If artifact contains data, the tool successfully retrieved annotations.
|
80
|
+
test_condition = True
|
81
|
+
break
|
82
|
+
# assert test_condition
|
83
|
+
assert test_condition, "Expected rejection message for NADH but did not find it."
|
84
|
+
|
85
|
+
# Test with an invalid species name and a valid species name
|
86
|
+
app, config = make_graph
|
87
|
+
prompt = "Extract annotations of species NADH, NAD, and IL7 in model 64."
|
88
|
+
app.invoke(
|
89
|
+
{"messages": [HumanMessage(content=prompt)]},
|
90
|
+
config=config
|
91
|
+
)
|
92
|
+
current_state = app.get_state(config)
|
93
|
+
# dic_annotations_data = current_state.values["dic_annotations_data"]
|
94
|
+
reversed_messages = current_state.values["messages"][::-1]
|
95
|
+
# Loop through the reversed messages until a
|
96
|
+
# ToolMessage is found.
|
97
|
+
artifact_was_none = False
|
98
|
+
for msg in reversed_messages:
|
99
|
+
# Assert that the one of the messages is a ToolMessage
|
100
|
+
# and its artifact is None.
|
101
|
+
if isinstance(msg, ToolMessage) and msg.name == "get_annotation":
|
102
|
+
# print (msg.artifact, msg.content)
|
103
|
+
|
104
|
+
if msg.artifact is True and 'IL7' in msg.content:
|
105
|
+
artifact_was_none = True
|
106
|
+
break
|
107
|
+
assert artifact_was_none
|
108
|
+
|
109
|
+
def test_all_species_annotations(make_graph):
|
110
|
+
'''
|
111
|
+
Test the tool by asking for annotations of all species is specific models.
|
112
|
+
Here, we test the tool with three models since they have different use cases:
|
113
|
+
- model 12 contains a species with no URL provided.
|
114
|
+
- model 20 contains a species without description.
|
115
|
+
- model 56 contains a species with database outside of KEGG, UniProt, and OLS.
|
116
|
+
|
117
|
+
We are testing a condition where the user asks for annotations
|
118
|
+
of all species in a specific model.
|
119
|
+
'''
|
120
|
+
# Loop through the models and test the tool
|
121
|
+
# for each model's unique use case.
|
122
|
+
for model_id in [12, 20, 56]:
|
123
|
+
app, config = make_graph
|
124
|
+
prompt = f"Extract annotations of all species model {model_id}."
|
125
|
+
# Test the tool get_modelinfo
|
126
|
+
app.invoke({"messages": [HumanMessage(content=prompt)]},
|
127
|
+
config=config
|
128
|
+
)
|
129
|
+
current_state = app.get_state(config)
|
130
|
+
|
131
|
+
reversed_messages = current_state.values["messages"][::-1]
|
132
|
+
# Coveres all of the use cases for the expecetd sting on all the species
|
133
|
+
test_condition = False
|
134
|
+
for msg in reversed_messages:
|
135
|
+
# Skip messages that are not ToolMessages and those that are not
|
136
|
+
# from the get_annotation tool.
|
137
|
+
if not isinstance(msg, ToolMessage) or msg.name != "get_annotation":
|
138
|
+
continue
|
139
|
+
if model_id == 12:
|
140
|
+
# Extact the first and second description of the LacI protein
|
141
|
+
# We already know that the first or second description is missing ('-')
|
142
|
+
dic_annotations_data = current_state.values["dic_annotations_data"][0]
|
143
|
+
first_descp_laci_protein = dic_annotations_data['data']['Description'][0]
|
144
|
+
second_descp_laci_protein = dic_annotations_data['data']['Description'][1]
|
145
|
+
|
146
|
+
# Expect a successful extraction (artifact is True) and that the content
|
147
|
+
# matches what is returned by prepare_content_msg for species.
|
148
|
+
# And that the first or second description of the LacI protein is missing.
|
149
|
+
if (msg.artifact is True and msg.content == prepare_content_msg([],[])
|
150
|
+
and msg.status=="success" and (first_descp_laci_protein == '-' or
|
151
|
+
second_descp_laci_protein == '-')):
|
152
|
+
test_condition = True
|
153
|
+
break
|
154
|
+
|
155
|
+
if model_id == 20:
|
156
|
+
# Expect an error message containing a note
|
157
|
+
# that species extraction failed.
|
158
|
+
if ("Unable to extract species from the model"
|
159
|
+
in msg.content and msg.status == "error"):
|
160
|
+
test_condition = True
|
161
|
+
break
|
162
|
+
|
163
|
+
if model_id == 56:
|
164
|
+
# Expect a successful extraction (artifact is True) and that the content
|
165
|
+
# matches for for missing description ['ORI'].
|
166
|
+
if (msg.artifact is True and
|
167
|
+
msg.content == prepare_content_msg([],['ORI'])
|
168
|
+
and msg.status == "success"):
|
169
|
+
test_condition = True
|
170
|
+
break
|
171
|
+
assert test_condition # Expected output is validated
|
@@ -0,0 +1,26 @@
|
|
1
|
+
'''
|
2
|
+
Test cases for Talk2Biomodels get_modelinfo tool.
|
3
|
+
'''
|
4
|
+
|
5
|
+
from langchain_core.messages import HumanMessage
|
6
|
+
from ..agents.t2b_agent import get_app
|
7
|
+
|
8
|
+
def test_get_modelinfo_tool():
|
9
|
+
'''
|
10
|
+
Test the get_modelinfo tool.
|
11
|
+
'''
|
12
|
+
unique_id = 12345
|
13
|
+
app = get_app(unique_id)
|
14
|
+
config = {"configurable": {"thread_id": unique_id}}
|
15
|
+
# Update state
|
16
|
+
app.update_state(config,
|
17
|
+
{"sbml_file_path": ["aiagents4pharma/talk2biomodels/tests/BIOMD0000000449_url.xml"]})
|
18
|
+
prompt = "Extract all relevant information from the uploaded model."
|
19
|
+
# Test the tool get_modelinfo
|
20
|
+
response = app.invoke(
|
21
|
+
{"messages": [HumanMessage(content=prompt)]},
|
22
|
+
config=config
|
23
|
+
)
|
24
|
+
assistant_msg = response["messages"][-1].content
|
25
|
+
# Check if the assistant message is a string
|
26
|
+
assert isinstance(assistant_msg, str)
|