-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbeta2fasta.py
More file actions
executable file
·80 lines (59 loc) · 2.16 KB
/
beta2fasta.py
File metadata and controls
executable file
·80 lines (59 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
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
#!/usr/bin/python
import string
from sys import argv,stdout
from os import popen,system
from os.path import exists,basename
from amino_acids import longer_names
pdbnames = argv[1:]
#chainid = ' '
#if len(argv)>2:
# chainid = argv[2]
for pdbname in pdbnames:
# if (pdbname[-4:] != '.pdb'):
# pdbname += '.pdb'
outfile = pdbname
removechain = 0
if argv.count('-nochain'):
removechain = 1
netpdbname = pdbname
assert( exists(netpdbname))
#print 'Reading ... '+netpdbname
lines = open(netpdbname,'r').readlines()
#outid = open( outfile, 'w')
#print 'Writing ... '+pdbname
#fastafile = pdbname+'.fasta'
#fastaid = open( fastafile, 'w')
#print 'Writing ... '+fastafile
fastaid = stdout
fastaid.write('>'+basename(pdbname)+'\n');
oldresnum = ' '
count = 0;
for line in lines:
if (len(line)>20): # and (chainid == line[21]):
line_edit = line
if line[0:3] == 'TER':
break
elif (line[0:6] == 'HETATM') & (line[17:20]=='MSE'): #Selenomethionine
line_edit = 'ATOM '+line[6:17]+'MET'+line[20:]
if (line_edit[12:14] == 'SE'):
line_edit = line_edit[0:12]+' S'+line_edit[14:]
if len(line_edit)>75:
if (line_edit[76:78] == 'SE'):
line_edit = line_edit[0:76]+' S'+line_edit[78:]
if line_edit[0:4] == 'ATOM':
resnum = line_edit[23:26]
if not resnum == oldresnum:
count = count + 1
longname = line_edit[17:20]
if longer_names.has_key(longname) and (count%3 == 2) :
fastaid.write( longer_names[longname] );
if (count%12 == 0): fastaid.write( ' ' )
oldresnum = resnum
newnum = '%3d' % count
line_edit = line_edit[0:23] + newnum + line_edit[26:]
if removechain:
line_edit = line_edit[0:21]+' '+line_edit[22:]
#outid.write(line_edit)
fastaid.write('\n')
#outid.close()
#fastaid.close()