annotate tools/rgenetics/rgManQQ_code.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 from galaxy import datatypes,model
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 import sys,string,time
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 def timenow():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 """return current time as a string
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 def get_phecols(i,addNone,hint):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 return a list of phenotype columns for a multi-select list
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 hint = hint.lower()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 fname = i.dataset.file_name
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 f = open(fname,'r')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 return [('get_phecols unable to open file "%s"' % fname,'None',False),]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 header = f.next()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 h = header.strip().split()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 dat = [(x,'%d' % i,False) for i,x in enumerate(h)]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 matches = [i for i,x in enumerate(h) if x.lower().find(hint) <> -1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 if len(matches) > 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 sel = matches[0]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 dat[sel] = (dat[sel][0],dat[sel][1],True)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 if addNone:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 dat.insert(0,('None - no Manhattan plot','0', False ))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 return dat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 """Sets the name of the data
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 <outputs>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 <data format="pdf" name="allqq" />
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 <data format="pdf" name="lowqq" parent="allqq"/>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 </outputs>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 outfile = 'out_html'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 job_name = param_dict.get( 'name', 'Manhattan QQ plots' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 killme = string.punctuation + string.whitespace
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 trantab = string.maketrans(killme,'_'*len(killme))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 newname = '%s.html' % job_name.translate(trantab)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 data = out_data[outfile]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 data.name = newname
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 data.info='%s run at %s' % (job_name,timenow())
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 out_data[outfile] = data
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 app.model.context.flush()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50