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

Source Code for Module Bio.Geo.Record

 1  # Copyright 2001 by Katharine Lindner.  All rights reserved. 
 2  # Copyright 2006 by PeterC.  All rights reserved. 
 3  # This code is part of the Biopython distribution and governed by its 
 4  # license.  Please see the LICENSE file that should have been included 
 5  # as part of this package. 
 6   
 7  """ 
 8  Hold GEO data in a straightforward format. 
 9   
10  classes: 
11  o Record - All of the information in an GEO record. 
12   
13  See http://www.ncbi.nlm.nih.gov/geo/ 
14  """ 
15   
16   
17 -class Record(object):
18 """Hold GEO information in a format similar to the original record. 19 20 The Record class is meant to make data easy to get to when you are 21 just interested in looking at GEO data. 22 23 Attributes: 24 entity_type 25 entity_id 26 entity_attributes 27 col_defs 28 table_rows 29 30 """
31 - def __init__(self):
32 self.entity_type = '' 33 self.entity_id = '' 34 self.entity_attributes = {} 35 self.col_defs = {} 36 self.table_rows = []
37
38 - def __str__( self ):
39 output = '' 40 output = output + 'GEO Type: %s\n' % self.entity_type 41 output = output + 'GEO Id: %s\n' % self.entity_id 42 att_keys = self.entity_attributes.keys() 43 att_keys.sort() 44 for key in att_keys: 45 contents = self.entity_attributes[ key ] 46 if isinstance(contents, list): 47 for item in contents: 48 try: 49 output = output + '%s: %s\n' % ( key, item[ :40 ] ) 50 output = output + out_block( item[ 40: ] ) 51 except: 52 pass 53 elif isinstance(contents, str): 54 output = output + '%s: %s\n' % ( key, contents[ :40 ] ) 55 output = output + out_block( contents[ 40: ] ) 56 else: 57 print contents 58 output = output + '%s: %s\n' % ( key, val[ :40 ] ) 59 output = output + out_block( val[ 40: ] ) 60 col_keys = self.col_defs.keys() 61 col_keys.sort() 62 output = output + 'Column Header Definitions\n' 63 for key in col_keys: 64 val = self.col_defs[ key ] 65 output = output + ' %s: %s\n' % ( key, val[ :40 ] ) 66 output = output + out_block( val[ 40: ], ' ' ) 67 #May have to display VERY large tables, 68 #so only show the first 20 lines of data 69 MAX_ROWS = 20+1 # include header in count 70 for row in self.table_rows[0:MAX_ROWS]: 71 output = output + '%s: ' % self.table_rows.index( row ) 72 for col in row: 73 output = output + '%s\t' % col 74 output = output + '\n' 75 if len(self.table_rows) > MAX_ROWS: 76 output = output + '...\n' 77 row = self.table_rows[-1] 78 output = output + '%s: ' % self.table_rows.index( row ) 79 for col in row: 80 output = output + '%s\t' % col 81 output = output + '\n' 82 83 return output
84 85
86 -def out_block( text, prefix = '' ):
87 output = '' 88 for j in range( 0, len( text ), 80 ): 89 output = output + '%s%s\n' % ( prefix, text[ j: j + 80 ] ) 90 output = output + '\n' 91 return output
92