aiagents4pharma 0.0.0__py3-none-any.whl

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 (336) hide show
  1. aiagents4pharma/__init__.py +11 -0
  2. aiagents4pharma/talk2aiagents4pharma/.dockerignore +13 -0
  3. aiagents4pharma/talk2aiagents4pharma/Dockerfile +133 -0
  4. aiagents4pharma/talk2aiagents4pharma/README.md +1 -0
  5. aiagents4pharma/talk2aiagents4pharma/__init__.py +5 -0
  6. aiagents4pharma/talk2aiagents4pharma/agents/__init__.py +6 -0
  7. aiagents4pharma/talk2aiagents4pharma/agents/main_agent.py +70 -0
  8. aiagents4pharma/talk2aiagents4pharma/configs/__init__.py +5 -0
  9. aiagents4pharma/talk2aiagents4pharma/configs/agents/__init__.py +5 -0
  10. aiagents4pharma/talk2aiagents4pharma/configs/agents/main_agent/default.yaml +29 -0
  11. aiagents4pharma/talk2aiagents4pharma/configs/app/__init__.py +0 -0
  12. aiagents4pharma/talk2aiagents4pharma/configs/app/frontend/__init__.py +0 -0
  13. aiagents4pharma/talk2aiagents4pharma/configs/app/frontend/default.yaml +102 -0
  14. aiagents4pharma/talk2aiagents4pharma/configs/config.yaml +4 -0
  15. aiagents4pharma/talk2aiagents4pharma/docker-compose/cpu/.env.example +23 -0
  16. aiagents4pharma/talk2aiagents4pharma/docker-compose/cpu/docker-compose.yml +93 -0
  17. aiagents4pharma/talk2aiagents4pharma/docker-compose/gpu/.env.example +23 -0
  18. aiagents4pharma/talk2aiagents4pharma/docker-compose/gpu/docker-compose.yml +108 -0
  19. aiagents4pharma/talk2aiagents4pharma/install.md +154 -0
  20. aiagents4pharma/talk2aiagents4pharma/states/__init__.py +5 -0
  21. aiagents4pharma/talk2aiagents4pharma/states/state_talk2aiagents4pharma.py +18 -0
  22. aiagents4pharma/talk2aiagents4pharma/tests/__init__.py +3 -0
  23. aiagents4pharma/talk2aiagents4pharma/tests/test_main_agent.py +312 -0
  24. aiagents4pharma/talk2biomodels/.dockerignore +13 -0
  25. aiagents4pharma/talk2biomodels/Dockerfile +104 -0
  26. aiagents4pharma/talk2biomodels/README.md +1 -0
  27. aiagents4pharma/talk2biomodels/__init__.py +5 -0
  28. aiagents4pharma/talk2biomodels/agents/__init__.py +6 -0
  29. aiagents4pharma/talk2biomodels/agents/t2b_agent.py +104 -0
  30. aiagents4pharma/talk2biomodels/api/__init__.py +5 -0
  31. aiagents4pharma/talk2biomodels/api/ols.py +75 -0
  32. aiagents4pharma/talk2biomodels/api/uniprot.py +36 -0
  33. aiagents4pharma/talk2biomodels/configs/__init__.py +5 -0
  34. aiagents4pharma/talk2biomodels/configs/agents/__init__.py +5 -0
  35. aiagents4pharma/talk2biomodels/configs/agents/t2b_agent/__init__.py +3 -0
  36. aiagents4pharma/talk2biomodels/configs/agents/t2b_agent/default.yaml +14 -0
  37. aiagents4pharma/talk2biomodels/configs/app/__init__.py +0 -0
  38. aiagents4pharma/talk2biomodels/configs/app/frontend/__init__.py +0 -0
  39. aiagents4pharma/talk2biomodels/configs/app/frontend/default.yaml +72 -0
  40. aiagents4pharma/talk2biomodels/configs/config.yaml +7 -0
  41. aiagents4pharma/talk2biomodels/configs/tools/__init__.py +5 -0
  42. aiagents4pharma/talk2biomodels/configs/tools/ask_question/__init__.py +3 -0
  43. aiagents4pharma/talk2biomodels/configs/tools/ask_question/default.yaml +30 -0
  44. aiagents4pharma/talk2biomodels/configs/tools/custom_plotter/__init__.py +3 -0
  45. aiagents4pharma/talk2biomodels/configs/tools/custom_plotter/default.yaml +8 -0
  46. aiagents4pharma/talk2biomodels/configs/tools/get_annotation/__init__.py +3 -0
  47. aiagents4pharma/talk2biomodels/configs/tools/get_annotation/default.yaml +8 -0
  48. aiagents4pharma/talk2biomodels/install.md +63 -0
  49. aiagents4pharma/talk2biomodels/models/__init__.py +5 -0
  50. aiagents4pharma/talk2biomodels/models/basico_model.py +125 -0
  51. aiagents4pharma/talk2biomodels/models/sys_bio_model.py +60 -0
  52. aiagents4pharma/talk2biomodels/states/__init__.py +6 -0
  53. aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py +49 -0
  54. aiagents4pharma/talk2biomodels/tests/BIOMD0000000449_url.xml +1585 -0
  55. aiagents4pharma/talk2biomodels/tests/__init__.py +3 -0
  56. aiagents4pharma/talk2biomodels/tests/article_on_model_537.pdf +0 -0
  57. aiagents4pharma/talk2biomodels/tests/test_api.py +31 -0
  58. aiagents4pharma/talk2biomodels/tests/test_ask_question.py +42 -0
  59. aiagents4pharma/talk2biomodels/tests/test_basico_model.py +67 -0
  60. aiagents4pharma/talk2biomodels/tests/test_get_annotation.py +190 -0
  61. aiagents4pharma/talk2biomodels/tests/test_getmodelinfo.py +92 -0
  62. aiagents4pharma/talk2biomodels/tests/test_integration.py +116 -0
  63. aiagents4pharma/talk2biomodels/tests/test_load_biomodel.py +35 -0
  64. aiagents4pharma/talk2biomodels/tests/test_param_scan.py +71 -0
  65. aiagents4pharma/talk2biomodels/tests/test_query_article.py +184 -0
  66. aiagents4pharma/talk2biomodels/tests/test_save_model.py +47 -0
  67. aiagents4pharma/talk2biomodels/tests/test_search_models.py +35 -0
  68. aiagents4pharma/talk2biomodels/tests/test_simulate_model.py +44 -0
  69. aiagents4pharma/talk2biomodels/tests/test_steady_state.py +86 -0
  70. aiagents4pharma/talk2biomodels/tests/test_sys_bio_model.py +67 -0
  71. aiagents4pharma/talk2biomodels/tools/__init__.py +17 -0
  72. aiagents4pharma/talk2biomodels/tools/ask_question.py +125 -0
  73. aiagents4pharma/talk2biomodels/tools/custom_plotter.py +165 -0
  74. aiagents4pharma/talk2biomodels/tools/get_annotation.py +342 -0
  75. aiagents4pharma/talk2biomodels/tools/get_modelinfo.py +159 -0
  76. aiagents4pharma/talk2biomodels/tools/load_arguments.py +134 -0
  77. aiagents4pharma/talk2biomodels/tools/load_biomodel.py +44 -0
  78. aiagents4pharma/talk2biomodels/tools/parameter_scan.py +310 -0
  79. aiagents4pharma/talk2biomodels/tools/query_article.py +64 -0
  80. aiagents4pharma/talk2biomodels/tools/save_model.py +98 -0
  81. aiagents4pharma/talk2biomodels/tools/search_models.py +96 -0
  82. aiagents4pharma/talk2biomodels/tools/simulate_model.py +137 -0
  83. aiagents4pharma/talk2biomodels/tools/steady_state.py +187 -0
  84. aiagents4pharma/talk2biomodels/tools/utils.py +23 -0
  85. aiagents4pharma/talk2cells/README.md +1 -0
  86. aiagents4pharma/talk2cells/__init__.py +5 -0
  87. aiagents4pharma/talk2cells/agents/__init__.py +6 -0
  88. aiagents4pharma/talk2cells/agents/scp_agent.py +87 -0
  89. aiagents4pharma/talk2cells/states/__init__.py +6 -0
  90. aiagents4pharma/talk2cells/states/state_talk2cells.py +15 -0
  91. aiagents4pharma/talk2cells/tests/scp_agent/test_scp_agent.py +22 -0
  92. aiagents4pharma/talk2cells/tools/__init__.py +6 -0
  93. aiagents4pharma/talk2cells/tools/scp_agent/__init__.py +6 -0
  94. aiagents4pharma/talk2cells/tools/scp_agent/display_studies.py +27 -0
  95. aiagents4pharma/talk2cells/tools/scp_agent/search_studies.py +78 -0
  96. aiagents4pharma/talk2knowledgegraphs/.dockerignore +13 -0
  97. aiagents4pharma/talk2knowledgegraphs/Dockerfile +131 -0
  98. aiagents4pharma/talk2knowledgegraphs/README.md +1 -0
  99. aiagents4pharma/talk2knowledgegraphs/__init__.py +5 -0
  100. aiagents4pharma/talk2knowledgegraphs/agents/__init__.py +5 -0
  101. aiagents4pharma/talk2knowledgegraphs/agents/t2kg_agent.py +99 -0
  102. aiagents4pharma/talk2knowledgegraphs/configs/__init__.py +5 -0
  103. aiagents4pharma/talk2knowledgegraphs/configs/agents/t2kg_agent/__init__.py +3 -0
  104. aiagents4pharma/talk2knowledgegraphs/configs/agents/t2kg_agent/default.yaml +62 -0
  105. aiagents4pharma/talk2knowledgegraphs/configs/app/__init__.py +5 -0
  106. aiagents4pharma/talk2knowledgegraphs/configs/app/frontend/__init__.py +3 -0
  107. aiagents4pharma/talk2knowledgegraphs/configs/app/frontend/default.yaml +79 -0
  108. aiagents4pharma/talk2knowledgegraphs/configs/config.yaml +13 -0
  109. aiagents4pharma/talk2knowledgegraphs/configs/tools/__init__.py +5 -0
  110. aiagents4pharma/talk2knowledgegraphs/configs/tools/graphrag_reasoning/__init__.py +3 -0
  111. aiagents4pharma/talk2knowledgegraphs/configs/tools/graphrag_reasoning/default.yaml +24 -0
  112. aiagents4pharma/talk2knowledgegraphs/configs/tools/multimodal_subgraph_extraction/__init__.py +0 -0
  113. aiagents4pharma/talk2knowledgegraphs/configs/tools/multimodal_subgraph_extraction/default.yaml +33 -0
  114. aiagents4pharma/talk2knowledgegraphs/configs/tools/subgraph_extraction/__init__.py +3 -0
  115. aiagents4pharma/talk2knowledgegraphs/configs/tools/subgraph_extraction/default.yaml +43 -0
  116. aiagents4pharma/talk2knowledgegraphs/configs/tools/subgraph_summarization/__init__.py +3 -0
  117. aiagents4pharma/talk2knowledgegraphs/configs/tools/subgraph_summarization/default.yaml +9 -0
  118. aiagents4pharma/talk2knowledgegraphs/configs/utils/database/milvus/__init__.py +3 -0
  119. aiagents4pharma/talk2knowledgegraphs/configs/utils/database/milvus/default.yaml +61 -0
  120. aiagents4pharma/talk2knowledgegraphs/configs/utils/enrichments/ols_terms/default.yaml +3 -0
  121. aiagents4pharma/talk2knowledgegraphs/configs/utils/enrichments/reactome_pathways/default.yaml +3 -0
  122. aiagents4pharma/talk2knowledgegraphs/configs/utils/enrichments/uniprot_proteins/default.yaml +6 -0
  123. aiagents4pharma/talk2knowledgegraphs/configs/utils/pubchem_utils/default.yaml +5 -0
  124. aiagents4pharma/talk2knowledgegraphs/datasets/__init__.py +5 -0
  125. aiagents4pharma/talk2knowledgegraphs/datasets/biobridge_primekg.py +607 -0
  126. aiagents4pharma/talk2knowledgegraphs/datasets/dataset.py +25 -0
  127. aiagents4pharma/talk2knowledgegraphs/datasets/primekg.py +212 -0
  128. aiagents4pharma/talk2knowledgegraphs/datasets/starkqa_primekg.py +210 -0
  129. aiagents4pharma/talk2knowledgegraphs/docker-compose/cpu/.env.example +23 -0
  130. aiagents4pharma/talk2knowledgegraphs/docker-compose/cpu/docker-compose.yml +93 -0
  131. aiagents4pharma/talk2knowledgegraphs/docker-compose/gpu/.env.example +23 -0
  132. aiagents4pharma/talk2knowledgegraphs/docker-compose/gpu/docker-compose.yml +108 -0
  133. aiagents4pharma/talk2knowledgegraphs/entrypoint.sh +180 -0
  134. aiagents4pharma/talk2knowledgegraphs/install.md +165 -0
  135. aiagents4pharma/talk2knowledgegraphs/milvus_data_dump.py +886 -0
  136. aiagents4pharma/talk2knowledgegraphs/states/__init__.py +5 -0
  137. aiagents4pharma/talk2knowledgegraphs/states/state_talk2knowledgegraphs.py +40 -0
  138. aiagents4pharma/talk2knowledgegraphs/tests/__init__.py +0 -0
  139. aiagents4pharma/talk2knowledgegraphs/tests/test_agents_t2kg_agent.py +318 -0
  140. aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_biobridge_primekg.py +248 -0
  141. aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_dataset.py +33 -0
  142. aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_primekg.py +86 -0
  143. aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_starkqa_primekg.py +125 -0
  144. aiagents4pharma/talk2knowledgegraphs/tests/test_tools_graphrag_reasoning.py +257 -0
  145. aiagents4pharma/talk2knowledgegraphs/tests/test_tools_milvus_multimodal_subgraph_extraction.py +1444 -0
  146. aiagents4pharma/talk2knowledgegraphs/tests/test_tools_multimodal_subgraph_extraction.py +159 -0
  147. aiagents4pharma/talk2knowledgegraphs/tests/test_tools_subgraph_extraction.py +152 -0
  148. aiagents4pharma/talk2knowledgegraphs/tests/test_tools_subgraph_summarization.py +201 -0
  149. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_database_milvus_connection_manager.py +812 -0
  150. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_embeddings.py +51 -0
  151. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_huggingface.py +49 -0
  152. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_nim_molmim.py +59 -0
  153. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_ollama.py +63 -0
  154. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_sentencetransformer.py +47 -0
  155. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_enrichments.py +40 -0
  156. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_ollama.py +94 -0
  157. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_ols.py +70 -0
  158. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_pubchem.py +45 -0
  159. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_reactome.py +44 -0
  160. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_uniprot.py +48 -0
  161. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_extractions_milvus_multimodal_pcst.py +759 -0
  162. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_kg_utils.py +78 -0
  163. aiagents4pharma/talk2knowledgegraphs/tests/test_utils_pubchem_utils.py +123 -0
  164. aiagents4pharma/talk2knowledgegraphs/tools/__init__.py +11 -0
  165. aiagents4pharma/talk2knowledgegraphs/tools/graphrag_reasoning.py +138 -0
  166. aiagents4pharma/talk2knowledgegraphs/tools/load_arguments.py +22 -0
  167. aiagents4pharma/talk2knowledgegraphs/tools/milvus_multimodal_subgraph_extraction.py +965 -0
  168. aiagents4pharma/talk2knowledgegraphs/tools/multimodal_subgraph_extraction.py +374 -0
  169. aiagents4pharma/talk2knowledgegraphs/tools/subgraph_extraction.py +291 -0
  170. aiagents4pharma/talk2knowledgegraphs/tools/subgraph_summarization.py +123 -0
  171. aiagents4pharma/talk2knowledgegraphs/utils/__init__.py +5 -0
  172. aiagents4pharma/talk2knowledgegraphs/utils/database/__init__.py +5 -0
  173. aiagents4pharma/talk2knowledgegraphs/utils/database/milvus_connection_manager.py +586 -0
  174. aiagents4pharma/talk2knowledgegraphs/utils/embeddings/__init__.py +5 -0
  175. aiagents4pharma/talk2knowledgegraphs/utils/embeddings/embeddings.py +81 -0
  176. aiagents4pharma/talk2knowledgegraphs/utils/embeddings/huggingface.py +111 -0
  177. aiagents4pharma/talk2knowledgegraphs/utils/embeddings/nim_molmim.py +54 -0
  178. aiagents4pharma/talk2knowledgegraphs/utils/embeddings/ollama.py +87 -0
  179. aiagents4pharma/talk2knowledgegraphs/utils/embeddings/sentence_transformer.py +73 -0
  180. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/__init__.py +12 -0
  181. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/enrichments.py +37 -0
  182. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/ollama.py +129 -0
  183. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/ols_terms.py +89 -0
  184. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/pubchem_strings.py +78 -0
  185. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/reactome_pathways.py +71 -0
  186. aiagents4pharma/talk2knowledgegraphs/utils/enrichments/uniprot_proteins.py +98 -0
  187. aiagents4pharma/talk2knowledgegraphs/utils/extractions/__init__.py +5 -0
  188. aiagents4pharma/talk2knowledgegraphs/utils/extractions/milvus_multimodal_pcst.py +762 -0
  189. aiagents4pharma/talk2knowledgegraphs/utils/extractions/multimodal_pcst.py +298 -0
  190. aiagents4pharma/talk2knowledgegraphs/utils/extractions/pcst.py +229 -0
  191. aiagents4pharma/talk2knowledgegraphs/utils/kg_utils.py +67 -0
  192. aiagents4pharma/talk2knowledgegraphs/utils/pubchem_utils.py +104 -0
  193. aiagents4pharma/talk2scholars/.dockerignore +13 -0
  194. aiagents4pharma/talk2scholars/Dockerfile +104 -0
  195. aiagents4pharma/talk2scholars/README.md +1 -0
  196. aiagents4pharma/talk2scholars/__init__.py +7 -0
  197. aiagents4pharma/talk2scholars/agents/__init__.py +13 -0
  198. aiagents4pharma/talk2scholars/agents/main_agent.py +89 -0
  199. aiagents4pharma/talk2scholars/agents/paper_download_agent.py +96 -0
  200. aiagents4pharma/talk2scholars/agents/pdf_agent.py +101 -0
  201. aiagents4pharma/talk2scholars/agents/s2_agent.py +135 -0
  202. aiagents4pharma/talk2scholars/agents/zotero_agent.py +127 -0
  203. aiagents4pharma/talk2scholars/configs/__init__.py +7 -0
  204. aiagents4pharma/talk2scholars/configs/agents/__init__.py +7 -0
  205. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/__init__.py +7 -0
  206. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/main_agent/__init__.py +3 -0
  207. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/main_agent/default.yaml +52 -0
  208. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/paper_download_agent/__init__.py +3 -0
  209. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/paper_download_agent/default.yaml +19 -0
  210. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/pdf_agent/__init__.py +3 -0
  211. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/pdf_agent/default.yaml +19 -0
  212. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/s2_agent/__init__.py +3 -0
  213. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/s2_agent/default.yaml +44 -0
  214. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/zotero_agent/__init__.py +3 -0
  215. aiagents4pharma/talk2scholars/configs/agents/talk2scholars/zotero_agent/default.yaml +19 -0
  216. aiagents4pharma/talk2scholars/configs/app/__init__.py +7 -0
  217. aiagents4pharma/talk2scholars/configs/app/frontend/__init__.py +3 -0
  218. aiagents4pharma/talk2scholars/configs/app/frontend/default.yaml +72 -0
  219. aiagents4pharma/talk2scholars/configs/config.yaml +16 -0
  220. aiagents4pharma/talk2scholars/configs/tools/__init__.py +21 -0
  221. aiagents4pharma/talk2scholars/configs/tools/multi_paper_recommendation/__init__.py +3 -0
  222. aiagents4pharma/talk2scholars/configs/tools/multi_paper_recommendation/default.yaml +26 -0
  223. aiagents4pharma/talk2scholars/configs/tools/paper_download/__init__.py +3 -0
  224. aiagents4pharma/talk2scholars/configs/tools/paper_download/default.yaml +124 -0
  225. aiagents4pharma/talk2scholars/configs/tools/question_and_answer/__init__.py +3 -0
  226. aiagents4pharma/talk2scholars/configs/tools/question_and_answer/default.yaml +62 -0
  227. aiagents4pharma/talk2scholars/configs/tools/retrieve_semantic_scholar_paper_id/__init__.py +3 -0
  228. aiagents4pharma/talk2scholars/configs/tools/retrieve_semantic_scholar_paper_id/default.yaml +12 -0
  229. aiagents4pharma/talk2scholars/configs/tools/search/__init__.py +3 -0
  230. aiagents4pharma/talk2scholars/configs/tools/search/default.yaml +26 -0
  231. aiagents4pharma/talk2scholars/configs/tools/single_paper_recommendation/__init__.py +3 -0
  232. aiagents4pharma/talk2scholars/configs/tools/single_paper_recommendation/default.yaml +26 -0
  233. aiagents4pharma/talk2scholars/configs/tools/zotero_read/__init__.py +3 -0
  234. aiagents4pharma/talk2scholars/configs/tools/zotero_read/default.yaml +57 -0
  235. aiagents4pharma/talk2scholars/configs/tools/zotero_write/__inti__.py +3 -0
  236. aiagents4pharma/talk2scholars/configs/tools/zotero_write/default.yaml +55 -0
  237. aiagents4pharma/talk2scholars/docker-compose/cpu/.env.example +21 -0
  238. aiagents4pharma/talk2scholars/docker-compose/cpu/docker-compose.yml +90 -0
  239. aiagents4pharma/talk2scholars/docker-compose/gpu/.env.example +21 -0
  240. aiagents4pharma/talk2scholars/docker-compose/gpu/docker-compose.yml +105 -0
  241. aiagents4pharma/talk2scholars/install.md +122 -0
  242. aiagents4pharma/talk2scholars/state/__init__.py +7 -0
  243. aiagents4pharma/talk2scholars/state/state_talk2scholars.py +98 -0
  244. aiagents4pharma/talk2scholars/tests/__init__.py +3 -0
  245. aiagents4pharma/talk2scholars/tests/test_agents_main_agent.py +256 -0
  246. aiagents4pharma/talk2scholars/tests/test_agents_paper_agents_download_agent.py +139 -0
  247. aiagents4pharma/talk2scholars/tests/test_agents_pdf_agent.py +114 -0
  248. aiagents4pharma/talk2scholars/tests/test_agents_s2_agent.py +198 -0
  249. aiagents4pharma/talk2scholars/tests/test_agents_zotero_agent.py +160 -0
  250. aiagents4pharma/talk2scholars/tests/test_s2_tools_display_dataframe.py +91 -0
  251. aiagents4pharma/talk2scholars/tests/test_s2_tools_query_dataframe.py +191 -0
  252. aiagents4pharma/talk2scholars/tests/test_states_state.py +38 -0
  253. aiagents4pharma/talk2scholars/tests/test_tools_paper_downloader.py +507 -0
  254. aiagents4pharma/talk2scholars/tests/test_tools_question_and_answer_tool.py +105 -0
  255. aiagents4pharma/talk2scholars/tests/test_tools_s2_multi.py +307 -0
  256. aiagents4pharma/talk2scholars/tests/test_tools_s2_retrieve.py +67 -0
  257. aiagents4pharma/talk2scholars/tests/test_tools_s2_search.py +286 -0
  258. aiagents4pharma/talk2scholars/tests/test_tools_s2_single.py +298 -0
  259. aiagents4pharma/talk2scholars/tests/test_utils_arxiv_downloader.py +469 -0
  260. aiagents4pharma/talk2scholars/tests/test_utils_base_paper_downloader.py +598 -0
  261. aiagents4pharma/talk2scholars/tests/test_utils_biorxiv_downloader.py +669 -0
  262. aiagents4pharma/talk2scholars/tests/test_utils_medrxiv_downloader.py +500 -0
  263. aiagents4pharma/talk2scholars/tests/test_utils_nvidia_nim_reranker.py +117 -0
  264. aiagents4pharma/talk2scholars/tests/test_utils_pdf_answer_formatter.py +67 -0
  265. aiagents4pharma/talk2scholars/tests/test_utils_pdf_batch_processor.py +92 -0
  266. aiagents4pharma/talk2scholars/tests/test_utils_pdf_collection_manager.py +173 -0
  267. aiagents4pharma/talk2scholars/tests/test_utils_pdf_document_processor.py +68 -0
  268. aiagents4pharma/talk2scholars/tests/test_utils_pdf_generate_answer.py +72 -0
  269. aiagents4pharma/talk2scholars/tests/test_utils_pdf_gpu_detection.py +129 -0
  270. aiagents4pharma/talk2scholars/tests/test_utils_pdf_paper_loader.py +116 -0
  271. aiagents4pharma/talk2scholars/tests/test_utils_pdf_rag_pipeline.py +88 -0
  272. aiagents4pharma/talk2scholars/tests/test_utils_pdf_retrieve_chunks.py +190 -0
  273. aiagents4pharma/talk2scholars/tests/test_utils_pdf_singleton_manager.py +159 -0
  274. aiagents4pharma/talk2scholars/tests/test_utils_pdf_vector_normalization.py +121 -0
  275. aiagents4pharma/talk2scholars/tests/test_utils_pdf_vector_store.py +406 -0
  276. aiagents4pharma/talk2scholars/tests/test_utils_pubmed_downloader.py +1007 -0
  277. aiagents4pharma/talk2scholars/tests/test_utils_read_helper_utils.py +106 -0
  278. aiagents4pharma/talk2scholars/tests/test_utils_s2_utils_ext_ids.py +403 -0
  279. aiagents4pharma/talk2scholars/tests/test_utils_tool_helper_utils.py +85 -0
  280. aiagents4pharma/talk2scholars/tests/test_utils_zotero_human_in_the_loop.py +266 -0
  281. aiagents4pharma/talk2scholars/tests/test_utils_zotero_path.py +496 -0
  282. aiagents4pharma/talk2scholars/tests/test_utils_zotero_pdf_downloader_utils.py +46 -0
  283. aiagents4pharma/talk2scholars/tests/test_utils_zotero_read.py +743 -0
  284. aiagents4pharma/talk2scholars/tests/test_utils_zotero_write.py +151 -0
  285. aiagents4pharma/talk2scholars/tools/__init__.py +9 -0
  286. aiagents4pharma/talk2scholars/tools/paper_download/__init__.py +12 -0
  287. aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py +442 -0
  288. aiagents4pharma/talk2scholars/tools/paper_download/utils/__init__.py +22 -0
  289. aiagents4pharma/talk2scholars/tools/paper_download/utils/arxiv_downloader.py +207 -0
  290. aiagents4pharma/talk2scholars/tools/paper_download/utils/base_paper_downloader.py +336 -0
  291. aiagents4pharma/talk2scholars/tools/paper_download/utils/biorxiv_downloader.py +313 -0
  292. aiagents4pharma/talk2scholars/tools/paper_download/utils/medrxiv_downloader.py +196 -0
  293. aiagents4pharma/talk2scholars/tools/paper_download/utils/pubmed_downloader.py +323 -0
  294. aiagents4pharma/talk2scholars/tools/pdf/__init__.py +7 -0
  295. aiagents4pharma/talk2scholars/tools/pdf/question_and_answer.py +170 -0
  296. aiagents4pharma/talk2scholars/tools/pdf/utils/__init__.py +37 -0
  297. aiagents4pharma/talk2scholars/tools/pdf/utils/answer_formatter.py +62 -0
  298. aiagents4pharma/talk2scholars/tools/pdf/utils/batch_processor.py +198 -0
  299. aiagents4pharma/talk2scholars/tools/pdf/utils/collection_manager.py +172 -0
  300. aiagents4pharma/talk2scholars/tools/pdf/utils/document_processor.py +76 -0
  301. aiagents4pharma/talk2scholars/tools/pdf/utils/generate_answer.py +97 -0
  302. aiagents4pharma/talk2scholars/tools/pdf/utils/get_vectorstore.py +59 -0
  303. aiagents4pharma/talk2scholars/tools/pdf/utils/gpu_detection.py +150 -0
  304. aiagents4pharma/talk2scholars/tools/pdf/utils/nvidia_nim_reranker.py +97 -0
  305. aiagents4pharma/talk2scholars/tools/pdf/utils/paper_loader.py +123 -0
  306. aiagents4pharma/talk2scholars/tools/pdf/utils/rag_pipeline.py +113 -0
  307. aiagents4pharma/talk2scholars/tools/pdf/utils/retrieve_chunks.py +197 -0
  308. aiagents4pharma/talk2scholars/tools/pdf/utils/singleton_manager.py +140 -0
  309. aiagents4pharma/talk2scholars/tools/pdf/utils/tool_helper.py +86 -0
  310. aiagents4pharma/talk2scholars/tools/pdf/utils/vector_normalization.py +150 -0
  311. aiagents4pharma/talk2scholars/tools/pdf/utils/vector_store.py +327 -0
  312. aiagents4pharma/talk2scholars/tools/s2/__init__.py +21 -0
  313. aiagents4pharma/talk2scholars/tools/s2/display_dataframe.py +110 -0
  314. aiagents4pharma/talk2scholars/tools/s2/multi_paper_rec.py +111 -0
  315. aiagents4pharma/talk2scholars/tools/s2/query_dataframe.py +233 -0
  316. aiagents4pharma/talk2scholars/tools/s2/retrieve_semantic_scholar_paper_id.py +128 -0
  317. aiagents4pharma/talk2scholars/tools/s2/search.py +101 -0
  318. aiagents4pharma/talk2scholars/tools/s2/single_paper_rec.py +102 -0
  319. aiagents4pharma/talk2scholars/tools/s2/utils/__init__.py +5 -0
  320. aiagents4pharma/talk2scholars/tools/s2/utils/multi_helper.py +223 -0
  321. aiagents4pharma/talk2scholars/tools/s2/utils/search_helper.py +205 -0
  322. aiagents4pharma/talk2scholars/tools/s2/utils/single_helper.py +216 -0
  323. aiagents4pharma/talk2scholars/tools/zotero/__init__.py +7 -0
  324. aiagents4pharma/talk2scholars/tools/zotero/utils/__init__.py +7 -0
  325. aiagents4pharma/talk2scholars/tools/zotero/utils/read_helper.py +270 -0
  326. aiagents4pharma/talk2scholars/tools/zotero/utils/review_helper.py +74 -0
  327. aiagents4pharma/talk2scholars/tools/zotero/utils/write_helper.py +194 -0
  328. aiagents4pharma/talk2scholars/tools/zotero/utils/zotero_path.py +180 -0
  329. aiagents4pharma/talk2scholars/tools/zotero/utils/zotero_pdf_downloader.py +133 -0
  330. aiagents4pharma/talk2scholars/tools/zotero/zotero_read.py +105 -0
  331. aiagents4pharma/talk2scholars/tools/zotero/zotero_review.py +162 -0
  332. aiagents4pharma/talk2scholars/tools/zotero/zotero_write.py +91 -0
  333. aiagents4pharma-0.0.0.dist-info/METADATA +335 -0
  334. aiagents4pharma-0.0.0.dist-info/RECORD +336 -0
  335. aiagents4pharma-0.0.0.dist-info/WHEEL +4 -0
  336. aiagents4pharma-0.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,607 @@
