annotate format_input_selector.py @ 0:e7cd19afda2e draft

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