Package Bio :: Package FSSP :: Module FSSPTools
[hide private]
[frames] | no frames]

Source Code for Module Bio.FSSP.FSSPTools

 1  from Bio import FSSP 
 2  import copy 
 3  from Bio.Align import Generic 
 4  from Bio import Alphabet 
 5  import time 
 6   
7 -class FSSPAlign(Generic.Alignment):
8 - def _add_numbering_table(self, new_record):
9 new_record.annotations['abs2pdb'] = {} 10 new_record.annotations['pdb2abs'] = {}
11 12
13 -class FSSPMultAlign(dict):
14 - def __init__(self):
15 self.abs_res = [] 16 self.pdb_res = [] 17 self.data = {}
18 -def mult_align(sum_dict,align_dict):
19 """Returns a biopython multiple alignment instance (Bio.Align.Generic)""" 20 mult_align_dict = {} 21 for j in align_dict.abs(1).pos_align_dict.keys(): 22 mult_align_dict[j] = '' 23 24 for i in range(1,len(align_dict)+1): 25 # loop on positions 26 for j in align_dict.abs(i).pos_align_dict.keys(): 27 # loop within a position 28 mult_align_dict[j] += align_dict.abs(i).pos_align_dict[j].aa 29 seq_order = mult_align_dict.keys() 30 seq_order.sort() 31 fssp_align = Generic.Alignment(Alphabet.Gapped( 32 Alphabet.IUPAC.extended_protein)) 33 for i in seq_order: 34 fssp_align.add_sequence(sum_dict[i].pdb2+sum_dict[i].chain2, 35 mult_align_dict[i]) 36 # fssp_align._add_numbering_table() 37 return fssp_align
38 39 40 # Several routines used to extract information from FSSP sections 41 # filter: 42 # filters a passed summary section and alignment section according to a numeric 43 # attribute in the summary section. Returns new summary and alignment sections 44 # For example, to filter in only those records which have a zscore greater than 45 # 4.0 and lesser than 7.5: 46 # new_sum, new_align = filter(sum, align, 'zscore', 4, 7.5) 47 # 48 # Warning: this function really slows down when filtering large FSSP files. 49 # The reason is the use of copy.deepcopy() to copy align_dict into 50 # new_align_dict. I have to figure out something better. 51 # Took me ~160 seconds for the largest FSSP file (1reqA.fssp) 52 # 53
54 -def filter(sum_dict,align_dict,filter_attribute,low_bound, high_bound):
55 """filters a passed summary section and alignment section according to a numeric 56 attribute in the summary section. Returns new summary and alignment sections""" 57 new_sum_dict = FSSP.FSSPSumDict() 58 new_align_dict = copy.deepcopy(align_dict) 59 # for i in align_dict.keys(): 60 # new_align_dict[i] = copy.copy(align_dict[i]) 61 # new_align_dict = copy.copy(align_dict) 62 for prot_num in sum_dict.keys(): 63 attr_value = getattr(sum_dict[prot_num],filter_attribute) 64 if (attr_value >= low_bound and 65 attr_value <= high_bound): 66 new_sum_dict[prot_num] = sum_dict[prot_num] 67 prot_numbers = new_sum_dict.keys() 68 prot_numbers.sort() 69 for pos_num in new_align_dict.abs_res_dict.keys(): 70 new_align_dict.abs(pos_num).pos_align_dict = {} 71 for prot_num in prot_numbers: 72 new_align_dict.abs(pos_num).pos_align_dict[prot_num] = \ 73 align_dict.abs(pos_num).pos_align_dict[prot_num] 74 return new_sum_dict, new_align_dict
75
76 -def name_filter(sum_dict, align_dict, name_list):
77 """ Accepts a list of names. Returns a new Summary block and Alignment block which 78 contain the info only for those names passed.""" 79 new_sum_dict = FSSP.FSSPSumDict() 80 new_align_dict = copy.deepcopy(align_dict) 81 for cur_pdb_name in name_list: 82 for prot_num in sum_dict.keys(): 83 if sum_dict[prot_num].pdb2+sum_dict[prot_num].chain2 == cur_pdb_name: 84 new_sum_dict[prot_num] = sum_dict[prot_num] 85 prot_numbers = new_sum_dict.keys() 86 prot_numbers.sort() 87 for pos_num in new_align_dict.abs_res_dict.keys(): 88 new_align_dict.abs(pos_num).pos_align_dict = {} 89 for prot_num in prot_numbers: 90 new_align_dict.abs(pos_num).pos_align_dict[prot_num] = \ 91 align_dict.abs(pos_num).pos_align_dict[prot_num] 92 return new_sum_dict, new_align_dict
93