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 | |
---|
11 | def get_phecols(i,addNone,hint): |
---|
12 | """ |
---|
13 | return a list of phenotype columns for a multi-select list |
---|
14 | """ |
---|
15 | hint = hint.lower() |
---|
16 | fname = i.dataset.file_name |
---|
17 | try: |
---|
18 | f = open(fname,'r') |
---|
19 | except: |
---|
20 | return [('get_phecols unable to open file "%s"' % fname,'None',False),] |
---|
21 | header = f.next() |
---|
22 | h = header.strip().split() |
---|
23 | dat = [(x,'%d' % i,False) for i,x in enumerate(h)] |
---|
24 | matches = [i for i,x in enumerate(h) if x.lower().find(hint) <> -1] |
---|
25 | if len(matches) > 0: |
---|
26 | sel = matches[0] |
---|
27 | dat[sel] = (dat[sel][0],dat[sel][1],True) |
---|
28 | if addNone: |
---|
29 | dat.insert(0,('None - no Manhattan plot','0', False )) |
---|
30 | return dat |
---|
31 | |
---|
32 | |
---|
33 | def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr): |
---|
34 | """Sets the name of the data |
---|
35 | <outputs> |
---|
36 | <data format="pdf" name="allqq" /> |
---|
37 | <data format="pdf" name="lowqq" parent="allqq"/> |
---|
38 | </outputs> |
---|
39 | """ |
---|
40 | outfile = 'out_html' |
---|
41 | job_name = param_dict.get( 'name', 'Manhattan QQ plots' ) |
---|
42 | killme = string.punctuation + string.whitespace |
---|
43 | trantab = string.maketrans(killme,'_'*len(killme)) |
---|
44 | newname = '%s.html' % job_name.translate(trantab) |
---|
45 | data = out_data[outfile] |
---|
46 | data.name = newname |
---|
47 | data.info='%s run at %s' % (job_name,timenow()) |
---|
48 | out_data[outfile] = data |
---|
49 | app.model.context.flush() |
---|
50 | |
---|