annotate rgedgeR/rgGSEA.py @ 0:82e0af566160 draft

Uploaded
author fubar
date Wed, 12 Jun 2013 02:58:43 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
82e0af566160 Uploaded
fubar
parents:
diff changeset
1 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
2 April 2013
82e0af566160 Uploaded
fubar
parents:
diff changeset
3 eeesh GSEA does NOT respect the mode flag!
82e0af566160 Uploaded
fubar
parents:
diff changeset
4
82e0af566160 Uploaded
fubar
parents:
diff changeset
5 Now realise that the creation of the input rank file for gsea needs to take the lowest p value for duplicate
82e0af566160 Uploaded
fubar
parents:
diff changeset
6 feature names. To make Ish's life easier, remove duplicate gene ids from any gene set to stop GSEA from
82e0af566160 Uploaded
fubar
parents:
diff changeset
7 barfing.
82e0af566160 Uploaded
fubar
parents:
diff changeset
8
82e0af566160 Uploaded
fubar
parents:
diff changeset
9 October 14 2012
82e0af566160 Uploaded
fubar
parents:
diff changeset
10 Amazingly long time to figure out that GSEA fails with useless error message if any filename contains a dash "-"
82e0af566160 Uploaded
fubar
parents:
diff changeset
11 eesh.
82e0af566160 Uploaded
fubar
parents:
diff changeset
12
82e0af566160 Uploaded
fubar
parents:
diff changeset
13 Added history .gmt source - requires passing a faked name to gsea
82e0af566160 Uploaded
fubar
parents:
diff changeset
14 Wrapper for GSEA http://www.broadinstitute.org/gsea/index.jsp
82e0af566160 Uploaded
fubar
parents:
diff changeset
15 Started Feb 22
82e0af566160 Uploaded
fubar
parents:
diff changeset
16 Copyright 2012 Ross Lazarus
82e0af566160 Uploaded
fubar
parents:
diff changeset
17 All rights reserved
82e0af566160 Uploaded
fubar
parents:
diff changeset
18 Licensed under the LGPL
82e0af566160 Uploaded
fubar
parents:
diff changeset
19
82e0af566160 Uploaded
fubar
parents:
diff changeset
20 called eg as
82e0af566160 Uploaded
fubar
parents:
diff changeset
21
82e0af566160 Uploaded
fubar
parents:
diff changeset
22 #!/bin/sh
82e0af566160 Uploaded
fubar
parents:
diff changeset
23 GALAXY_LIB="/data/extended/galaxy/lib"
82e0af566160 Uploaded
fubar
parents:
diff changeset
24 if [ "$GALAXY_LIB" != "None" ]; then
82e0af566160 Uploaded
fubar
parents:
diff changeset
25 if [ -n "$PYTHONPATH" ]; then
82e0af566160 Uploaded
fubar
parents:
diff changeset
26 PYTHONPATH="$GALAXY_LIB:$PYTHONPATH"
82e0af566160 Uploaded
fubar
parents:
diff changeset
27 else
82e0af566160 Uploaded
fubar
parents:
diff changeset
28 PYTHONPATH="$GALAXY_LIB"
82e0af566160 Uploaded
fubar
parents:
diff changeset
29 fi
82e0af566160 Uploaded
fubar
parents:
diff changeset
30 export PYTHONPATH
82e0af566160 Uploaded
fubar
parents:
diff changeset
31 fi
82e0af566160 Uploaded
fubar
parents:
diff changeset
32
82e0af566160 Uploaded
fubar
parents:
diff changeset
33 cd /data/extended/galaxy/database/job_working_directory/027/27311
82e0af566160 Uploaded
fubar
parents:
diff changeset
34 python /data/extended/galaxy/tools/rgenetics/rgGSEA.py --input_tab "/data/extended/galaxy/database/files/033/dataset_33806.dat" --adjpvalcol "5" --signcol "2"
82e0af566160 Uploaded
fubar
parents:
diff changeset
35 --idcol "1" --outhtml "/data/extended/galaxy/database/files/034/dataset_34455.dat" --input_name "actaearly-Controlearly-actalate-Controllate_topTable.xls"
82e0af566160 Uploaded
fubar
parents:
diff changeset
36 --setMax "500" --setMin "15" --nPerm "1000" --plotTop "20"
82e0af566160 Uploaded
fubar
parents:
diff changeset
37 --gsea_jar "/data/extended/galaxy/tool-data/shared/jars/gsea2-2.0.12.jar"
82e0af566160 Uploaded
fubar
parents:
diff changeset
38 --output_dir "/data/extended/galaxy/database/job_working_directory/027/27311/dataset_34455_files" --mode "Max_probe"
82e0af566160 Uploaded
fubar
parents:
diff changeset
39 --title " actaearly-Controlearly-actalate-Controllate_interpro_GSEA" --builtin_gmt "/data/genomes/gsea/3.1/IPR_DOMAIN.gmt"
82e0af566160 Uploaded
fubar
parents:
diff changeset
40
82e0af566160 Uploaded
fubar
parents:
diff changeset
41
82e0af566160 Uploaded
fubar
parents:
diff changeset
42 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
43 import optparse
82e0af566160 Uploaded
fubar
parents:
diff changeset
44 import tempfile
82e0af566160 Uploaded
fubar
parents:
diff changeset
45 import os
82e0af566160 Uploaded
fubar
parents:
diff changeset
46 import sys
82e0af566160 Uploaded
fubar
parents:
diff changeset
47 import subprocess
82e0af566160 Uploaded
fubar
parents:
diff changeset
48 import time
82e0af566160 Uploaded
fubar
parents:
diff changeset
49 import shutil
82e0af566160 Uploaded
fubar
parents:
diff changeset
50 import glob
82e0af566160 Uploaded
fubar
parents:
diff changeset
51 import math
82e0af566160 Uploaded
fubar
parents:
diff changeset
52 import re
82e0af566160 Uploaded
fubar
parents:
diff changeset
53
82e0af566160 Uploaded
fubar
parents:
diff changeset
54 KEEPSELECTION = False # detailed records for selection of multiple probes
82e0af566160 Uploaded
fubar
parents:
diff changeset
55
82e0af566160 Uploaded
fubar
parents:
diff changeset
56 def timenow():
82e0af566160 Uploaded
fubar
parents:
diff changeset
57 """return current time as a string
82e0af566160 Uploaded
fubar
parents:
diff changeset
58 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
59 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
82e0af566160 Uploaded
fubar
parents:
diff changeset
60
82e0af566160 Uploaded
fubar
parents:
diff changeset
61
82e0af566160 Uploaded
fubar
parents:
diff changeset
62
82e0af566160 Uploaded
fubar
parents:
diff changeset
63 def fix_subdir(adir,destdir):
82e0af566160 Uploaded
fubar
parents:
diff changeset
64 """ Galaxy wants everything in the same files_dir
82e0af566160 Uploaded
fubar
parents:
diff changeset
65 if os.path.exists(adir):
82e0af566160 Uploaded
fubar
parents:
diff changeset
66 for (d,dirs,files) in os.path.walk(adir):
82e0af566160 Uploaded
fubar
parents:
diff changeset
67 for f in files:
82e0af566160 Uploaded
fubar
parents:
diff changeset
68 sauce = os.path.join(d,f)
82e0af566160 Uploaded
fubar
parents:
diff changeset
69 shutil.copy(sauce,destdir)
82e0af566160 Uploaded
fubar
parents:
diff changeset
70 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
71
82e0af566160 Uploaded
fubar
parents:
diff changeset
72 def fixAffycrap(apath=''):
82e0af566160 Uploaded
fubar
parents:
diff changeset
73 """class='richTable'>RUNNING ES</th><th class='richTable'>CORE ENRICHMENT</th><tr><td class='lessen'>1</td>
82e0af566160 Uploaded
fubar
parents:
diff changeset
74 <td><a href='https://www.affymetrix.com/LinkServlet?probeset=LBR'>LBR</a></td><td></td><td></td><td>1113</td>
82e0af566160 Uploaded
fubar
parents:
diff changeset
75 <td>0.194</td><td>-0.1065</td><td>No</td></tr><tr><td class='lessen'>2</td><td>
82e0af566160 Uploaded
fubar
parents:
diff changeset
76 <a href='https://www.affymetrix.com/LinkServlet?probeset=GGPS1'>GGPS1</a></td><td></td><td></td><td>4309</td><td>0.014</td><td>-0.4328</td>
82e0af566160 Uploaded
fubar
parents:
diff changeset
77 <td>No</td></tr>
82e0af566160 Uploaded
fubar
parents:
diff changeset
78 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
79 html = []
82e0af566160 Uploaded
fubar
parents:
diff changeset
80 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
81 html = open(apath,'r').readlines()
82e0af566160 Uploaded
fubar
parents:
diff changeset
82 except:
82e0af566160 Uploaded
fubar
parents:
diff changeset
83 return html
82e0af566160 Uploaded
fubar
parents:
diff changeset
84 for i,row in enumerate(html):
82e0af566160 Uploaded
fubar
parents:
diff changeset
85 row = re.sub('https\:\/\/www.affymetrix.com\/LinkServlet\?probeset=',"http://www.genecards.org/index.php?path=/Search/keyword/",row)
82e0af566160 Uploaded
fubar
parents:
diff changeset
86 html[i] = row
82e0af566160 Uploaded
fubar
parents:
diff changeset
87 return html
82e0af566160 Uploaded
fubar
parents:
diff changeset
88
82e0af566160 Uploaded
fubar
parents:
diff changeset
89 cleanup = False
82e0af566160 Uploaded
fubar
parents:
diff changeset
90 if os.path.exists(adir):
82e0af566160 Uploaded
fubar
parents:
diff changeset
91 flist = os.listdir(adir) # get all files created
82e0af566160 Uploaded
fubar
parents:
diff changeset
92 for f in flist:
82e0af566160 Uploaded
fubar
parents:
diff changeset
93 apath = os.path.join(adir,f)
82e0af566160 Uploaded
fubar
parents:
diff changeset
94 dest = os.path.join(destdir,f)
82e0af566160 Uploaded
fubar
parents:
diff changeset
95 if not os.path.isdir(apath):
82e0af566160 Uploaded
fubar
parents:
diff changeset
96 if os.path.splitext(f)[1].lower() == '.html':
82e0af566160 Uploaded
fubar
parents:
diff changeset
97 html = fixAffycrap(apath)
82e0af566160 Uploaded
fubar
parents:
diff changeset
98 fixed = open(apath,'w')
82e0af566160 Uploaded
fubar
parents:
diff changeset
99 fixed.write('\n'.join(html))
82e0af566160 Uploaded
fubar
parents:
diff changeset
100 fixed.write('\n')
82e0af566160 Uploaded
fubar
parents:
diff changeset
101 fixed.close()
82e0af566160 Uploaded
fubar
parents:
diff changeset
102 if not os.path.isfile(dest):
82e0af566160 Uploaded
fubar
parents:
diff changeset
103 shutil.copy(apath,dest)
82e0af566160 Uploaded
fubar
parents:
diff changeset
104 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
105 fix_subdir(apath,destdir)
82e0af566160 Uploaded
fubar
parents:
diff changeset
106 if cleanup:
82e0af566160 Uploaded
fubar
parents:
diff changeset
107 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
108 shutil.rmtree(path=adir,ignore_errors=True)
82e0af566160 Uploaded
fubar
parents:
diff changeset
109 except:
82e0af566160 Uploaded
fubar
parents:
diff changeset
110 pass
82e0af566160 Uploaded
fubar
parents:
diff changeset
111
82e0af566160 Uploaded
fubar
parents:
diff changeset
112
82e0af566160 Uploaded
fubar
parents:
diff changeset
113
82e0af566160 Uploaded
fubar
parents:
diff changeset
114 def getFileString(fpath, outpath):
82e0af566160 Uploaded
fubar
parents:
diff changeset
115 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
116 format a nice file size string
82e0af566160 Uploaded
fubar
parents:
diff changeset
117 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
118 size = ''
82e0af566160 Uploaded
fubar
parents:
diff changeset
119 fp = os.path.join(outpath, fpath)
82e0af566160 Uploaded
fubar
parents:
diff changeset
120 s = fpath
82e0af566160 Uploaded
fubar
parents:
diff changeset
121 if os.path.isfile(fp):
82e0af566160 Uploaded
fubar
parents:
diff changeset
122 n = float(os.path.getsize(fp))
82e0af566160 Uploaded
fubar
parents:
diff changeset
123 if n > 2**20:
82e0af566160 Uploaded
fubar
parents:
diff changeset
124 size = ' (%1.1f MB)' % (n/2**20)
82e0af566160 Uploaded
fubar
parents:
diff changeset
125 elif n > 2**10:
82e0af566160 Uploaded
fubar
parents:
diff changeset
126 size = ' (%1.1f KB)' % (n/2**10)
82e0af566160 Uploaded
fubar
parents:
diff changeset
127 elif n > 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
128 size = ' (%d B)' % (int(n))
82e0af566160 Uploaded
fubar
parents:
diff changeset
129 s = '%s %s' % (fpath, size)
82e0af566160 Uploaded
fubar
parents:
diff changeset
130 return s
82e0af566160 Uploaded
fubar
parents:
diff changeset
131
82e0af566160 Uploaded
fubar
parents:
diff changeset
132 class gsea_wrapper:
82e0af566160 Uploaded
fubar
parents:
diff changeset
133 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
134 GSEA java desktop client has a CL interface. CL can be gleaned by clicking the 'command line' button after setting up an analysis
82e0af566160 Uploaded
fubar
parents:
diff changeset
135 We don't want gsea to do the analysis but it can read .rnk files containing rows of identifiers and an evidence weight such as the signed t statistic from limma for differential expression
82e0af566160 Uploaded
fubar
parents:
diff changeset
136 (vgalaxy)rlazarus@iaas1:~/public_html/idle_illumina_analysis$ cat gseaHumanREFSEQ.sh
82e0af566160 Uploaded
fubar
parents:
diff changeset
137 #!/bin/bash
82e0af566160 Uploaded
fubar
parents:
diff changeset
138 for RNK in `ls *.rnk`
82e0af566160 Uploaded
fubar
parents:
diff changeset
139 do
82e0af566160 Uploaded
fubar
parents:
diff changeset
140 DIRNAME=${RNK%.*}
82e0af566160 Uploaded
fubar
parents:
diff changeset
141 echo $DIRNAME
82e0af566160 Uploaded
fubar
parents:
diff changeset
142 qsub -cwd -b y java -Xmx4096m -cp /data/app/bin/gsea2-2.07.jar xtools.gsea.GseaPreranked -gmx ../msigdb.v3.0.symbols.gmt -collapse true -mode Max_probe -norm meandiv
82e0af566160 Uploaded
fubar
parents:
diff changeset
143 -nperm 1000 -rnk $RNK -scoring_scheme weighted -rpt_label $RNK -chip ../RefSeq_human.chip -include_only_symbols true -make_sets true -plot_top_x 20 -rnd_seed timestamp
82e0af566160 Uploaded
fubar
parents:
diff changeset
144 -set_max 500 -set_min 15 -zip_report false -out gseaout/${DIRNAME} -gui false
82e0af566160 Uploaded
fubar
parents:
diff changeset
145 done
82e0af566160 Uploaded
fubar
parents:
diff changeset
146 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
147
82e0af566160 Uploaded
fubar
parents:
diff changeset
148 def __init__(self,myName=None,opts=None):
82e0af566160 Uploaded
fubar
parents:
diff changeset
149 """ setup cl for gsea
82e0af566160 Uploaded
fubar
parents:
diff changeset
150 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
151 self.idcol = 0
82e0af566160 Uploaded
fubar
parents:
diff changeset
152 self.signcol = 0
82e0af566160 Uploaded
fubar
parents:
diff changeset
153 self.adjpvalcol = 0
82e0af566160 Uploaded
fubar
parents:
diff changeset
154 self.progname=myName
82e0af566160 Uploaded
fubar
parents:
diff changeset
155 self.opts = opts
82e0af566160 Uploaded
fubar
parents:
diff changeset
156 remove_duplicates=True
82e0af566160 Uploaded
fubar
parents:
diff changeset
157 if not os.path.isdir(opts.output_dir):
82e0af566160 Uploaded
fubar
parents:
diff changeset
158 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
159 os.makedirs(opts.output_dir)
82e0af566160 Uploaded
fubar
parents:
diff changeset
160 except:
82e0af566160 Uploaded
fubar
parents:
diff changeset
161 print >> sys.stderr,'##Error: GSEA wrapper unable to create or find output directory %s. Stopping' % (opts.output_dir)
82e0af566160 Uploaded
fubar
parents:
diff changeset
162 sys.exit(1)
82e0af566160 Uploaded
fubar
parents:
diff changeset
163 fakeGMT = re.sub('[^a-zA-Z0-9_]+', '', opts.input_name) # gives a more useful title for the GSEA report
82e0af566160 Uploaded
fubar
parents:
diff changeset
164 fakeGMT = os.path.join(opts.output_dir,fakeGMT)
82e0af566160 Uploaded
fubar
parents:
diff changeset
165 fakeGMT = os.path.abspath(fakeGMT)
82e0af566160 Uploaded
fubar
parents:
diff changeset
166 fakeRanks = '%s.rnk' % fakeGMT
82e0af566160 Uploaded
fubar
parents:
diff changeset
167 if not fakeGMT.endswith('.gmt'):
82e0af566160 Uploaded
fubar
parents:
diff changeset
168 fakeGMT = '%s.gmt' % fakeGMT
82e0af566160 Uploaded
fubar
parents:
diff changeset
169 if opts.builtin_gmt and opts.history_gmt:
82e0af566160 Uploaded
fubar
parents:
diff changeset
170 newfile = open(fakeGMT,'w')
82e0af566160 Uploaded
fubar
parents:
diff changeset
171 subprocess.call(['cat',opts.builtin_gmt,opts.history_gmt],stdout=newfile)
82e0af566160 Uploaded
fubar
parents:
diff changeset
172 newfile.close()
82e0af566160 Uploaded
fubar
parents:
diff changeset
173 elif opts.history_gmt:
82e0af566160 Uploaded
fubar
parents:
diff changeset
174 subprocess.call(['cp',opts.history_gmt,fakeGMT])
82e0af566160 Uploaded
fubar
parents:
diff changeset
175 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
176 subprocess.call(['cp',opts.builtin_gmt,fakeGMT])
82e0af566160 Uploaded
fubar
parents:
diff changeset
177 # remove dupes from each gene set
82e0af566160 Uploaded
fubar
parents:
diff changeset
178 gmt = open(fakeGMT,'r').readlines()
82e0af566160 Uploaded
fubar
parents:
diff changeset
179 gmt = [x for x in gmt if len(x.split('\t')) > 3]
82e0af566160 Uploaded
fubar
parents:
diff changeset
180 ugmt = []
82e0af566160 Uploaded
fubar
parents:
diff changeset
181 for i,row in enumerate(gmt):
82e0af566160 Uploaded
fubar
parents:
diff changeset
182 rows = row.rstrip().split('\t')
82e0af566160 Uploaded
fubar
parents:
diff changeset
183 gmtname = rows[0]
82e0af566160 Uploaded
fubar
parents:
diff changeset
184 gmtcomment = rows[1]
82e0af566160 Uploaded
fubar
parents:
diff changeset
185 glist = list(set(rows[2:]))
82e0af566160 Uploaded
fubar
parents:
diff changeset
186 newgmt = [gmtname,gmtcomment]
82e0af566160 Uploaded
fubar
parents:
diff changeset
187 newgmt += glist
82e0af566160 Uploaded
fubar
parents:
diff changeset
188 ugmt.append('\t'.join(newgmt))
82e0af566160 Uploaded
fubar
parents:
diff changeset
189 gmt = open(fakeGMT,'w')
82e0af566160 Uploaded
fubar
parents:
diff changeset
190 gmt.write('\n'.join(ugmt))
82e0af566160 Uploaded
fubar
parents:
diff changeset
191 gmt.write('\n')
82e0af566160 Uploaded
fubar
parents:
diff changeset
192 gmt.close()
82e0af566160 Uploaded
fubar
parents:
diff changeset
193 if opts.input_ranks:
82e0af566160 Uploaded
fubar
parents:
diff changeset
194 infname = opts.input_ranks
82e0af566160 Uploaded
fubar
parents:
diff changeset
195 rdat = open(opts.input_ranks,'r').readlines() # suck in and remove blank ids that cause gsea to barf rml april 10 2012
82e0af566160 Uploaded
fubar
parents:
diff changeset
196 rdat = [x.rstrip().split('\t') for x in rdat[1:]] # ignore head
82e0af566160 Uploaded
fubar
parents:
diff changeset
197 dat = [[x[0],x[1],x[1]] for x in rdat]
82e0af566160 Uploaded
fubar
parents:
diff changeset
198 # fake same structure as input tabular file
82e0af566160 Uploaded
fubar
parents:
diff changeset
199 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
200 pvals = [float(x[1]) for x in dat]
82e0af566160 Uploaded
fubar
parents:
diff changeset
201 signs = [float(x[1]) for x in dat]
82e0af566160 Uploaded
fubar
parents:
diff changeset
202 except:
82e0af566160 Uploaded
fubar
parents:
diff changeset
203 print >> sys.stderr, '## error converting floating point - cannot process this input'
82e0af566160 Uploaded
fubar
parents:
diff changeset
204 sys.exit(99)
82e0af566160 Uploaded
fubar
parents:
diff changeset
205 else: # read tabular
82e0af566160 Uploaded
fubar
parents:
diff changeset
206 self.idcol = int(opts.idcol) - 1
82e0af566160 Uploaded
fubar
parents:
diff changeset
207 self.signcol = int(opts.signcol) - 1
82e0af566160 Uploaded
fubar
parents:
diff changeset
208 self.adjpvalcol = int(opts.adjpvalcol) - 1
82e0af566160 Uploaded
fubar
parents:
diff changeset
209 maxcol = max(self.idcol,self.signcol,self.adjpvalcol)
82e0af566160 Uploaded
fubar
parents:
diff changeset
210 infname = opts.input_tab
82e0af566160 Uploaded
fubar
parents:
diff changeset
211 indat = open(opts.input_tab,'r').readlines()
82e0af566160 Uploaded
fubar
parents:
diff changeset
212 dat = [x.rstrip().split('\t') for x in indat[1:]]
82e0af566160 Uploaded
fubar
parents:
diff changeset
213 dat = [x for x in dat if len(x) > maxcol]
82e0af566160 Uploaded
fubar
parents:
diff changeset
214 dat = [[x[self.idcol],x[self.adjpvalcol],x[self.signcol]] for x in dat] # reduce to rank form
82e0af566160 Uploaded
fubar
parents:
diff changeset
215 pvals = [float(x[1]) for x in dat]
82e0af566160 Uploaded
fubar
parents:
diff changeset
216 outofrange = [x for x in pvals if ((x < 0.0) or (x > 1.0))]
82e0af566160 Uploaded
fubar
parents:
diff changeset
217 assert len(outofrange) == 0, '## p values outside 0-1 encountered - was that the right column for adjusted p value?'
82e0af566160 Uploaded
fubar
parents:
diff changeset
218 signs = [float(x[2]) for x in dat]
82e0af566160 Uploaded
fubar
parents:
diff changeset
219 outofrange = [i for i,x in enumerate(signs) if (not x) and (dat[i][self.signcol] <> '0')]
82e0af566160 Uploaded
fubar
parents:
diff changeset
220 bad = [dat[x][2] for x in outofrange]
82e0af566160 Uploaded
fubar
parents:
diff changeset
221 assert len(outofrange) == 0, '## null numeric values encountered for sign - was that the right column? %s' % bad
82e0af566160 Uploaded
fubar
parents:
diff changeset
222 ids = [x[0] for x in dat]
82e0af566160 Uploaded
fubar
parents:
diff changeset
223 res = []
82e0af566160 Uploaded
fubar
parents:
diff changeset
224 self.comments = []
82e0af566160 Uploaded
fubar
parents:
diff changeset
225 useme = []
82e0af566160 Uploaded
fubar
parents:
diff changeset
226 for i,row in enumerate(dat):
82e0af566160 Uploaded
fubar
parents:
diff changeset
227 if row[1].upper() != 'NA' and row[2].upper() != 'NA' and row[0] != '' :
82e0af566160 Uploaded
fubar
parents:
diff changeset
228 useme.append(i)
82e0af566160 Uploaded
fubar
parents:
diff changeset
229 lost = len(dat) - len(useme)
82e0af566160 Uploaded
fubar
parents:
diff changeset
230 if lost <> 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
231 newdat = [dat[x] for x in useme]
82e0af566160 Uploaded
fubar
parents:
diff changeset
232 del dat
82e0af566160 Uploaded
fubar
parents:
diff changeset
233 dat = newdat
82e0af566160 Uploaded
fubar
parents:
diff changeset
234 print >> sys.stdout, '## %d lost - NA values or null id' % lost
82e0af566160 Uploaded
fubar
parents:
diff changeset
235 if remove_duplicates:
82e0af566160 Uploaded
fubar
parents:
diff changeset
236 uids = list(set(ids)) # complex procedure to get min pval for each unique id
82e0af566160 Uploaded
fubar
parents:
diff changeset
237 if len(uids) <> len(ids): # dupes - deal with mode
82e0af566160 Uploaded
fubar
parents:
diff changeset
238 print >> sys.stdout,'## Dealing with %d uids in %d ids' % (len(uids),len(ids))
82e0af566160 Uploaded
fubar
parents:
diff changeset
239 ures = {}
82e0af566160 Uploaded
fubar
parents:
diff changeset
240 for i,id in enumerate(ids):
82e0af566160 Uploaded
fubar
parents:
diff changeset
241 p = pvals[i]
82e0af566160 Uploaded
fubar
parents:
diff changeset
242 ures.setdefault(id,[])
82e0af566160 Uploaded
fubar
parents:
diff changeset
243 ures[id].append((p,signs[i]))
82e0af566160 Uploaded
fubar
parents:
diff changeset
244 for id in uids:
82e0af566160 Uploaded
fubar
parents:
diff changeset
245 tlist = ures[id]
82e0af566160 Uploaded
fubar
parents:
diff changeset
246 tp = [x[0] for x in tlist]
82e0af566160 Uploaded
fubar
parents:
diff changeset
247 ts = [x[1] for x in tlist]
82e0af566160 Uploaded
fubar
parents:
diff changeset
248 if len(tp) == 1:
82e0af566160 Uploaded
fubar
parents:
diff changeset
249 p = tp[0]
82e0af566160 Uploaded
fubar
parents:
diff changeset
250 sign = ts[0]
82e0af566160 Uploaded
fubar
parents:
diff changeset
251 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
252 if opts.mode == "Max_probe":
82e0af566160 Uploaded
fubar
parents:
diff changeset
253 p = min(tp)
82e0af566160 Uploaded
fubar
parents:
diff changeset
254 sign = ts[tp.index(p)]
82e0af566160 Uploaded
fubar
parents:
diff changeset
255 else: # guess median - too bad if even count
82e0af566160 Uploaded
fubar
parents:
diff changeset
256 tp.sort()
82e0af566160 Uploaded
fubar
parents:
diff changeset
257 ltp = len(tp)
82e0af566160 Uploaded
fubar
parents:
diff changeset
258 ind = ltp/2 # yes, this is wrong for evens but what if sign wobbles?
82e0af566160 Uploaded
fubar
parents:
diff changeset
259 if ltp % 2 == 1: # odd
82e0af566160 Uploaded
fubar
parents:
diff changeset
260 ind += 1 # take the median
82e0af566160 Uploaded
fubar
parents:
diff changeset
261 p = tp[ind]
82e0af566160 Uploaded
fubar
parents:
diff changeset
262 sign = ts[ind]
82e0af566160 Uploaded
fubar
parents:
diff changeset
263 if KEEPSELECTION:
82e0af566160 Uploaded
fubar
parents:
diff changeset
264 self.comments.append('## for id=%s, got tp=%s, ts=%s, chose p=%f, sign =%f'\
82e0af566160 Uploaded
fubar
parents:
diff changeset
265 % (id,str(tp),str(ts),p,sign))
82e0af566160 Uploaded
fubar
parents:
diff changeset
266 if opts.input_ranks: # must be a rank file
82e0af566160 Uploaded
fubar
parents:
diff changeset
267 res.append((id,'%f' % p))
82e0af566160 Uploaded
fubar
parents:
diff changeset
268 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
269 if p == 0.0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
270 p = 1e-99
82e0af566160 Uploaded
fubar
parents:
diff changeset
271 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
272 lp = -math.log10(p) # large positive if low p value
82e0af566160 Uploaded
fubar
parents:
diff changeset
273 except ValueError:
82e0af566160 Uploaded
fubar
parents:
diff changeset
274 lp = 0.0
82e0af566160 Uploaded
fubar
parents:
diff changeset
275 if sign < 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
276 lp = -lp # if negative, swap p to negative
82e0af566160 Uploaded
fubar
parents:
diff changeset
277 res.append((id,'%f' % lp))
82e0af566160 Uploaded
fubar
parents:
diff changeset
278 else: # no duplicates
82e0af566160 Uploaded
fubar
parents:
diff changeset
279 for i,row in enumerate(dat):
82e0af566160 Uploaded
fubar
parents:
diff changeset
280 (id,p,sign) = (row[0],float(row[1]),float(row[2]))
82e0af566160 Uploaded
fubar
parents:
diff changeset
281 if opts.input_ranks: # must be a rank file
82e0af566160 Uploaded
fubar
parents:
diff changeset
282 res.append((id,'%f' % p))
82e0af566160 Uploaded
fubar
parents:
diff changeset
283 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
284 if p == 0.0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
285 p = 1e-99
82e0af566160 Uploaded
fubar
parents:
diff changeset
286 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
287 lp = -math.log10(p) # large positive if low p value
82e0af566160 Uploaded
fubar
parents:
diff changeset
288 except ValueError:
82e0af566160 Uploaded
fubar
parents:
diff changeset
289 lp = 0.0
82e0af566160 Uploaded
fubar
parents:
diff changeset
290 if sign < 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
291 lp = -lp # if negative, swap p to negative
82e0af566160 Uploaded
fubar
parents:
diff changeset
292 res.append((id,'%f' % lp))
82e0af566160 Uploaded
fubar
parents:
diff changeset
293 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
294 for i,row in enumerate(dat):
82e0af566160 Uploaded
fubar
parents:
diff changeset
295 (id,p,sign) = (row[0],float(row[1]),float(row[2]))
82e0af566160 Uploaded
fubar
parents:
diff changeset
296 if opts.input_ranks: # must be a rank file
82e0af566160 Uploaded
fubar
parents:
diff changeset
297 res.append((id,'%f' % p))
82e0af566160 Uploaded
fubar
parents:
diff changeset
298 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
299 if p == 0.0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
300 p = 1e-99
82e0af566160 Uploaded
fubar
parents:
diff changeset
301 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
302 lp = -math.log10(p) # large positive if low p value
82e0af566160 Uploaded
fubar
parents:
diff changeset
303 except ValueError:
82e0af566160 Uploaded
fubar
parents:
diff changeset
304 lp = 0.0
82e0af566160 Uploaded
fubar
parents:
diff changeset
305 if sign < 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
306 lp = -lp # if negative, swap p to negative
82e0af566160 Uploaded
fubar
parents:
diff changeset
307 res.append((id,'%f' % lp))
82e0af566160 Uploaded
fubar
parents:
diff changeset
308 len1 = len(ids)
82e0af566160 Uploaded
fubar
parents:
diff changeset
309 len2 = len(ranks)
82e0af566160 Uploaded
fubar
parents:
diff changeset
310 delta = len1 - len2
82e0af566160 Uploaded
fubar
parents:
diff changeset
311 if delta <> 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
312 print >> sys.stdout,'NOTE: %d of %d rank input file %s rows deleted - dup, null or NA IDs, pvals or logFCs' % (delta,len1,infname)
82e0af566160 Uploaded
fubar
parents:
diff changeset
313 ranks = [(float(x[1]),x) for x in ranks] # decorate
82e0af566160 Uploaded
fubar
parents:
diff changeset
314 ranks.sort()
82e0af566160 Uploaded
fubar
parents:
diff changeset
315 ranks.reverse()
82e0af566160 Uploaded
fubar
parents:
diff changeset
316 ranks = [x[1] for x in ranks] # undecorate
82e0af566160 Uploaded
fubar
parents:
diff changeset
317 if opts.chip == '': # if mouse - need HUGO
82e0af566160 Uploaded
fubar
parents:
diff changeset
318 ranks = [[x[0].upper(),x[1]] for x in ranks]
82e0af566160 Uploaded
fubar
parents:
diff changeset
319 print >> sys.stdout, '## Fixed any lower case - now have',','.join([x[0] for x in ranks[:5]])
82e0af566160 Uploaded
fubar
parents:
diff changeset
320 ranks = ['\t'.join(x) for x in ranks]
82e0af566160 Uploaded
fubar
parents:
diff changeset
321 if len(ranks) < 2:
82e0af566160 Uploaded
fubar
parents:
diff changeset
322 print >> sys.stderr,'Input %s has 1 or less rows with two tab delimited fields - please check the tool documentation' % infname
82e0af566160 Uploaded
fubar
parents:
diff changeset
323 sys.exit(1)
82e0af566160 Uploaded
fubar
parents:
diff changeset
324 print '### opening %s and writing %s' % (fakeRanks,str(ranks[:10]))
82e0af566160 Uploaded
fubar
parents:
diff changeset
325 rclean = open(fakeRanks,'w')
82e0af566160 Uploaded
fubar
parents:
diff changeset
326 rclean.write('contig\tscore\n')
82e0af566160 Uploaded
fubar
parents:
diff changeset
327 rclean.write('\n'.join(ranks))
82e0af566160 Uploaded
fubar
parents:
diff changeset
328 rclean.write('\n')
82e0af566160 Uploaded
fubar
parents:
diff changeset
329 rclean.close()
82e0af566160 Uploaded
fubar
parents:
diff changeset
330 cl = []
82e0af566160 Uploaded
fubar
parents:
diff changeset
331 a = cl.append
82e0af566160 Uploaded
fubar
parents:
diff changeset
332 a('java -Xmx6G -cp')
82e0af566160 Uploaded
fubar
parents:
diff changeset
333 a(opts.gsea_jar)
82e0af566160 Uploaded
fubar
parents:
diff changeset
334 a('xtools.gsea.GseaPreranked')
82e0af566160 Uploaded
fubar
parents:
diff changeset
335 a('-gmx %s' % fakeGMT) # ensure .gmt extension as required by GSEA - gene sets to use
82e0af566160 Uploaded
fubar
parents:
diff changeset
336 a('-gui false') # use preranked file mode and no gui
82e0af566160 Uploaded
fubar
parents:
diff changeset
337 a('-make_sets true -rnd_seed timestamp') # more things from the GUI command line display
82e0af566160 Uploaded
fubar
parents:
diff changeset
338 a('-norm meandiv -zip_report false -scoring_scheme weighted') # ? need to set these?
82e0af566160 Uploaded
fubar
parents:
diff changeset
339 a('-rnk %s' % fakeRanks) # input ranks file symbol (the chip file is the crosswalk for ids in first column)
82e0af566160 Uploaded
fubar
parents:
diff changeset
340 a('-out %s' % opts.output_dir)
82e0af566160 Uploaded
fubar
parents:
diff changeset
341 a('-set_max %s' % opts.setMax)
82e0af566160 Uploaded
fubar
parents:
diff changeset
342 a('-set_min %s' % opts.setMin)
82e0af566160 Uploaded
fubar
parents:
diff changeset
343 a('-mode %s' % opts.mode)
82e0af566160 Uploaded
fubar
parents:
diff changeset
344 if opts.chip > '':
82e0af566160 Uploaded
fubar
parents:
diff changeset
345 #a('-chip %s -collapse true -include_only_symbols true' % opts.chip)
82e0af566160 Uploaded
fubar
parents:
diff changeset
346 a('-chip %s -collapse true' % opts.chip)
82e0af566160 Uploaded
fubar
parents:
diff changeset
347 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
348 a("-collapse false") # needed if no chip
82e0af566160 Uploaded
fubar
parents:
diff changeset
349 a('-nperm %s' % opts.nPerm)
82e0af566160 Uploaded
fubar
parents:
diff changeset
350 a('-rpt_label %s' % opts.title)
82e0af566160 Uploaded
fubar
parents:
diff changeset
351 a('-plot_top_x %s' % opts.plotTop)
82e0af566160 Uploaded
fubar
parents:
diff changeset
352 self.cl = cl
82e0af566160 Uploaded
fubar
parents:
diff changeset
353 self.comments.append('## GSEA command line:')
82e0af566160 Uploaded
fubar
parents:
diff changeset
354 self.comments.append(' '.join(self.cl))
82e0af566160 Uploaded
fubar
parents:
diff changeset
355 self.fakeRanks = fakeRanks
82e0af566160 Uploaded
fubar
parents:
diff changeset
356 self.fakeGMT = fakeGMT
82e0af566160 Uploaded
fubar
parents:
diff changeset
357
82e0af566160 Uploaded
fubar
parents:
diff changeset
358 def grepIds(self):
82e0af566160 Uploaded
fubar
parents:
diff changeset
359 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
360 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
361 found = []
82e0af566160 Uploaded
fubar
parents:
diff changeset
362 allids = open(self.opts.input_ranks,'r').readlines()
82e0af566160 Uploaded
fubar
parents:
diff changeset
363 allids = [x.strip().split() for x in allids]
82e0af566160 Uploaded
fubar
parents:
diff changeset
364 allids = [x[0] for x in allids] # list of ids
82e0af566160 Uploaded
fubar
parents:
diff changeset
365 gmtpath = os.path.split(self.opts.fakeGMT)[0] # get path to all chip
82e0af566160 Uploaded
fubar
parents:
diff changeset
366
82e0af566160 Uploaded
fubar
parents:
diff changeset
367 def run(self):
82e0af566160 Uploaded
fubar
parents:
diff changeset
368 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
369
82e0af566160 Uploaded
fubar
parents:
diff changeset
370 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
371 tlog = os.path.join(self.opts.output_dir,"gsea_runner.log")
82e0af566160 Uploaded
fubar
parents:
diff changeset
372 sto = open(tlog,'w')
82e0af566160 Uploaded
fubar
parents:
diff changeset
373 x = subprocess.Popen(' '.join(self.cl),shell=True,stdout=sto,stderr=sto,cwd=self.opts.output_dir)
82e0af566160 Uploaded
fubar
parents:
diff changeset
374 retval = x.wait()
82e0af566160 Uploaded
fubar
parents:
diff changeset
375 sto.close()
82e0af566160 Uploaded
fubar
parents:
diff changeset
376 d = glob.glob(os.path.join(self.opts.output_dir,'%s*' % self.opts.title))
82e0af566160 Uploaded
fubar
parents:
diff changeset
377 if len(d) > 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
378 fix_subdir(d[0],self.opts.output_dir)
82e0af566160 Uploaded
fubar
parents:
diff changeset
379 htmlfname = os.path.join(self.opts.output_dir,'index.html')
82e0af566160 Uploaded
fubar
parents:
diff changeset
380 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
381 html = open(htmlfname,'r').readlines()
82e0af566160 Uploaded
fubar
parents:
diff changeset
382 html = [x.strip() for x in html if len(x.strip()) > 0]
82e0af566160 Uploaded
fubar
parents:
diff changeset
383 if len(self.comments) > 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
384 s = ['<pre>']
82e0af566160 Uploaded
fubar
parents:
diff changeset
385 s += self.comments
82e0af566160 Uploaded
fubar
parents:
diff changeset
386 s.append('</pre>')
82e0af566160 Uploaded
fubar
parents:
diff changeset
387 try:
82e0af566160 Uploaded
fubar
parents:
diff changeset
388 i = html.index('<div id="footer">')
82e0af566160 Uploaded
fubar
parents:
diff changeset
389 except:
82e0af566160 Uploaded
fubar
parents:
diff changeset
390 i = len(html) - 7 # fudge
82e0af566160 Uploaded
fubar
parents:
diff changeset
391 html = html[:i] + s + html[i:]
82e0af566160 Uploaded
fubar
parents:
diff changeset
392 except:
82e0af566160 Uploaded
fubar
parents:
diff changeset
393 html = []
82e0af566160 Uploaded
fubar
parents:
diff changeset
394 htmlhead = '<html><head></head><body>'
82e0af566160 Uploaded
fubar
parents:
diff changeset
395 html.append('## Galaxy GSEA wrapper failure')
82e0af566160 Uploaded
fubar
parents:
diff changeset
396 html.append('## Unable to find index.html in %s - listdir=%s' % (d,' '.join(os.listdir(self.opts.output_dir))))
82e0af566160 Uploaded
fubar
parents:
diff changeset
397 html.append('## Command line was %s' % (' '.join(self.cl)))
82e0af566160 Uploaded
fubar
parents:
diff changeset
398 html.append('## commonly caused by mismatched ID/chip selection')
82e0af566160 Uploaded
fubar
parents:
diff changeset
399 glog = open(os.path.join(self.opts.output_dir,'gsea_runner.log'),'r').readlines()
82e0af566160 Uploaded
fubar
parents:
diff changeset
400 html.append('## gsea_runner.log=%s' % '\n'.join(glog))
82e0af566160 Uploaded
fubar
parents:
diff changeset
401 #tryme = self.grepIds()
82e0af566160 Uploaded
fubar
parents:
diff changeset
402 retval = 1
82e0af566160 Uploaded
fubar
parents:
diff changeset
403 print >> sys.stderr,'\n'.join(html)
82e0af566160 Uploaded
fubar
parents:
diff changeset
404 html = ['%s<br/>' % x for x in html]
82e0af566160 Uploaded
fubar
parents:
diff changeset
405 html.insert(0,htmlhead)
82e0af566160 Uploaded
fubar
parents:
diff changeset
406 html.append('</body></html>')
82e0af566160 Uploaded
fubar
parents:
diff changeset
407 htmlf = file(self.opts.outhtml,'w')
82e0af566160 Uploaded
fubar
parents:
diff changeset
408 htmlf.write('\n'.join(html))
82e0af566160 Uploaded
fubar
parents:
diff changeset
409 htmlf.write('\n')
82e0af566160 Uploaded
fubar
parents:
diff changeset
410 htmlf.close()
82e0af566160 Uploaded
fubar
parents:
diff changeset
411 os.unlink(self.fakeRanks)
82e0af566160 Uploaded
fubar
parents:
diff changeset
412 os.unlink(self.fakeGMT)
82e0af566160 Uploaded
fubar
parents:
diff changeset
413 if opts.outtab_neg:
82e0af566160 Uploaded
fubar
parents:
diff changeset
414 tabs = glob.glob(os.path.join(opts.output_dir,"gsea_report_for_*.xls"))
82e0af566160 Uploaded
fubar
parents:
diff changeset
415 if len(tabs) > 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
416 for tabi,t in enumerate(tabs):
82e0af566160 Uploaded
fubar
parents:
diff changeset
417 tkind = os.path.basename(t).split('_')[4].lower()
82e0af566160 Uploaded
fubar
parents:
diff changeset
418 if tkind == 'neg':
82e0af566160 Uploaded
fubar
parents:
diff changeset
419 outtab = opts.outtab_neg
82e0af566160 Uploaded
fubar
parents:
diff changeset
420 elif tkind == 'pos':
82e0af566160 Uploaded
fubar
parents:
diff changeset
421 outtab = opts.outtab_pos
82e0af566160 Uploaded
fubar
parents:
diff changeset
422 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
423 print >> sys.stderr, '## tab file matched %s which is not "neg" or "pos" in 4th segment %s' % (t,tkind)
82e0af566160 Uploaded
fubar
parents:
diff changeset
424 sys.exit()
82e0af566160 Uploaded
fubar
parents:
diff changeset
425 content = open(t).readlines()
82e0af566160 Uploaded
fubar
parents:
diff changeset
426 tabf = open(outtab,'w')
82e0af566160 Uploaded
fubar
parents:
diff changeset
427 tabf.write(''.join(content))
82e0af566160 Uploaded
fubar
parents:
diff changeset
428 tabf.close()
82e0af566160 Uploaded
fubar
parents:
diff changeset
429 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
430 print >> sys.stdout, 'Odd, maketab = %s but no matches - tabs = %s' % (makeTab,tabs)
82e0af566160 Uploaded
fubar
parents:
diff changeset
431 return retval
82e0af566160 Uploaded
fubar
parents:
diff changeset
432
82e0af566160 Uploaded
fubar
parents:
diff changeset
433
82e0af566160 Uploaded
fubar
parents:
diff changeset
434 if __name__ == "__main__":
82e0af566160 Uploaded
fubar
parents:
diff changeset
435 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
436 called as:
82e0af566160 Uploaded
fubar
parents:
diff changeset
437 <command interpreter="python">rgGSEA.py --input_ranks "$input1" --outhtml "$html_file"
82e0af566160 Uploaded
fubar
parents:
diff changeset
438 --setMax "$setMax" --setMin "$setMin" --nPerm "$nPerm" --plotTop "$plotTop" --gsea_jar "$GALAXY_DATA_INDEX_DIR/shared/jars/gsea2-2.07.jar"
82e0af566160 Uploaded
fubar
parents:
diff changeset
439 --output_dir "$html_file.files_path" --use_gmt ""${use_gmt.fields.path}"" --chip "${use_chip.fields.path}"
82e0af566160 Uploaded
fubar
parents:
diff changeset
440 </command>
82e0af566160 Uploaded
fubar
parents:
diff changeset
441 """
82e0af566160 Uploaded
fubar
parents:
diff changeset
442 op = optparse.OptionParser()
82e0af566160 Uploaded
fubar
parents:
diff changeset
443 a = op.add_option
82e0af566160 Uploaded
fubar
parents:
diff changeset
444 a('--input_ranks',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
445 a('--input_tab',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
446 a('--input_name',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
447 a('--use_gmt',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
448 a('--history_gmt',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
449 a('--builtin_gmt',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
450 a('--history_gmt_name',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
451 a('--setMax',default="500")
82e0af566160 Uploaded
fubar
parents:
diff changeset
452 a('--setMin',default="15")
82e0af566160 Uploaded
fubar
parents:
diff changeset
453 a('--nPerm',default="1000")
82e0af566160 Uploaded
fubar
parents:
diff changeset
454 a('--title',default="GSEA report")
82e0af566160 Uploaded
fubar
parents:
diff changeset
455 a('--chip',default='')
82e0af566160 Uploaded
fubar
parents:
diff changeset
456 a('--plotTop',default='20')
82e0af566160 Uploaded
fubar
parents:
diff changeset
457 a('--outhtml',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
458 a('--makeTab',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
459 a('--output_dir',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
460 a('--outtab_neg',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
461 a('--outtab_pos',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
462 a('--adjpvalcol',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
463 a('--signcol',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
464 a('--idcol',default=None)
82e0af566160 Uploaded
fubar
parents:
diff changeset
465 a('--mode',default='Max_probe')
82e0af566160 Uploaded
fubar
parents:
diff changeset
466 a('-j','--gsea_jar',default='/usr/local/bin/gsea2-2.07.jar')
82e0af566160 Uploaded
fubar
parents:
diff changeset
467 opts, args = op.parse_args()
82e0af566160 Uploaded
fubar
parents:
diff changeset
468 assert os.path.isfile(opts.gsea_jar),'## GSEA runner unable to find supplied gsea java desktop executable file %s' % opts.gsea_jar
82e0af566160 Uploaded
fubar
parents:
diff changeset
469 if opts.input_ranks:
82e0af566160 Uploaded
fubar
parents:
diff changeset
470 inpf = opts.input_ranks
82e0af566160 Uploaded
fubar
parents:
diff changeset
471 else:
82e0af566160 Uploaded
fubar
parents:
diff changeset
472 inpf = opts.input_tab
82e0af566160 Uploaded
fubar
parents:
diff changeset
473 assert opts.idcol <> None, '## GSEA runner needs an id column if a tabular file provided'
82e0af566160 Uploaded
fubar
parents:
diff changeset
474 assert opts.signcol <> None, '## GSEA runner needs a sign column if a tabular file provided'
82e0af566160 Uploaded
fubar
parents:
diff changeset
475 assert opts.adjpvalcol <> None, '## GSEA runner needs an adjusted p value column if a tabular file provided'
82e0af566160 Uploaded
fubar
parents:
diff changeset
476 assert os.path.isfile(inpf),'## GSEA runner unable to open supplied input file %s' % inpf
82e0af566160 Uploaded
fubar
parents:
diff changeset
477 if opts.chip > '':
82e0af566160 Uploaded
fubar
parents:
diff changeset
478 assert os.path.isfile(opts.chip),'## GSEA runner unable to open supplied chip file %s' % opts.chip
82e0af566160 Uploaded
fubar
parents:
diff changeset
479 some = None
82e0af566160 Uploaded
fubar
parents:
diff changeset
480 if opts.history_gmt <> None:
82e0af566160 Uploaded
fubar
parents:
diff changeset
481 some = 1
82e0af566160 Uploaded
fubar
parents:
diff changeset
482 assert os.path.isfile(opts.history_gmt),'## GSEA runner unable to open supplied history gene set matrix (.gmt) file %s' % opts.history_gmt
82e0af566160 Uploaded
fubar
parents:
diff changeset
483 if opts.builtin_gmt <> None:
82e0af566160 Uploaded
fubar
parents:
diff changeset
484 some = 1
82e0af566160 Uploaded
fubar
parents:
diff changeset
485 assert os.path.isfile(opts.builtin_gmt),'## GSEA runner unable to open supplied history gene set matrix (.gmt) file %s' % opts.builtin_gmt
82e0af566160 Uploaded
fubar
parents:
diff changeset
486 assert some, '## GSEA runner needs a gene set matrix file - none chosen?'
82e0af566160 Uploaded
fubar
parents:
diff changeset
487 opts.title = re.sub('[^a-zA-Z0-9_]+', '', opts.title)
82e0af566160 Uploaded
fubar
parents:
diff changeset
488 myName=os.path.split(sys.argv[0])[-1]
82e0af566160 Uploaded
fubar
parents:
diff changeset
489 gse = gsea_wrapper(myName, opts=opts)
82e0af566160 Uploaded
fubar
parents:
diff changeset
490 retcode = gse.run()
82e0af566160 Uploaded
fubar
parents:
diff changeset
491 if retcode <> 0:
82e0af566160 Uploaded
fubar
parents:
diff changeset
492 sys.exit(retcode) # indicate failure to job runner
82e0af566160 Uploaded
fubar
parents:
diff changeset
493
82e0af566160 Uploaded
fubar
parents:
diff changeset
494