Package Bio :: Package PDB :: Module PSEA
[hide private]
[frames] | no frames]

Source Code for Module Bio.PDB.PSEA

 1  # Copyright (C) 2006, Thomas Hamelryck (thamelry@binf.ku.dk) 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6   
 7  import os 
 8  from Bio.PDB import * 
 9   
10   
11 -def run_psea(fname):
12 """ 13 Run PSEA and return output filename. 14 """ 15 os.system("psea "+fname) 16 last=fname.split("/")[-1] 17 base=last.split(".")[0] 18 return base+".sea"
19
20 -def psea(pname):
21 """ 22 Parse PSEA output file. 23 """ 24 fname=run_psea(pname) 25 start=0 26 ss="" 27 fp=open(fname, 'r') 28 for l in fp.readlines(): 29 if l[0:6]==">p-sea": 30 start=1 31 continue 32 if not start: 33 continue 34 if l[0]=="\n": 35 break 36 ss=ss+l[0:-1] 37 fp.close() 38 return ss
39
40 -def psea2HEC(pseq):
41 """ 42 Translate PSEA secondary structure string into HEC. 43 """ 44 seq=[] 45 for ss in pseq: 46 if ss=="a": 47 n="H" 48 elif ss=="b": 49 n="E" 50 elif ss=="c": 51 n="C" 52 seq.append(n) 53 return seq
54
55 -def annotate(m, ss_seq):
56 c=m.get_list()[0] 57 all=c.get_list() 58 residues=[] 59 # Now remove HOH etc. 60 for res in all: 61 if is_aa(res): 62 residues.append(res) 63 L=len(residues) 64 if not (L==len(ss_seq)): 65 raise ValueError("Length mismatch %i %i" % (L, len(ss_seq))) 66 for i in range(0, L): 67 residues[i].xtra["SS_PSEA"]=ss_seq[i] 68 #os.system("rm "+fname) 69
70 -class PSEA:
71 - def __init__(self, model, filename):
72 ss_seq=psea(filename) 73 ss_seq=psea2HEC(ss_seq) 74 annotate(model, ss_seq) 75 self.ss_seq=ss_seq
76
77 - def get_seq(self):
78 """ 79 Return secondary structure string. 80 """ 81 return self.ss_seq
82 83 84 if __name__=="__main__": 85 86 import sys 87 from Bio.PDB import * 88 89 # Parse PDB file 90 p=PDBParser() 91 s=p.get_structure('X', sys.argv[1]) 92 93 # Annotate structure with PSEA sceondary structure info 94 PSEA(s[0], sys.argv[1]) 95