-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActiveSubstance_Tagging.py
More file actions
202 lines (102 loc) · 6.47 KB
/
ActiveSubstance_Tagging.py
File metadata and controls
202 lines (102 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import openpyxl
import numpy as np
import datetime
import pandas as pd
import os
import glob
## Import files from a folder:
# Ask the user for the location path of the files.
def Read_multipleFiles ():
file_path = input('Enter a file path: ')
file_type = input('Define a file type (Excel, csv): ')
# Use os to get all the files in the folder
if file_type.lower() == "excel":
if os.path.exists(file_path):
files_xlsx = glob.glob(os.path.join(file_path, "*.xlsx"))
df = []
# Loop over list of files to append to empty dataframe:
df = pd.concat((pd.read_excel(f) for f in files_xlsx), ignore_index=True)
df.fillna('EMPTY', inplace=True)
#Erase duplicates in the dataframe.
Datos = df.drop_duplicates(keep="first")
Dup = len(df) - len(Datos)
print(Dup,"duplicates removed")
if len(files_xlsx) == 1:
print("There is", len(files_xlsx),"file in the folder")
else:
print("There are", len(files_xlsx),"files in the folder")
else:
print('The specified file path does NOT exist')
print(files_xlsx)
elif file_type.lower == "csv":
if os.path.exists(file_path):
files_csv = glob.glob(os.path.join(file_path, "*.csv"))
df = []
# Loop over list of files to append to empty dataframe:
df = pd.concat((pd.read_csv(f,sheet_name= "Results") for f in files_csv), ignore_index=True)
df.fillna('EMPTY', inplace=True)
#Erase duplicates in the dataframe.
Datos = df.drop_duplicates(keep="first")
Dup = len(df) - len(Datos)
print(Dup,"duplicates removed")
if len(files_csv) == 1:
print("There is", len(files_csv),"file in the folder")
else:
print("There are", len(files_csv),"files in the folder")
else:
print('The specified file path does NOT exist')
print(files_csv)
Read_multipleFiles()
def Cortellis_ATCtagging(Datos):
file_path = input("Enter a file path to export your results: ")
# Iteration through each row on the dataframe and appending to each list the right tag for "Type of active substance" and "Category" for each drug.
Datos["concat"] = Datos["Technologies"] + "; " + Datos["Other Actions"]
Type = []
Category =[]
# For loop to iterate through the columns of interest in the data frame
for colums,rows in Datos.iterrows():
if "small molecule therapeutic" in str(rows["concat"]).lower() or "small molecule therapeutic" in str(rows["Extract"]).lower():
Type.append("Small molecule therapeutic")
Category.append("Other")
elif "vaccine" in str(rows["concat"]).lower() or "vaccine" in str(rows["Extract"]).lower():
Type.append("Biological therapeutic")
Category.append("Vaccine")
elif "gene therapy" in str(rows["concat"]).lower() or "gene therapy" in str(rows["Extract"]).lower() or "gene editing" in str(rows["concat"]).lower() or "gene editing" in str(rows["Extract"]).lower() or "gene technology" in str(rows["concat"]).lower():
Type.append("Biological therapeutic")
Category.append("Gene Therapy")
elif "cell therapy" in str(rows["concat"]).lower() or "cell therapy" in str(rows["Extract"]).lower():
Type.append("Biological therapeutic")
Category.append("Cell Therapy")
elif "oligo" in str(rows["concat"]).lower() or "RNA" in str(rows["concat"]) or "antisense" in str(rows["concat"]).lower():
Type.append("Biological therapeutic")
Category.append("Oligonucleotide")
elif "antibody conjugated" in str(rows["concat"]).lower() or "antibody drug conjugate" in str(rows["concat"]).lower() or "conjugated antibody" in str(rows["concat"]).lower() or "antibody conjugated" in str(rows["Extract"]).lower():
Type.append("Biological therapeutic")
Category.append("Antibody-drug conjugated")
elif "antibody" in str(rows["concat"]).lower():
Type.append("Biological therapeutic")
Category.append("Antibody")
elif "protein fusion" in str(rows["concat"]).lower() or "protein recombinant" in str(rows["concat"]).lower() or "glycoprotein" in str(rows["concat"]).lower() or "protein conjugated" in str(rows["concat"]).lower() or "recombinant enzyme" in str(rows["concat"]).lower() or "enzyme" in str(rows["concat"]).lower() or "lipoprotein" in str(rows["concat"]).lower():
Type.append("Biological therapeutic")
Category.append("Therapeutic protein")
elif "peptide" in str(rows["concat"]).lower():
Type.append("Biological therapeutic")
Category.append("Peptide")
elif "biological therapeutic" in str(rows["Technologies"]).lower() or "virus recombinant" in str(rows["Technologies"]).lower() or "virus therapy" in str(rows["Technologies"]).lower() or "probiotic" in str(rows["Extract"]).lower() or "yeast recombinant" in str(rows["Technologies"]).lower() or "bacteria recombinant" in str(rows["Technologies"]).lower() :
Type.append("Biological therapeutic")
Category.append("Other")
elif "small molecule" in str(rows["Extract"]).lower() :
Type.append("Small molecule therapeutic")
Category.append("Other")
else:
Type.append("Other")
Category.append("Other")
#Datos["Type of active substance"] = Type
Datos.drop(["concat"], axis = 1, inplace = True)
Datos["Type of active substance"] = Type
Datos["Category"] = Category
Datos.replace('EMPTY',"", inplace=True)
## Exporting dataframe in an excel file:
# Export the dataframe in an excel file at the same location path where we got the files.
Datos.to_excel(file_path + "\2023_Cortellis_tagging_Final.xlsx", index= False)
Cortellis_ATCtagging()