-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_fasta.py
executable file
·37 lines (32 loc) · 1.08 KB
/
make_fasta.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
#!/usr/bin/env python
import os
import sys
import re
logfile, upfile, ofile = sys.argv[1:]
uniprot = {}
with open(upfile, 'r') as up:
pseq = ''
for line in up:
if line.startswith('>'):
if pseq != '':
uniprot[genename] = pseq
pseq = ''
genename = re.findall('GN=(\S+)', line)[0] if 'GN=' in line else 'TRASH'
else:
pseq += line.strip()
uniprot[genename] = pseq
with open(logfile, 'r') as log:
for line in log:
if 'FAILED' in line:
continue
content = line.split()
gene_name = content[4]
prot_sequence = uniprot[gene_name]
sub = content[-1]
offset = int(re.findall('\d+', sub)[0]) - 1
if (prot_sequence[offset] != sub[0] and prot_sequence[offset] != sub[-1]) and 'DISCORDANT' not in line:
print line
continue
prot_sequence = prot_sequence[:offset] + sub[0] + prot_sequence[offset + 1:]
with open(ofile, 'a') as outp:
outp.write('>' + gene_name + ' ' + sub + '\n' + prot_sequence + '\n')