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
16
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 """
32 self.entity_type = ''
33 self.entity_id = ''
34 self.entity_attributes = {}
35 self.col_defs = {}
36 self.table_rows = []
37
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
68
69 MAX_ROWS = 20+1
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
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