-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuniprot2refgene.py
More file actions
38 lines (33 loc) · 900 Bytes
/
uniprot2refgene.py
File metadata and controls
38 lines (33 loc) · 900 Bytes
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
# make association for uniprot name and refgene name
import sys
if len(sys.argv) != 4:
print '''Usage: {0}
<refGene.txt file>
<uniprot trembl .dat file>
<species name (OS field in uniprot.dat file)>\n'''.format(sys.argv[0])
sys.exit()
refgenefile, unidatfile, species = sys.argv[1:]
# read target gene names from refGene file
targetgene = set()
with open(refgenefile) as fin:
for line in fin:
lst = line.split('\t')
targetgene.add(lst[1])
targetgene.add(lst[12])
# go over uniprot file
with open(unidatfile) as fin:
ac = None
gn = None
for line in fin:
if line.startswith("AC"):
ac = line.split()[1][:-1]
#gn = None
elif line.startswith("GN"):
if 'Name=' in line:
gn = line.split('Name=')[1].split(';')[0]
if gn not in targetgene:
gn = None
elif line.startswith("OS"):
if species in line:
if gn is not None:
print '{0}\t{1}'.format(ac, gn)