aiagents4pharma 1.8.2__tar.gz → 1.8.3__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.
Files changed (69) hide show
  1. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/PKG-INFO +1 -1
  2. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/__init__.py +1 -0
  3. aiagents4pharma-1.8.3/aiagents4pharma/configs/__init__.py +5 -0
  4. aiagents4pharma-1.8.3/aiagents4pharma/configs/config.yaml +3 -0
  5. aiagents4pharma-1.8.3/aiagents4pharma/configs/talk2biomodels/__init__.py +5 -0
  6. aiagents4pharma-1.8.3/aiagents4pharma/configs/talk2biomodels/agents/__init__.py +5 -0
  7. aiagents4pharma-1.8.3/aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/__init__.py +3 -0
  8. aiagents4pharma-1.8.3/aiagents4pharma/configs/talk2biomodels/agents/t2b_agent/default.yaml +6 -0
  9. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/agents/t2b_agent.py +3 -3
  10. aiagents4pharma-1.8.3/aiagents4pharma/talk2biomodels/tests/__init__.py +3 -0
  11. aiagents4pharma-1.8.3/aiagents4pharma/talk2biomodels/tests/test_basico_model.py +55 -0
  12. aiagents4pharma-1.8.3/aiagents4pharma/talk2biomodels/tests/test_langgraph.py +189 -0
  13. aiagents4pharma-1.8.3/aiagents4pharma/talk2biomodels/tests/test_sys_bio_model.py +57 -0
  14. aiagents4pharma-1.8.3/aiagents4pharma/talk2cells/tests/scp_agent/test_scp_agent.py +23 -0
  15. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/tests/__init__.py +0 -0
  16. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_biobridge_primekg.py +242 -0
  17. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_dataset.py +29 -0
  18. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_primekg.py +73 -0
  19. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_starkqa_primekg.py +116 -0
  20. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_embeddings.py +47 -0
  21. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_huggingface.py +45 -0
  22. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_sentencetransformer.py +40 -0
  23. aiagents4pharma-1.8.3/aiagents4pharma/talk2knowledgegraphs/utils/__init__.py +0 -0
  24. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma.egg-info/PKG-INFO +1 -1
  25. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma.egg-info/SOURCES.txt +20 -0
  26. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/pyproject.toml +9 -19
  27. aiagents4pharma-1.8.3/release_version.txt +1 -0
  28. aiagents4pharma-1.8.2/release_version.txt +0 -1
  29. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/LICENSE +0 -0
  30. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/README.md +0 -0
  31. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/__init__.py +0 -0
  32. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/agents/__init__.py +0 -0
  33. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/models/__init__.py +0 -0
  34. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/models/basico_model.py +0 -0
  35. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/models/sys_bio_model.py +0 -0
  36. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/states/__init__.py +0 -0
  37. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py +0 -0
  38. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/tools/__init__.py +0 -0
  39. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/tools/ask_question.py +0 -0
  40. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/tools/custom_plotter.py +0 -0
  41. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/tools/get_modelinfo.py +0 -0
  42. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/tools/load_biomodel.py +0 -0
  43. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/tools/search_models.py +0 -0
  44. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2biomodels/tools/simulate_model.py +0 -0
  45. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/__init__.py +0 -0
  46. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/agents/__init__.py +0 -0
  47. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/agents/scp_agent.py +0 -0
  48. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/states/__init__.py +0 -0
  49. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/states/state_talk2cells.py +0 -0
  50. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/tools/__init__.py +0 -0
  51. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/tools/scp_agent/__init__.py +0 -0
  52. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/tools/scp_agent/display_studies.py +0 -0
  53. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2cells/tools/scp_agent/search_studies.py +0 -0
  54. {aiagents4pharma-1.8.2/aiagents4pharma/talk2knowledgegraphs/utils → aiagents4pharma-1.8.3/aiagents4pharma/talk2competitors}/__init__.py +0 -0
  55. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/__init__.py +0 -0
  56. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/datasets/__init__.py +0 -0
  57. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/datasets/biobridge_primekg.py +0 -0
  58. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/datasets/dataset.py +0 -0
  59. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/datasets/primekg.py +0 -0
  60. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/datasets/starkqa_primekg.py +0 -0
  61. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/utils/embeddings/__init__.py +0 -0
  62. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/utils/embeddings/embeddings.py +0 -0
  63. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/utils/embeddings/huggingface.py +0 -0
  64. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/utils/embeddings/sentence_transformer.py +0 -0
  65. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma/talk2knowledgegraphs/utils/kg_utils.py +0 -0
  66. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma.egg-info/dependency_links.txt +0 -0
  67. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma.egg-info/requires.txt +0 -0
  68. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/aiagents4pharma.egg-info/top_level.txt +0 -0
  69. {aiagents4pharma-1.8.2 → aiagents4pharma-1.8.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: aiagents4pharma
3
- Version: 1.8.2
3
+ Version: 1.8.3
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
@@ -5,3 +5,4 @@ This file is used to import aiagents4pharma modules.
5
5
  from . import talk2biomodels
6
6
  from . import talk2cells
7
7
  from . import talk2knowledgegraphs
8
+ from . import configs
@@ -0,0 +1,5 @@
1
+ '''
2
+ Import all the modules in the package
3
+ '''
4
+
5
+ from . import talk2biomodels
@@ -0,0 +1,3 @@
1
+ defaults:
2
+ - _self_
3
+ - talk2biomodels/agents/t2b_agent: default
@@ -0,0 +1,5 @@
1
+ '''
2
+ Import all the modules in the package
3
+ '''
4
+
5
+ from . import agents
@@ -0,0 +1,5 @@
1
+ '''
2
+ Import all the modules in the package
3
+ '''
4
+
5
+ from . import t2b_agent
@@ -0,0 +1,3 @@
1
+ '''
2
+ Import all the modules in the package
3
+ '''
@@ -0,0 +1,6 @@
1
+ _target_: talk2biomodels.agents.t2b_agent.get_app
2
+ state_modifier: >
3
+ You are Talk2BioModels agent.
4
+ If the user asks for the uploaded model,
5
+ then pass the use_uploaded_model argument
6
+ as True.
@@ -52,10 +52,10 @@ def get_app(uniq_id, llm_model='gpt-4o-mini'):
52
52
  llm = ChatOpenAI(model=llm_model, temperature=0)
53
53
  # Load hydra configuration
54
54
  logger.log(logging.INFO, "Load Hydra configuration for Talk2BioModels agent.")
55
- with hydra.initialize(version_base=None, config_path="../../../configs"):
55
+ with hydra.initialize(version_base=None, config_path="../../configs"):
56
56
  cfg = hydra.compose(config_name='config',
57
- overrides=['aiagents4pharma/talk2biomodels/agents/t2b_agent=default'])
58
- cfg = cfg.aiagents4pharma.talk2biomodels.agents.t2b_agent
57
+ overrides=['talk2biomodels/agents/t2b_agent=default'])
58
+ cfg = cfg.talk2biomodels.agents.t2b_agent
59
59
  logger.log(logging.INFO, "state_modifier: %s", cfg.state_modifier)
