Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 189 lines (172 sloc) 6.705 kb
#!/usr/bin/env ./
# Start a batch operation from a web page
import cgitb
print "Content-Type: text/html\r"
print "\r"
import sys
import cgi
import os
import urllib
import cellprofiler.pipeline as cpp
import cellprofiler.preferences
form_data = cgi.FieldStorage()
myself = os.path.split(__file__)[1]
if len(myself) == 0:
myself = __file__
def show_directory(key, title, default, hidden_vars):
'''Show the directory structure for the variable given by the key
key - key into form_data
title - the user-visible title of the field
default - default value for the field
returns the current value of the key
if form_data.has_key(key):
value = form_data[key].value
value = default
paths = []
path = value
hvs = hidden_vars_inputs(hidden_vars)
while True:
head,tail = os.path.split(path)
if len(tail) == 0:
paths.insert(0,(head, path))
paths.insert(0,(tail, path))
path = head
print '''<div id="%(key)s_div">
<label for='input_%(key)s'>%(title)s:&nbsp;</label><input type='text'
<input type='button' value='Browse...'
for dirname, dirpath in paths:
all_keys = dict(hidden_vars)
all_keys[key] = dirpath
url = "%s?%s"%(myself, urllib.urlencode(all_keys))
print '''<ul><li><a href='%(url)s'>%(dirname)s</a></li>'''%(locals())
filenames = [(filename, os.path.join(value, filename))
for filename in os.listdir(value)
if os.path.isdir(os.path.join(value, filename))]
if len(filenames):
print '''<ul>'''
for dirname, dirpath in filenames:
all_keys = dict(hidden_vars)
all_keys[key] = dirpath
url = "%s?%s"%(myself, urllib.urlencode(all_keys))
print '''<li><a href='%(url)s'>%(dirname)s</a></li>'''%(locals())
print '''</ul>'''
print ''.join(['</ul>']*len(paths))
print '''</div>
return value
def hidden_vars_inputs(hidden_vars):
'''Create hidden input elements for each key in hidden_vars'''
s = ''
for key in hidden_vars.keys():
s+= '''<input type='hidden' name='%s' value='%s'/>'''%(key,hidden_vars[key])
return s
def lookup(key, default):
if form_data.has_key(key):
return form_data[key].value
return default
def minus_key(d, key):
d = dict(d)
del d[key]
return d
print '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html lang="en-US" xml:lang="en-US" xmlns="">
<title>CellProfiler 2.0 Batch submission</title>
<script language='JavaScript'>
function go_to_key(key) {
add_char = "?"
all_k = new Array("output_dir","image_dir","email","queue",
for (k in all_k) {
v = document.getElementById('input_'+all_k[k]).value
url = url+add_char+all_k[k]+'='+escape(v)
add_char = "&"
parent.location = url+"#input_"+key
<H1>CellProfiler 2.0 Batch submission</H1>
Submit a Batch_data.mat file created by CellProfiler 2.0. You need to
specify the Default Output Folder, which should contain your
Batch_data file and the default input folder for the pipeline. In
addition, there are some parameters that tailor how the batch is run.
keys = { 'output_dir':lookup('output_dir', '/imaging/analysis'),
'image_dir':lookup('image_dir', '/imaging/analysis'),
'email':lookup('email', ''),
'queue':lookup('queue', 'broad'),
print '''<form action=''>
<div style='white-space=nowrap'><label for='input_email'>E-mail:&nbsp;</label>
<input type='text' size="40" id='input_email' name='email' value='%(email)s'/></div>
<div style='white-space=nowrap'><label for='input_queue'>Queue:&nbsp;</label>
<select id='input_queue' name='queue'>
for queue in ('broad','short','long','hugemem','preview','priority'):
selected = 'selected="selected"' if queue == keys['queue'] else ''
print '''<option value='%(queue)s' %(selected)s>%(queue)s</option>'''%(locals())
print '''</select></div>'''
print '''<div style='white-space=nowrap'><label for='input_email'>Project:&nbsp;</label>
<input type='text' id='input_project' name='project' value='%(project)s'/></div>
<div style='white-space=nowrap'><label for='input_email'>Batch size:&nbsp;</label>
<input type='text' id='input_batch_size' name='batch_size' value='%(batch_size)s'/></div>
<div style='white-space=nowrap'><label for='input_email'>Memory limit:&nbsp;</label>
<input type='text' id='input_memory_limit' name='memory_limit' value='%(memory_limit)s'/></div>
batch_file = os.path.join(keys['output_dir'], 'Batch_data.mat')
grouping_keys = None
if os.path.exists(batch_file):
pipeline = cpp.Pipeline()
image_set_list = pipeline.prepare_run(None)
grouping_keys, groups = pipeline.get_groupings(image_set_list)
print "Failed to open %s"%batch_file
show_directory('output_dir','Default output directory',keys['output_dir'],
show_directory('image_dir','Default image directory', keys['image_dir'],
if grouping_keys is not None:
if len(grouping_keys):
print '<h2>Groups</h2>'
print '<table><tr>'
for key in grouping_keys:
print '<th>%s</th>'%key
print '<th># of image sets</th></tr>'
for group in groups:
print '<tr>'
for key in grouping_keys:
print '<td>%s</td>'%group[0][key]
print '<td>%d</td></tr>'%len(group[1])
print '</table>'
print 'Batch_data.mat has %d image sets'%image_set_list.count()
print '</form>'
print '</body></html>'
Jump to Line
Something went wrong with that request. Please try again.