-
Notifications
You must be signed in to change notification settings - Fork 0
/
OMIM_AllelicVariantExtractor.py
94 lines (52 loc) · 1.5 KB
/
OMIM_AllelicVariantExtractor.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
# coding: utf-8
# In[1]:
import urllib2
import sys
import re
# In[2]:
def phenotype(s):
iName = re.search("\w.+",s[1])
return iName.group()
# In[3]:
def mutation(s):
mut = re.search("\w.+",s[2]).group().split(", ")
if str(mut).find("span") == -1:
mut2 = mut[1].split()
data = [mut[0],mut2[0]]
return data
else:
return "ERROR"
# In[4]:
def SNP(s):
init_snp = s[3].find("rs")
final_snp = s[3].find(";",init_snp)
init_clinvar = s[5].find("RCV")
final_clinvar = s[5].find("\"",init_clinvar)
clinvar = s[5][init_clinvar:final_clinvar]
if clinvar.find("OR") != -1:
return [s[3][init_snp:final_snp], clinvar.split()[0]]
else:
return [s[3][init_snp:final_snp], clinvar]
# In[7]:
def ShowVariant(ID):
site= "https://www.omim.org/allelicVariant/" + ID
hdr = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(site,headers=hdr)
page = urllib2.urlopen(req)
code = page.read()
init = code.split("<a name=\"")
for i in init[1:]:
sub = i.split("<span class=\"mim-font\">")
two_data = mutation(sub)
if two_data != "ERROR":
print two_data[0] + "\t",
print SNP(sub)[0] + "\t",
print SNP(sub)[1] + "\t",
print two_data[1] + "\t",
print phenotype(sub)
page.close()
# In[ ]:
infile = open(sys.argv[1])
for i in infile.readlines():
ShowVariant(i)
# In[45]: