comparison format_input_selector.py @ 0:e7cd19afda2e draft

Lefse
author george-weingart
date Tue, 13 May 2014 21:57:00 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e7cd19afda2e
1 from galaxy import datatypes,model
2 import sys,string,time
3
4
5 def timenow():
6 """return current time as a string
7 """
8 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
9
10 def get_opt(data):
11 return [('r','r',False),('c','c',False)]
12
13 def red(st,l):
14 if len(st) <= l: return st
15 l1,l2 = l/2,l/2
16 return st[:l1]+".."+st[len(st)-l2:]
17
18 def get_row_names(data,t):
19 if data == "": return []
20 max_len =38
21 fname = data.dataset.file_name
22 opt = []
23 rc = ''
24 # lines = [(red(v.split()[0],max_len),'%s' % str(v.split()[0]),False) for i,v in enumerate(open(fname))]
25 if t == 'b': lines = [(red(v.split()[0],max_len),'%d' % (i+1),False) for i,v in enumerate(open(fname)) if len(v.split()) > 3 ]
26 else: lines = [(red(v.split()[0],max_len),'%d' % (i+1),False) for i,v in enumerate(open(fname))]
27 return sorted(opt+lines)
28
29 def get_cols(data,t,c):
30 if data == "": return []
31 max_len =32
32 fname = data.dataset.file_name
33 opt = []
34 if c != 'cl':
35 opt.append(('no '+c,'%d' % -1,False))
36 if t == 'c':
37 rc = ''
38 lines = [(red((rc+"#"+str(i+1)+":"+v[0]),max_len),'%d' % (i+1),False) for i,v in enumerate(zip(*[line.split() for line in open(fname)]))]
39 else:
40 rc = ''
41 lines = [(red((rc+"#"+str(i+1)+":"+v.split()[0]),max_len),'%d' % (i+1),False) for i,v in enumerate(open(fname))]
42 return opt+lines
43
44 """
45 def get_phecols(i,addNone,hint):
46 hint = hint.lower()
47 fname = i.dataset.file_name
48 try:
49 f = open(fname,'r')
50 except:
51 return [('get_phecols unable to open file "%s"' % fname,'None',False),]
52 header = f.next()
53 h = header.strip().split()
54 dat = [(x,'%d' % i,False) for i,x in enumerate(h)]
55 matches = [i for i,x in enumerate(h) if x.lower().find(hint) <> -1]
56 if len(matches) > 0:
57 sel = matches[0]
58 dat[sel] = (dat[sel][0],dat[sel][1],True)
59 if addNone:
60 dat.insert(0,('None - no Manhattan plot','0', False ))
61 return dat
62 """
63
64
65 """
66 def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr):
67 outfile = 'out_html'
68 job_name = param_dict.get( 'name', 'Manhattan QQ plots' )
69 killme = string.punctuation + string.whitespace
70 trantab = string.maketrans(killme,'_'*len(killme))
71 newname = '%s.html' % job_name.translate(trantab)
72 data = out_data[outfile]
73 data.name = newname
74 data.info='%s run at %s' % (job_name,timenow())
75 out_data[outfile] = data
76 app.model.context.flush()
77 """