Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
92 lines (79 loc) · 2.78 KB
/
Copy pathutils.py
File metadata and controls
92 lines (79 loc) · 2.78 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
# -*- encoding: utf-8 -*-
"""
Utilitary functions do download and parse data from Orpha net
"""
from requests import post
from bs4 import BeautifulSoup
from biomart import BiomartServer
from lxml import etree
from collections import defaultdict
def search_orphanet(keyword, search_type='Gen'):
"""
Returns the HTML of a Orphanet search. By default,
it searches for a gene
"""
search_url = r"http://www.orpha.net/consor/cgi-bin/Disease_Search_Simple.php?lng=EN"
search_data = {
'Disease_Disease_Search_diseaseGroup': keyword,
'Disease_Disease_Search_diseaseType': search_type
}
request = post(search_url, search_data)
if request.status_code == 200:
return request.text
else:
raise Exception("Search failed with status {}".format(request.status_code))
def get_first_result(orphanet_search):
"""
Returns the HTML link for the first result of a search
"""
soup = BeautifulSoup(orphanet_search, 'html.parser')
first = soup.find_all('div', class_="blockResults")
if not first:
return ''
else:
return first[0].a.get('href')+"\t"+first[0].a.getText()
def convert_entrez_to_gene_symbol(keyword_list):
"""
Convert Refseq ID to Gene Symbol and description using Biomart
"""
#print("\nConverting Refseq to Gene Symbol\n")
server = BiomartServer( "http://mar2017.archive.ensembl.org/biomart" )
#server.verbose = True
#server.show_databases()
#server.show_datasets()
hsapiens = server.datasets['hsapiens_gene_ensembl']
#hsapiens.show_filters()
#hsapiens.show_attributes()
# run a search with custom filters and attributes (no header)
response = hsapiens.search({
'filters': {
'entrezgene': keyword_list
},
'attributes': [
'external_gene_name', 'description', 'entrezgene'
]
})
return response
def load_orpha_genes(xml):
orpha_genes = {}
tree = etree.parse(xml)
symbols = tree.findall('//Symbol')
for gene in symbols:
orpha_genes[gene.text] = [gene.getparent().getparent().getparent().getparent().find("OrphaNumber").text, gene.getparent().getparent().getparent().getparent().find("Name").text]
return orpha_genes
def load_hyb_db_genes(hyb):
hyb_db = defaultdict(list)
hyb_file = open(hyb).read().splitlines()
for line in hyb_file:
fields = line.split(",")
hyb_db[fields[10]].append(fields[11])
hyb_db[fields[11]].append(fields[10])
return hyb_db
def load_biogrid_genes(biogrid):
biogrid_db = defaultdict(list)
biogrid_file = open(biogrid).read().splitlines()
for line in biogrid_file:
fields = line.split("\t")
biogrid_db[fields[1]].append(fields[2])
biogrid_db[fields[2]].append(fields[1])
return biogrid_db