1
2
3
4
5
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
17 """Hold GEO information in a format similar to the original record.
18
19 The Record class is meant to make data easy to get to when you are
20 just interested in looking at GEO data.
21
22 Attributes:
23 entity_type
24 entity_id
25 entity_attributes
26 col_defs
27 table_rows
28
29 """
31 self.entity_type = ''
32 self.entity_id = ''
33 self.entity_attributes = {}
34 self.col_defs = {}
35 self.table_rows = []
36
38 output = ''
39 output = output + 'GEO Type: %s\n' % self.entity_type
40 output = output + 'GEO Id: %s\n' % self.entity_id
41 att_keys = self.entity_attributes.keys()
42 att_keys.sort()
43 for key in att_keys:
44 contents = self.entity_attributes[ key ]
45 if( type( contents ) == type( [] ) ):
46 for item in contents:
47 try:
48 output = output + '%s: %s\n' % ( key, item[ :40 ] )
49 output = output + out_block( item[ 40: ] )
50 except:
51 pass
52 elif( type( contents ) == type( '' ) ):
53 output = output + '%s: %s\n' % ( key, contents[ :40 ] )
54 output = output + out_block( contents[ 40: ] )
55 else:
56 print contents
57 output = output + '%s: %s\n' % ( key, val[ :40 ] )
58 output = output + out_block( val[ 40: ] )
59 col_keys = self.col_defs.keys()
60 col_keys.sort()
61 output = output + 'Column Header Definitions\n'
62 for key in col_keys:
63 val = self.col_defs[ key ]
64 output = output + ' %s: %s\n' % ( key, val[ :40 ] )
65 output = output + out_block( val[ 40: ], ' ' )
66
67
68 MAX_ROWS = 20+1
69 for row in self.table_rows[0:MAX_ROWS]:
70 output = output + '%s: ' % self.table_rows.index( row )
71 for col in row:
72 output = output + '%s\t' % col
73 output = output + '\n'
74 if len(self.table_rows) > MAX_ROWS:
75 output = output + '...\n'
76 row = self.table_rows[-1]
77 output = output + '%s: ' % self.table_rows.index( row )
78 for col in row:
79 output = output + '%s\t' % col
80 output = output + '\n'
81
82 return output
83
85 output = ''
86 for j in range( 0, len( text ), 80 ):
87 output = output + '%s%s\n' % ( prefix, text[ j: j + 80 ] )
88 output = output + '\n'
89 return output
90