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  """Hold GEO data in a straightforward format. 
 8   
 9  classes: 
10  o Record - All of the information in an GEO record. 
11   
12  See http://www.ncbi.nlm.nih.gov/geo/ 
13  """ 
14   
15   
16  from __future__ import print_function 
17   
18 -class Record(object):
19 """Hold GEO information in a format similar to the original record. 20 21 The Record class is meant to make data easy to get to when you are 22 just interested in looking at GEO data. 23 24 Attributes: 25 entity_type 26 entity_id 27 entity_attributes 28 col_defs 29 table_rows 30 31 """
32 - def __init__(self):
33 self.entity_type = '' 34 self.entity_id = '' 35 self.entity_attributes = {} 36 self.col_defs = {} 37 self.table_rows = []
38
39 - def __str__( self ):
40 output = '' 41 output += 'GEO Type: %s\n' % self.entity_type 42 output += 'GEO Id: %s\n' % self.entity_id 43 att_keys = sorted(self.entity_attributes) 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 += '%s: %s\n' % ( key, item[:40]) 50 output += out_block(item[40:]) 51 except: 52 pass 53 elif isinstance(contents, str): 54 output += '%s: %s\n' % (key, contents[:40]) 55 output += out_block(contents[40:]) 56 else: 57 print(contents) 58 output += '%s: %s\n' % (key, val[:40]) 59 output += out_block(val[40:]) 60 col_keys = sorted(self.col_defs) 61 output += 'Column Header Definitions\n' 62 for key in col_keys: 63 val = self.col_defs[key] 64 output += ' %s: %s\n' % (key, val[:40]) 65 output += out_block(val[40:], ' ') 66 #May have to display VERY large tables, 67 #so only show the first 20 lines of data 68 MAX_ROWS = 20 + 1 # include header in count 69 for row in self.table_rows[0:MAX_ROWS]: 70 output += '%s: ' % self.table_rows.index(row) 71 for col in row: 72 output += '%s\t' % col 73 output += '\n' 74 if len(self.table_rows) > MAX_ROWS: 75 output += '...\n' 76 row = self.table_rows[-1] 77 output += '%s: ' % self.table_rows.index(row) 78 for col in row: 79 output += '%s\t' % col 80 output += '\n' 81 82 return output
83 84
85 -def out_block( text, prefix = '' ):
86 output = '' 87 for j in range(0, len(text), 80): 88 output += '%s%s\n' % (prefix, text[j:j+80]) 89 output += '\n' 90 return output
91