Package Bio :: Package SearchIO :: Package _model :: Module _base
[hide private]
[frames] | no frames]

Source Code for Module Bio.SearchIO._model._base

 1  # Copyright 2012 by Wibowo Arindrarto.  All rights reserved. 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  """Abstract base classes for the SearchIO object model.""" 
 7   
 8   
 9  from Bio._utils import getattr_str, trim_str 
10   
11   
12 -class _BaseSearchObject(object):
13 14 """Abstract class for SearchIO objects.""" 15 16 _NON_STICKY_ATTRS = () 17
18 - def _transfer_attrs(self, obj):
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 # list of attribute names we don't want to transfer 33 for attr in self.__dict__: 34 if attr not in self._NON_STICKY_ATTRS: 35 setattr(obj, attr, self.__dict__[attr])
36 37
38 -class _BaseHSP(_BaseSearchObject):
39 40 """Abstract base class for HSP objects.""" 41
42 - def _str_hsp_header(self):
43 """Prints the alignment header info.""" 44 lines = [] 45 # set query id line 46 qid_line = trim_str(' Query: %s %s' % 47 (self.query_id, self.query_description), 80, '...') 48 # set hit id line 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 # coordinates 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 # strands 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