annotate micropita_format_input_selector.py @ 1:cd71e90abfab draft

Updated version that suppresses the future warnings option that was causing a problem
author george-weingart
date Sun, 08 Feb 2015 18:27:54 -0500
parents 2f4f6f08c8c4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
1 #!/usr/bin/env python
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
2
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
3 """
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
4 Author: George Weingart
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
5 Description: Dynamically read columns from input file for UI
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
6 """
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
7
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
8 #####################################################################################
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
9 #Copyright (C) <2012>
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
10 #
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
11 #Permission is hereby granted, free of charge, to any person obtaining a copy of
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
12 #this software and associated documentation files (the "Software"), to deal in the
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
13 #Software without restriction, including without limitation the rights to use, copy,
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
14 #modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
15 #and to permit persons to whom the Software is furnished to do so, subject to
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
16 #the following conditions:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
17 #
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
18 #The above copyright notice and this permission notice shall be included in all copies
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
19 #or substantial portions of the Software.
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
20 #
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
21 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
22 #INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
23 #PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
24 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
25 #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
26 #SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
27 #####################################################################################
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
28
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
29 __author__ = "George Weingart"
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
30 __copyright__ = "Copyright 2012"
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
31 __credits__ = ["George Weingart"]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
32 __license__ = "MIT"
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
33 __maintainer__ = "George Weingart"
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
34 __email__ = "george.weingart@gmail.com"
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
35 __status__ = "Development"
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
36
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
37 import sys,string,time
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
38 from pprint import pprint
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
39
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
40 def red(st,l):
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
41 if len(st) <= l: return st
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
42 l1,l2 = l/2,l/2
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
43 return st[:l1]+".."+st[len(st)-l2:]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
44
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
45 def get_cols(data,full_names):
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
46 if data == "": return []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
47 max_len =32
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
48 fname = data.dataset.file_name
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
49 input_file = open(fname,'rU')
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
50 input_lines = input_file.readlines()
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
51 input_file.close()
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
52 table_lines = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
53 for x in input_lines:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
54 first_column = x.split('\t')[0]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
55 table_lines.append(first_column)
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
56
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
57 opt = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
58 rc = ''
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
59 lines = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
60 try:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
61 lines = [(red((rc+v.split()[0]),max_len),'%d' % (i+1),False) for i,v in enumerate(table_lines) if v]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
62
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
63 except:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
64 l1 = '*ALL*'
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
65 l2 = 1
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
66 l3 = False
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
67 MyList = [l1,l2,l3]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
68 lines.append(MyList)
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
69 return opt+lines
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
70
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
71 def get_cols_add_line(data,full_names,lastmeta):
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
72 if data == "": return []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
73 display_to = 1
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
74 try:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
75 display_to = int(lastmeta)
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
76 except:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
77 pass
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
78
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
79 max_len = 32
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
80 fname = data.dataset.file_name
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
81 input_file = open(fname,'rU')
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
82 input_lines = input_file.readlines()
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
83 input_file.close()
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
84 table_lines = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
85 for x in input_lines:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
86 first_column = x.split('\t')[0]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
87 table_lines.append(first_column)
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
88 table_lines.insert(0,'-')
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
89 if not display_to == 1:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
90 del table_lines[display_to + 1:]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
91
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
92
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
93 opt = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
94 rc = ''
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
95 lines = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
96 try:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
97 lines = [(red((rc+v.split()[0]),max_len),'%d' % (i+1),False) for i,v in enumerate(table_lines) if v]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
98
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
99 except:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
100 l1 = '*ALL*'
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
101 l2 = 1
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
102 l3 = False
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
103 MyList = [l1,l2,l3]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
104 lines.append(MyList)
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
105 return opt+lines
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
106
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
107 def get_cols_features(data,full_names,lastmeta):
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
108 if data == "": return []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
109 display_from = 1
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
110 try:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
111 display_from = int(lastmeta)
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
112 except:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
113 pass
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
114 max_len = 32
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
115 fname = data.dataset.file_name
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
116 input_file = open(fname,'rU')
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
117
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
118 input_lines = input_file.readlines()
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
119 input_file.close()
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
120 table_lines = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
121 for x in input_lines:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
122 first_column = x.split('\t')[0]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
123 table_lines.append(first_column)
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
124
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
125 opt = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
126 rc = ''
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
127 del table_lines[:display_from]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
128 lines = []
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
129 try:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
130 lines = [(red((rc+v.split()[0]),max_len),'%d' % (i+1),False) for i,v in enumerate(table_lines) if v]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
131
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
132 except:
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
133 l1 = '*ALL*'
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
134 l2 = 1
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
135 l3 = False
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
136 MyList = [l1,l2,l3]
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
137 lines.append(MyList)
2f4f6f08c8c4 Uploaded
george-weingart
parents:
diff changeset
138 return opt+lines