1
+ """
2
+ Class for loading BioBridgePrimeKG dataset.
3
+ """
4
+
5
+ import json
6
+ import os
7
+
8
+ import joblib
9
+ import numpy as np
10
+ import pandas as pd
11
+ import requests
12
+ from tqdm import tqdm
13
+
14
+ from .dataset import Dataset
15
+ from .primekg import PrimeKG
16
+
17
+
18
+ class BioBridgePrimeKG(Dataset):
19
+ """
20
+ Class for loading BioBridgePrimeKG dataset.
21
+ It downloads the data from the BioBridge repo and stores it in the local directory.
22
+ The data is then loaded into pandas DataFrame of nodes and edges.
23
+ This class was adapted from the BioBridge repo:
24
+ https://github.com/RyanWangZf/BioBridge
25
+ """
26
+
27
+ def __init__(
28
+ self,
29
+ primekg_dir: str = "../../../data/primekg/",
30
+ local_dir: str = "../../../data/biobridge_primekg/",
31
+ random_seed: int = 0,
32
+ n_neg_samples: int = 5,
33
+ ):
34
+ """
35
+ Constructor for BioBridgePrimeKG class.
36
+
37
+ Args:
38
+ primekg_dir (str): The directory of PrimeKG dataset.
39
+ local_dir (str): The directory to store the downloaded data.
40
+ random_seed (int): The random seed value.
41
+ """
42
+ self.name: str = "biobridge_primekg"
43
+ self.primekg_dir: str = primekg_dir
44
+ self.local_dir: str = local_dir
45
+ self.random_seed = random_seed
46
+ self.n_neg_samples = n_neg_samples
47
+ # Preselected node types:
48
+ # protein, molecular function, cellular component, biological process, drug, disease
49
+ self.preselected_node_types = ["protein", "mf", "cc", "bp", "drug", "disease"]
50
+ self.node_type_map = {
51
+ "protein": "gene/protein",
52
+ "mf": "molecular_function",
53
+ "cc": "cellular_component",
54
+ "bp": "biological_process",
55
+ "drug": "drug",
56
+ "disease": "disease",
57
+ }
58
+
59
+ # Attributes to store the data
60
+ self.primekg = None
61
+ self.primekg_triplets = None
62
+ self.primekg_triplets_negative = None
63
+ self.data_config = None
64
+ self.emb_dict = None
65
+ self.df_train = None
66
+ self.df_node_train = None
67
+ self.df_test = None
68
+ self.df_node_test = None
69
+ self.node_info_dict = None
70
+
71
+ # Set up the dataset
72
+ self.setup()
73
+
74
+ def setup(self):
75
+ """
76
+ A method to set up the dataset.
77
+ """
78
+ # Make the directories if it doesn't exist
79
+ os.makedirs(os.path.dirname(self.primekg_dir), exist_ok=True)
80
+ os.makedirs(os.path.dirname(self.local_dir), exist_ok=True)
81
+
82
+ # Set the random seed
83
+ self.set_random_seed(self.random_seed)
84
+
85
+ # Set SettingWithCopyWarning warnings to none
86
+ pd.options.mode.chained_assignment = None
87
+
88
+ def _load_primekg(self) -> PrimeKG:
89
+ """
90
+ Private method to load related files of PrimeKG dataset.
91
+
92
+ Returns:
93
+ The PrimeKG dataset.
94
+ """
95
+ primekg_data = PrimeKG(local_dir=self.primekg_dir)
96
+ primekg_data.load_data()
97
+
98
+ return primekg_data
99
+
100
+ def _download_file(self, remote_url: str, local_dir: str, local_filename: str):
101
+ """
102
+ A helper function to download a file from remote URL to the local directory.
103
+
104
+ Args:
105
+ remote_url (str): The remote URL of the file to be downloaded.
106
+ local_dir (str): The local directory to store the downloaded file.
107
+ local_filename (str): The local filename to store the downloaded file.
108
+ """
109
+ # Make the local directory if it does not exist
110
+ if not os.path.exists(local_dir):
111
+ os.makedirs(local_dir)
112
+ # Download the file from remote URL to local directory
113
+ local_path = os.path.join(local_dir, local_filename)
114
+ if os.path.exists(local_path):
115
+ print(f"File {local_filename} already exists in {local_dir}.")
116
+ else:
117
+ print(f"Downloading {local_filename} from {remote_url} to {local_dir}...")
118
+ response = requests.get(remote_url, stream=True, timeout=300)
119
+ response.raise_for_status()
120
+ progress_bar = tqdm(
121
+ total=int(response.headers.get("content-length", 0)),
122
+ unit="iB",
123
+ unit_scale=True,
124
+ )
125
+ with open(os.path.join(local_dir, local_filename), "wb") as file:
126
+ for data in response.iter_content(1024):
127
+ progress_bar.update(len(data))
128
+ file.write(data)
129
+ progress_bar.close()
130
+
131
+ def _load_data_config(self) -> dict:
132
+ """
133
+ Load the data config file of BioBridgePrimeKG dataset.
134
+
135
+ Returns:
136
+ The data config file of BioBridgePrimeKG dataset.
137
+ """
138
+ # Download the data config file of BioBridgePrimeKG
139
+ self._download_file(
140
+ remote_url=(
141
+ "https://raw.githubusercontent.com/RyanWangZf/BioBridge/"
142
+ "refs/heads/main/data/BindData/data_config.json"
143
+ ),
144
+ local_dir=self.local_dir,
145
+ local_filename="data_config.json",
146
+ )
147
+
148
+ # Load the downloaded data config file
149
+ with open(os.path.join(self.local_dir, "data_config.json"), encoding="utf-8") as f:
150
+ data_config = json.load(f)
151
+
152
+ return data_config
153
+
154
+ def _build_node_embeddings(self) -> dict:
155
+ """
156
+ Build the node embeddings for BioBridgePrimeKG dataset.
157
+
158
+ Returns:
159
+ The dictionary of node embeddings.
160
+ """
161
+ processed_file_path = os.path.join(self.local_dir, "embeddings", "embedding_dict.pkl")
162
+ if os.path.exists(processed_file_path):
163
+ # Load the embeddings from the local directory
164
+ emb_dict_all = joblib.load(processed_file_path)
165
+ else:
166
+ # Download the embeddings from the BioBridge repo and further process them
167
+ # List of embedding source files
168
+ url = (
169
+ "https://media.githubusercontent.com/media/RyanWangZf/BioBridge/"
170
+ "refs/heads/main/data/embeddings/esm2b_unimo_pubmedbert/"
171
+ )
172
+ file_list = [f"{n}.pkl" for n in self.preselected_node_types]
173
+
174
+ # Download the embeddings
175
+ for file in file_list:
176
+ self._download_file(
177
+ remote_url=os.path.join(url, file),
178
+ local_dir=os.path.join(self.local_dir, "embeddings"),
179
+ local_filename=file,
180
+ )
181
+
182
+ # Unified embeddings
183
+ emb_dict_all = {}
184
+ for file in file_list:
185
+ emb = joblib.load(os.path.join(self.local_dir, "embeddings", file))
186
+ emb_ar = emb["embedding"]
187
+ if not isinstance(emb_ar, list):
188
+ emb_ar = emb_ar.tolist()
189
+ emb_dict_all.update(dict(zip(emb["node_index"], emb_ar, strict=False)))
190
+
191
+ # Store embeddings using secure joblib
192
+ joblib.dump(emb_dict_all, processed_file_path)
193
+
194
+ return emb_dict_all
195
+
196
+ def _build_full_triplets(self) -> tuple[pd.DataFrame, dict]:
197
+ """
198
+ Build the full triplets for BioBridgePrimeKG dataset.
199
+
200
+ Returns:
201
+ The full triplets for BioBridgePrimeKG dataset.
202
+ The dictionary of node information.
203
+ """
204
+ processed_file_path = os.path.join(self.local_dir, "processed", "triplet_full.tsv.gz")
205
+ if os.path.exists(processed_file_path):
206
+ # Load the file from the local directory
207
+ with open(processed_file_path, "rb") as f:
208
+ primekg_triplets = pd.read_csv(f, sep="\t", compression="gzip", low_memory=False)
209
+
210
+ # Load each dataframe in the local directory
211
+ node_info_dict = {}
212
+ for i, node_type in enumerate(self.preselected_node_types):
213
+ with open(os.path.join(self.local_dir, "processed", f"{node_type}.csv"), "rb") as f:
214
+ df_node = pd.read_csv(f)
215
+ node_info_dict[self.node_type_map[node_type]] = df_node
216
+ print(i)
217
+ else:
218
+ # Download the related files from the BioBridge repo and further process them
219
+ # List of processed files
220
+ url = (
221
+ "https://media.githubusercontent.com/media/RyanWangZf/BioBridge/"
222
+ "refs/heads/main/data/Processed/"
223
+ )
224
+ file_list = [
225
+ "protein",
226
+ "molecular",
227
+ "cellular",
228
+ "biological",
229
+ "drug",
230
+ "disease",
231
+ ]
232
+
233
+ # Download the processed files
234
+ for i, file in enumerate(file_list):
235
+ self._download_file(
236
+ remote_url=os.path.join(url, f"{file}.csv"),
237
+ local_dir=os.path.join(self.local_dir, "processed"),
238
+ local_filename=f"{self.preselected_node_types[i]}.csv",
239
+ )
240
+
241
+ # Build the node index list
242
+ node_info_dict = {}
243
+ node_index_list = []
244
+ for i, file in enumerate(file_list):
245
+ df_node = pd.read_csv(
246
+ os.path.join(
247
+ self.local_dir,
248
+ "processed",
249
+ f"{self.preselected_node_types[i]}.csv",
250
+ )
251
+ )
252
+ node_info_dict[self.node_type_map[self.preselected_node_types[i]]] = df_node
253
+ node_index_list.extend(df_node["node_index"].tolist())
254
+ print(i, file)
255
+
256
+ # Filter the PrimeKG dataset to take into account only the selected node types
257
+ primekg_triplets = self.primekg.get_edges().copy()
258
+ primekg_triplets = primekg_triplets[
259
+ primekg_triplets["head_index"].isin(node_index_list)
260
+ & primekg_triplets["tail_index"].isin(node_index_list)
261
+ ]
262
+ primekg_triplets = primekg_triplets.reset_index(drop=True)
263
+
264
+ # Perform mapping of node types
265
+ primekg_triplets["head_type"] = primekg_triplets["head_type"].apply(
266
+ lambda x: self.data_config["node_type"][x]
267
+ )
268
+ primekg_triplets["tail_type"] = primekg_triplets["tail_type"].apply(
269
+ lambda x: self.data_config["node_type"][x]
270
+ )
271
+
272
+ # Perform mapping of relation types
273
+ primekg_triplets["display_relation"] = primekg_triplets["display_relation"].apply(
274
+ lambda x: self.data_config["relation_type"][x]
275
+ )
276
+
277
+ # Store the processed triplets
278
+ primekg_triplets.to_csv(processed_file_path, sep="\t", compression="gzip", index=False)
279
+
280
+ return primekg_triplets, node_info_dict
281
+
282
+ def _build_train_test_split(
283
+ self,
284
+ ) -> tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame, pd.DataFrame, pd.DataFrame]:
285
+ """
286
+ Build the train-test split for BioBridgePrimeKG dataset.
287
+
288
+ Returns:
289
+ The train triplets for BioBridgePrimeKG dataset.
290
+ The train nodes for BioBridgePrimeKG dataset.
291
+ The test triplets for BioBridgePrimeKG dataset.
292
+ The test nodes for BioBridgePrimeKG dataset.
293
+ The full triplets for BioBridgePrimeKG dataset.
294
+ """
295
+ if os.path.exists(os.path.join(self.local_dir, "processed", "triplet_full_altered.tsv.gz")):
296
+ # Load each dataframe in the local directory
297
+ with open(os.path.join(self.local_dir, "processed", "triplet_train.tsv.gz"), "rb") as f:
298
+ df_train = pd.read_csv(f, sep="\t", compression="gzip", low_memory=False)
299
+
300
+ with open(os.path.join(self.local_dir, "processed", "node_train.tsv.gz"), "rb") as f:
301
+ df_node_train = pd.read_csv(f, sep="\t", compression="gzip", low_memory=False)
302
+
303
+ with open(os.path.join(self.local_dir, "processed", "triplet_test.tsv.gz"), "rb") as f:
304
+ df_test = pd.read_csv(f, sep="\t", compression="gzip", low_memory=False)
305
+
306
+ with open(os.path.join(self.local_dir, "processed", "node_test.tsv.gz"), "rb") as f:
307
+ df_node_test = pd.read_csv(f, sep="\t", compression="gzip", low_memory=False)
308
+
309
+ with open(
310
+ os.path.join(self.local_dir, "processed", "triplet_full_altered.tsv.gz"),
311
+ "rb",
312
+ ) as f:
313
+ triplets = pd.read_csv(f, sep="\t", compression="gzip", low_memory=False)
314
+ else:
315
+ # Filtering out some nodes in the embedding dictionary
316
+ triplets = self.primekg_triplets.copy()
317
+ triplets = triplets[
318
+ triplets["head_index"].isin(list(self.emb_dict.keys()))
319
+ & triplets["tail_index"].isin(list(self.emb_dict.keys()))
320
+ ].reset_index(drop=True)
321
+
322
+ # Perform splitting of the triplets
323
+ list_split = {
324
+ "train": [],
325
+ "test": [],
326
+ }
327
+ node_split = {
328
+ "train": {
329
+ "node_index": [],
330
+ "node_type": [],
331
+ },
332
+ "test": {
333
+ "node_index": [],
334
+ "node_type": [],
335
+ },
336
+ }
337
+ # Loop over the node types
338
+ for node_type in triplets["head_type"].unique():
339
+ df_sub = triplets[triplets["head_type"] == node_type]
340
+ all_x_indexes = df_sub["head_index"].unique()
341
+ # By default, we use 90% of the nodes for training and 10% for testing
342
+ te_x_indexes = np.random.choice(
343
+ all_x_indexes, size=int(0.1 * len(all_x_indexes)), replace=False
344
+ )
345
+ df_subs = {}
346
+ df_subs["test"] = df_sub[df_sub["head_index"].isin(te_x_indexes)]
347
+ df_subs["train"] = df_sub[~df_sub["head_index"].isin(te_x_indexes)]
348
+ list_split["train"].append(df_subs["train"])
349
+ list_split["test"].append(df_subs["test"])
350
+
351
+ # record the split
352
+ node_index = {}
353
+ node_index["train"] = df_subs["train"]["head_index"].unique()
354
+ node_split["train"]["node_index"].extend(node_index["train"].tolist())
355
+ node_split["train"]["node_type"].extend([node_type] * len(node_index["train"]))
356
+ node_index["test"] = df_subs["test"]["head_index"].unique()
357
+ node_split["test"]["node_index"].extend(node_index["test"].tolist())
358
+ node_split["test"]["node_type"].extend([node_type] * len(node_index["test"]))
359
+
360
+ print(f"Number of {node_type} nodes in train: {len(node_index['train'])}")
361
+ print(f"Number of {node_type} nodes in test: {len(node_index['test'])}")
362
+
363
+ # Prepare train and test DataFrames
364
+ df_train = pd.concat(list_split["train"])
365
+ df_node_train = pd.DataFrame(node_split["train"])
366
+ df_test = pd.concat(list_split["test"])
367
+ df_node_test = pd.DataFrame(node_split["test"])
368
+
369
+ # Store each dataframe in the local directory
370
+ df_train.to_csv(
371
+ os.path.join(self.local_dir, "processed", "triplet_train.tsv.gz"),
372
+ sep="\t",
373
+ compression="gzip",
374
+ index=False,
375
+ )
376
+ df_node_train.to_csv(
377
+ os.path.join(self.local_dir, "processed", "node_train.tsv.gz"),
378
+ sep="\t",
379
+ compression="gzip",
380
+ index=False,
381
+ )
382
+ df_test.to_csv(
383
+ os.path.join(self.local_dir, "processed", "triplet_test.tsv.gz"),
384
+ sep="\t",
385
+ compression="gzip",
386
+ index=False,
387
+ )
388
+ df_node_test.to_csv(
389
+ os.path.join(self.local_dir, "processed", "node_test.tsv.gz"),
390
+ sep="\t",
391
+ compression="gzip",
392
+ index=False,
393
+ )
394
+ # Store altered full triplets as well
395
+ triplets.to_csv(
396
+ os.path.join(self.local_dir, "processed", "triplet_full_altered.tsv.gz"),
397
+ sep="\t",
398
+ compression="gzip",
399
+ index=False,
400
+ )
401
+
402
+ return df_train, df_node_train, df_test, df_node_test, triplets
403
+
404
+ # def _negative_sampling(self,
405
+ # batch_df: pd.DataFrame,
406
+ # process_index: int,
407
+ # index_map: dict,
408
+ # node_train_dict: dict) -> pd.DataFrame:
409
+ # """
410
+ # A helper function to perform negative sampling for a batch of triplets.
411
+ # """
412
+ # negative_y_index_list = []
413
+ # for _, row in tqdm(batch_df.iterrows(),
414
+ # total=batch_df.shape[0],
415
+ # desc=f"Process {process_index}"):
416
+ # x_index = row['head_index']
417
+ # # y_index = row['y_index']
418
+ # y_index_type = row['tail_type']
419
+ # paired_y_index_list = index_map[x_index]
420
+
421
+ # # sample a list of negative y_index
422
+ # node_train_sub = node_train_dict[y_index_type]
423
+ # negative_y_index = node_train_sub[
424
+ # ~node_train_sub['node_index'].isin(paired_y_index_list)
425
+ # ]['node_index'].sample(self.n_neg_samples).tolist()
426
+ # negative_y_index_list.append(negative_y_index)
427
+
428
+ # batch_df.loc[:, 'negative_tail_index'] = negative_y_index_list
429
+ # return batch_df
430
+
431
+ # def _build_negative_triplets(self,
432
+ # chunk_size: int=100000,
433
+ # n_neg_samples: int=10):
434
+ # """
435
+ # Build the negative triplets for BioBridgePrimeKG dataset.
436
+ # """
437
+ # processed_file_path = os.path.join(self.local_dir,
438
+ # "processed",
439
+ # "triplet_train_negative.tsv.gz")
440
+ # if os.path.exists(processed_file_path):
441
+ # # Load the negative triplets from the local directory
442
+ # with open(processed_file_path, "rb") as f:
443
+ # triplets_negative = pd.read_csv(f, sep="\t", compression="gzip", low_memory=False)
444
+ # else:
445
+ # # Set the number samples for negative sampling
446
+ # self.n_neg_samples = n_neg_samples
447
+
448
+ # # Split node list by type
449
+ # node_train_dict = {}
450
+ # type_list = self.df_node_train['node_type'].unique()
451
+ # for node_type in type_list:
452
+ # node_train_dict[node_type] = self.df_node_train[
453
+ # self.df_node_train['node_type'] == node_type
454
+ # ].reset_index(drop=True)
455
+
456
+ # # create an index mapping from x_index to y_index
457
+ # index_map = self.df_train[
458
+ # ['head_index', 'tail_index']
459
+ # ].drop_duplicates().groupby('head_index').agg(list).to_dict()['tail_index']
460
+
461
+ # # Negative sampling
462
+ # batch_df_list = []
463
+ # for i in tqdm(range(0, self.df_train.shape[0], chunk_size)):
464
+ # batch_df_list.append(self.df_train.iloc[i:i+chunk_size])
465
+ # # Process negative sampling
466
+ # results = [
467
+ # self._negative_sampling(batch_df,
468
+ # num_piece,
469
+ # index_map,
470
+ # node_train_dict)
471
+ # for num_piece, batch_df in enumerate(batch_df_list)
472
+ # ]
473
+
474
+ # # Store the negative triplets
475
+ # triplets_negative = pd.concat(results, axis=0)
476
+ # triplets_negative.to_csv(processed_file_path,
477
+ # sep="\t", compression="gzip", index=False)
478
+
479
+ # # Set attribute
480
+ # self.primekg_triplets_negative = triplets_negative
481
+
482
+ # return triplets_negative
483
+
484
+ # def load_data(self,
485
+ # build_neg_triplest: bool= False,
486
+ # chunk_size: int=100000,
487
+ # n_neg_samples: int=10):
488
+
489
+ def load_data(self):
490
+ """
491
+ Load the BioBridgePrimeKG dataset into pandas DataFrame of nodes and edges.
492
+
493
+ Args:
494
+ build_neg_triplest (bool): Whether to build negative triplets.
495
+ chunk_size (int): The chunk size for negative sampling.
496
+ n_neg_samples (int): The number of negative samples for negative sampling.
497
+ """
498
+ # Load PrimeKG dataset
499
+ print("Loading PrimeKG dataset...")
500
+ self.primekg = self._load_primekg()
501
+
502
+ # Load data config file of BioBridgePrimeKG
503
+ print("Loading data config file of BioBridgePrimeKG...")
504
+ self.data_config = self._load_data_config()
505
+
506
+ # Build node embeddings
507
+ print("Building node embeddings...")
508
+ self.emb_dict = self._build_node_embeddings()
509
+
510
+ # Build full triplets
511
+ print("Building full triplets...")
512
+ self.primekg_triplets, self.node_info_dict = self._build_full_triplets()
513
+
514
+ # Build train-test split
515
+ print("Building train-test split...")
516
+ (
517
+ self.df_train,
518
+ self.df_node_train,
519
+ self.df_test,
520
+ self.df_node_test,
521
+ self.primekg_triplets,
522
+ ) = self._build_train_test_split()
523
+
524
+ # if build_neg_triplest:
525
+ # # Build negative triplets
526
+ # print("Building negative triplets...")
527
+ # self.primekg_triplets_negative = self._build_negative_triplets(
528
+ # chunk_size=chunk_size,
529
+ # n_neg_samples=n_neg_samples
530
+ # )
531
+
532
+ def set_random_seed(self, seed: int):
533
+ """
534
+ Set the random seed for reproducibility.
535
+
536
+ Args:
537
+ seed (int): The random seed value.
538
+ """
539
+ np.random.seed(seed)
540
+
541
+ def get_primekg(self) -> PrimeKG:
542
+ """
543
+ Get the PrimeKG dataset.
544
+
545
+ Returns:
546
+ The PrimeKG dataset.
547
+ """
548
+ return self.primekg
549
+
550
+ def get_data_config(self) -> dict:
551
+ """
552
+ Get the data config file of BioBridgePrimeKG dataset.
553
+
554
+ Returns:
555
+ The data config file of BioBridgePrimeKG dataset.
556
+ """
557
+ return self.data_config
558
+
559
+ def get_node_embeddings(self) -> dict:
560
+ """
561
+ Get the node embeddings for BioBridgePrimeKG dataset.
562
+
563
+ Returns:
564
+ The dictionary of node embeddings.
565
+ """
566
+ return self.emb_dict
567
+
568
+ def get_primekg_triplets(self) -> pd.DataFrame:
569
+ """
570
+ Get the full triplets for BioBridgePrimeKG dataset.
571
+
572
+ Returns:
573
+ The full triplets for BioBridgePrimeKG dataset.
574
+ """
575
+ return self.primekg_triplets
576
+
577
+ # def get_primekg_triplets_negative(self) -> pd.DataFrame:
578
+ # """
579
+ # Get the negative triplets for BioBridgePrimeKG dataset.
580
+
581
+ # Returns:
582
+ # The negative triplets for BioBridgePrimeKG dataset.
583
+ # """
584
+ # return self.primekg_triplets_negative
585
+
586
+ def get_train_test_split(self) -> dict:
587
+ """
588
+ Get the train-test split for BioBridgePrimeKG dataset.
589
+
590
+ Returns:
591
+ The train-test split for BioBridgePrimeKG dataset.
592
+ """
593
+ return {
594
+ "train": self.df_train,
595
+ "node_train": self.df_node_train,
596
+ "test": self.df_test,
597
+ "node_test": self.df_node_test,
598
+ }
599
+
600
+ def get_node_info_dict(self) -> dict:
601
+ """
602
+ Get the node information dictionary for BioBridgePrimeKG dataset.
603
+
604
+ Returns:
605
+ The node information dictionary for BioBridgePrimeKG dataset.
606
+ """
607
+ return self.node_info_dict
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Abstract class for dataset.
5
+ """
6
+
7
+ from abc import ABC, abstractmethod
8
+
9
+
10
+ class Dataset(ABC):
11
+ """
12
+ Abstract class for dataset.
13
+ """
14
+
15
+ @abstractmethod
16
+ def setup(self):
17
+ """
18
+ A method to set up the dataset.
19
+ """
20
+
21
+ @abstractmethod
22
+ def load_data(self):
23
+ """
24
+ A method to load the dataset and potentially preprocess it.
25
+ """