60
60
  # Create the agent
61
61
  model = create_react_agent(
@@ -0,0 +1,3 @@
1
+ '''
2
+ This module contains the test cases.
3
+ '''
@@ -0,0 +1,55 @@
1
+ '''
2
+ A test BasicoModel class for pytest unit testing.
3
+ '''
4
+
5
+ import pandas as pd
6
+ import pytest
7
+ import basico
8
+ from ..models.basico_model import BasicoModel
9
+
10
+ @pytest.fixture(name="model")
11
+ def model_fixture():
12
+ """
13
+ A fixture for the BasicoModel class.
14
+ """
15
+ return BasicoModel(biomodel_id=64, species={"Pyruvate": 100}, duration=2, interval=2)
16
+
17
+ def test_with_biomodel_id(model):
18
+ """
19
+ Test initialization of BasicoModel with biomodel_id.
20
+ """
21
+ assert model.biomodel_id == 64
22
+ # check if the simulation results are a pandas DataFrame object
23
+ assert isinstance(model.simulate(parameters={'Pyruvate': 0.5, 'KmPFKF6P': 1.5},
24
+ duration=2,
25
+ interval=2),
26
+ pd.DataFrame)
27
+ assert isinstance(model.simulate(parameters={None: None}, duration=2, interval=2),
28
+ pd.DataFrame)
29
+ assert model.description == basico.biomodels.get_model_info(model.biomodel_id)["description"]
30
+
31
+ def test_with_sbml_file():
32
+ """
33
+ Test initialization of BasicoModel with sbml_file_path.
34
+ """
35
+ model_object = BasicoModel(sbml_file_path="./BIOMD0000000064_url.xml")
36
+ assert model_object.sbml_file_path == "./BIOMD0000000064_url.xml"
37
+ assert isinstance(model_object.simulate(duration=2, interval=2), pd.DataFrame)
38
+ assert isinstance(model_object.simulate(parameters={'NADH': 0.5}, duration=2, interval=2),
39
+ pd.DataFrame)
40
+
41
+ def test_check_biomodel_id_or_sbml_file_path():
42
+ '''
43
+ Test the check_biomodel_id_or_sbml_file_path method of the BioModel class.
44
+ '''
45
+ with pytest.raises(ValueError):
46
+ BasicoModel(species={"Pyruvate": 100}, duration=2, interval=2)
47
+
48
+ def test_get_model_metadata():
49
+ """
50
+ Test the get_model_metadata method of the BasicoModel class.
51
+ """
52
+ model = BasicoModel(biomodel_id=64)
53
+ metadata = model.get_model_metadata()
54
+ assert metadata["Model Type"] == "SBML Model (COPASI)"
55
+ assert metadata["Parameter Count"] == len(basico.get_parameters())
@@ -0,0 +1,189 @@
1
+ '''
2
+ Test cases
3
+ '''
4
+
5
+ from langchain_core.messages import HumanMessage, ToolMessage
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,{"sbml_file_path": ["BIOMD0000000537.xml"]})
17
+ prompt = "Extract all relevant information from the uploaded model."
18
+ # Test the tool get_modelinfo
19
+ response = app.invoke(
20
+ {"messages": [HumanMessage(content=prompt)]},
21
+ config=config
22
+ )
23
+ assistant_msg = response["messages"][-1].content
24
+ # Check if the assistant message is a string
25
+ assert isinstance(assistant_msg, str)
26
+
27
+ def test_search_models_tool():
28
+ '''
29
+ Test the search_models tool.
30
+ '''
31
+ unique_id = 12345
32
+ app = get_app(unique_id)
33
+ config = {"configurable": {"thread_id": unique_id}}
34
+ # Update state
35
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
36
+ prompt = "Search for models on Crohn's disease."
37
+ # Test the tool get_modelinfo
38
+ response = app.invoke(
39
+ {"messages": [HumanMessage(content=prompt)]},
40
+ config=config
41
+ )
42
+ assistant_msg = response["messages"][-1].content
43
+ # Check if the assistant message is a string
44
+ assert isinstance(assistant_msg, str)
45
+ # Check if the assistant message contains the
46
+ # biomodel id BIO0000000537
47
+ assert "BIOMD0000000537" in assistant_msg
48
+
49
+ def test_ask_question_tool():
50
+ '''
51
+ Test the ask_question tool without the simulation results.
52
+ '''
53
+ unique_id = 12345
54
+ app = get_app(unique_id, llm_model='gpt-4o-mini')
55
+ config = {"configurable": {"thread_id": unique_id}}
56
+
57
+ ##########################################
58
+ # Test ask_question tool when simulation
59
+ # results are not available
60
+ ##########################################
61
+ # Update state
62
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
63
+ prompt = "Call the ask_question tool to answer the "
64
+ prompt += "question: What is the concentration of CRP "
65
+ prompt += "in serum at 1000 hours?"
66
+
67
+ # Test the tool get_modelinfo
68
+ response = app.invoke(
69
+ {"messages": [HumanMessage(content=prompt)]},
70
+ config=config
71
+ )
72
+ assistant_msg = response["messages"][-1].content
73
+ # Check if the assistant message is a string
74
+ assert isinstance(assistant_msg, str)
75
+
76
+ def test_simulate_model_tool():
77
+ '''
78
+ Test the simulate_model tool.
79
+ '''
80
+ unique_id = 123
81
+ app = get_app(unique_id)
82
+ config = {"configurable": {"thread_id": unique_id}}
83
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
84
+ # ##########################################
85
+ # ## Test simulate_model tool
86
+ # ##########################################
87
+ prompt = "Simulate the model 537 for 2016 hours and intervals"
88
+ prompt += " 2016 with an initial concentration of `DoseQ2W` "
89
+ prompt += "set to 300 and `Dose` set to 0. Reset the concentration"
90
+ prompt += " of `NAD` to 100 every 500 hours."
91
+ # Test the tool get_modelinfo
92
+ response = app.invoke(
93
+ {"messages": [HumanMessage(content=prompt)]},
94
+ config=config
95
+ )
96
+ assistant_msg = response["messages"][-1].content
97
+ print (assistant_msg)
98
+ # Check if the assistant message is a string
99
+ assert isinstance(assistant_msg, str)
100
+ ##########################################
101
+ # Test ask_question tool when simulation
102
+ # results are available
103
+ ##########################################
104
+ # Update state
105
+ app.update_state(config, {"llm_model": "gpt-4o-mini"})
106
+ prompt = "What is the concentration of CRP in serum at 1000 hours? "
107
+ # prompt += "Show only the concentration, rounded to 1 decimal place."
108
+ # prompt += "For example, if the concentration is 0.123456, "
109
+ # prompt += "your response should be `0.1`. Do not return any other information."
110
+ # Test the tool get_modelinfo
111
+ response = app.invoke(
112
+ {"messages": [HumanMessage(content=prompt)]},
113
+ config=config
114
+ )
115
+ assistant_msg = response["messages"][-1].content
116
+ # print (assistant_msg)
117
+ # Check if the assistant message is a string
118
+ assert "1.7" in assistant_msg
119
+
120
+ ##########################################
121
+ # Test custom_plotter tool when the
122
+ # simulation results are available
123
+ ##########################################
124
+ prompt = "Plot only CRP related species."
125
+
126
+ # Update state
127
+ app.update_state(config, {"llm_model": "gpt-4o-mini"}
128
+ )
129
+ # Test the tool get_modelinfo
130
+ response = app.invoke(
131
+ {"messages": [HumanMessage(content=prompt)]},
132
+ config=config
133
+ )
134
+ assistant_msg = response["messages"][-1].content
135
+ current_state = app.get_state(config)
136
+ # Get the messages from the current state
137
+ # and reverse the order
138
+ reversed_messages = current_state.values["messages"][::-1]
139
+ # Loop through the reversed messages
140
+ # until a ToolMessage is found.
141
+ expected_artifact = ['CRP[serum]', 'CRPExtracellular']
142
+ expected_artifact += ['CRP Suppression (%)', 'CRP (% of baseline)']
143
+ expected_artifact += ['CRP[liver]']
144
+ predicted_artifact = []
145
+ for msg in reversed_messages:
146
+ if isinstance(msg, ToolMessage):
147
+ # Work on the message if it is a ToolMessage
148
+ # These may contain additional visuals that
149
+ # need to be displayed to the user.
150
+ if msg.name == "custom_plotter":
151
+ predicted_artifact = msg.artifact
152
+ break
153
+ # Check if the two artifacts are equal
154
+ # assert expected_artifact in predicted_artifact
155
+ assert set(expected_artifact).issubset(set(predicted_artifact))
156
+ ##########################################
157
+ # Test custom_plotter tool when the
158
+ # simulation results are available but
159
+ # the species is not available
160
+ ##########################################
161
+ prompt = "Plot the species `TP53`."
162
+
163
+ # Update state
164
+ app.update_state(config, {"llm_model": "gpt-4o-mini"}
165
+ )
166
+ # Test the tool get_modelinfo
167
+ response = app.invoke(
168
+ {"messages": [HumanMessage(content=prompt)]},
169
+ config=config
170
+ )
171
+ assistant_msg = response["messages"][-1].content
172
+ # print (response["messages"])
173
+ current_state = app.get_state(config)
174
+ # Get the messages from the current state
175
+ # and reverse the order
176
+ reversed_messages = current_state.values["messages"][::-1]
177
+ # Loop through the reversed messages until a
178
+ # ToolMessage is found.
179
+ predicted_artifact = []
180
+ for msg in reversed_messages:
181
+ if isinstance(msg, ToolMessage):
182
+ # Work on the message if it is a ToolMessage
183
+ # These may contain additional visuals that
184
+ # need to be displayed to the user.
185
+ if msg.name == "custom_plotter":
186
+ predicted_artifact = msg.artifact
187
+ break
188
+ # Check if the the predicted artifact is `None`
189
+ assert predicted_artifact is None
@@ -0,0 +1,57 @@
1
+ '''
2
+ This file contains the unit tests for the BioModel class.
3
+ '''
4
+
5
+ from typing import List, Dict, Union, Optional
6
+ from pydantic import Field
7
+ import pytest
8
+ from ..models.sys_bio_model import SysBioModel
9
+
10
+ class TestBioModel(SysBioModel):
11
+ '''
12
+ A test BioModel class for unit testing.
13
+ '''
14
+
15
+ biomodel_id: Optional[int] = Field(None, description="BioModel ID of the model")
16
+ sbml_file_path: Optional[str] = Field(None, description="Path to an SBML file")
17
+ name: Optional[str] = Field(..., description="Name of the model")
18
+ description: Optional[str] = Field("", description="Description of the model")
19
+
20
+ def get_model_metadata(self) -> Dict[str, Union[str, int]]:
21
+ '''
22
+ Get the metadata of the model.
23
+ '''
24
+ return self.biomodel_id
25
+
26
+ def simulate(self,
27
+ parameters: Dict[str, Union[float, int]],
28
+ duration: Union[int, float]) -> List[float]:
29
+ '''
30
+ Simulate the model.
31
+ '''
32
+ param1 = parameters.get('param1', 0.0)
33
+ param2 = parameters.get('param2', 0.0)
34
+ return [param1 + param2 * t for t in range(int(duration))]
35
+
36
+ def test_get_model_metadata():
37
+ '''
38
+ Test the get_model_metadata method of the BioModel class.
39
+ '''
40
+ model = TestBioModel(biomodel_id=123, name="Test Model", description="A test model")
41
+ metadata = model.get_model_metadata()
42
+ assert metadata == 123
43
+
44
+ def test_check_biomodel_id_or_sbml_file_path():
45
+ '''
46
+ Test the check_biomodel_id_or_sbml_file_path method of the BioModel class.
47
+ '''
48
+ with pytest.raises(ValueError):
49
+ TestBioModel(name="Test Model", description="A test model")
50
+
51
+ def test_simulate():
52
+ '''
53
+ Test the simulate method of the BioModel class.
54
+ '''
55
+ model = TestBioModel(biomodel_id=123, name="Test Model", description="A test model")
56
+ results = model.simulate(parameters={'param1': 1.0, 'param2': 2.0}, duration=4.0)
57
+ assert results == [1.0, 3.0, 5.0, 7.0]
@@ -0,0 +1,23 @@
1
+ '''
2
+ Test cases for the search_studies
3
+ '''
4
+
5
+ # from ..tools.search_studies import search_studies
6
+ from aiagents4pharma.talk2cells.agents.scp_agent import get_app
7
+ from langchain_core.messages import HumanMessage
8
+
9
+ def test_agent_scp():
10
+ '''
11
+ Test the agent_scp.
12
+ '''
13
+ unique_id = 12345
14
+ app = get_app(unique_id)
15
+ config = {"configurable": {"thread_id": unique_id}}
16
+ prompt = "Search for studies on Crohns Disease."
17
+ response = app.invoke(
18
+ {"messages": [HumanMessage(content=prompt)]},
19
+ config=config
20
+ )
21
+ assistant_msg = response["messages"][-1].content
22
+ # Check if the assistant message is a string
23
+ assert isinstance(assistant_msg, str)
@@ -0,0 +1,242 @@
1
+ """
2
+ Test cases for datasets/primekg_loader.py
3
+ """
4
+
5
+ import os
6
+ import shutil
7
+ import pytest
8
+ from ..datasets.biobridge_primekg import BioBridgePrimeKG
9
+
10
+ # Remove the data folder for testing if it exists
11
+ PRIMEKG_LOCAL_DIR = "../data/primekg_test/"
12
+ LOCAL_DIR = "../data/biobridge_primekg_test/"
13
+ shutil.rmtree(LOCAL_DIR, ignore_errors=True)
14
+
15
+ @pytest.fixture(name="biobridge_primekg")
16
+ def biobridge_primekg_fixture():
17
+ """
18
+ Fixture for creating an instance of PrimeKG.
19
+ """
20
+ return BioBridgePrimeKG(primekg_dir=PRIMEKG_LOCAL_DIR,
21
+ local_dir=LOCAL_DIR)
22
+
23
+ def test_download_primekg(biobridge_primekg):
24
+ """
25
+ Test the loading method of the BioBridge-PrimeKG class by downloading data from repository.
26
+ """
27
+ # Load BioBridge-PrimeKG data
28
+ biobridge_primekg.load_data()
29
+ primekg_nodes = biobridge_primekg.get_primekg().get_nodes()
30
+ primekg_edges = biobridge_primekg.get_primekg().get_edges()
31
+ biobridge_data_config = biobridge_primekg.get_data_config()
32
+ biobridge_emb_dict = biobridge_primekg.get_node_embeddings()
33
+ biobridge_triplets = biobridge_primekg.get_primekg_triplets()
34
+ biobridge_splits = biobridge_primekg.get_train_test_split()
35
+ biobridge_node_info = biobridge_primekg.get_node_info_dict()
36
+
37
+ # Check if the local directories exists
38
+ assert os.path.exists(biobridge_primekg.primekg_dir)
39
+ assert os.path.exists(biobridge_primekg.local_dir)
40
+ # Check if downloaded and processed files exist
41
+ # PrimeKG files
42
+ files = ["nodes.tab", "primekg_nodes.tsv.gz",
43
+ "edges.csv", "primekg_edges.tsv.gz"]
44
+ for file in files:
45
+ path = f"{biobridge_primekg.primekg_dir}/{file}"
46
+ assert os.path.exists(path)
47
+ # BioBridge data config
48
+ assert os.path.exists(f"{biobridge_primekg.local_dir}/data_config.json")
49
+ # BioBridge embeddings
50
+ files = [
51
+ "protein.pkl",
52
+ "mf.pkl",
53
+ "cc.pkl",
54
+ "bp.pkl",
55
+ "drug.pkl",
56
+ "disease.pkl",
57
+ "embedding_dict.pkl"
58
+ ]
59
+ for file in files:
60
+ path = f"{biobridge_primekg.local_dir}/embeddings/{file}"
61
+ assert os.path.exists(path)
62
+ # BioBridge processed files
63
+ files = [
64
+ "protein.csv",
65
+ "mf.csv",
66
+ "cc.csv",
67
+ "bp.csv",
68
+ "drug.csv",
69
+ "disease.csv",
70
+ "triplet_full.tsv.gz",
71
+ "triplet_full_altered.tsv.gz",
72
+ "node_train.tsv.gz",
73
+ "triplet_train.tsv.gz",
74
+ "node_test.tsv.gz",
75
+ "triplet_test.tsv.gz",
76
+ ]
77
+ for file in files:
78
+ path = f"{biobridge_primekg.local_dir}/processed/{file}"
79
+ assert os.path.exists(path)
80
+ # Check processed PrimeKG dataframes
81
+ # Nodes
82
+ assert primekg_nodes is not None
83
+ assert len(primekg_nodes) > 0
84
+ assert primekg_nodes.shape[0] == 129375
85
+ # Edges
86
+ assert primekg_edges is not None
87
+ assert len(primekg_edges) > 0
88
+ assert primekg_edges.shape[0] == 8100498
89
+ # Check processed BioBridge data config
90
+ assert biobridge_data_config is not None
91
+ assert len(biobridge_data_config) > 0
92
+ assert len(biobridge_data_config['node_type']) == 10
93
+ assert len(biobridge_data_config['relation_type']) == 18
94
+ assert len(biobridge_data_config['emb_dim']) == 6
95
+ # Check processed BioBridge embeddings
96
+ assert biobridge_emb_dict is not None
97
+ assert len(biobridge_emb_dict) > 0
98
+ assert len(biobridge_emb_dict) == 85466
99
+ # Check processed BioBridge triplets
100
+ assert biobridge_triplets is not None
101
+ assert len(biobridge_triplets) > 0
102
+ assert biobridge_triplets.shape[0] == 3904610
103
+ assert list(biobridge_splits.keys()) == ['train', 'node_train', 'test', 'node_test']
104
+ assert len(biobridge_splits['train']) == 3510930
105
+ assert len(biobridge_splits['node_train']) == 76486
106
+ assert len(biobridge_splits['test']) == 393680
107
+ assert len(biobridge_splits['node_test']) == 8495
108
+ # Check node info dictionary
109
+ assert list(biobridge_node_info.keys()) == ['gene/protein',
110
+ 'molecular_function',
111
+ 'cellular_component',
112
+ 'biological_process',
113
+ 'drug',
114
+ 'disease']
115
+ assert len(biobridge_node_info['gene/protein']) == 19162
116
+ assert len(biobridge_node_info['molecular_function']) == 10966
117
+ assert len(biobridge_node_info['cellular_component']) == 4013
118
+ assert len(biobridge_node_info['biological_process']) == 27478
119
+ assert len(biobridge_node_info['drug']) == 6948
120
+ assert len(biobridge_node_info['disease']) == 44133
121
+
122
+
123
+ def test_load_existing_primekg(biobridge_primekg):
124
+ """
125
+ Test the loading method of the BioBridge-PrimeKG class by loading existing data in local.
126
+ """
127
+ # Load BioBridge-PrimeKG data
128
+ biobridge_primekg.load_data()
129
+ primekg_nodes = biobridge_primekg.get_primekg().get_nodes()
130
+ primekg_edges = biobridge_primekg.get_primekg().get_edges()
131
+ biobridge_data_config = biobridge_primekg.get_data_config()
132
+ biobridge_emb_dict = biobridge_primekg.get_node_embeddings()
133
+ biobridge_triplets = biobridge_primekg.get_primekg_triplets()
134
+ biobridge_splits = biobridge_primekg.get_train_test_split()
135
+ biobridge_node_info = biobridge_primekg.get_node_info_dict()
136
+
137
+ # Check if the local directories exists
138
+ assert os.path.exists(biobridge_primekg.primekg_dir)
139
+ assert os.path.exists(biobridge_primekg.local_dir)
140
+ # Check if downloaded and processed files exist
141
+ # PrimeKG files
142
+ files = ["nodes.tab", "primekg_nodes.tsv.gz",
143
+ "edges.csv", "primekg_edges.tsv.gz"]
144
+ for file in files:
145
+ path = f"{biobridge_primekg.primekg_dir}/{file}"
146
+ assert os.path.exists(path)
147
+ # BioBridge data config
148
+ assert os.path.exists(f"{biobridge_primekg.local_dir}/data_config.json")
149
+ # BioBridge embeddings
150
+ files = [
151
+ "protein.pkl",
152
+ "mf.pkl",
153
+ "cc.pkl",
154
+ "bp.pkl",
155
+ "drug.pkl",
156
+ "disease.pkl",
157
+ "embedding_dict.pkl"
158
+ ]
159
+ for file in files:
160
+ path = f"{biobridge_primekg.local_dir}/embeddings/{file}"
161
+ assert os.path.exists(path)
162
+ # BioBridge processed files
163
+ files = [
164
+ "protein.csv",
165
+ "mf.csv",
166
+ "cc.csv",
167
+ "bp.csv",
168
+ "drug.csv",
169
+ "disease.csv",
170
+ "triplet_full.tsv.gz",
171
+ "triplet_full_altered.tsv.gz",
172
+ "node_train.tsv.gz",
173
+ "triplet_train.tsv.gz",
174
+ "node_test.tsv.gz",
175
+ "triplet_test.tsv.gz",
176
+ ]
177
+ for file in files:
178
+ path = f"{biobridge_primekg.local_dir}/processed/{file}"
179
+ assert os.path.exists(path)
180
+ # Check processed PrimeKG dataframes
181
+ # Nodes
182
+ assert primekg_nodes is not None
183
+ assert len(primekg_nodes) > 0
184
+ assert primekg_nodes.shape[0] == 129375
185
+ # Edges
186
+ assert primekg_edges is not None
187
+ assert len(primekg_edges) > 0
188
+ assert primekg_edges.shape[0] == 8100498
189
+ # Check processed BioBridge data config
190
+ assert biobridge_data_config is not None
191
+ assert len(biobridge_data_config) > 0
192
+ assert len(biobridge_data_config['node_type']) == 10
193
+ assert len(biobridge_data_config['relation_type']) == 18
194
+ assert len(biobridge_data_config['emb_dim']) == 6
195
+ # Check processed BioBridge embeddings
196
+ assert biobridge_emb_dict is not None
197
+ assert len(biobridge_emb_dict) > 0
198
+ assert len(biobridge_emb_dict) == 85466
199
+ # Check processed BioBridge triplets
200
+ assert biobridge_triplets is not None
201
+ assert len(biobridge_triplets) > 0
202
+ assert biobridge_triplets.shape[0] == 3904610
203
+ assert list(biobridge_splits.keys()) == ['train', 'node_train', 'test', 'node_test']
204
+ assert len(biobridge_splits['train']) == 3510930
205
+ assert len(biobridge_splits['node_train']) == 76486
206
+ assert len(biobridge_splits['test']) == 393680
207
+ assert len(biobridge_splits['node_test']) == 8495
208
+ # Check node info dictionary
209
+ assert list(biobridge_node_info.keys()) == ['gene/protein',
210
+ 'molecular_function',
211
+ 'cellular_component',
212
+ 'biological_process',
213
+ 'drug',
214
+ 'disease']
215
+ assert len(biobridge_node_info['gene/protein']) == 19162
216
+ assert len(biobridge_node_info['molecular_function']) == 10966
217
+ assert len(biobridge_node_info['cellular_component']) == 4013
218
+ assert len(biobridge_node_info['biological_process']) == 27478
219
+ assert len(biobridge_node_info['drug']) == 6948
220
+ assert len(biobridge_node_info['disease']) == 44133
221
+
222
+ # def test_load_existing_primekg_with_negative_triplets(biobridge_primekg):
223
+ # """
224
+ # Test the loading method of the BioBridge-PrimeKG class by loading existing data in local.
225
+ # In addition, it builds negative triplets for training data.
226
+ # """
227
+ # # Load BioBridge-PrimeKG data
228
+ # # Using 1 negative sample per positive triplet
229
+ # biobridge_primekg.load_data(build_neg_triplest=True, n_neg_samples=1)
230
+ # biobridge_neg_triplets = biobridge_primekg.get_primekg_triplets_negative()
231
+
232
+ # # Check if the local directories exists
233
+ # assert os.path.exists(biobridge_primekg.primekg_dir)
234
+ # assert os.path.exists(biobridge_primekg.local_dir)
235
+ # # Check if downloaded and processed files exist
236
+ # path = f"{biobridge_primekg.local_dir}/processed/triplet_train_negative.tsv.gz"
237
+ # assert os.path.exists(path)
238
+ # # Check processed BioBridge triplets
239
+ # assert biobridge_neg_triplets is not None
240
+ # assert len(biobridge_neg_triplets) > 0
241
+ # assert biobridge_neg_triplets.shape[0] == 3510930
242
+ # assert len(biobridge_neg_triplets.negative_tail_index[0]) == 1
@@ -0,0 +1,29 @@
1
+ """
2
+ Test cases for datasets/dataset.py
3
+ """
4
+
5
+ from ..datasets.dataset import Dataset
6
+
7
+ class MockDataset(Dataset):
8
+ """
9
+ Mock dataset class for testing purposes.
10
+ """
11
+ def setup(self):
12
+ pass
13
+
14
+ def load_data(self):
15
+ pass
16
+
17
+ def test_dataset_setup():
18
+ """
19
+ Test the setup method of the Dataset class.
20
+ """
21
+ dataset = MockDataset()
22
+ assert dataset.setup() is None
23
+
24
+ def test_dataset_load_data():
25
+ """
26
+ Test the load_data method of the Dataset class.
27
+ """
28
+ dataset = MockDataset()
29
+ assert dataset.load_data() is None