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

Source Code for Module Bio.FSSP.FSSPTools

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