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