Package Bio :: Package CDD :: Module Record
[hide private]
[frames] | no frames]

Source Code for Module Bio.CDD.Record

  1  # Copyright 2001 by Katharine Lindner.  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  """Hold CDD data in a straightforward format. 
  6   
  7  classes: 
  8  o Record - All of the information in a CDD record. 
  9  """ 
 10   
 11  # standard library 
 12  import string 
 13  from Bio.Seq import Seq 
 14   
15 -class Record( dict ):
16 """Hold CDD information in a format similar to the original record. 17 18 The Record class is meant to make data easy to get to when you are 19 just interested in looking at CDD data. 20 21 Attributes: 22 cd 23 description 24 status 25 source 26 date 27 reference 28 taxonomy 29 aligned 30 representative 31 range 32 sequence 33 """
34 - def __init__(self):
35 dict.__init__( self ) 36 self[ 'references' ] = [] 37 self[ 'alignment_lookup' ] = {}
38
39 - def __str__( self ):
40 output = '' 41 keys = self.keys() 42 keys.sort() 43 for key in keys: 44 output = output + '%s:\n\n' % key.upper() 45 contents = self[ key ] 46 if( type( contents ) == type( '' ) ): 47 if( key == 'Sequence' ): 48 output = output + out_multiline( contents ) 49 else: 50 output = output + '%s\n' % contents 51 elif( type( contents ) == type( {} ) ): 52 output = output + output_dict( contents, 1 ) 53 elif( type( contents ) == type( [] ) ): 54 output = output + output_list( contents, 1 ) 55 elif( isinstance( contents, Seq ) ): 56 output = output + out_multiline( contents.data ) 57 output = output + '\n\n' 58 return output
59
60 -def output_dict( dict, level = 0 ):
61 output = '' 62 prefix = '' 63 for j in range( 0, level ): 64 prefix = prefix + ' ' 65 keys = dict.keys() 66 keys.sort() 67 for key in keys: 68 contents = dict[ key ] 69 if( type( contents ) == type( '' ) ): 70 output = output + '%s%s = %s\n' % ( prefix, key, contents ) 71 elif( type( contents ) == type( {} ) ): 72 output = output + output_dict( contents, level + 1 ) 73 elif( type( contents ) == type( [] ) ): 74 output = output + output_list( contents, level + 1 ) 75 output = output + '\n' 76 return output
77
78 -def output_list( items, level = 0 ):
79 output = '' 80 prefix = '' 81 for j in range( 0, level ): 82 prefix = prefix + ' ' 83 for item in items: 84 if( type( item ) == type( '' ) ): 85 output = output + '%s%s\n' % ( prefix, item ) 86 elif( type( item ) == type( {} ) ): 87 output = output + output_dict( item, level + 1 ) 88 elif( type( item ) == type( [] ) ): 89 output = output + output_list( item, level + 1 ) 90 output = output + '\n' 91 return output
92
93 -def out_multiline( multiline ):
94 output = '' 95 for j in range( 0, len( multiline ), 80 ): 96 output = output + '%s\n' % multiline[ j: j + 80 ] 97 output = output + '\n' 98 return output
99