annotate galaxy_micropita/micropita_format_input_selector.py @ 3:8fb4630ab314 draft default tip

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