comparison maaslin-4450aa4ecc84/maaslin_format_input_selector.py @ 1:a87d5a5f2776

Uploaded the version running on the prod server
author george-weingart
date Sun, 08 Feb 2015 23:08:38 -0500
parents
children
comparison
equal deleted inserted replaced
0:e0b5980139d9 1:a87d5a5f2776
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):
46 if data == "": return []
47 max_len =32
48 fname = data.dataset.file_name
49 input_file = open(fname)
50 input_lines = input_file.readlines()
51 input_file.close()
52 table_lines = []
53 for x in input_lines:
54 first_column = x.split('\t')[0]
55 table_lines.append(first_column)
56
57 opt = []
58 rc = ''
59 lines = []
60 try:
61 lines = [(red((rc+v.split()[0]),max_len),'%d' % (i+1),False) for i,v in enumerate(table_lines) if v]
62
63 except:
64 l1 = '*ALL*'
65 l2 = 1
66 l3 = False
67 MyList = [l1,l2,l3]
68 lines.append(MyList)
69 return opt+lines
70
71 def get_cols_add_line(data,full_names,lastmeta):
72 if data == "": return []
73 display_to = 1
74 try:
75 display_to = int(lastmeta)
76 except:
77 pass
78
79 max_len = 32
80 fname = data.dataset.file_name
81 input_file = open(fname)
82 input_lines = input_file.readlines()
83 input_file.close()
84 table_lines = []
85 for x in input_lines:
86 first_column = x.split('\t')[0]
87 table_lines.append(first_column)
88 table_lines.insert(0,'-')
89 if not display_to == 1:
90 del table_lines[display_to + 1:]
91
92
93 opt = []
94 rc = ''
95 lines = []
96 try:
97 lines = [(red((rc+v.split()[0]),max_len),'%d' % (i+1),False) for i,v in enumerate(table_lines) if v]
98
99 except:
100 l1 = '*ALL*'
101 l2 = 1
102 l3 = False
103 MyList = [l1,l2,l3]
104 lines.append(MyList)
105 return opt+lines
106
107 def get_cols_features(data,full_names,lastmeta):
108 if data == "": return []
109 display_from = 1
110 try:
111 display_from = int(lastmeta)
112 except:
113 pass
114 max_len = 32
115 fname = data.dataset.file_name
116 input_file = open(fname)
117 input_lines = input_file.readlines()
118 input_file.close()
119 table_lines = []
120 for x in input_lines:
121 first_column = x.split('\t')[0]
122 table_lines.append(first_column)
123
124 opt = []
125 rc = ''
126 del table_lines[:display_from]
127 lines = []
128 try:
129 lines = [(red((rc+v.split()[0]),max_len),'%d' % (i+1),False) for i,v in enumerate(table_lines) if v]
130
131 except:
132 l1 = '*ALL*'
133 l2 = 1
134 l3 = False
135 MyList = [l1,l2,l3]
136 lines.append(MyList)
137 return opt+lines