Package Bio :: Package GenBank :: Module utils
[hide private]
[frames] | no frames]

Source Code for Module Bio.GenBank.utils

 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  """Useful utilities for helping in parsing GenBank files. 
 7  """ 
 8   
 9   
10 -class FeatureValueCleaner(object):
11 """Provide specialized capabilities for cleaning up values in features. 12 13 This class is designed to provide a mechanism to clean up and process 14 values in the key/value pairs of GenBank features. This is useful 15 because in cases like: 16 17 /translation="MED 18 YDPWNLRFQSKYKSRDA" 19 20 you'll end up with a value with \012s and spaces in it like: 21 "MED\012 YDPWEL..." 22 23 which you probably don't want. 24 25 This cleaning needs to be done on a case by case basis since it is 26 impossible to interpret whether you should be concatenating everything 27 (as in translations), or combining things with spaces (as might be 28 the case with /notes). 29 """ 30 keys_to_process = ["translation"] 31
32 - def __init__(self, to_process = keys_to_process):
33 """Initialize with the keys we should deal with. 34 """ 35 self._to_process = to_process
36
37 - def clean_value(self, key_name, value):
38 """Clean the specified value and return it. 39 40 If the value is not specified to be dealt with, the original value 41 will be returned. 42 """ 43 if key_name in self._to_process: 44 try: 45 cleaner = getattr(self, "_clean_%s" % key_name) 46 value = cleaner(value) 47 except AttributeError: 48 raise AssertionError("No function to clean key: %s" 49 % key_name) 50 return value
51
52 - def _clean_translation(self, value):
53 """Concatenate a translation value to one long protein string. 54 """ 55 translation_parts = value.split() 56 return "".join(translation_parts)
57