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