Repository navigation
Expand file tree
/
Copy pathfetch_OMIM_allelic_variants.py
More file actions
54 lines (47 loc) · 2.16 KB
/
Copy pathfetch_OMIM_allelic_variants.py
File metadata and controls
54 lines (47 loc) · 2.16 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''This script queries the OMIM database for known mutations affecting a given set of proteins/genes.'''
import os
import requests
from time import sleep
# OMIM's terms of use apply to this data. For programmatic access, register for the OMIM API:
# https://www.omim.org/api
# load OMIM db
genemap2 = []
with open("./OMIM/genemap2.txt", "r") as in_omim :
for entry in in_omim.readlines() :
if entry[0] == "#" : continue
genemap2.append(entry)
for pathway_name in ["insulin signaling", "tryptophan metabolism"] :
pathway_folder = "./%s" % pathway_name.replace(" ", "_")
output_folder = "%s/%s_OMIM" % (pathway_folder, pathway_name.replace(" ", "_"))
if not os.path.exists(output_folder): os.makedirs(output_folder)
# load gene id and names from file
gene_ids = set()
gene_symbol = {}
with open("%s/official_gene_symbols_and_names.txt" % pathway_folder, "r") as in_genes :
header = in_genes.readline()
for gene in in_genes.readlines() :
gene_fields = gene.split("\t")
gene_id = gene_fields[2]
gene_symbol[gene_id] = gene_fields[5]
gene_ids.add(gene_id)
with open("%s/OMIM_gene_entries.txt" % pathway_folder , "w") as out_omim :
for entry in genemap2 :
omim_id = entry.split("\t")[5]
gene_id = entry.split("\t")[9]
if gene_id in gene_ids :
out_omim.write(entry)
url = "https://www.omim.org/allelicVariant/%s?format=tsv" % omim_id
print "Currently parsing MIM: %s, Gene ID: %s" % (omim_id, gene_id)
print url
try :
req = requests.get(url)
response = req.text.encode('utf-8')
if not "OMIM Error" in response :
with open("%s/%s_%s_%s_Allelic_Variants.txt" %(output_folder, gene_id, gene_symbol[gene_id], omim_id), "w") as out_file :
out_file.write(response)
except Exception,e:
print e
continue
sleep(3) # not too aggressive...