forked from emreg00/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_drugbank.py
596 lines (562 loc) · 21.9 KB
/
parse_drugbank.py
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
##############################################################################
# DrugBank v4.3 XML parser
#
# eg 15/01/2016
##############################################################################
from xml.etree.ElementTree import iterparse
import os, cPickle
import re, math
def main():
base_dir = "../data/drugbank/"
#file_name = base_dir + "drugbank.xml"
file_name = base_dir + "test.xml"
parser = DrugBankXMLParser(file_name)
parser.parse()
drug = "DB00843"
target = "BE0000426" #"BE0004796" #"P22303"
for i in dir(parser):
print i
if i.startswith("drug"):
d = getattr(parser, i)
if drug in d: print d[drug]
elif i.startswith("target"):
d = getattr(parser, i)
if target in d: print d[target]
print parser.drug_to_target_to_values
drug_to_uniprots = parser.get_targets(target_types = set(["target", "enzyme"]), only_paction=False)
print drug_to_uniprots
return
class DrugBankXMLParser(object):
NS="{http://www.drugbank.ca}"
def __init__(self, filename):
self.file_name = filename
self.drug_to_name = {}
self.drug_to_description = {}
self.drug_to_type = {}
self.drug_to_groups = {}
self.drug_to_indication = {}
self.drug_to_pharmacodynamics = {}
self.drug_to_moa = {}
self.drug_to_toxicity = {}
self.drug_to_synonyms = {}
self.drug_to_products = {}
self.drug_to_brands = {}
self.drug_to_uniprot = {}
self.drug_to_interactions = {}
self.drug_to_pubchem = {}
self.drug_to_pubchem_substance = {}
self.drug_to_kegg = {}
self.drug_to_kegg_compound = {}
self.drug_to_pharmgkb = {}
self.drug_to_chembl = {}
self.drug_to_target_to_values = {} # drug - target - (type {target / enzyme / transporter / carrier}, known action, [action types])
self.drug_to_categories = {}
self.drug_to_atc_codes = {}
self.drug_to_inchi_key = {}
self.drug_to_smiles = {}
self.target_to_name = {}
self.target_to_gene = {}
self.target_to_uniprot = {}
return
def parse(self):
# get an iterable
context = iterparse(self.file_name, ["start", "end"])
# turn it into an iterator
context = iter(context)
# get the root element
event, root = context.next()
state_stack = [ root.tag ]
drug_id = None
drug_type = None
drug_id_partner = None
current_target = None
resource = None
current_property = None
target_types = set(map(lambda x: self.NS+x, ["target", "enzyme", "carrier", "transporter"]))
target_types_plural = set(map(lambda x: x+"s", target_types))
for (event, elem) in context:
if event == "start":
state_stack.append(elem.tag)
if len(state_stack) <= 2 and elem.tag == self.NS+"drug":
if "type" in elem.attrib:
drug_type = elem.attrib["type"]
else:
drug_type = None
elif elem.tag == self.NS+"drugbank-id":
if "primary" in elem.attrib and state_stack[-3] == self.NS+"drugbank" and state_stack[-2] == self.NS+"drug":
drug_id = None
elif len(state_stack) > 3 and state_stack[-3] == self.NS+"drug-interactions" and state_stack[-2] == self.NS+"drug-interaction":
drug_id_partner = None
elif elem.tag == self.NS+"resource":
resource = None
elif elem.tag == self.NS+"property":
current_property = None
elif elem.tag in target_types:
if state_stack[-2] in target_types_plural:
current_target = None
if event == "end":
if len(state_stack) <= 2 and elem.tag == self.NS+"drug":
if "type" in elem.attrib:
drug_type = elem.attrib["type"]
else:
drug_type = None
if elem.tag == self.NS+"drugbank-id":
if state_stack[-2] == self.NS+"drug":
if "primary" in elem.attrib:
drug_id = elem.text
if drug_type is not None:
self.drug_to_type[drug_id] = drug_type
#print drug_id, drug_type
elif len(state_stack) > 3 and state_stack[-3] == self.NS+"drug-interactions" and state_stack[-2] == self.NS+"drug-interaction":
d = self.drug_to_interactions.setdefault(drug_id, {})
drug_id_partner = elem.text
d[drug_id_partner] = ""
elif elem.tag == self.NS+"name":
if len(state_stack) <= 3 and state_stack[-2] == self.NS+"drug":
self.drug_to_name[drug_id] = elem.text.strip()
elif state_stack[-2] == self.NS+"product" and state_stack[-3] == self.NS+"products":
product = elem.text
product = product.strip().encode('ascii','ignore')
if product != "":
self.drug_to_products.setdefault(drug_id, set()).add(product)
elif state_stack[-2] == self.NS+"international-brand" and state_stack[-3] == self.NS+"international-brands":
brand = elem.text
#idx = brand.find(" [")
#if idx != -1:
# brand = brand[:idx]
brand = brand.strip().encode('ascii','ignore')
if brand != "":
self.drug_to_brands.setdefault(drug_id, set()).add(brand)
#elif state_stack[-3] == self.NS+"targets" and state_stack[-2] == self.NS+"target":
elif state_stack[-3] in target_types_plural and state_stack[-2] in target_types:
self.target_to_name[current_target] = elem.text
elif elem.tag == self.NS+"description":
if state_stack[-2] == self.NS+"drug":
self.drug_to_description[drug_id] = elem.text
if len(state_stack) > 3 and state_stack[-3] == self.NS+"drug-interactions" and state_stack[-2] == self.NS+"drug-interaction":
self.drug_to_interactions[drug_id][drug_id_partner] = elem.text
elif elem.tag == self.NS+"group":
if state_stack[-2] == self.NS+"groups":
self.drug_to_groups.setdefault(drug_id, set()).add(elem.text)
elif elem.tag == self.NS+"indication":
if state_stack[-2] == self.NS+"drug":
self.drug_to_indication[drug_id] = elem.text
elif elem.tag == self.NS+"pharmacodynamics":
if state_stack[-2] == self.NS+"drug":
self.drug_to_pharmacodynamics[drug_id] = elem.text
elif elem.tag == self.NS+"mechanism-of-action":
if state_stack[-2] == self.NS+"drug":
self.drug_to_moa[drug_id] = elem.text
elif elem.tag == self.NS+"toxicity":
if state_stack[-2] == self.NS+"drug":
self.drug_to_toxicity[drug_id] = elem.text
elif elem.tag == self.NS+"synonym":
if state_stack[-2] == self.NS+"synonyms" and state_stack[-3] == self.NS+"drug":
synonym = elem.text
idx = synonym.find(" [")
if idx != -1:
synonym = synonym[:idx]
synonym = synonym.strip().encode('ascii','ignore')
if synonym != "":
self.drug_to_synonyms.setdefault(drug_id, set()).add(synonym)
elif elem.tag == self.NS+"category":
if state_stack[-2] == self.NS+"categories":
self.drug_to_categories.setdefault(drug_id, set()).add(elem.text)
elif elem.tag == self.NS+"atc-code":
if state_stack[-2] == self.NS+"atc-codes":
self.drug_to_atc_codes.setdefault(drug_id, set()).add(elem.attrib["code"])
elif elem.tag == self.NS+"id":
if state_stack[-3] in target_types_plural and state_stack[-2] in target_types:
current_target = elem.text
d = self.drug_to_target_to_values.setdefault(drug_id, {})
d[current_target] = [state_stack[-2], False, []]
#print current_target
elif elem.tag == self.NS+"action":
if state_stack[-3] in target_types and state_stack[-2] == self.NS+"actions":
self.drug_to_target_to_values[drug_id][current_target][2].append(elem.text)
elif elem.tag == self.NS+"known-action":
if state_stack[-2] in target_types:
if elem.text == "yes":
self.drug_to_target_to_values[drug_id][current_target][1] = True
if len(self.drug_to_target_to_values[drug_id][current_target][2]) == 0:
#print "Inconsistency with target action: %s %s" % (drug_id, current_target)
pass
elif elem.tag == self.NS+"gene-name":
if state_stack[-3] in target_types and state_stack[-2] == self.NS+"polypeptide":
self.target_to_gene[current_target] = elem.text
elif elem.tag == self.NS+"kind":
if state_stack[-3] == self.NS+"calculated-properties" and state_stack[-2] == self.NS+"property":
current_property = elem.text # InChIKey or SMILES
elif elem.tag == self.NS+"value":
if state_stack[-3] == self.NS+"calculated-properties" and state_stack[-2] == self.NS+"property":
if current_property == "InChIKey":
inchi_key = elem.text # strip InChIKey=
if inchi_key.startswith("InChIKey="):
inchi_key = inchi_key[len("InChIKey="):]
self.drug_to_inchi_key[drug_id] = inchi_key
if current_property == "SMILES":
self.drug_to_smiles[drug_id] = elem.text
elif elem.tag == self.NS+"resource":
if state_stack[-3] == self.NS+"external-identifiers" and state_stack[-2] == self.NS+"external-identifier":
resource = elem.text
elif elem.tag == self.NS+"identifier":
if state_stack[-3] == self.NS+"external-identifiers" and state_stack[-2] == self.NS+"external-identifier":
if state_stack[-5] in target_types and state_stack[-4] == self.NS+"polypeptide":
if resource == "UniProtKB":
self.target_to_uniprot[current_target] = elem.text
elif state_stack[-4] == self.NS+"drug":
if resource == "PubChem Compound":
self.drug_to_pubchem[drug_id] = elem.text
elif resource == "PubChem Substance":
self.drug_to_pubchem_substance[drug_id] = elem.text
elif resource == "KEGG Drug":
self.drug_to_kegg[drug_id] = elem.text
elif resource == "KEGG Compound":
self.drug_to_kegg_compound[drug_id] = elem.text
elif resource == "UniProtKB":
self.drug_to_uniprot[drug_id] = elem.text
elif resource == "PharmGKB":
self.drug_to_pharmgkb[drug_id] = elem.text
elif resource == "ChEMBL":
self.drug_to_chembl[drug_id] = elem.text
elem.clear()
state_stack.pop()
root.clear()
return
def get_targets(self, target_types = set(["target"]), only_paction=False):
# Map target ids to uniprot ids
target_types = map(lambda x: self.NS + x, target_types)
drug_to_uniprots = {}
for drug, target_to_values in self.drug_to_target_to_values.iteritems():
for target, values in target_to_values.iteritems():
#print target, values
try:
uniprot = self.target_to_uniprot[target]
except:
# drug target has no uniprot
#print "No uniprot information for", target
continue
target_type, known, actions = values
flag = False
if only_paction:
if known:
flag = True
else:
if target_type in target_types:
flag = True
if flag:
drug_to_uniprots.setdefault(drug, set()).add(uniprot)
return drug_to_uniprots
def get_synonyms(self, selected_drugs=None, only_synonyms=False):
name_to_drug = {}
for drug, name in self.drug_to_name.iteritems():
if selected_drugs is not None and drug not in selected_drugs:
continue
name_to_drug[name.lower()] = drug
synonym_to_drug = {}
for drug, synonyms in self.drug_to_synonyms.iteritems():
for synonym in synonyms:
if selected_drugs is not None and drug not in selected_drugs:
continue
synonym_to_drug[synonym.lower()] = drug
if only_synonyms:
return name_to_drug, synonym_to_drug
for drug, brands in self.drug_to_brands.iteritems():
for brand in brands:
if selected_drugs is not None and drug not in selected_drugs:
continue
synonym_to_drug[brand.lower()] = drug
for drug, products in self.drug_to_products.iteritems():
for product in products:
if selected_drugs is not None and drug not in selected_drugs:
continue
synonym_to_drug[product.lower()] = drug
return name_to_drug, synonym_to_drug
def get_drugs_by_group(self, groups_to_include = set(["approved"]), groups_to_exclude=set(["withdrawn"])):
selected_drugs = set()
for drugbank_id, name in self.drug_to_name.iteritems():
# Consider only approved drugs
if drugbank_id not in self.drug_to_groups:
continue
groups = self.drug_to_groups[drugbank_id]
#if "approved" not in groups or "withdrawn" in groups:
if len(groups & groups_to_include) == 0:
continue
if len(groups & groups_to_exclude) > 0:
continue
selected_drugs.add(drugbank_id)
return selected_drugs
def output_data(file_name, out_file):
dump_file = file_name + ".pcl"
if os.path.exists(dump_file):
parser = cPickle.load(open(dump_file))
else:
parser = DrugBankXMLParser(file_name)
parser.parse()
cPickle.dump(parser, open(dump_file, 'w'))
#target_type_list = ["target", "enzyme", "carrier", "transporter"]
#for target_type in target_type_list:
target_type_list = ["target"]
drug_to_uniprots = parser.get_targets(target_types = set(target_type_list), only_paction=False)
f = open(out_file, 'w')
f.write("Drugbank id\tName\tGroup\tTargets\n")
#f.write("Drugbank id\tName\tGroup\tTarget uniprots\tEnzyme uniprots\tTransporter uniprots\tCarrier uniprots\tDescription\tIndication\tPubChem\tSMILES\tInchi\tAlternative names\t\n")
#drug_to_description drug_to_indication drug_to_synonyms drug_to_products drug_to_brands
for drug, uniprots in drug_to_uniprots.iteritems():
name = parser.drug_to_name[drug]
groups = parser.drug_to_groups[drug]
values = [ drug, name.encode("ascii", "replace") ]
values.append(" | ".join(groups))
values.append(" | ".join(uniprots))
try:
f.write("%s\n" % "\t".join(values))
except:
print values
f.close()
return
def get_drugs_by_group(parser, groups_to_include = set(["approved"]), groups_to_exclude=set(["withdrawn"])):
selected_drugs = set()
for drugbank_id, name in parser.drug_to_name.iteritems():
# Consider only approved drugs
if drugbank_id not in parser.drug_to_groups:
continue
groups = parser.drug_to_groups[drugbank_id]
#if "approved" not in groups or "withdrawn" in groups:
if len(groups & groups_to_include) == 0:
continue
if len(groups & groups_to_exclude) > 0:
continue
selected_drugs.add(drugbank_id)
return selected_drugs
def get_disease_specific_drugs(parser, selected_drugs, phenotypes):
import text_utilities
disease_to_drugs = {}
indication_to_diseases = {}
for drug, indication in parser.drug_to_indication.iteritems():
if drug not in selected_drugs:
continue
if indication is None:
continue
#if any(map(lambda x: x is not None, [ exp.search(indication) for exp in exps ])):
#disease = keywords[0]
#disease_to_drugs.setdefault(disease, set()).add(drug)
#for disease, exp in zip(phenotypes, exps):
# if exp.search(indication.lower()) is not None:
# disease_to_drugs.setdefault(disease, set()).add(drug)
indication = indication.lower()
for disease in phenotypes:
#if all([ indication.find(word.strip()) != -1 for word in disease.split(",") ]):
# disease_to_drugs.setdefault(disease, set()).add(drug)
values = text_utilities.tokenize_disease_name(disease)
#print disease, values
indication_to_diseases.setdefault(indication, set())
if all([ indication.find(word.strip()) != -1 for word in values ]):
#print disease, drug
disease_to_drugs.setdefault(disease, set()).add(drug)
indication_to_diseases.setdefault(indication, set()).add(disease)
else:
values = text_utilities.tokenize_disease_name(disease.replace("2", "II"))
if all([ indication.find(word.strip()) != -1 for word in values ]):
disease_to_drugs.setdefault(disease, set()).add(drug)
indication_to_diseases.setdefault(indication, set()).add(disease)
else:
values = text_utilities.tokenize_disease_name(disease.replace("1", "I"))
if all([ indication.find(word.strip()) != -1 for word in values ]):
disease_to_drugs.setdefault(disease, set()).add(drug)
indication_to_diseases.setdefault(indication, set()).add(disease)
return disease_to_drugs
# Print non-matching indications
for indication, diseases in indication_to_diseases.iteritems():
if len(diseases) == 0:
print indication.encode('ascii','ignore')
elif indication.find(" not ") != -1 or indication.find(" except ") != -1:
print diseases, indication.encode('ascii','ignore')
#print disease_to_drugs["diabetes mellitus, type 2"]
return disease_to_drugs
def get_drugs_for_targets(file_name, output_file):
parser = DrugBankXMLParser(file_name)
parser.parse()
uniprot_to_drugs = {}
for drug, targets in parser.drug_to_targets.iteritems():
#print drug
for uniprot in targets:
uniprot_to_drugs.setdefault(uniprot, set()).add(drug)
f = open(output_file, 'w')
for uniprot, drugs in uniprot_to_drugs.iteritems():
f.write("%s\t%s\n" % (uniprot, ";".join(drugs)))
f.close()
return
def output_drug_info(file_name, output_file):
parser = DrugBankXMLParser(file_name)
parser.parse()
f = open(output_file, 'w')
f.write("drugbank id\tname\tgroups\tpubchem id\tdescription\tindication\ttargets\n")
for drug, name in parser.drug_to_name.iteritems():
name = name.encode('ascii','ignore')
try:
groups = parser.drug_to_groups[drug]
except:
groups = []
try:
description = parser.drug_to_description[drug]
description = description.replace("\n", "").encode('ascii','ignore')
except:
description = ""
try:
indication = parser.drug_to_indication[drug]
indication = indication.replace("\n", "").encode('ascii','ignore')
except:
#print drug
indication = ""
if drug in parser.drug_to_pubchem:
pubchem = parser.drug_to_pubchem[drug]
else:
pubchem = ""
if drug in parser.drug_to_targets:
targets = parser.drug_to_targets[drug]
else:
targets = []
try:
f.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (drug, name, ";".join(groups), pubchem, description, indication, ";".join(targets)))
except:
print drug, name, groups, pubchem, description, indication, targets
return
f.close()
return
def get_drugbank_id_from_name(name, name_to_drug, synonym_to_drug, regex_db_name = False):
"""
regex_db_name: True creates a regex with each drugbank name and looks for in in the given name
(useful for rxname mappings which contain dosages)
"""
drugbank_id = None
drugbank_name = None
name = name.lower()
# Try exact match first
if name in name_to_drug:
drugbank_id = name_to_drug[name]
drugbank_name = name
elif name in synonym_to_drug:
drugbank_id = synonym_to_drug[name]
drugbank_name = name
# Try matching drugbank name in the given name
else:
if not regex_db_name:
if len(set("[()]") & set(name)) > 0:
return drugbank_id, drugbank_name
exp = re.compile(r"\b%s\b" % name)
for db_name, db_id in name_to_drug.iteritems():
if len(set("[()]") & set(db_name)) > 0:
continue
db_name = db_name.lower()
if regex_db_name:
exp = re.compile(r"\b%s\b" % db_name)
m = exp.search(name)
else:
m = exp.search(db_name)
if m is None:
continue
#if drugbank_id is not None:
# print "Multiple match:", drugbank_name, db_name, name
drugbank_id = db_id
drugbank_name = db_name
break
if drugbank_id is None:
for db_name, db_id in synonym_to_drug.iteritems():
if len(set("[()]") & set(db_name)) > 0:
continue
db_name = db_name.lower()
if regex_db_name:
try:
exp = re.compile(r"\b%s\b" % db_name)
except:
continue
m = exp.search(name)
else:
m = exp.search(db_name)
if m is None:
continue
#if drugbank_id is not None:
# print drugbank_id, db_id, name
drugbank_id = db_id
drugbank_name = db_name
return drugbank_id, drugbank_name
def get_drug_info(drug_info_file):
drug_to_values = {}
f = open(drug_info_file)
header = f.readline().strip().split("\t")
col_to_idx = dict((k, i) for i, k in enumerate(header[1:]))
for line in f:
words = line.strip("\n").split("\t")
drug_to_values[words[0]] = words[1:]
return col_to_idx, drug_to_values
def get_drug_targets(file_name, drugs_file=None):
parser = DrugBankXMLParser(file_name)
parser.parse()
drugs = None
if drugs_file is not None:
drugs = set([ line.strip().lower() for line in open(drugs_file) ])
#exp = re.compile("brain")
#exp2 = re.compile("metastasis")
for drug, description in parser.drug_to_description.iteritems():
#drug = drug.lower()
if description is None:
continue
#m = exp.search(description)
#m2 = exp2.search(description)
if True: # m is not None and m2 is not None:
drugs.add(drug)
for drug, indication in parser.drug_to_indication.iteritems():
#drug = drug.lower()
if indication is None:
continue
#m = exp.search(indication)
#m2 = exp2.search(indication)
if True: # m is not None and m2 is not None:
drugs.add(drug)
#print drugs
drug_to_targets = {}
for drug, partner_ids in parser.drug_to_partner_ids.iteritems():
#drug = drug.lower()
if drugs is not None and drug not in drugs:
continue
#print drug
for partner_id in partner_ids:
gene = parser.partner_id_to_gene[partner_id]
if gene is None:
continue
drug_to_targets.setdefault(drug, set()).add(gene)
return drug_to_targets, parser.drug_to_description, parser.drug_to_indication
def output_drug_targets(drug_to_targets):
f = open("drug_to_targets.txt", 'w')
f2 = open("drug_targets.txt", 'w')
for drug, targets in drug_to_targets.iteritems():
f.write("%s\t%s\n" % (drug, "\t".join(targets)))
f2.write("%s\n" % "\n".join(targets))
f.close()
f2.close()
return
def score_drugs_by_target_score(drug_to_targets, scores_file, output_file):
gene_to_score = dict([ line.strip().split() for line in open(scores_file)])
values = []
for drug, targets in drug_to_targets.iteritems():
scores = []
for target in targets:
if target in gene_to_score:
scores.append(float(gene_to_score[target]))
if len(scores) == 0:
continue
values.append((calculate_score(scores), drug))
values.sort()
values.reverse()
f = open(output_file, 'w')
for score, drug in values:
f.write("%s\t%s\n" % (drug, str(score)))
f.close()
return
def calculate_drug_score_from_targets(values):
val = 0.0
for value in values:
val += value * value
return math.sqrt(val)
if __name__ == "__main__":
main()