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