1
2
3
4
5
6 """Abstract base classes for the SearchIO object model."""
7
8
9 from Bio._utils import getattr_str, trim_str
10
11
13
14 """Abstract class for SearchIO objects."""
15
16 _NON_STICKY_ATTRS = ()
17
19 """Transfer instance attributes to the given object.
20
21 This method is used to transfer attributes set externally (for example
22 using `setattr`) to a new object created from this one (for example
23 from slicing).
24
25 The reason this method is necessary is because different parsers will
26 set different attributes for each QueryResult, Hit, HSP, or HSPFragment
27 objects, depending on the attributes they found in the search output
28 file. Ideally, we want these attributes to 'stick' with any new instance
29 object created from the original one.
30
31 """
32
33 for attr in self.__dict__.keys():
34 if attr not in self._NON_STICKY_ATTRS:
35 setattr(obj, attr, self.__dict__[attr])
36
37
39
40 """Abstract base class for HSP objects."""
41
43 """Prints the alignment header info."""
44 lines = []
45
46 qid_line = trim_str(' Query: %s %s' %
47 (self.query_id, self.query_description), 80, '...')
48
49 hid_line = trim_str(' Hit: %s %s' %
50 (self.hit_id, self.hit_description), 80, '...')
51 lines.append(qid_line)
52 lines.append(hid_line)
53
54
55 query_start = getattr_str(self, 'query_start')
56 query_end = getattr_str(self, 'query_end')
57 hit_start = getattr_str(self, 'hit_start')
58 hit_end = getattr_str(self, 'hit_end')
59
60
61 try:
62 qstrand = self.query_strand
63 hstrand = self.hit_strand
64 except ValueError:
65 qstrand = self.query_strand_all[0]
66 hstrand = self.hit_strand_all[0]
67 lines.append('Query range: [%s:%s] (%r)' % (query_start, query_end,
68 qstrand))
69 lines.append(' Hit range: [%s:%s] (%r)' % (hit_start, hit_end,
70 hstrand))
71
72 return '\n'.join(lines)
73