def main_common( filename,option='select_genes' ): global current_outputdir cod = current_outputdir img_select_genes = 'dumy' # required for menu_template.htm img_cluster_genes = 'dummy' # required for menu_template.htm img_cluster_tissues = 'dummy' # required for menu_template.htm if option=='select_genes': img_select_genes = 'img' if option=='cluster_genes': img_cluster_genes = 'img' if option=='cluster_tissues': img_cluster_tissues = 'img' if option=='select_genes': program = 'all' else: program = option option_formatted = option.replace("_"," ").title() menus = \ """ <font size="2" face="Arial"> <p> <a href="conf_select_data?program=%(program)s&filter=*.dat&initial_file=%(filename)s">Specify</a> data file. (Currently %(filename)s)</p> <p> <a href="conf_select_genes">Set options for %(option_formatted)s</a></p> <p> <a href="conf_select_outputdir">Specify output directory</a>. (Currently %(cod)s ) </p> <p> <form method="post" action="/run"> <input type="hidden" name="select_genes" value="1" /> <input type="submit" value="GO"/> </form> </p> <p> <a href="/review">Review</a> results</p> </font> """ % locals() menus = menus.replace('select_genes', option) return webutil.apply_template('menu_template.htm', locals(), globals())
def review_corr_thumbnails(directory, REQUEST): "Reviews the thumbnails of the correlation coefficients" def check_display(file): return file.endswith(".cor") body = _thumbnails(directory,check_display) URL0 = "Correlation Thumbnails" return webutil.apply_template('review_sub.htm', locals(), globals())
def review_data_thumbnails(directory, REQUEST): """Reviews all the heatmaps in a directory in a thumbnail format""" def check_display(file): description, show_heatmap = _file_info(file) return show_heatmap body = _thumbnails(directory,check_display) URL0 = "Thumbnails" return webutil.apply_template('review_sub.htm', locals(), globals())
def display_running_processes(): "Returns a list of what's running" list = [] for program_name, data_file, stdin_file, stdout_file in \ EmmixProcessManager.listRunningProcesses(): list.append( """ <tr> <td><a href="display_info?stdout=%s">%s</a></td> <td>%s</td> </tr> """ % (stdout_file,program_name, data_file)) body = "".join(list) return webutil.apply_template('running.htm', locals(), globals())
def review_sstats(filename, REQUEST): "Reviews the sstats file for a given filename" results, URL0 = _getEmmixResult(filename) datafile = results.data_filename result_dir = results.result_dirname html=""" Edit the gene descriptions <a href="/edit_gene_info?datafile=%s&result_dir=%s">here</a>. """ % (datafile, result_dir) html+=""" <table> <tr> <!--<th>n-th selected gene</th>--> <th>log-lambda</th> <th>minimum cluster size</th> <th>original gene number</th> <th>gene description</th> </tr> """ try: for line in open(filename,'r').readlines(): selected_gene_number, loglambda, minsample, gene_number = \ filter(lambda x: x, line.split(' ')) html+=''' <tr> <!-- <td align="right">%s</td> --> <td align="right">%s</td> <td align="right">%s</td> <td align="right">%s</td>''' \ % (selected_gene_number, loglambda, minsample, gene_number) gene=results.getSelectedGene(int(selected_gene_number)) if gene: html+='<td>%s</td></tr>\n' % gene.description else: html+='<td>No description found</td></tr>\n' html+='</table></html>' body=html except TypeError: # Hmm, sstats has less than 4 columns body='<pre>%s</pre>' % open(filename,'r').read() return webutil.apply_template('review_sub.htm', locals(), globals())
def review(directory=None,REQUEST=None): """Review the results""" if not directory: outputdir=open(CURRENT_OUTPUTDIR_PATH).read() outputdir=outputdir.split('results\\')[1] REQUEST.response.redirect(REQUEST.URL + '/%s/' % outputdir) return # # Work out a path into a directory # traverse_subpath = REQUEST.traverse_subpath path = os.path.join( *[RESULT_PATH, directory] + traverse_subpath) REQUEST['path']=path relative_path=os.path.join( * ([directory] + traverse_subpath) ) # If correlation files need to be computed then # do it now if os.path.isdir(path): emmixgene.calculateCorrelationForDirectory(path) else: emmixgene.calculateCorrelationForDirectory(os.path.dirname(path)) # if file is an image, let the image module # handle it # extension=os.path.splitext(path.lower())[1] if extension in (".png",".svg"): return _heatmap(path, REQUEST) # if file is sstats, then use EmmixResult class # help in the display if path.lower().endswith('.sstats') or \ path.lower().endswith('.stats'): return review_sstats(path, REQUEST) if path.lower().find(".dat.cut_list") >= 0 : return review_list(path, REQUEST) # # if file exists, set mime type and return the file # otherwise, return a directory listing # if os.path.isfile(path): REQUEST.response.setHeader("Mime-Type","text/html") body='<pre>%s</pre>' % open(path,"rb").read() URL0=os.path.basename(path) return webutil.apply_template('review_sub.htm', locals(), globals()) elif os.path.isdir(path): if not REQUEST.URL.endswith('/'): REQUEST.response.setBase(REQUEST.URL+"/") else: # path is not a file and not a directory # try and make it a directory print "xxx making directory " , path, extension recurse_mkdir(path) # # directory listing # files = os.listdir(path) import numsort files = numsort.sorted_copy(files) output = "" review_correlations = "" for file in files: if file.endswith(".cor") and not review_correlations: # allow people to review correlation heatmaps # if .cor files exist review_correlations = """<p>View correlation coefficients <a href="/review_corr_thumbnails?directory=%s">as thumbnails</a> </p>""" % relative_path description, show_heatmap = _file_info(file) if (description != "" and show_heatmap != 0): # generate heatmaps for these output += ''' <a href="%(file)s">%(file)s</a> <b>%(description)s</b> <a href="%(file)s.png" title="png format">[heatmap]</a> <a href="%(file)s.svg" title="svg format">[heatmap]</a><br/> ''' % locals() elif (description !="" and show_heatmap == 0): # only display the file output += '<a href="%s">%s</a> <b>%s</b> <br/>' % \ (file, file, description) files = os.listdir("results") other_directories = "" for file in files: dir_path = os.path.join("results",file) if os.path.isdir(dir_path): other_directories += '<a href="../%s/">%s</a><br/>\n' % (file, file) body = """ <h1>Review results</h1> <h2>You are reviewing: %(path)s</h2> <p>View heatmaps <a href="/review_data_thumbnails?directory=%(relative_path)s">as thumbnails</a> </p> %(review_correlations)s %(output)s <p><a href="file://%(path)s" target="_blank">Open</a> the current results folder</p> <hr/> <H2> Review results in other directories </H2> %(other_directories)s <hr/> <b>Note the following is a mock up only</b> <h2>Logs</h2> <font size="-1"> <TABLE> <TR> <TD>Data File </TD> <TD>Anon.dat </TD> </TR> <TR> <TD>Date run </TD> <TD>15/10/2001 </TD> </TR> <TR> <TD>Researcher Notes </TD> <TD>ddd </TD> </TR> <TR> <TD>%(path)s </TD> <TD> </TD> </TR> </TABLE> </font> <hr/> """ % webutil._multimap(globals(), locals()) return webutil.apply_template('review.htm', locals(), globals())
def conf_cluster_tissues(REQUEST): """Screen to configure cluster tissue parameters""" if REQUEST['REQUEST_METHOD']=="POST": # # By default limit the number of rows # unless specified # limit_rows=1 if REQUEST.has_key('limit_rows'): if REQUEST['limit_rows']=='0': limit_rows=0 for key in current_rule.params_cluster_tissues.keys(): if REQUEST.has_key(key): if key == 'num_rows' and not limit_rows: current_rule.params_cluster_tissues['num_rows']=0 elif REQUEST[key]: current_rule.params_cluster_tissues[key]=REQUEST[key] current_rule.params_cluster_tissues['use_factor_analyzers']=\ getattr(REQUEST, 'use_factor_analyzers', 0) current_rule.store_rule(CURRENT_RULE_PATH) REQUEST.response.redirect("/main_cluster_tissues") return "" option_formatted = """ <a href="/main_cluster_tissues">Cluster Tissues</a> > Options """ img_select_genes = "dummy" img_cluster_genes = "dummy" img_cluster_tissues = "img" html = """ <h2>Options for cluster-tissues</h2> <form action="" method="post"> Use factor analyzers <input type="checkbox" oldvalue="%(use_factor_analyzers)s" name="use_factor_analyzers" value="1"/><br/> Number of factors (only used with factor analyzers) <input type="text" name="num_factors:int" value="%(num_factors)s"><br/> Number of components <input type="text" name="num_components:int" value="%(num_components)s"><br/> Random starts <input type="text" name="random_starts:int" value="%(random_starts)s"><br/> K-Mean starts <input type="text" name="kmean_starts:int" value="%(kmean_starts)s"><br/> Random seed 1 <input type="text" name="random_seed1:int" value="%(random_seed1)s"><br/> Random seed 2 <input type="text" name="random_seed2:int" value="%(random_seed2)s"><br/> Random seed 3 <input type="text" name="random_seed3:int" value="%(random_seed3)s"><br/> <!-- ============== limit number of rows computed ============== --> <input type="radio" id="limit_rows" name="limit_rows" value="1">Limit rows <input type="radio" id="all_rows" name="limit_rows" value="0"/> Use all rows<br/> Number of rows to use (from top of file) <input type="text" name="num_rows" value="%(num_rows)s"><br/> <p> <input type="button" value="Restore to default"><BR/> <input type="submit" value="OK"> <input type="submit" value="Cancel"> </p> """ % current_rule.params_cluster_tissues html = html.replace('oldvalue="1"', 'checked') if current_rule.params_cluster_tissues['num_rows']: html = html.replace('id="limit_rows"','checked') else: html = html.replace('id="all_rows"','checked') menus = html return webutil.apply_template('menu_template.htm',locals(), globals())
def conf_cluster_genes(REQUEST): """Web screen to configure Cluster Genes parameters""" if REQUEST['REQUEST_METHOD']=="POST": # # By default limit the number of rows # unless specified # limit_rows=1 if REQUEST.has_key('limit_rows'): if REQUEST['limit_rows']=='0': limit_rows=0 for key in current_rule.params_cluster_genes.keys(): if REQUEST.has_key(key): if key == 'num_rows' and not limit_rows: current_rule.params_cluster_genes['num_rows']=0 elif REQUEST[key]: current_rule.params_cluster_genes[key]=REQUEST[key] for key in ['robust', 'reorder']: if not REQUEST.has_key(key): current_rule.params_cluster_genes[key]="no" current_rule.store_rule(CURRENT_RULE_PATH) REQUEST.response.redirect("/main_cluster_genes") return "" option_formatted = """ <a href="/main_cluster_genes">Cluster Genes</a> > Configure """ img_select_genes = "dummy" img_cluster_genes = "img" img_cluster_tissues = "dummy" html = """ <h2>Options to run cluster-genes with</h2> <form action="" method="post"> Random starts <input type="text" name="random_starts" value="%(random_starts)s"><br/> K-Mean starts <input type="text" name="kmean_starts" value="%(kmean_starts)s"><br/> Random starts spherical <input type="text" name="random_starts_spherical" value="%(random_starts_spherical)s"><br/> K-Mean starts spherical <input type="text" name="kmean_starts_spherical" value="%(kmean_starts_spherical)s"><br/> Number of groups to cluster <input type="text" name="cluster_groups" value="%(cluster_groups)s"><br/> Threshold cluster size <input type="text" name="threshold_clustersize" value="%(threshold_clustersize)s"><br/> Random seed 1 <input type="text" name="random_seed1" value="%(random_seed1)s"><br/> Random seed 2 <input type="text" name="random_seed2" value="%(random_seed2)s"><br/> Random seed 3 <input type="text" name="random_seed3" value="%(random_seed3)s"><br/> Reorder tissues <input type="checkbox" name="reorder" id="reorder" value="yes" oldvalue="%(reorder)s"> <br/> Robust <input type="checkbox" name="robust" id="robust" value="yes" oldvalue="%(robust)s"> <br/> Common value of nu <input type="text" name="nu" value="%(nu)s"> (robust version only) <br/> <!-- ============== limit number of rows computed ============== --> <input type="radio" id="limit_rows" name="limit_rows" value="1">Limit rows <input type="radio" id="all_rows" name="limit_rows" value="0"/> Use all rows<br/> Number of rows to use (from top of file) <input type="text" name="num_rows" value="%(num_rows)s"><br/> <input type="button" value="Restore to default"><BR/> <input type="submit" value="OK"> <input type="submit" value="Cancel"> </p> """ % current_rule.params_cluster_genes if current_rule.params_cluster_genes['num_rows']: html = html.replace('id="limit_rows"','checked') else: html = html.replace('id="all_rows"','checked') # # replace checkboxes values # html = html.replace('oldvalue="yes"', 'checked') menus = html return webutil.apply_template('menu_template.htm',locals(), globals())
def conf_select_genes(REQUEST): """Screen to configure select genes parameters""" global current_rule if REQUEST['REQUEST_METHOD']=="POST": # # By default limit the number of rows # unless specified # limit_rows=1 if REQUEST.has_key('limit_rows'): if REQUEST['limit_rows']=='0': limit_rows=0 for key in current_rule.params_select_genes.keys(): if REQUEST.has_key(key): if key == 'num_rows' and not limit_rows: current_rule.params_select_genes['num_rows']=0 elif REQUEST[key]: current_rule.params_select_genes[key]=REQUEST[key] for key in ['resume']: if not REQUEST.has_key(key): current_rule.params_select_genes[key]=0 current_rule.store_rule(CURRENT_RULE_PATH) REQUEST.response.redirect("/main_select_genes") return "" option_formatted = """ <a href="/main_select_genes">Select Genes</a> > Options """ img_select_genes = "img" img_cluster_genes = "dummy" img_cluster_tissues = "dummy" html = """ <h2>Options to run select-genes with</h2> <form action="" method="post"> <table> <tr> <td>Random starts</td> <td><input type="text" name="random_starts" value="%(random_starts)s"></td> </tr> <tr> <td>K-Mean starts</td> <td><input type="text" name="kmean_starts" value="%(kmean_starts)s"></td> </tr> <tr> <td>Random seed 1</td> <td><input type="text" name="random_seed1" value="%(random_seed1)s"></td> </tr> <tr> <td>Random seed 2</td> <td><input type="text" name="random_seed2" value="%(random_seed2)s"></td> </tr> <tr> <td>Random seed 3</td> <td><input type="text" name="random_seed3" value="%(random_seed3)s"></td> </tr> <tr> <td>Threshold likelihood</td> <td><input type="text" name="threshold_likelihood" value="%(threshold_likelihood)s"></td> </tr> <tr> <td>Threshold cluster size</td> <td><input type="text" name="threshold_clustersize" value="%(threshold_clustersize)s"></td> </tr> <!-- ============== limit number of rows computed ============== --> <tr> <td colspan="2"> <input type="radio" id="limit_rows" name="limit_rows" value="1">Limit rows <input type="radio" id="all_rows" name="limit_rows" value="0"/> Use all rows </td> </tr> <tr> <td>Number of rows to use (from top of file)</td> <td><input type="text" name="num_rows" value="%(num_rows)s"></td> </tr> <!-- ============= resume past calculation ===================== --> <tr> <td colspan="2"> <input type="checkbox" name="resume:int" value="1" checked="%(resume)s">If unfinished job exists, resume unfinished job. </td> </tr> <tr colspan="2"> <td><input type="button" value="Restore to default"></td> </tr> <tr colspan="2"> <td> <input type="submit" value="OK"> <input type="submit" value="Cancel"> </td> </tr> </table> """ % current_rule.params_select_genes if current_rule.params_select_genes['num_rows']: html = html.replace('id="limit_rows"','checked') else: html = html.replace('id="all_rows"','checked') html = html.replace('checked="0"', '') menus = html return webutil.apply_template('menu_template.htm',locals(), globals())
def index_html(REQUEST, RESPONSE): "Obligatory doc_string" msgs.restore('messages.txt') messages=msgs.displayMessages() select_genes_filename=current_datafiles.select_genes.filename cluster_genes_filename=current_datafiles.cluster_genes.filename cluster_tissues_filename=current_datafiles.cluster_tissues.filename RESPONSE.setHeader("Expires","-1") RESPONSE.setHeader("Cache-Control", "no-cache") RESPONSE.setHeader("Pragma", "no-cache") if messages: messages=""" <h3>Messages</h3> <table bgcolor="#cccc99" border="0"> <tr> <td> %(messages)s </td> </tr> <tr align="right"> <td> <a href="/msgs/deleteAllMessages">Delete all messages</a> </td> </tr> </table> """ % locals() return webutil.apply_template('default.htm', locals(), globals()) html =""" %(standard_html_header)s <H2>Main menu</H2> <table valign="top"> <tr valign="top"> <td valign="top"> <p> <a href="/main_select_genes">Select-genes</a> </p> <p> <a href="/main_cluster_genes">Cluster-genes</a> </p> <p> <a href="/main_cluster_tissues">Cluster-tissues</a> </p> </td> <td> <h3>Running processes</h3> <table bgcolor="#cccc99" border="0"> <tr> <td> %(runningProcesses)s </td> </tr> </table> <!-- **************** MESSAGES ************* --> %(messages)s <p> <a href="/reportBack">Create an error report</a> for Chui</a> </p> </td> </tr> </table> <hr/> <H2>Help</H2> <p><b>select-genes</b> uses the emmix algorithm to reduce a large dataset of genes to a smaller set which is subsequently used for clustering.</p> <p><b>cluster-genes</b> clusters commonly expressed genes into groups.</p> <p><b>cluster-tissues</b> ... </p> %(standard_html_footer)s """ % _multimap(locals(), globals()) return html % _multimap(locals(), globals())