ddi-fw 0.0.214__tar.gz → 0.0.215__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.
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/PKG-INFO +1 -1
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/pyproject.toml +1 -1
- ddi_fw-0.0.215/src/ddi_fw/datasets/db_utils.py +204 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/base.py +14 -14
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/base.py +4 -4
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/base.py +0 -1
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/pipeline/multi_pipeline.py +7 -1
- ddi_fw-0.0.215/src/ddi_fw/pipeline/multi_pipeline_v2.py +231 -0
- ddi_fw-0.0.215/src/ddi_fw/pipeline/ner_pipeline.py +134 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw.egg-info/PKG-INFO +1 -1
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw.egg-info/SOURCES.txt +1 -0
- ddi_fw-0.0.214/src/ddi_fw/datasets/db_utils.py +0 -204
- ddi_fw-0.0.214/src/ddi_fw/pipeline/ner_pipeline.py +0 -139
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/README.md +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/setup.cfg +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/core.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/dataset_splitter.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/data/event.db +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/debug.log +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/test_indexes.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/train_fold_0.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/train_fold_1.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/train_fold_2.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/train_fold_3.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/train_fold_4.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/train_indexes.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/validation_fold_0.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/validation_fold_1.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/validation_fold_2.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/validation_fold_3.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes/validation_fold_4.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/test_indexes.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/train_fold_0.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/train_fold_1.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/train_fold_2.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/train_fold_3.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/train_fold_4.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/train_indexes.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/validation_fold_0.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/validation_fold_1.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/validation_fold_2.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/validation_fold_3.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/indexes_old/validation_fold_4.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl/readme.md +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/data/event.db +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/test_indexes.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/train_fold_0.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/train_fold_1.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/train_fold_2.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/train_fold_3.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/train_fold_4.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/train_indexes.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/validation_fold_0.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/validation_fold_1.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/validation_fold_2.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/validation_fold_3.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/ddi_mdl_text/indexes/validation_fold_4.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/df_extraction_cleanxiaoyu50.csv +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/drug_information_del_noDDIxiaoyu50.csv +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/test_indexes.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/train_fold_0.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/train_fold_1.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/train_fold_2.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/train_fold_3.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/train_fold_4.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/train_indexes.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/validation_fold_0.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/validation_fold_1.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/validation_fold_2.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/validation_fold_3.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/indexes/validation_fold_4.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/mdf_sa_ddi/mdf-sa-ddi.zip +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/datasets/setup_._py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/drugbank/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/drugbank/drugbank.xsd +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/drugbank/drugbank_parser.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/drugbank/drugbank_processor.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/drugbank/drugbank_processor_org.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/drugbank/event_extractor.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/langchain/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/langchain/embeddings.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/langchain/sentence_splitter.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/langchain/storage.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ml/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ml/evaluation_helper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ml/ml_helper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ml/model_wrapper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ml/pytorch_wrapper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ml/tensorflow_wrapper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ner/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ner/mmlrestclient.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/ner/ner.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/pipeline/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/pipeline/multi_modal_combination_strategy.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/pipeline/pipeline.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/categorical_data_encoding_checker.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/enums.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/json_helper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/kaggle.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/numpy_utils.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/package_helper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/py7zr_helper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/utils.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/utils/zip_helper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/vectorization/__init__.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/vectorization/feature_vector_generation.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw/vectorization/idf_helper.py +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw.egg-info/dependency_links.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw.egg-info/requires.txt +0 -0
- {ddi_fw-0.0.214 → ddi_fw-0.0.215}/src/ddi_fw.egg-info/top_level.txt +0 -0
@@ -0,0 +1,204 @@
|
|
1
|
+
|
2
|
+
from sqlite3 import Error
|
3
|
+
import sqlite3
|
4
|
+
import pandas as pd
|
5
|
+
import numpy as np
|
6
|
+
|
7
|
+
|
8
|
+
def create_connection(db_file=r"./event.db"):
|
9
|
+
""" create a database connection to the SQLite database
|
10
|
+
specified by db_file
|
11
|
+
:param db_file: database file
|
12
|
+
:return: Connection object or None
|
13
|
+
"""
|
14
|
+
conn = None
|
15
|
+
try:
|
16
|
+
conn = sqlite3.connect(db_file)
|
17
|
+
except Error as e:
|
18
|
+
print(e)
|
19
|
+
|
20
|
+
return conn
|
21
|
+
|
22
|
+
|
23
|
+
# def select_all_drugs(conn):
|
24
|
+
# cur = conn.cursor()
|
25
|
+
# cur.execute(
|
26
|
+
# '''select "index", id, name, target, enzyme, pathway, smile from drug''')
|
27
|
+
# rows = cur.fetchall()
|
28
|
+
# return rows
|
29
|
+
|
30
|
+
|
31
|
+
# def select_all_drugs_as_dataframe(conn):
|
32
|
+
# headers = ['index','id', 'name', 'target', 'enzyme', 'pathway', 'smile']
|
33
|
+
# rows = select_all_drugs(conn)
|
34
|
+
# df = pd.DataFrame(columns=headers, data=rows)
|
35
|
+
# df['enzyme'] = df['enzyme'].apply(lambda x: x.split('|'))
|
36
|
+
# df['target'] = df['target'].apply(lambda x: x.split('|'))
|
37
|
+
# df['pathway'] = df['pathway'].apply(lambda x: x.split('|'))
|
38
|
+
# df['smile'] = df['smile'].apply(lambda x: x.split('|'))
|
39
|
+
# return df
|
40
|
+
|
41
|
+
|
42
|
+
# def select_all_events(conn):
|
43
|
+
# """
|
44
|
+
# Query all rows in the event table
|
45
|
+
# :param conn: the Connection object
|
46
|
+
# :return:
|
47
|
+
# """
|
48
|
+
# cur = conn.cursor()
|
49
|
+
# cur.execute("select * from event")
|
50
|
+
|
51
|
+
# rows = cur.fetchall()
|
52
|
+
# return rows
|
53
|
+
|
54
|
+
|
55
|
+
# def select_all_events_as_dataframe(conn):
|
56
|
+
# headers = ["index", "id1", "name1", "id2", "name2", "event_category"]
|
57
|
+
# rows = select_all_events(conn)
|
58
|
+
# return pd.DataFrame(columns=headers, data=rows)
|
59
|
+
|
60
|
+
|
61
|
+
# def select_events_with_category(conn):
|
62
|
+
# sql = '''select id1, name1, id2, name2, mechanism || ' ' ||action from event ev
|
63
|
+
# join extraction ex
|
64
|
+
# on ev.name1 = ex.drugA and ev.name2 = ex.drugB
|
65
|
+
# union
|
66
|
+
# select id1, name1, id2, name2, mechanism || ' ' ||action from event ev
|
67
|
+
# join extraction ex
|
68
|
+
# on ev.name1 = ex.drugB and ev.name2 = ex.drugA
|
69
|
+
# '''
|
70
|
+
# cur = conn.cursor()
|
71
|
+
# cur.execute(sql)
|
72
|
+
|
73
|
+
# rows = cur.fetchall()
|
74
|
+
|
75
|
+
# headers = ['id1', 'name1', 'id2', 'name2', 'event_category']
|
76
|
+
# return pd.DataFrame(columns=headers, data=rows)
|
77
|
+
|
78
|
+
|
79
|
+
# def select_all_interactions_tuple_as_dataframe(conn):
|
80
|
+
# cur = conn.cursor()
|
81
|
+
# cur.execute("select id1, id2 from event")
|
82
|
+
# rows = cur.fetchall()
|
83
|
+
# headers = ['id1', 'id2']
|
84
|
+
|
85
|
+
# return pd.DataFrame(columns=headers, data=rows)
|
86
|
+
|
87
|
+
|
88
|
+
# def select_ddi_pairs(conn):
|
89
|
+
# cur = conn.cursor()
|
90
|
+
# cur.execute('''
|
91
|
+
# select d1.[index] as Drug1Index, d2.[index] as Drug2Index, 1 from event e
|
92
|
+
# join drug d1 on e.id1 = d1.id
|
93
|
+
# join drug d2 on e.id2 = d2.id
|
94
|
+
# ''')
|
95
|
+
# rows = cur.fetchall()
|
96
|
+
# return rows
|
97
|
+
|
98
|
+
|
99
|
+
# def select_ddi_pairs_as_dataframe(conn):
|
100
|
+
# headers = ["Drug1Index", "Drug2Index", "Interaction"]
|
101
|
+
# rows = select_ddi_pairs(conn)
|
102
|
+
# return pd.DataFrame(columns=headers, data=rows)
|
103
|
+
|
104
|
+
|
105
|
+
# def get_interactions(conn):
|
106
|
+
# cur = conn.cursor()
|
107
|
+
# cur.execute('''
|
108
|
+
# select
|
109
|
+
# drug_1_id,
|
110
|
+
# drug_1,
|
111
|
+
# drug_2_id,
|
112
|
+
# drug_2,
|
113
|
+
# mechanism_action,
|
114
|
+
# interaction,
|
115
|
+
# masked_interaction
|
116
|
+
# from _Interactions
|
117
|
+
# ''')
|
118
|
+
|
119
|
+
# rows = cur.fetchall()
|
120
|
+
|
121
|
+
# headers = ['id1', 'name1', 'id2', 'name2',
|
122
|
+
# 'event_category', 'interaction', 'masked_interaction']
|
123
|
+
# df = pd.DataFrame(columns=headers, data=rows)
|
124
|
+
# return df
|
125
|
+
|
126
|
+
|
127
|
+
# def get_extended_version(conn):
|
128
|
+
# cur = conn.cursor()
|
129
|
+
# cur.execute('''
|
130
|
+
# select
|
131
|
+
# _Drugs."index",
|
132
|
+
# drugbank_id,
|
133
|
+
# _Drugs.name,
|
134
|
+
# description,
|
135
|
+
# synthesis_reference,
|
136
|
+
# indication,
|
137
|
+
# pharmacodynamics,
|
138
|
+
# mechanism_of_action,
|
139
|
+
# toxicity,
|
140
|
+
# metabolism,
|
141
|
+
# absorption,
|
142
|
+
# half_life,
|
143
|
+
# protein_binding,
|
144
|
+
# route_of_elimination,
|
145
|
+
# volume_of_distribution,
|
146
|
+
# clearance,
|
147
|
+
# smiles,
|
148
|
+
# smiles_morgan_fingerprint,
|
149
|
+
# enzymes_polypeptides,
|
150
|
+
# targets_polypeptides
|
151
|
+
|
152
|
+
# from drug
|
153
|
+
# join _Drugs on drug.id = _Drugs.drugbank_id
|
154
|
+
# where
|
155
|
+
# targets_polypeptides is not null and
|
156
|
+
# enzymes_polypeptides is not null and
|
157
|
+
# smiles_morgan_fingerprint is not null
|
158
|
+
# ''')
|
159
|
+
# # pathway is absent
|
160
|
+
|
161
|
+
# rows = cur.fetchall()
|
162
|
+
# headers = ['index', 'id', 'name', 'description', 'synthesis_reference', 'indication', 'pharmacodynamics', 'mechanism_of_action', 'toxicity', 'metabolism', 'absorption', 'half_life',
|
163
|
+
# 'protein_binding', 'route_of_elimination', 'volume_of_distribution', 'clearance', 'smiles_notation', 'smile', 'enzyme', 'target']
|
164
|
+
# df = pd.DataFrame(columns=headers, data=rows)
|
165
|
+
# df['smile'] = df['smile'].apply(lambda x:
|
166
|
+
# np.fromstring(
|
167
|
+
# x.replace(
|
168
|
+
# '\n', '')
|
169
|
+
# .replace('[', '')
|
170
|
+
# .replace(']', '')
|
171
|
+
# .replace(' ', ' '), sep=','))
|
172
|
+
# df['enzyme'] = df['enzyme'].apply(
|
173
|
+
# lambda x: x.split('|'))
|
174
|
+
# df['target'] = df['target'].apply(
|
175
|
+
# lambda x: x.split('|'))
|
176
|
+
# return df
|
177
|
+
|
178
|
+
|
179
|
+
# SELECT
|
180
|
+
# CASE
|
181
|
+
# WHEN masked_interaction like '%'+drug_1+'%' THEN drug_1
|
182
|
+
# WHEN masked_interaction like '%'+drug_2+'%' THEN drug_2
|
183
|
+
# Else drug_2
|
184
|
+
# END AS Absent,
|
185
|
+
|
186
|
+
# drug_1, drug_2,
|
187
|
+
# masked_interaction
|
188
|
+
|
189
|
+
# from _Interactions
|
190
|
+
# where LENGTH(masked_interaction) = LENGTH(REPLACE(masked_interaction, 'DRUG', ''))
|
191
|
+
# or LENGTH(masked_interaction) = LENGTH(REPLACE(masked_interaction, 'DRUG', '')) + 4
|
192
|
+
|
193
|
+
# if __name__ == "__main__":
|
194
|
+
# conn = create_connection(r"./event-extended.db")
|
195
|
+
# extended_version_df = get_extended_version(conn)
|
196
|
+
|
197
|
+
# df = select_all_events_as_dataframe(conn)
|
198
|
+
# print(df.head())
|
199
|
+
|
200
|
+
# events_with_category_df = select_events_with_category(conn)
|
201
|
+
# print(events_with_category_df.head())
|
202
|
+
|
203
|
+
# u = events_with_category_df['event_category'].unique()
|
204
|
+
# print(len(u))
|
@@ -96,10 +96,10 @@ class DDIMDLDataset(BaseDataset,TextDatasetMixin):
|
|
96
96
|
logger.info(f'{self.dataset_name} is initialized')
|
97
97
|
|
98
98
|
def load_drugs_and_events(self):
|
99
|
-
self.drugs_df = self.
|
100
|
-
self.ddis_df = self.
|
99
|
+
self.drugs_df = self.__select_all_drugs_as_dataframe()
|
100
|
+
self.ddis_df = self.__select_all_events()
|
101
101
|
|
102
|
-
def
|
102
|
+
def __select_all_drugs_as_dataframe(self):
|
103
103
|
headers = ['index', 'id', 'name',
|
104
104
|
'target', 'enzyme', 'pathway', 'smile']
|
105
105
|
if self._conn is None:
|
@@ -117,7 +117,7 @@ class DDIMDLDataset(BaseDataset,TextDatasetMixin):
|
|
117
117
|
|
118
118
|
return df
|
119
119
|
|
120
|
-
def
|
120
|
+
def __select_all_events(self):
|
121
121
|
if self._conn is None:
|
122
122
|
raise Exception("There is no connection")
|
123
123
|
cur = self._conn.cursor()
|
@@ -221,16 +221,16 @@ class DDIMDLDataset(BaseDataset,TextDatasetMixin):
|
|
221
221
|
lambda_fnc, args=(value,), axis=1)
|
222
222
|
self.columns.append(key)
|
223
223
|
print(self.ddis_df[key].head())
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
224
|
+
if isinstance(self, TextDatasetMixin):
|
225
|
+
if self.embedding_dict is not None:
|
226
|
+
for embedding_column in self.embedding_columns:
|
227
|
+
print(f"concat {embedding_column} embeddings")
|
228
|
+
embeddings_after_pooling = {k: self.pooling_strategy.apply(
|
229
|
+
v) for k, v in self.embedding_dict[embedding_column].items()}
|
230
|
+
# column_embeddings_dict = embedding_values[embedding_column]
|
231
|
+
self.ddis_df[embedding_column+'_embedding'] = self.ddis_df.apply(
|
232
|
+
x_fnc, args=(embeddings_after_pooling,), axis=1)
|
233
|
+
self.columns.append(embedding_column+'_embedding')
|
234
234
|
|
235
235
|
dataframe = self.ddis_df.copy()
|
236
236
|
if not isinstance(classes, (list, pd.Series, np.ndarray)):
|
@@ -90,8 +90,8 @@ class DDIMDLDatasetV2(BaseDataset):
|
|
90
90
|
db = HERE.joinpath('data/event.db')
|
91
91
|
conn = create_connection(db)
|
92
92
|
print("db prep")
|
93
|
-
self.drugs_df = self.
|
94
|
-
self.ddis_df = self.
|
93
|
+
self.drugs_df = self.__select_all_drugs_as_dataframe(conn)
|
94
|
+
self.ddis_df = self.__select_all_events(conn)
|
95
95
|
print("db bitti")
|
96
96
|
self.index_path = kwargs.get('index_path')
|
97
97
|
|
@@ -121,7 +121,7 @@ class DDIMDLDatasetV2(BaseDataset):
|
|
121
121
|
# print(self.ddis_df[key].head())
|
122
122
|
# print("init finished")
|
123
123
|
|
124
|
-
def
|
124
|
+
def __select_all_drugs_as_dataframe(self, conn):
|
125
125
|
headers = ['index', 'id', 'name',
|
126
126
|
'target', 'enzyme', 'pathway', 'smile']
|
127
127
|
cur = conn.cursor()
|
@@ -137,7 +137,7 @@ class DDIMDLDatasetV2(BaseDataset):
|
|
137
137
|
|
138
138
|
return df
|
139
139
|
|
140
|
-
def
|
140
|
+
def __select_all_events(self, conn):
|
141
141
|
"""
|
142
142
|
Query all rows in the event table
|
143
143
|
:param conn: the Connection object
|
@@ -9,7 +9,6 @@ from ddi_fw.utils import ZipHelper
|
|
9
9
|
from .. import BaseDataset
|
10
10
|
from ddi_fw.langchain.embeddings import PoolingStrategy
|
11
11
|
from ..db_utils import create_connection
|
12
|
-
# from ..db_utils import create_connection, select_all_drugs_as_dataframe, select_events_with_category
|
13
12
|
|
14
13
|
HERE = pathlib.Path(__file__).resolve().parent
|
15
14
|
list_of_embedding_columns = ['all_text', 'description',
|
@@ -120,6 +120,8 @@ class MultiPipeline():
|
|
120
120
|
columns = config.get("columns")
|
121
121
|
ner_data_file = config.get("ner_data_file")
|
122
122
|
ner_threshold = config.get("ner_threshold")
|
123
|
+
ner_min_threshold_dict = config.get("ner_min_threshold_dict")
|
124
|
+
ner_max_threshold_dict = config.get("ner_max_threshold_dict")
|
123
125
|
column_embedding_configs = config.get("column_embedding_configs")
|
124
126
|
vector_db_persist_directory = config.get("vector_db_persist_directory")
|
125
127
|
vector_db_collection_name = config.get("vector_db_collection_name")
|
@@ -170,10 +172,14 @@ class MultiPipeline():
|
|
170
172
|
experiment_tags=experiment_tags,
|
171
173
|
tracking_uri=tracking_uri,
|
172
174
|
dataset_type=dataset_type,
|
175
|
+
dataset_splitter_type=dataset_splitter_type,
|
173
176
|
umls_code_types = None,
|
174
177
|
text_types = None,
|
175
|
-
|
178
|
+
min_threshold_dict=ner_min_threshold_dict,
|
179
|
+
max_threshold_dict=ner_max_threshold_dict,
|
180
|
+
columns=columns,
|
176
181
|
ner_data_file=ner_data_file,
|
182
|
+
default_model=default_model,
|
177
183
|
multi_modal= multi_modal
|
178
184
|
)
|
179
185
|
|
@@ -0,0 +1,231 @@
|
|
1
|
+
import json
|
2
|
+
from typing import Optional
|
3
|
+
from ddi_fw.pipeline.pipeline import Pipeline
|
4
|
+
from ddi_fw.pipeline.ner_pipeline import NerParameterSearch
|
5
|
+
import importlib
|
6
|
+
|
7
|
+
|
8
|
+
def load_config(file_path):
|
9
|
+
with open(file_path, 'r') as file:
|
10
|
+
config = json.load(file)
|
11
|
+
return config
|
12
|
+
|
13
|
+
|
14
|
+
def get_import(full_path_of_import):
|
15
|
+
"""Dynamically imports an object from a module given its full path.
|
16
|
+
|
17
|
+
Args:
|
18
|
+
full_path_of_import (str): The full path of the import (e.g., 'module.submodule.ClassName').
|
19
|
+
|
20
|
+
Returns:
|
21
|
+
object: The imported object.
|
22
|
+
|
23
|
+
Raises:
|
24
|
+
ImportError: If the module cannot be imported.
|
25
|
+
AttributeError: If the attribute does not exist in the module.
|
26
|
+
"""
|
27
|
+
if not full_path_of_import:
|
28
|
+
raise ValueError("The import path cannot be empty.")
|
29
|
+
|
30
|
+
parts = full_path_of_import.split('.')
|
31
|
+
import_name = parts[-1]
|
32
|
+
module_name = ".".join(parts[:-1]) if len(parts) > 1 else ""
|
33
|
+
|
34
|
+
try:
|
35
|
+
module = importlib.import_module(module_name)
|
36
|
+
return getattr(module, import_name)
|
37
|
+
except ModuleNotFoundError as e:
|
38
|
+
raise ImportError(f"Module '{module_name}' could not be found.") from e
|
39
|
+
except AttributeError as e:
|
40
|
+
raise AttributeError(
|
41
|
+
f"'{module_name}' has no attribute '{import_name}'") from e
|
42
|
+
|
43
|
+
|
44
|
+
class MultiPipeline():
|
45
|
+
# def __init__(self, experiments_config_file, experiments_config):
|
46
|
+
# if experiments_config_file is None and experiments_config is None:
|
47
|
+
# raise ValueError("Either experiments_config_file or experiments_config must be provided.")
|
48
|
+
# if experiments_config_file is not None and experiments_config is not None:
|
49
|
+
# raise ValueError("Only one of experiments_config_file or experiments_config should be provided.")
|
50
|
+
# if experiments_config_file is not None:
|
51
|
+
# self.experiments_config = load_config(experiments_config_file)
|
52
|
+
# else:
|
53
|
+
# self.experiments_config = experiments_config
|
54
|
+
# self.items = []
|
55
|
+
# self.pipeline_resuts = dict()
|
56
|
+
|
57
|
+
def __init__(self, experiments_config_file: Optional[str] = None, experiments_config: Optional[dict] = None):
|
58
|
+
"""
|
59
|
+
Initialize the MultiPipeline.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
experiments_config_file (str, optional): Path to the experiments configuration file.
|
63
|
+
experiments_config (dict, optional): Dictionary containing the experiments configuration.
|
64
|
+
|
65
|
+
Raises:
|
66
|
+
ValueError: If neither or both of the parameters are provided.
|
67
|
+
"""
|
68
|
+
self.experiments_config = self._validate_and_load_config(experiments_config_file, experiments_config)
|
69
|
+
self.items = []
|
70
|
+
# self.pipeline_results = {}
|
71
|
+
self.pipeline_resuts = dict()
|
72
|
+
|
73
|
+
def _validate_and_load_config(self, experiments_config_file: Optional[str], experiments_config: Optional[dict]) -> dict:
|
74
|
+
"""
|
75
|
+
Validate and load the experiments configuration.
|
76
|
+
|
77
|
+
Args:
|
78
|
+
experiments_config_file (str, optional): Path to the experiments configuration file.
|
79
|
+
experiments_config (dict, optional): Dictionary containing the experiments configuration.
|
80
|
+
|
81
|
+
Returns:
|
82
|
+
dict: The loaded experiments configuration.
|
83
|
+
|
84
|
+
Raises:
|
85
|
+
ValueError: If neither or both of the parameters are provided.
|
86
|
+
"""
|
87
|
+
if experiments_config_file is None and experiments_config is None:
|
88
|
+
raise ValueError("Either 'experiments_config_file' or 'experiments_config' must be provided.")
|
89
|
+
if experiments_config_file is not None and experiments_config is not None:
|
90
|
+
raise ValueError("Only one of 'experiments_config_file' or 'experiments_config' should be provided.")
|
91
|
+
|
92
|
+
if experiments_config_file is not None:
|
93
|
+
try:
|
94
|
+
config = load_config(experiments_config_file)
|
95
|
+
except FileNotFoundError:
|
96
|
+
raise FileNotFoundError(f"Configuration file '{experiments_config_file}' not found.")
|
97
|
+
else:
|
98
|
+
config = experiments_config
|
99
|
+
if config is None:
|
100
|
+
raise ValueError("Configuration cannot be None.")
|
101
|
+
if not isinstance(config, dict):
|
102
|
+
raise ValueError("Configuration must be a dictionary.")
|
103
|
+
# if "experiments" not in config:
|
104
|
+
# raise ValueError("Configuration must contain 'experiments' key.")
|
105
|
+
return config
|
106
|
+
|
107
|
+
def __create_pipeline(self, config):
|
108
|
+
type = config.get("type")
|
109
|
+
library = config.get("library")
|
110
|
+
experiment_name = config.get("experiment_name")
|
111
|
+
experiment_description = config.get("experiment_description")
|
112
|
+
experiment_tags = config.get("experiment_tags")
|
113
|
+
|
114
|
+
# Tracking configuration
|
115
|
+
tracking_config = config.get("tracking_config", {})
|
116
|
+
tracking_library = tracking_config.get("library")
|
117
|
+
use_tracking = tracking_config.get("use_tracking", False)
|
118
|
+
tracking_params = tracking_config.get("params", {}).get(tracking_library, {})
|
119
|
+
|
120
|
+
# tracking_uri = config.get("tracking_uri")
|
121
|
+
# artifact_location = config.get("artifact_location")
|
122
|
+
|
123
|
+
# Dataset configuration
|
124
|
+
dataset_config = config.get("dataset", {})
|
125
|
+
dataset_type = get_import(dataset_config.get("dataset_type"))
|
126
|
+
dataset_splitter_type = get_import(dataset_config.get("dataset_splitter_type"))
|
127
|
+
columns = dataset_config.get("columns", [])
|
128
|
+
additional_config = dataset_config.get("additional_config", {})
|
129
|
+
|
130
|
+
# Vector database configuration
|
131
|
+
vector_database = config.get("vector_databases", {})
|
132
|
+
vector_db_persist_directory = None
|
133
|
+
vector_db_collection_name = None
|
134
|
+
embedding_pooling_strategy = None
|
135
|
+
if vector_database:
|
136
|
+
vector_db_persist_directory = vector_database.get("vector_db_persist_directory")
|
137
|
+
vector_db_collection_name = vector_database.get("vector_db_collection_name")
|
138
|
+
embedding_pooling_strategy = get_import(vector_database.get("embedding_pooling_strategy"))
|
139
|
+
column_embedding_configs = vector_database.get("column_embedding_configs")
|
140
|
+
|
141
|
+
# Combination strategy
|
142
|
+
combination_strategy_config = config.get("combination_strategy", {})
|
143
|
+
combination_type = get_import(combination_strategy_config.get("type")) if combination_strategy_config else None
|
144
|
+
kwargs_combination_params = combination_strategy_config.get("params", {})
|
145
|
+
combinations = combination_type(**kwargs_combination_params).generate() if combination_type else []
|
146
|
+
|
147
|
+
# Default model configuration
|
148
|
+
default_model_config = config.get("default_model", {})
|
149
|
+
default_model_type = get_import(default_model_config.get("model_type"))
|
150
|
+
default_model_params = default_model_config.get("params", {})
|
151
|
+
|
152
|
+
multi_modal = config.get("multi_modal")
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
#ner move it to related dataset
|
157
|
+
|
158
|
+
# ner_data_file = config.get("ner_data_file")
|
159
|
+
# ner_threshold = config.get("ner_threshold")
|
160
|
+
|
161
|
+
|
162
|
+
combination_type = None
|
163
|
+
kwargs_combination_params=None
|
164
|
+
if config.get("combination_strategy"):
|
165
|
+
combination_type = get_import(config.get("combination_strategy").get("type"))
|
166
|
+
kwargs_combination_params = config.get("combination_strategy").get("params")
|
167
|
+
combinations = []
|
168
|
+
if combination_type is not None:
|
169
|
+
combinations = combination_type(**kwargs_combination_params).generate()
|
170
|
+
|
171
|
+
|
172
|
+
pipeline = None
|
173
|
+
if type == "general":
|
174
|
+
pipeline = Pipeline(
|
175
|
+
library=library,
|
176
|
+
use_mlflow=use_mlflow,
|
177
|
+
experiment_name=experiment_name,
|
178
|
+
experiment_description=experiment_description,
|
179
|
+
experiment_tags=experiment_tags,
|
180
|
+
artifact_location=artifact_location,
|
181
|
+
tracking_uri=tracking_uri,
|
182
|
+
dataset_type=dataset_type,
|
183
|
+
dataset_splitter_type=dataset_splitter_type,
|
184
|
+
columns=columns,
|
185
|
+
column_embedding_configs=column_embedding_configs,
|
186
|
+
vector_db_persist_directory=vector_db_persist_directory,
|
187
|
+
vector_db_collection_name=vector_db_collection_name,
|
188
|
+
embedding_pooling_strategy_type=embedding_pooling_strategy,
|
189
|
+
ner_data_file=ner_data_file,
|
190
|
+
ner_threshold=ner_threshold,
|
191
|
+
combinations=combinations,
|
192
|
+
default_model=default_model,
|
193
|
+
multi_modal= multi_modal)
|
194
|
+
elif type== "ner_search":
|
195
|
+
pipeline = NerParameterSearch(
|
196
|
+
library=library,
|
197
|
+
experiment_name=experiment_name,
|
198
|
+
experiment_description=experiment_description,
|
199
|
+
experiment_tags=experiment_tags,
|
200
|
+
tracking_uri=tracking_uri,
|
201
|
+
dataset_type=dataset_type,
|
202
|
+
umls_code_types = None,
|
203
|
+
text_types = None,
|
204
|
+
columns=['tui', 'cui', 'entities'],
|
205
|
+
ner_data_file=ner_data_file,
|
206
|
+
multi_modal= multi_modal
|
207
|
+
)
|
208
|
+
|
209
|
+
|
210
|
+
return {
|
211
|
+
"name": experiment_name,
|
212
|
+
"library": library,
|
213
|
+
"pipeline": pipeline}
|
214
|
+
|
215
|
+
def build(self):
|
216
|
+
for config in self.experiments_config['experiments']:
|
217
|
+
item = self.__create_pipeline(config)
|
218
|
+
self.items.append(item)
|
219
|
+
return self
|
220
|
+
|
221
|
+
def run(self):
|
222
|
+
for item in self.items:
|
223
|
+
print(f"{item['name']} is running")
|
224
|
+
pipeline = item['pipeline']
|
225
|
+
pipeline.build()
|
226
|
+
result = pipeline.run()
|
227
|
+
self.pipeline_resuts[item['name']] = result
|
228
|
+
return self
|
229
|
+
|
230
|
+
def results(self):
|
231
|
+
return self.pipeline_resuts
|