annotate micropita_format_input_selector.py @ 0:0de566f21448 draft default tip

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