def enter_batch_mode(self, workspace): '''Restore the image set list from its setting as we go into batch mode''' pipeline = workspace.pipeline assert isinstance(pipeline, cpp.Pipeline) assert not self.distributed_mode, "Distributed mode no longer supported" cpprefs.set_default_output_directory(self.custom_output_directory.value) cpprefs.set_default_image_directory(self.default_image_directory.value)
def test_03_02_pipeline_preferences(self): # # Walk the worker up through pipelines and preferences. # self.awthread = self.AWThread(self.announce_addr) self.awthread.start() self.set_work_socket() self.awthread.ex(self.awthread.aw.do_job, cpanalysis.WorkReply( image_set_numbers = [1], worker_runs_post_group = False, wants_dictionary = True)) # # The worker should ask for the pipeline and preferences next. # req = self.awthread.recv(self.work_socket) self.assertIsInstance(req, cpanalysis.PipelinePreferencesRequest) self.assertEqual(req.analysis_id, self.analysis_id) maybe_download_example_image(["ExampleSBSImages"], "Channel1-01-A-01.tif") maybe_download_example_image(["ExampleHT29"], "AS_09125_050116030001_D03f00d0.tif") input_dir = os.path.normcase( os.path.join(example_images_directory(), "ExampleSBSImages")) output_dir = os.path.normcase( os.path.join(example_images_directory(), "ExampleHT29")) cpprefs.set_default_image_directory(input_dir) input_dir = cpprefs.get_default_image_directory() cpprefs.set_default_output_directory(output_dir) output_dir = cpprefs.get_default_output_directory() preferences = {cpprefs.DEFAULT_IMAGE_DIRECTORY: cpprefs.config_read(cpprefs.DEFAULT_IMAGE_DIRECTORY), cpprefs.DEFAULT_OUTPUT_DIRECTORY: cpprefs.config_read(cpprefs.DEFAULT_OUTPUT_DIRECTORY)} cpprefs.set_default_image_directory(example_images_directory()) cpprefs.set_default_output_directory(example_images_directory()) rep = cpanalysis.Reply( pipeline_blob = np.array(GOOD_PIPELINE), preferences = preferences) req.reply(rep) # # Get the next request so that we know the worker has # processed the preferences. # req = self.awthread.recv(self.work_socket) self.assertEqual(cpprefs.get_default_image_directory(), input_dir) self.assertEqual(cpprefs.get_default_output_directory(), output_dir) self.assertIn(self.analysis_id, self.awthread.aw.pipelines_and_preferences) pipe, prefs = self.awthread.aw.pipelines_and_preferences[ self.analysis_id] self.assertEqual(len(pipe.modules()), 7) # # Cancel and check for exit # req.reply(cpanalysis.ServerExited()) self.assertRaises(cpp.CancelledException, self.awthread.ecute)
def analyze(conn, plate, pipeline): warnings.filterwarnings('ignore') print("analyzing...") # Set Cell Output Directory new_output_directory = os.path.normcase(tempfile.mkdtemp()) cpprefs.set_default_output_directory(new_output_directory) wells = list(plate.listChildren()) wells = wells[0:5] # use the first 5 wells for count, well in enumerate(wells): # Load a single Image per Well image = well.getImage(0) print(image.getName()) pixels = image.getPrimaryPixels() size_c = image.getSizeC() # For each Image in OMERO, we copy pipeline and inject image modules pipeline_copy = pipeline.copy() # Inject image for each Channel (pipeline only handles 2 channels) for c in range(0, size_c): plane = pixels.getPlane(0, c, 0) image_name = image.getName() # Name of the channel expected in the pipeline if c == 0: image_name = 'OrigBlue' if c == 1: image_name = 'OrigGreen' inject_image_module = InjectImage(image_name, plane) inject_image_module.set_module_num(1) pipeline_copy.add_module(inject_image_module) pipeline_copy.run() # Results obtained as CSV from Cell Profiler path = new_output_directory + '/Nuclei.csv' save_results(conn, path, image) print("analysis done")
def test_01_06_run_pipeline(self): import cellprofiler.pipeline as cpp import cellprofiler.cpmodule as cpm import os from cellprofiler.preferences import \ set_default_image_directory, set_default_output_directory maybe_download_fly() example_fly_dir = os.path.join(self.example_dir(), "ExampleFlyImages") set_default_image_directory(example_fly_dir) output_dir = tempfile.mkdtemp() set_default_output_directory(output_dir) try: pipeline_file = os.path.join(example_fly_dir, "ExampleFlyURL.cppipe") if not os.path.exists(pipeline_file): pipeline_file = os.path.join(example_fly_dir, "ExampleFly.cp") pipeline = cpp.Pipeline() def callback(caller, event): self.assertFalse( isinstance( event, (cpp.LoadExceptionEvent, cpp.RunExceptionEvent))) pipeline.add_listener(callback) pipeline.load(pipeline_file) while True: removed_something = False for module in reversed(pipeline.modules()): self.assertTrue(isinstance(module, cpm.CPModule)) if module.module_name in ("SaveImages", "CalculateStatistics", "ExportToSpreadsheet", "ExportToDatabase"): pipeline.remove_module(module.module_num) removed_something = True break if not removed_something: break for module in pipeline.modules(): module.show_window = False m = pipeline.run(image_set_end=1) del m finally: for file_name in os.listdir(output_dir): try: os.remove(os.path.join(output_dir, file_name)) except Exception, e: print "Failed to remove %s" % os.path.join( output_dir, file_name), e traceback.print_exc() try: os.rmdir(output_dir) except: print "Failed to remove %s" % output_dir traceback.print_exc()
def setUp(self): self.out_dir = tempfile.mkdtemp() cpprefs.set_default_output_directory(self.out_dir) self.announce_addr = "inproc://"+uuid.uuid4().hex self.work_addr = "inproc://"+uuid.uuid4().hex self.announce_socket = self.zmq_context.socket(zmq.PUB) self.announce_socket.bind(self.announce_addr) self.work_socket = self.zmq_context.socket(zmq.REP) self.work_socket.bind(self.work_addr) self.awthread = None
def test_01_06_run_pipeline(self): import cellprofiler.pipeline as cpp import cellprofiler.cpmodule as cpm import os from cellprofiler.preferences import set_default_image_directory, set_default_output_directory maybe_download_fly() example_fly_dir = os.path.join(self.example_dir(), "ExampleFlyImages") set_default_image_directory(example_fly_dir) output_dir = tempfile.mkdtemp() set_default_output_directory(output_dir) try: pipeline_file = os.path.join(example_fly_dir, "ExampleFlyURL.cppipe") if not os.path.exists(pipeline_file): pipeline_file = os.path.join(example_fly_dir, "ExampleFly.cp") pipeline = cpp.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, (cpp.LoadExceptionEvent, cpp.RunExceptionEvent))) pipeline.add_listener(callback) pipeline.load(pipeline_file) while True: removed_something = False for module in reversed(pipeline.modules()): self.assertTrue(isinstance(module, cpm.CPModule)) if module.module_name in ( "SaveImages", "CalculateStatistics", "ExportToSpreadsheet", "ExportToDatabase", ): pipeline.remove_module(module.module_num) removed_something = True break if not removed_something: break for module in pipeline.modules(): module.show_window = False m = pipeline.run(image_set_end=1) del m finally: for file_name in os.listdir(output_dir): try: os.remove(os.path.join(output_dir, file_name)) except Exception, e: print "Failed to remove %s" % os.path.join(output_dir, file_name), e traceback.print_exc() try: os.rmdir(output_dir) except: print "Failed to remove %s" % output_dir traceback.print_exc()
def enter_batch_mode(self, workspace): '''Restore the image set list from its setting as we go into batch mode''' image_set_list = workspace.image_set_list pipeline = workspace.pipeline assert isinstance(image_set_list, cpi.ImageSetList) assert isinstance(pipeline, cpp.Pipeline) if self.distributed_mode: import tempfile try: cpprefs.set_default_output_directory(tempfile.gettempdir()) cpprefs.set_default_image_directory(tempfile.gettempdir()) except: pass else: cpprefs.set_default_output_directory(self.custom_output_directory.value) cpprefs.set_default_image_directory(self.default_image_directory.value)
def setUp(self): # # Make three temporary directory structures # cpprefs.set_headless() self.directories = [tempfile.mkdtemp() for i in range(3)] for directory in self.directories: for i in range(3): os.mkdir(os.path.join(directory, str(i))) for j in range(3): os.mkdir(os.path.join(directory, str(i), str(j))) for k in range(3): os.mkdir(os.path.join(directory, str(i), str(j), str(k))) cpprefs.set_default_image_directory(os.path.join(self.directories[0], "1")) cpprefs.set_default_output_directory(os.path.join(self.directories[1], "1")) self.root_directory = os.path.join(self.directories[2], "1")
def __run_cp(self, img_list): image_set_file = os.path.join(os.getcwd(), uuid.uuid4().hex) with open(image_set_file, 'w') as fo: for img in img_list: fo.write('%s\n' % img) cpprefs.set_image_set_file(image_set_file) out_dir = os.path.join(os.getcwd(), uuid.uuid4().hex) os.mkdir(out_dir) cpprefs.set_default_output_directory(out_dir) pipeline = Pipeline() pipeline.load(self.pipeline_filename) pipeline.read_file_list(image_set_file) pipeline.run(image_set_start=None, image_set_end=None, grouping=None, measurements_filename=None, initial_measurements=None) return self.__build_results_dict(out_dir)
def enter_batch_mode(self, workspace): '''Restore the image set list from its setting as we go into batch mode''' pipeline = workspace.pipeline assert isinstance(pipeline, cpp.Pipeline) assert not self.distributed_mode, "Distributed mode no longer supported" default_output_directory = self.custom_output_directory.value default_image_directory = self.default_image_directory.value if os.path.isdir(default_output_directory): cpprefs.set_default_output_directory(default_output_directory) else: logger.info( "Batch file default output directory, \"%s\", does not exist" % default_output_directory) if os.path.isdir(default_image_directory): cpprefs.set_default_image_directory(default_image_directory) else: logger.info( "Batch file default input directory \"%s\", does not exist" % default_image_directory)
def __run_cp(self, img_list): image_set_file = os.path.join(os.getcwd(), uuid.uuid4().hex) with open(image_set_file, 'w') as fo: for img in img_list: fo.write('%s\n' % img) cpprefs.set_image_set_file(image_set_file) out_dir = os.path.join(os.getcwd(), uuid.uuid4().hex) os.mkdir(out_dir) cpprefs.set_default_output_directory(out_dir) pipeline = Pipeline() pipeline.load(self.pipeline_filename) pipeline.read_file_list(image_set_file) pipeline.run( image_set_start=None, image_set_end=None, grouping=None, measurements_filename=None, initial_measurements=None ) return self.__build_results_dict(out_dir)
def check_preferences(self): """Return True if preferences are OK (e.g. directories exist)""" path = self.__image_edit_box.Value if not os.path.isdir(path): if ( wx.MessageBox( ( 'The Default Input Folder is "%s", but ' "the directory does not exist. Do you want to " "create it?" ) % path, "Warning, cannot run pipeline", style=wx.YES_NO, ) == wx.NO ): return False, "Image directory does not exist" os.makedirs(path) cpprefs.set_default_image_directory(path) path = self.__output_edit_box.Value if not os.path.isdir(path): if ( wx.MessageBox( ( 'The Default Output Folder is "%s", but ' "the directory does not exist. Do you want to " "create it?" ) % path, "Warning, cannot run pipeline", style=wx.YES_NO, ) == wx.NO ): return False, "Output directory does not exist" os.makedirs(path) cpprefs.set_default_output_directory(path) return True, "OK"
def analyze(plate, pipeline): warnings.filterwarnings('ignore') print("analyzing...") # Set Cell Output Directory new_output_directory = os.path.normcase(tempfile.mkdtemp()) cpprefs.set_default_output_directory(new_output_directory) files = list() wells = list(plate.listChildren()) wells = wells[0:5] # use the first 5 wells plate_id = plate.getId() for count, well in enumerate(wells): # Load a single Image per Well image = well.getImage(0) print(image.getName()) data = load_dask_array_from_s3(plate_id, (well.row + 1) * (well.column + 1) - 1) size_c = image.getSizeC() # For each Image in OMERO, we copy pipeline and inject image modules pipeline_copy = pipeline.copy() # Inject image for each Channel (pipeline only handles 2 channels) for c in range(0, size_c): plane = data[0, c, 0, :, :] image_name = image.getName() # Name of the channel expected in the pipeline if c == 0: image_name = 'OrigBlue' if c == 1: image_name = 'OrigGreen' inject_image_module = InjectImage(image_name, plane) inject_image_module.set_module_num(1) pipeline_copy.add_module(inject_image_module) pipeline_copy.run() # Results obtained as CSV from Cell Profiler path = new_output_directory + '/Nuclei.csv' files.append(path) print("analysis done") return files
def check_preferences(self): '''Return True if preferences are OK (e.g. directories exist)''' path = self.__image_edit_box.Value if not os.path.isdir(path): if wx.MessageBox(('The Default Input Folder is "%s", but ' 'the directory does not exist. Do you want to ' 'create it?') % path, "Warning, cannot run pipeline", style=wx.YES_NO) == wx.NO: return False, "Image directory does not exist" os.makedirs(path) cpprefs.set_default_image_directory(path) path = self.__output_edit_box.Value if not os.path.isdir(path): if wx.MessageBox(('The Default Output Folder is "%s", but ' 'the directory does not exist. Do you want to ' 'create it?') % path, "Warning, cannot run pipeline", style=wx.YES_NO) == wx.NO: return False, "Output directory does not exist" os.makedirs(path) cpprefs.set_default_output_directory(path) return True, "OK"
def main(args=None): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if args is None: args = sys.argv import cellprofiler.preferences as cpprefs cpprefs.set_awt_headless(True) exit_code = 0 switches = ('--work-announce', '--knime-bridge-address') if any([any([arg.startswith(switch) for switch in switches]) for arg in args]): # # Go headless ASAP # cpprefs.set_headless() for i, arg in enumerate(args): if arg == "--ij-plugins-directory" and len(args) > i + 1: cpprefs.set_ij_plugin_directory(args[i + 1]) break import cellprofiler.analysis_worker cellprofiler.analysis_worker.aw_parse_args() cellprofiler.analysis_worker.main() sys.exit(exit_code) options, args = parse_args(args) if options.print_version: from cellprofiler.utilities.version import \ dotted_version, version_string, git_hash, version_number print "CellProfiler %s" % dotted_version print "Git %s" % git_hash print "Version %s" % version_number print "Built %s" % version_string.split(" ")[0] sys.exit(exit_code) # # Important to go headless ASAP # if (not options.show_gui) or options.write_schema_and_exit: import cellprofiler.preferences as cpprefs cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.jvm_heap_size is not None: from cellprofiler.preferences import set_jvm_heap_mb set_jvm_heap_mb(options.jvm_heap_size, False) set_log_level(options) if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.run_ilastik: run_ilastik() return if options.add_message_for_user: if len(args) != 3: sys.stderr.write("Usage: (for add_message-for-user)\n") sys.stderr.write("CellProfiler --add-message-for-user <caption> <message> <pipeline-or-project>\n") sys.stderr.write("where:\n") sys.stderr.write(" <caption> - the message box caption\n") sys.stderr.write(" <message> - the message displayed inside the message box\n") sys.stderr.write(" <pipeline-or-project> - the path to the pipeline or project file to modify\n") return caption = args[0] message = args[1] path = args[2] import h5py using_hdf5 = h5py.is_hdf5(path) if using_hdf5: import cellprofiler.measurements as cpmeas m = cpmeas.Measurements( filename=path, mode="r+") pipeline_text = m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] else: with open(path, "r") as fd: pipeline_text = fd.read() header, body = pipeline_text.split("\n\n", 1) pipeline_text = header + \ ("\nMessageForUser:%s|%s\n\n" % (caption, message)) + body if using_hdf5: m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] = pipeline_text m.close() else: with open(path, "w") as fd: fd.write(pipeline_text) print "Message added to %s" % path return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if options.omero_credentials is not None: set_omero_credentials_from_string(options.omero_credentials) if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory, globally=False) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory, globally=False) if options.temp_dir is not None: if not os.path.exists(options.temp_dir): os.makedirs(options.temp_dir) cpprefs.set_temporary_directory(options.temp_dir, globally=False) if not options.allow_schema_write: cpprefs.set_allow_schema_write(False) # # After the crucial preferences are established, we can start the VM # from cellprofiler.utilities.cpjvm import cp_start_vm cp_start_vm() # # Not so crucial preferences... # if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file) try: # --------------------------------------- # # Handle command-line tasks that that need to load the modules to run # if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.write_schema_and_exit: write_schema(options.pipeline_filename) return # # ------------------------------------------ if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.gui.app import App from cellprofiler.workspace import is_workspace_file if options.pipeline_filename: if is_workspace_file(options.pipeline_filename): workspace_path = os.path.expanduser(options.pipeline_filename) pipeline_path = None else: pipeline_path = os.path.expanduser(options.pipeline_filename) workspace_path = None elif options.new_project: workspace_path = False pipeline_path = None else: workspace_path = None pipeline_path = None app = App(0, workspace_path=workspace_path, pipeline_path=pipeline_path) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: if not os.path.exists(options.output_directory): os.makedirs(options.output_directory) cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: if options.run_pipeline: app.frame.pipeline_controller.do_analyze_images() app.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) exit_code = -1
def main(args): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if any([arg.startswith('--work-announce') for arg in args]): # # Go headless ASAP # import cellprofiler.preferences as cpprefs cpprefs.set_headless() import cellprofiler.analysis_worker cellprofiler.analysis_worker.main() sys.exit(0) options, args = parse_args(args) set_log_level(options) if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.run_ilastik: run_ilastik() return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if (not hasattr(sys, 'frozen')) and options.fetch_external_dependencies: import external_dependencies external_dependencies.fetch_external_dependencies(options.overwrite_external_dependencies) if (not hasattr(sys, 'frozen')) and options.build_extensions: build_extensions() if options.build_and_exit: return if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return try: if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.cellprofilerapp import CellProfilerApp show_splashbox = (options.pipeline_filename is None and options.workspace_filename is None and (not options.new_workspace) and options.show_splashbox) if options.workspace_filename: workspace_path = os.path.expanduser(options.workspace_filename) elif options.new_workspace: workspace_path = False else: workspace_path = None App = CellProfilerApp( 0, check_for_new_version = (options.pipeline_filename is None), show_splashbox = show_splashbox, workspace_path = workspace_path) # # Important to go headless ASAP # # cellprofiler.preferences can't be imported before we have a chance # to initialize the wx app. # import cellprofiler.preferences as cpprefs if not options.show_gui: cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory) if options.temp_dir is not None: cpprefs.set_temporary_directory(options.temp_dir) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file, False) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: import cellprofiler.gui.cpframe as cpgframe if options.pipeline_filename: pipeline_path = os.path.expanduser(options.pipeline_filename) try: App.frame.pipeline.load(pipeline_path) if options.run_pipeline: App.frame.Command(cpgframe.ID_FILE_ANALYZE_IMAGES) except: import wx wx.MessageBox( 'CellProfiler was unable to load the pipeline file, "%s"' % options.pipeline_filename, "Error loading pipeline", style = wx.OK | wx.ICON_ERROR) logging.root.error("Unable to load pipeline", exc_info=True) App.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) raise
def test_02_01_compare_to_matlab(self): expected = { 'EC50_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':3.982812, 'EC50_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':4.139827, 'EC50_DistCytoplasm_Intensity_MedianIntensity_CorrGreen':4.178600, 'EC50_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen':4.059770, 'EC50_DistCytoplasm_Intensity_MinIntensity_CorrGreen':4.066357, 'EC50_DistCytoplasm_Math_Ratio1':4.491367, 'EC50_DistCytoplasm_Math_Ratio2':3.848722, 'EC50_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':4.948056, 'EC50_DistCytoplasm_Texture_Entropy_CorrGreen_1':4.687104, 'EC50_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1':5.0285, 'EC50_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1':4.319017, 'EC50_DistCytoplasm_Texture_SumAverage_CorrGreen_1':4.548876, 'EC50_DistCytoplasm_Texture_SumEntropy_CorrGreen_1':4.779139, 'EC50_DistCytoplasm_Texture_Variance_CorrGreen_1':4.218379, 'EC50_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue':3.708711, 'EC50_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen':4.135146, 'EC50_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen':4.5372, 'EC50_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen':4.1371, 'EC50_DistanceCells_Intensity_MinIntensityEdge_CorrGreen':4.033999, 'EC50_DistanceCells_Intensity_MinIntensity_CorrGreen':4.079470, 'EC50_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1':5.118689, 'EC50_DistanceCells_Texture_Correlation_CorrGreen_1':4.002074, 'EC50_DistanceCells_Texture_Entropy_CorrGreen_1':5.008000, 'EC50_DistanceCells_Texture_InfoMeas1_CorrGreen_1':3.883586, 'EC50_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1':3.977216, 'EC50_DistanceCells_Texture_SumAverage_CorrGreen_1':4.9741, 'EC50_DistanceCells_Texture_SumEntropy_CorrGreen_1':5.1455, 'EC50_DistanceCells_Texture_SumVariance_CorrGreen_1':4.593041, 'EC50_DistanceCells_Texture_Variance_CorrGreen_1':4.619517, 'EC50_Nuclei_Correlation_Correlation_CorrGreenCorrBlue':3.751133, 'EC50_Nuclei_Math_Ratio1':4.491367, 'EC50_Nuclei_Math_Ratio2':3.848722, 'EC50_Nuclei_Texture_SumAverage_CorrGreen_1':3.765297, 'EC50_PropCells_AreaShape_Area':4.740853, 'EC50_PropCells_AreaShape_MajorAxisLength':5.064460, 'EC50_PropCells_AreaShape_MinorAxisLength':4.751471, 'EC50_PropCells_AreaShape_Perimeter':4.949292, 'EC50_PropCells_Correlation_Correlation_CorrGreenCorrBlue':3.772565, 'EC50_PropCells_Texture_GaborX_CorrGreen_1':5.007167, 'EC50_PropCells_Texture_InfoMeas2_CorrBlue_1':4.341353, 'EC50_PropCells_Texture_SumVariance_CorrBlue_1':4.298359, 'EC50_PropCells_Texture_SumVariance_CorrGreen_1':4.610826, 'EC50_PropCells_Texture_Variance_CorrBlue_1':4.396352, 'EC50_PropCells_Texture_Variance_CorrGreen_1':4.632468, 'EC50_PropCytoplasm_AreaShape_Area':4.669679, 'EC50_PropCytoplasm_AreaShape_MinorAxisLength':4.754476, 'EC50_PropCytoplasm_AreaShape_Perimeter':4.949292, 'EC50_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':4.072830, 'EC50_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen':4.0934, 'EC50_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':3.925800, 'EC50_PropCytoplasm_Intensity_MedianIntensity_CorrGreen':3.9252, 'EC50_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':4.777481, 'EC50_PropCytoplasm_Texture_Entropy_CorrGreen_1':4.4432, 'EC50_PropCytoplasm_Texture_GaborX_CorrGreen_1':5.163371, 'EC50_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1':4.701046, 'EC50_PropCytoplasm_Texture_SumEntropy_CorrGreen_1':4.510543, 'EC50_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1':4.560315, 'EC50_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1':4.966674, 'EC50_ThresholdedCells_Texture_Entropy_CorrBlue_1':4.457866, 'EC50_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1':4.624049, 'EC50_ThresholdedCells_Texture_SumAverage_CorrBlue_1':4.686706, 'EC50_ThresholdedCells_Texture_SumEntropy_CorrBlue_1':4.537378, 'EC50_ThresholdedCells_Texture_SumVariance_CorrBlue_1':4.322820, 'EC50_ThresholdedCells_Texture_SumVariance_CorrGreen_1':4.742158, 'EC50_ThresholdedCells_Texture_Variance_CorrBlue_1':4.265549, 'EC50_ThresholdedCells_Texture_Variance_CorrGreen_1':4.860020, 'OneTailedZfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen':-4.322503, 'OneTailedZfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen':-4.322503, 'OneTailedZfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen':-4.322503, 'OneTailedZfactor_DistCytoplasm_Math_Ratio1':0.622059, 'OneTailedZfactor_DistCytoplasm_Math_Ratio2':-4.508284, 'OneTailedZfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1':-4.645887, 'OneTailedZfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1':-4.279118, 'OneTailedZfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1':-4.765570, 'OneTailedZfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1':-4.682335, 'OneTailedZfactor_DistCytoplasm_Texture_Variance_CorrGreen_1':-4.415607, 'OneTailedZfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen':-4.200105, 'OneTailedZfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen':-4.316452, 'OneTailedZfactor_DistanceCells_Intensity_MinIntensity_CorrGreen':-4.316452, 'OneTailedZfactor_DistanceCells_Texture_Correlation_CorrGreen_1':0.202500, 'OneTailedZfactor_DistanceCells_Texture_Entropy_CorrGreen_1':-4.404815, 'OneTailedZfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1':-4.508513, 'OneTailedZfactor_DistanceCells_Texture_SumAverage_CorrGreen_1':-4.225356, 'OneTailedZfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1':-4.382768, 'OneTailedZfactor_DistanceCells_Texture_SumVariance_CorrGreen_1':0.492125, 'OneTailedZfactor_DistanceCells_Texture_Variance_CorrGreen_1':0.477360, 'OneTailedZfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue':0.563780, 'OneTailedZfactor_Nuclei_Math_Ratio1':0.622059, 'OneTailedZfactor_Nuclei_Math_Ratio2':-4.508284, 'OneTailedZfactor_Nuclei_Texture_SumAverage_CorrGreen_1':0.426178, 'OneTailedZfactor_PropCells_AreaShape_Area':-4.216674, 'OneTailedZfactor_PropCells_AreaShape_MajorAxisLength':-4.119131, 'OneTailedZfactor_PropCells_AreaShape_MinorAxisLength':-4.109793, 'OneTailedZfactor_PropCells_AreaShape_Perimeter':-4.068050, 'OneTailedZfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue':0.765440, 'OneTailedZfactor_PropCells_Texture_GaborX_CorrGreen_1':0.114982, 'OneTailedZfactor_PropCells_Texture_InfoMeas2_CorrBlue_1':0.108409, 'OneTailedZfactor_PropCells_Texture_SumVariance_CorrBlue_1':0.191251, 'OneTailedZfactor_PropCells_Texture_SumVariance_CorrGreen_1':0.559865, 'OneTailedZfactor_PropCells_Texture_Variance_CorrBlue_1':0.254078, 'OneTailedZfactor_PropCells_Texture_Variance_CorrGreen_1':0.556108, 'OneTailedZfactor_PropCytoplasm_AreaShape_Area':-4.223021, 'OneTailedZfactor_PropCytoplasm_AreaShape_MinorAxisLength':-4.095632, 'OneTailedZfactor_PropCytoplasm_AreaShape_Perimeter':-4.068050, 'OneTailedZfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen':-4.194663, 'OneTailedZfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1':-4.443338, 'OneTailedZfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1':0.207265, 'OneTailedZfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1':-4.297250, 'OneTailedZfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1':-4.525324, 'OneTailedZfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1':0.167795, 'OneTailedZfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1':0.067560, 'OneTailedZfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1':0.478527, 'OneTailedZfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1':0.155119, 'OneTailedZfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1':0.535907, 'OneTailedZfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1':0.572801, 'OneTailedZfactor_ThresholdedCells_Texture_Variance_CorrBlue_1':0.423454, 'OneTailedZfactor_ThresholdedCells_Texture_Variance_CorrGreen_1':0.440500, 'Vfactor_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':0.500429, 'Vfactor_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':0.325675, 'Vfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen':0.323524, 'Vfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen':0.138487, 'Vfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen':0.128157, 'Vfactor_DistCytoplasm_Math_Ratio1':0.503610, 'Vfactor_DistCytoplasm_Math_Ratio2':0.319610, 'Vfactor_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':0.522880, 'Vfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1':0.504303, 'Vfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1':0.289432, 'Vfactor_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1':0.234123, 'Vfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1':0.591687, 'Vfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1':0.520356, 'Vfactor_DistCytoplasm_Texture_Variance_CorrGreen_1':-0.007649, 'Vfactor_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue':0.761198, 'Vfactor_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen':0.234655, 'Vfactor_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen':0.252240, 'Vfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen':0.195125, 'Vfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen':0.138299, 'Vfactor_DistanceCells_Intensity_MinIntensity_CorrGreen':0.126784, 'Vfactor_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1':0.342691, 'Vfactor_DistanceCells_Texture_Correlation_CorrGreen_1':0.314396, 'Vfactor_DistanceCells_Texture_Entropy_CorrGreen_1':0.311771, 'Vfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1':0.410631, 'Vfactor_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1':0.170576, 'Vfactor_DistanceCells_Texture_SumAverage_CorrGreen_1':0.223147, 'Vfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1':0.269519, 'Vfactor_DistanceCells_Texture_SumVariance_CorrGreen_1':0.571528, 'Vfactor_DistanceCells_Texture_Variance_CorrGreen_1':0.566272, 'Vfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue':0.705051, 'Vfactor_Nuclei_Math_Ratio1':0.503610, 'Vfactor_Nuclei_Math_Ratio2':0.319610, 'Vfactor_Nuclei_Texture_SumAverage_CorrGreen_1':0.553708, 'Vfactor_PropCells_AreaShape_Area':0.340093, 'Vfactor_PropCells_AreaShape_MajorAxisLength':0.243838, 'Vfactor_PropCells_AreaShape_MinorAxisLength':0.320691, 'Vfactor_PropCells_AreaShape_Perimeter':0.238915, 'Vfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue':0.723520, 'Vfactor_PropCells_Texture_GaborX_CorrGreen_1':0.213161, 'Vfactor_PropCells_Texture_InfoMeas2_CorrBlue_1':0.199791, 'Vfactor_PropCells_Texture_SumVariance_CorrBlue_1':0.078959, 'Vfactor_PropCells_Texture_SumVariance_CorrGreen_1':0.642844, 'Vfactor_PropCells_Texture_Variance_CorrBlue_1':0.199105, 'Vfactor_PropCells_Texture_Variance_CorrGreen_1':0.640818, 'Vfactor_PropCytoplasm_AreaShape_Area':0.325845, 'Vfactor_PropCytoplasm_AreaShape_MinorAxisLength':0.312258, 'Vfactor_PropCytoplasm_AreaShape_Perimeter':0.238915, 'Vfactor_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':0.337565, 'Vfactor_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen':0.292900, 'Vfactor_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':0.175528, 'Vfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen':0.193308, 'Vfactor_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':0.276152, 'Vfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1':0.239567, 'Vfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1':0.332380, 'Vfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1':0.379141, 'Vfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1':0.337740, 'Vfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1':0.334520, 'Vfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1':0.192882, 'Vfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1':0.276245, 'Vfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1':0.139166, 'Vfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1':0.465237, 'Vfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1':0.355399, 'Vfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1':0.453937, 'Vfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1':0.564371, 'Vfactor_ThresholdedCells_Texture_Variance_CorrBlue_1':0.360566, 'Vfactor_ThresholdedCells_Texture_Variance_CorrGreen_1':0.548770, 'Zfactor_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':0.531914, 'Zfactor_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':0.265558, 'Zfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen':0.178586, 'Zfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen':0.084566, 'Zfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen':0.086476, 'Zfactor_DistCytoplasm_Math_Ratio1':0.623284, 'Zfactor_DistCytoplasm_Math_Ratio2':0.358916, 'Zfactor_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':0.429510, 'Zfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1':0.508275, 'Zfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1':0.068695, 'Zfactor_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1':0.347949, 'Zfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1':0.646576, 'Zfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1':0.494276, 'Zfactor_DistCytoplasm_Texture_Variance_CorrGreen_1':0.179011, 'Zfactor_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue':0.824686, 'Zfactor_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen':0.027644, 'Zfactor_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen':0.088491, 'Zfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen':0.065056, 'Zfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen':0.089658, 'Zfactor_DistanceCells_Intensity_MinIntensity_CorrGreen':0.078017, 'Zfactor_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1':0.238131, 'Zfactor_DistanceCells_Texture_Correlation_CorrGreen_1':0.301107, 'Zfactor_DistanceCells_Texture_Entropy_CorrGreen_1':0.251143, 'Zfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1':0.564957, 'Zfactor_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1':0.302767, 'Zfactor_DistanceCells_Texture_SumAverage_CorrGreen_1':0.036459, 'Zfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1':0.159798, 'Zfactor_DistanceCells_Texture_SumVariance_CorrGreen_1':0.516938, 'Zfactor_DistanceCells_Texture_Variance_CorrGreen_1':0.501186, 'Zfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue':0.691408, 'Zfactor_Nuclei_Math_Ratio1':0.623284, 'Zfactor_Nuclei_Math_Ratio2':0.358916, 'Zfactor_Nuclei_Texture_SumAverage_CorrGreen_1':0.587347, 'Zfactor_PropCells_AreaShape_Area':0.132425, 'Zfactor_PropCells_AreaShape_MajorAxisLength':0.034809, 'Zfactor_PropCells_AreaShape_MinorAxisLength':0.113864, 'Zfactor_PropCells_AreaShape_Perimeter':0.005984, 'Zfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue':0.717632, 'Zfactor_PropCells_Texture_GaborX_CorrGreen_1':0.251023, 'Zfactor_PropCells_Texture_InfoMeas2_CorrBlue_1':0.149719, 'Zfactor_PropCells_Texture_SumVariance_CorrBlue_1':0.102050, 'Zfactor_PropCells_Texture_SumVariance_CorrGreen_1':0.611960, 'Zfactor_PropCells_Texture_Variance_CorrBlue_1':0.197090, 'Zfactor_PropCells_Texture_Variance_CorrGreen_1':0.614879, 'Zfactor_PropCytoplasm_AreaShape_Area':0.205042, 'Zfactor_PropCytoplasm_AreaShape_MinorAxisLength':0.072682, 'Zfactor_PropCytoplasm_AreaShape_Perimeter':0.005984, 'Zfactor_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue':0.272017, 'Zfactor_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen':0.115327, 'Zfactor_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen':0.141850, 'Zfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen':0.105803, 'Zfactor_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1':0.107640, 'Zfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1':0.067896, 'Zfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1':0.136688, 'Zfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1':0.334749, 'Zfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1':0.208829, 'Zfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1':0.263467, 'Zfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1':0.124355, 'Zfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1':0.236433, 'Zfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1':0.125845, 'Zfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1':0.449333, 'Zfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1':0.323243, 'Zfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1':0.507477, 'Zfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1':0.599000, 'Zfactor_ThresholdedCells_Texture_Variance_CorrBlue_1':0.361424, 'Zfactor_ThresholdedCells_Texture_Variance_CorrGreen_1':0.481393 } temp_dir = tempfile.mkdtemp() m = None try: cpprefs.set_headless() cpprefs.set_default_output_directory(temp_dir) print "Writing output to %s"%temp_dir path = os.path.split(__file__)[0] matfile_path = os.path.join(path,'calculatestatistics.mat') if not os.path.isfile(matfile_path): # Download from GIT URL matfile_path = os.path.join(temp_dir, 'calculatestatistics.mat') url = github_url + ( "/cellprofiler/modules/tests/" "calculatestatistics.mat") urllib.urlretrieve(url, matfile_path) measurements = loadmat(matfile_path, struct_as_record = True) measurements = measurements['m'] image_set_list = cpi.ImageSetList() image_set = image_set_list.get_image_set(0) m = cpmeas.Measurements() doses = [0 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10, 0 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10, 0 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10, 0 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10, 10,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0, 10,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0, 10,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0, 10,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0] for i,dose in enumerate(doses): m.add_image_measurement("Dose",dose) for object_name in measurements.dtype.fields: omeasurements = measurements[object_name][0,0] for feature_name in omeasurements.dtype.fields: data = omeasurements[feature_name][0,0][0,i].flatten() m.add_measurement(object_name, feature_name, data) if i < len(doses)-1: m.next_image_set() pipeline = cpp.Pipeline() module = C.CalculateStatistics() module.grouping_values.value = "Dose" module.dose_values[0].log_transform.value = False module.dose_values[0].measurement.value = "Dose" module.dose_values[0].wants_save_figure.value = True module.dose_values[0].figure_name.value = "EC49_" module.module_num = 1 pipeline.add_module(module) def callback(caller, event): self.assertFalse(isinstance(event, cpp.RunExceptionEvent)) workspace = cpw.Workspace(pipeline, module, image_set, cpo.ObjectSet(), m, image_set_list) module.post_run(workspace) for feature_name in m.get_feature_names(cpmeas.EXPERIMENT): if not expected.has_key(feature_name): print "Missing measurement: %s"%feature_name continue value = m.get_experiment_measurement(feature_name) e_value = expected[feature_name] diff = abs(value-e_value) *2 /abs(value+e_value) self.assertTrue(diff < .05, "%s: Matlab: %f, Python: %f diff: %f" % (feature_name, e_value, value, diff)) if diff > .01: print ("Warning: > 1%% difference for %s: Matlab: %f, Python: %f diff: %f" % (feature_name, e_value, value, diff)) if feature_name.startswith("EC50"): filename = "EC49_"+feature_name[5:]+".pdf" self.assertTrue(os.path.isfile(os.path.join(temp_dir, filename))) finally: try: if m is not None: m.close() except: pass for filename in os.listdir(temp_dir): path = os.path.join(temp_dir, filename) os.remove(path) os.rmdir(temp_dir)
def main(args): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if any([arg.startswith('--work-announce') for arg in args]): # # Go headless ASAP # import cellprofiler.preferences as cpprefs cpprefs.set_headless() for i, arg in enumerate(args): if arg == "--ij-plugins-directory" and len(args) > i+1: cpprefs.set_ij_plugin_directory(args[i+1]) break import cellprofiler.analysis_worker cellprofiler.analysis_worker.aw_parse_args() cellprofiler.analysis_worker.main() sys.exit(0) options, args = parse_args(args) if options.jvm_heap_size != None: from cellprofiler.preferences import set_jvm_heap_mb set_jvm_heap_mb(options.jvm_heap_size, False) set_log_level(options) if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.run_ilastik: run_ilastik() return if options.add_message_for_user: if len(args) != 3: sys.stderr.write("Usage: (for add_message-for-user)\n") sys.stderr.write("CellProfiler --add-message-for-user <caption> <message> <pipeline-or-project>\n") sys.stderr.write("where:\n") sys.stderr.write(" <caption> - the message box caption\n") sys.stderr.write(" <message> - the message displayed inside the message box\n") sys.stderr.write(" <pipeline-or-project> - the path to the pipeline or project file to modify\n") return caption = args[0] message = args[1] path = args[2] import h5py using_hdf5 = h5py.is_hdf5(path) if using_hdf5: import cellprofiler.measurements as cpmeas m = cpmeas.Measurements( filename = path, mode="r+") pipeline_text = m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] else: with open(path, "r") as fd: pipeline_text = fd.read() header, body = pipeline_text.split("\n\n", 1) pipeline_text = header + \ ("\nMessageForUser:%s|%s\n\n" % (caption, message)) + body if using_hdf5: m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] = pipeline_text m.close() else: with open(path, "w") as fd: fd.write(pipeline_text) print "Message added to %s" % path return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if (not hasattr(sys, 'frozen')) and options.fetch_external_dependencies: import external_dependencies external_dependencies.fetch_external_dependencies(options.overwrite_external_dependencies) if (not hasattr(sys, 'frozen')) and options.build_extensions: build_extensions() if options.build_and_exit: return if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return if options.omero_credentials is not None: set_omero_credentials_from_string(options.omero_credentials) try: if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.cellprofilerapp import CellProfilerApp from cellprofiler.workspace import is_workspace_file show_splashbox = (options.pipeline_filename is None and (not options.new_project) and options.show_splashbox) if options.pipeline_filename: if is_workspace_file(options.pipeline_filename): workspace_path = os.path.expanduser(options.pipeline_filename) pipeline_path = None else: pipeline_path = os.path.expanduser(options.pipeline_filename) workspace_path = None elif options.new_project: workspace_path = False pipeline_path = None else: workspace_path = None pipeline_path = None App = CellProfilerApp( 0, check_for_new_version = (options.pipeline_filename is None), show_splashbox = show_splashbox, workspace_path = workspace_path, pipeline_path = pipeline_path) # # Important to go headless ASAP # # cellprofiler.preferences can't be imported before we have a chance # to initialize the wx app. # import cellprofiler.preferences as cpprefs if not options.show_gui: cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory) if options.temp_dir is not None: if not os.path.exists(options.temp_dir): os.makedirs(options.temp_dir) cpprefs.set_temporary_directory(options.temp_dir) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file, False) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: if not os.path.exists(options.output_directory): os.makedirs(options.output_directory) cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: if options.run_pipeline: App.frame.pipeline_controller.do_analyze_images() App.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) raise
else: image_set_start = int(options.first_image_set) else: image_set_start = None if not options.last_image_set is None: if not options.last_image_set.isdigit(): raise ValueError( "The --last-image-set option takes a numeric argument") else: image_set_end = int(options.last_image_set) else: image_set_end = None if options.output_directory: cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: import cellprofiler.gui.cpframe as cpgframe if options.pipeline_filename: try: App.frame.pipeline.load( os.path.expanduser(options.pipeline_filename)) if options.run_pipeline: App.frame.Command(cpgframe.ID_FILE_ANALYZE_IMAGES) except: import wx wx.MessageBox(
image_set_numbers = None if not options.last_image_set is None: if not options.last_image_set.isdigit(): raise ValueError("The --last-image-set option takes a numeric argument") else: image_set_end = int(options.last_image_set) if image_set_start is None: image_set_numbers = np.arange(1, image_set_end+1) else: image_set_numbers = np.arange(image_set_start, image_set_end+1) else: image_set_end = None if options.output_directory: cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: import cellprofiler.gui.cpframe as cpgframe if options.pipeline_filename: try: App.frame.pipeline.load(os.path.expanduser(options.pipeline_filename)) if options.run_pipeline: App.frame.Command(cpgframe.ID_FILE_ANALYZE_IMAGES) except: import wx wx.MessageBox( 'CellProfiler was unable to load the pipeline file, "%s"' %
def test_02_01_compare_to_matlab(self): expected = { 'EC50_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 3.982812, 'EC50_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 4.139827, 'EC50_DistCytoplasm_Intensity_MedianIntensity_CorrGreen': 4.178600, 'EC50_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen': 4.059770, 'EC50_DistCytoplasm_Intensity_MinIntensity_CorrGreen': 4.066357, 'EC50_DistCytoplasm_Math_Ratio1': 4.491367, 'EC50_DistCytoplasm_Math_Ratio2': 3.848722, 'EC50_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 4.948056, 'EC50_DistCytoplasm_Texture_Entropy_CorrGreen_1': 4.687104, 'EC50_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1': 5.0285, 'EC50_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1': 4.319017, 'EC50_DistCytoplasm_Texture_SumAverage_CorrGreen_1': 4.548876, 'EC50_DistCytoplasm_Texture_SumEntropy_CorrGreen_1': 4.779139, 'EC50_DistCytoplasm_Texture_Variance_CorrGreen_1': 4.218379, 'EC50_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue': 3.708711, 'EC50_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen': 4.135146, 'EC50_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen': 4.5372, 'EC50_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen': 4.1371, 'EC50_DistanceCells_Intensity_MinIntensityEdge_CorrGreen': 4.033999, 'EC50_DistanceCells_Intensity_MinIntensity_CorrGreen': 4.079470, 'EC50_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1': 5.118689, 'EC50_DistanceCells_Texture_Correlation_CorrGreen_1': 4.002074, 'EC50_DistanceCells_Texture_Entropy_CorrGreen_1': 5.008000, 'EC50_DistanceCells_Texture_InfoMeas1_CorrGreen_1': 3.883586, 'EC50_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1': 3.977216, 'EC50_DistanceCells_Texture_SumAverage_CorrGreen_1': 4.9741, 'EC50_DistanceCells_Texture_SumEntropy_CorrGreen_1': 5.1455, 'EC50_DistanceCells_Texture_SumVariance_CorrGreen_1': 4.593041, 'EC50_DistanceCells_Texture_Variance_CorrGreen_1': 4.619517, 'EC50_Nuclei_Correlation_Correlation_CorrGreenCorrBlue': 3.751133, 'EC50_Nuclei_Math_Ratio1': 4.491367, 'EC50_Nuclei_Math_Ratio2': 3.848722, 'EC50_Nuclei_Texture_SumAverage_CorrGreen_1': 3.765297, 'EC50_PropCells_AreaShape_Area': 4.740853, 'EC50_PropCells_AreaShape_MajorAxisLength': 5.064460, 'EC50_PropCells_AreaShape_MinorAxisLength': 4.751471, 'EC50_PropCells_AreaShape_Perimeter': 4.949292, 'EC50_PropCells_Correlation_Correlation_CorrGreenCorrBlue': 3.772565, 'EC50_PropCells_Texture_GaborX_CorrGreen_1': 5.007167, 'EC50_PropCells_Texture_InfoMeas2_CorrBlue_1': 4.341353, 'EC50_PropCells_Texture_SumVariance_CorrBlue_1': 4.298359, 'EC50_PropCells_Texture_SumVariance_CorrGreen_1': 4.610826, 'EC50_PropCells_Texture_Variance_CorrBlue_1': 4.396352, 'EC50_PropCells_Texture_Variance_CorrGreen_1': 4.632468, 'EC50_PropCytoplasm_AreaShape_Area': 4.669679, 'EC50_PropCytoplasm_AreaShape_MinorAxisLength': 4.754476, 'EC50_PropCytoplasm_AreaShape_Perimeter': 4.949292, 'EC50_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 4.072830, 'EC50_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen': 4.0934, 'EC50_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 3.925800, 'EC50_PropCytoplasm_Intensity_MedianIntensity_CorrGreen': 3.9252, 'EC50_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 4.777481, 'EC50_PropCytoplasm_Texture_Entropy_CorrGreen_1': 4.4432, 'EC50_PropCytoplasm_Texture_GaborX_CorrGreen_1': 5.163371, 'EC50_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1': 4.701046, 'EC50_PropCytoplasm_Texture_SumEntropy_CorrGreen_1': 4.510543, 'EC50_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1': 4.560315, 'EC50_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1': 4.966674, 'EC50_ThresholdedCells_Texture_Entropy_CorrBlue_1': 4.457866, 'EC50_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1': 4.624049, 'EC50_ThresholdedCells_Texture_SumAverage_CorrBlue_1': 4.686706, 'EC50_ThresholdedCells_Texture_SumEntropy_CorrBlue_1': 4.537378, 'EC50_ThresholdedCells_Texture_SumVariance_CorrBlue_1': 4.322820, 'EC50_ThresholdedCells_Texture_SumVariance_CorrGreen_1': 4.742158, 'EC50_ThresholdedCells_Texture_Variance_CorrBlue_1': 4.265549, 'EC50_ThresholdedCells_Texture_Variance_CorrGreen_1': 4.860020, 'OneTailedZfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen': -4.322503, 'OneTailedZfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen': -4.322503, 'OneTailedZfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen': -4.322503, 'OneTailedZfactor_DistCytoplasm_Math_Ratio1': 0.622059, 'OneTailedZfactor_DistCytoplasm_Math_Ratio2': -4.508284, 'OneTailedZfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1': -4.645887, 'OneTailedZfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1': -4.279118, 'OneTailedZfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1': -4.765570, 'OneTailedZfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1': -4.682335, 'OneTailedZfactor_DistCytoplasm_Texture_Variance_CorrGreen_1': -4.415607, 'OneTailedZfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen': -4.200105, 'OneTailedZfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen': -4.316452, 'OneTailedZfactor_DistanceCells_Intensity_MinIntensity_CorrGreen': -4.316452, 'OneTailedZfactor_DistanceCells_Texture_Correlation_CorrGreen_1': 0.202500, 'OneTailedZfactor_DistanceCells_Texture_Entropy_CorrGreen_1': -4.404815, 'OneTailedZfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1': -4.508513, 'OneTailedZfactor_DistanceCells_Texture_SumAverage_CorrGreen_1': -4.225356, 'OneTailedZfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1': -4.382768, 'OneTailedZfactor_DistanceCells_Texture_SumVariance_CorrGreen_1': 0.492125, 'OneTailedZfactor_DistanceCells_Texture_Variance_CorrGreen_1': 0.477360, 'OneTailedZfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue': 0.563780, 'OneTailedZfactor_Nuclei_Math_Ratio1': 0.622059, 'OneTailedZfactor_Nuclei_Math_Ratio2': -4.508284, 'OneTailedZfactor_Nuclei_Texture_SumAverage_CorrGreen_1': 0.426178, 'OneTailedZfactor_PropCells_AreaShape_Area': -4.216674, 'OneTailedZfactor_PropCells_AreaShape_MajorAxisLength': -4.119131, 'OneTailedZfactor_PropCells_AreaShape_MinorAxisLength': -4.109793, 'OneTailedZfactor_PropCells_AreaShape_Perimeter': -4.068050, 'OneTailedZfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue': 0.765440, 'OneTailedZfactor_PropCells_Texture_GaborX_CorrGreen_1': 0.114982, 'OneTailedZfactor_PropCells_Texture_InfoMeas2_CorrBlue_1': 0.108409, 'OneTailedZfactor_PropCells_Texture_SumVariance_CorrBlue_1': 0.191251, 'OneTailedZfactor_PropCells_Texture_SumVariance_CorrGreen_1': 0.559865, 'OneTailedZfactor_PropCells_Texture_Variance_CorrBlue_1': 0.254078, 'OneTailedZfactor_PropCells_Texture_Variance_CorrGreen_1': 0.556108, 'OneTailedZfactor_PropCytoplasm_AreaShape_Area': -4.223021, 'OneTailedZfactor_PropCytoplasm_AreaShape_MinorAxisLength': -4.095632, 'OneTailedZfactor_PropCytoplasm_AreaShape_Perimeter': -4.068050, 'OneTailedZfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen': -4.194663, 'OneTailedZfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1': -4.443338, 'OneTailedZfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1': 0.207265, 'OneTailedZfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1': -4.297250, 'OneTailedZfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1': -4.525324, 'OneTailedZfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1': 0.167795, 'OneTailedZfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1': 0.067560, 'OneTailedZfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1': 0.478527, 'OneTailedZfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1': 0.155119, 'OneTailedZfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1': 0.535907, 'OneTailedZfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1': 0.572801, 'OneTailedZfactor_ThresholdedCells_Texture_Variance_CorrBlue_1': 0.423454, 'OneTailedZfactor_ThresholdedCells_Texture_Variance_CorrGreen_1': 0.440500, 'Vfactor_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 0.500429, 'Vfactor_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 0.325675, 'Vfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen': 0.323524, 'Vfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen': 0.138487, 'Vfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen': 0.128157, 'Vfactor_DistCytoplasm_Math_Ratio1': 0.503610, 'Vfactor_DistCytoplasm_Math_Ratio2': 0.319610, 'Vfactor_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 0.522880, 'Vfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1': 0.504303, 'Vfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1': 0.289432, 'Vfactor_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1': 0.234123, 'Vfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1': 0.591687, 'Vfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1': 0.520356, 'Vfactor_DistCytoplasm_Texture_Variance_CorrGreen_1': -0.007649, 'Vfactor_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue': 0.761198, 'Vfactor_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen': 0.234655, 'Vfactor_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen': 0.252240, 'Vfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen': 0.195125, 'Vfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen': 0.138299, 'Vfactor_DistanceCells_Intensity_MinIntensity_CorrGreen': 0.126784, 'Vfactor_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1': 0.342691, 'Vfactor_DistanceCells_Texture_Correlation_CorrGreen_1': 0.314396, 'Vfactor_DistanceCells_Texture_Entropy_CorrGreen_1': 0.311771, 'Vfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1': 0.410631, 'Vfactor_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1': 0.170576, 'Vfactor_DistanceCells_Texture_SumAverage_CorrGreen_1': 0.223147, 'Vfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1': 0.269519, 'Vfactor_DistanceCells_Texture_SumVariance_CorrGreen_1': 0.571528, 'Vfactor_DistanceCells_Texture_Variance_CorrGreen_1': 0.566272, 'Vfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue': 0.705051, 'Vfactor_Nuclei_Math_Ratio1': 0.503610, 'Vfactor_Nuclei_Math_Ratio2': 0.319610, 'Vfactor_Nuclei_Texture_SumAverage_CorrGreen_1': 0.553708, 'Vfactor_PropCells_AreaShape_Area': 0.340093, 'Vfactor_PropCells_AreaShape_MajorAxisLength': 0.243838, 'Vfactor_PropCells_AreaShape_MinorAxisLength': 0.320691, 'Vfactor_PropCells_AreaShape_Perimeter': 0.238915, 'Vfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue': 0.723520, 'Vfactor_PropCells_Texture_GaborX_CorrGreen_1': 0.213161, 'Vfactor_PropCells_Texture_InfoMeas2_CorrBlue_1': 0.199791, 'Vfactor_PropCells_Texture_SumVariance_CorrBlue_1': 0.078959, 'Vfactor_PropCells_Texture_SumVariance_CorrGreen_1': 0.642844, 'Vfactor_PropCells_Texture_Variance_CorrBlue_1': 0.199105, 'Vfactor_PropCells_Texture_Variance_CorrGreen_1': 0.640818, 'Vfactor_PropCytoplasm_AreaShape_Area': 0.325845, 'Vfactor_PropCytoplasm_AreaShape_MinorAxisLength': 0.312258, 'Vfactor_PropCytoplasm_AreaShape_Perimeter': 0.238915, 'Vfactor_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 0.337565, 'Vfactor_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen': 0.292900, 'Vfactor_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 0.175528, 'Vfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen': 0.193308, 'Vfactor_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 0.276152, 'Vfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1': 0.239567, 'Vfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1': 0.332380, 'Vfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1': 0.379141, 'Vfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1': 0.337740, 'Vfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1': 0.334520, 'Vfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1': 0.192882, 'Vfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1': 0.276245, 'Vfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1': 0.139166, 'Vfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1': 0.465237, 'Vfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1': 0.355399, 'Vfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1': 0.453937, 'Vfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1': 0.564371, 'Vfactor_ThresholdedCells_Texture_Variance_CorrBlue_1': 0.360566, 'Vfactor_ThresholdedCells_Texture_Variance_CorrGreen_1': 0.548770, 'Zfactor_DistCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 0.531914, 'Zfactor_DistCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 0.265558, 'Zfactor_DistCytoplasm_Intensity_MedianIntensity_CorrGreen': 0.178586, 'Zfactor_DistCytoplasm_Intensity_MinIntensityEdge_CorrGreen': 0.084566, 'Zfactor_DistCytoplasm_Intensity_MinIntensity_CorrGreen': 0.086476, 'Zfactor_DistCytoplasm_Math_Ratio1': 0.623284, 'Zfactor_DistCytoplasm_Math_Ratio2': 0.358916, 'Zfactor_DistCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 0.429510, 'Zfactor_DistCytoplasm_Texture_Entropy_CorrGreen_1': 0.508275, 'Zfactor_DistCytoplasm_Texture_InfoMeas2_CorrGreen_1': 0.068695, 'Zfactor_DistCytoplasm_Texture_InverseDifferenceMoment_CorrGreen_1': 0.347949, 'Zfactor_DistCytoplasm_Texture_SumAverage_CorrGreen_1': 0.646576, 'Zfactor_DistCytoplasm_Texture_SumEntropy_CorrGreen_1': 0.494276, 'Zfactor_DistCytoplasm_Texture_Variance_CorrGreen_1': 0.179011, 'Zfactor_DistanceCells_Correlation_Correlation_CorrGreenCorrBlue': 0.824686, 'Zfactor_DistanceCells_Intensity_IntegratedIntensityEdge_CorrGreen': 0.027644, 'Zfactor_DistanceCells_Intensity_LowerQuartileIntensity_CorrGreen': 0.088491, 'Zfactor_DistanceCells_Intensity_MeanIntensityEdge_CorrGreen': 0.065056, 'Zfactor_DistanceCells_Intensity_MinIntensityEdge_CorrGreen': 0.089658, 'Zfactor_DistanceCells_Intensity_MinIntensity_CorrGreen': 0.078017, 'Zfactor_DistanceCells_Texture_AngularSecondMoment_CorrGreen_1': 0.238131, 'Zfactor_DistanceCells_Texture_Correlation_CorrGreen_1': 0.301107, 'Zfactor_DistanceCells_Texture_Entropy_CorrGreen_1': 0.251143, 'Zfactor_DistanceCells_Texture_InfoMeas1_CorrGreen_1': 0.564957, 'Zfactor_DistanceCells_Texture_InverseDifferenceMoment_CorrGreen_1': 0.302767, 'Zfactor_DistanceCells_Texture_SumAverage_CorrGreen_1': 0.036459, 'Zfactor_DistanceCells_Texture_SumEntropy_CorrGreen_1': 0.159798, 'Zfactor_DistanceCells_Texture_SumVariance_CorrGreen_1': 0.516938, 'Zfactor_DistanceCells_Texture_Variance_CorrGreen_1': 0.501186, 'Zfactor_Nuclei_Correlation_Correlation_CorrGreenCorrBlue': 0.691408, 'Zfactor_Nuclei_Math_Ratio1': 0.623284, 'Zfactor_Nuclei_Math_Ratio2': 0.358916, 'Zfactor_Nuclei_Texture_SumAverage_CorrGreen_1': 0.587347, 'Zfactor_PropCells_AreaShape_Area': 0.132425, 'Zfactor_PropCells_AreaShape_MajorAxisLength': 0.034809, 'Zfactor_PropCells_AreaShape_MinorAxisLength': 0.113864, 'Zfactor_PropCells_AreaShape_Perimeter': 0.005984, 'Zfactor_PropCells_Correlation_Correlation_CorrGreenCorrBlue': 0.717632, 'Zfactor_PropCells_Texture_GaborX_CorrGreen_1': 0.251023, 'Zfactor_PropCells_Texture_InfoMeas2_CorrBlue_1': 0.149719, 'Zfactor_PropCells_Texture_SumVariance_CorrBlue_1': 0.102050, 'Zfactor_PropCells_Texture_SumVariance_CorrGreen_1': 0.611960, 'Zfactor_PropCells_Texture_Variance_CorrBlue_1': 0.197090, 'Zfactor_PropCells_Texture_Variance_CorrGreen_1': 0.614879, 'Zfactor_PropCytoplasm_AreaShape_Area': 0.205042, 'Zfactor_PropCytoplasm_AreaShape_MinorAxisLength': 0.072682, 'Zfactor_PropCytoplasm_AreaShape_Perimeter': 0.005984, 'Zfactor_PropCytoplasm_Correlation_Correlation_CorrGreenCorrBlue': 0.272017, 'Zfactor_PropCytoplasm_Intensity_IntegratedIntensity_CorrGreen': 0.115327, 'Zfactor_PropCytoplasm_Intensity_LowerQuartileIntensity_CorrGreen': 0.141850, 'Zfactor_PropCytoplasm_Intensity_MedianIntensity_CorrGreen': 0.105803, 'Zfactor_PropCytoplasm_Texture_AngularSecondMoment_CorrGreen_1': 0.107640, 'Zfactor_PropCytoplasm_Texture_Entropy_CorrGreen_1': 0.067896, 'Zfactor_PropCytoplasm_Texture_GaborX_CorrGreen_1': 0.136688, 'Zfactor_PropCytoplasm_Texture_InfoMeas2_CorrGreen_1': 0.334749, 'Zfactor_PropCytoplasm_Texture_SumEntropy_CorrGreen_1': 0.208829, 'Zfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrBlue_1': 0.263467, 'Zfactor_ThresholdedCells_Texture_AngularSecondMoment_CorrGreen_1': 0.124355, 'Zfactor_ThresholdedCells_Texture_Entropy_CorrBlue_1': 0.236433, 'Zfactor_ThresholdedCells_Texture_InfoMeas2_CorrBlue_1': 0.125845, 'Zfactor_ThresholdedCells_Texture_SumAverage_CorrBlue_1': 0.449333, 'Zfactor_ThresholdedCells_Texture_SumEntropy_CorrBlue_1': 0.323243, 'Zfactor_ThresholdedCells_Texture_SumVariance_CorrBlue_1': 0.507477, 'Zfactor_ThresholdedCells_Texture_SumVariance_CorrGreen_1': 0.599000, 'Zfactor_ThresholdedCells_Texture_Variance_CorrBlue_1': 0.361424, 'Zfactor_ThresholdedCells_Texture_Variance_CorrGreen_1': 0.481393 } temp_dir = tempfile.mkdtemp() try: cpprefs.set_headless() cpprefs.set_default_output_directory(temp_dir) print "Writing output to %s" % temp_dir path = os.path.split(__file__)[0] measurements = loadmat(os.path.join(path, 'calculatestatistics.mat'), struct_as_record=True) measurements = measurements['m'] image_set_list = cpi.ImageSetList() image_set = image_set_list.get_image_set(0) m = cpmeas.Measurements() doses = [ 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 ] for i, dose in enumerate(doses): m.add_image_measurement("Dose", dose) for object_name in measurements.dtype.fields: omeasurements = measurements[object_name][0, 0] for feature_name in omeasurements.dtype.fields: data = omeasurements[feature_name][0, 0][0, i] m.add_measurement(object_name, feature_name, data) if i < len(doses) - 1: m.next_image_set() pipeline = cpp.Pipeline() module = C.CalculateStatistics() module.grouping_values.value = "Dose" module.dose_values[0].log_transform.value = False module.dose_values[0].measurement.value = "Dose" module.dose_values[0].wants_save_figure.value = True module.dose_values[0].figure_name.value = "EC49_" module.module_num = 1 pipeline.add_module(module) def callback(caller, event): self.assertFalse(isinstance(event, cpp.RunExceptionEvent)) workspace = cpw.Workspace(pipeline, module, image_set, cpo.ObjectSet(), m, image_set_list) module.post_run(workspace) for feature_name in m.get_feature_names(cpmeas.EXPERIMENT): if not expected.has_key(feature_name): print "Missing measurement: %s" % feature_name continue value = m.get_experiment_measurement(feature_name) e_value = expected[feature_name] diff = abs(value - e_value) * 2 / abs(value + e_value) self.assertTrue( diff < .05, "%s: Matlab: %f, Python: %f diff: %f" % (feature_name, e_value, value, diff)) if diff > .01: print( "Warning: > 1%% difference for %s: Matlab: %f, Python: %f diff: %f" % (feature_name, e_value, value, diff)) if feature_name.startswith("EC50"): filename = "EC49_" + feature_name[5:] + ".pdf" self.assertTrue( os.path.isfile(os.path.join(temp_dir, filename))) finally: try: workspace.measurements.hdf5_dict.hdf5_file.close() except: pass for filename in os.listdir(temp_dir): path = os.path.join(temp_dir, filename) os.remove(path) os.rmdir(temp_dir)
def main(args): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if any([arg.startswith('--work-announce') for arg in args]): # # Go headless ASAP # import cellprofiler.preferences as cpprefs cpprefs.set_headless() import cellprofiler.analysis_worker cellprofiler.analysis_worker.main() sys.exit(0) options, args = parse_args(args) set_log_level(options) if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.run_ilastik: run_ilastik() return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if (not hasattr(sys, 'frozen')) and options.fetch_external_dependencies: import external_dependencies external_dependencies.fetch_external_dependencies( options.overwrite_external_dependencies) if (not hasattr(sys, 'frozen')) and options.build_extensions: build_extensions() if options.build_and_exit: return if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return try: if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.cellprofilerapp import CellProfilerApp show_splashbox = (options.pipeline_filename is None and options.workspace_filename is None and (not options.new_workspace) and options.show_splashbox) if options.workspace_filename: workspace_path = os.path.expanduser(options.workspace_filename) elif options.new_workspace: workspace_path = False else: workspace_path = None App = CellProfilerApp( 0, check_for_new_version=(options.pipeline_filename is None), show_splashbox=show_splashbox, workspace_path=workspace_path) # # Important to go headless ASAP # # cellprofiler.preferences can't be imported before we have a chance # to initialize the wx app. # import cellprofiler.preferences as cpprefs if not options.show_gui: cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory) if options.temp_dir is not None: cpprefs.set_temporary_directory(options.temp_dir) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file, False) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: import cellprofiler.gui.cpframe as cpgframe if options.pipeline_filename: pipeline_path = os.path.expanduser(options.pipeline_filename) try: App.frame.pipeline.load(pipeline_path) if options.run_pipeline: App.frame.Command(cpgframe.ID_FILE_ANALYZE_IMAGES) except: import wx wx.MessageBox( 'CellProfiler was unable to load the pipeline file, "%s"' % options.pipeline_filename, "Error loading pipeline", style=wx.OK | wx.ICON_ERROR) logging.root.error("Unable to load pipeline", exc_info=True) App.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) raise
def main(args=None): '''Run CellProfiler args - command-line arguments, e.g. sys.argv ''' if args is None: args = sys.argv import cellprofiler.preferences as cpprefs cpprefs.set_awt_headless(True) exit_code = 0 switches = ('--work-announce', '--knime-bridge-address') if any( [any([arg.startswith(switch) for switch in switches]) for arg in args]): # # Go headless ASAP # cpprefs.set_headless() for i, arg in enumerate(args): if arg == "--ij-plugins-directory" and len(args) > i + 1: cpprefs.set_ij_plugin_directory(args[i + 1]) break import cellprofiler.worker cellprofiler.worker.aw_parse_args() cellprofiler.worker.main() sys.exit(exit_code) options, args = parse_args(args) if options.print_version: from cellprofiler.utilities.version import \ dotted_version, version_string, git_hash, version_number print "CellProfiler %s" % dotted_version print "Git %s" % git_hash print "Version %s" % version_number print "Built %s" % version_string.split(" ")[0] sys.exit(exit_code) # # Important to go headless ASAP # if (not options.show_gui) or options.write_schema_and_exit: import cellprofiler.preferences as cpprefs cpprefs.set_headless() # What's there to do but run if you're running headless? # Might want to change later if there's some headless setup options.run_pipeline = True if options.jvm_heap_size is not None: from cellprofiler.preferences import set_jvm_heap_mb set_jvm_heap_mb(options.jvm_heap_size, False) set_log_level(options) if options.print_groups_file is not None: print_groups(options.print_groups_file) return if options.batch_commands_file is not None: get_batch_commands(options.batch_commands_file) return if options.add_message_for_user: if len(args) != 3: sys.stderr.write("Usage: (for add_message-for-user)\n") sys.stderr.write( "CellProfiler --add-message-for-user <caption> <message> <pipeline-or-project>\n" ) sys.stderr.write("where:\n") sys.stderr.write(" <caption> - the message box caption\n") sys.stderr.write( " <message> - the message displayed inside the message box\n" ) sys.stderr.write( " <pipeline-or-project> - the path to the pipeline or project file to modify\n" ) return caption = args[0] message = args[1] path = args[2] import h5py using_hdf5 = h5py.is_hdf5(path) if using_hdf5: import cellprofiler.measurement as cpmeas m = cpmeas.Measurements(filename=path, mode="r+") pipeline_text = m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] else: with open(path, "r") as fd: pipeline_text = fd.read() header, body = pipeline_text.split("\n\n", 1) pipeline_text = header + \ ("\nMessageForUser:%s|%s\n\n" % (caption, message)) + body if using_hdf5: m[cpmeas.EXPERIMENT, "Pipeline_Pipeline"] = pipeline_text m.close() else: with open(path, "w") as fd: fd.write(pipeline_text) print "Message added to %s" % path return # necessary to prevent matplotlib trying to use Tkinter as its backend. # has to be done before CellProfilerApp is imported from matplotlib import use as mpluse mpluse('WXAgg') if options.omero_credentials is not None: set_omero_credentials_from_string(options.omero_credentials) if options.plugins_directory is not None: cpprefs.set_plugin_directory(options.plugins_directory, globally=False) if options.ij_plugins_directory is not None: cpprefs.set_ij_plugin_directory(options.ij_plugins_directory, globally=False) if options.temp_dir is not None: if not os.path.exists(options.temp_dir): os.makedirs(options.temp_dir) cpprefs.set_temporary_directory(options.temp_dir, globally=False) if not options.allow_schema_write: cpprefs.set_allow_schema_write(False) # # After the crucial preferences are established, we can start the VM # from cellprofiler.utilities.cpjvm import cp_start_vm cp_start_vm() # # Not so crucial preferences... # if options.image_set_file is not None: cpprefs.set_image_set_file(options.image_set_file) try: # --------------------------------------- # # Handle command-line tasks that that need to load the modules to run # if options.output_html: from cellprofiler.gui.html.manual import generate_html webpage_path = options.output_directory if options.output_directory else None generate_html(webpage_path) return if options.print_measurements: print_measurements(options) return if not hasattr(sys, "frozen") and options.code_statistics: print_code_statistics() return if options.write_schema_and_exit: write_schema(options.pipeline_filename) return # # ------------------------------------------ if options.show_gui: import wx wx.Log.EnableLogging(False) from cellprofiler.gui.app import App from cellprofiler.workspace import is_workspace_file if options.pipeline_filename: if is_workspace_file(options.pipeline_filename): workspace_path = os.path.expanduser( options.pipeline_filename) pipeline_path = None else: pipeline_path = os.path.expanduser( options.pipeline_filename) workspace_path = None elif options.new_project: workspace_path = False pipeline_path = None else: workspace_path = None pipeline_path = None app = App(0, workspace_path=workspace_path, pipeline_path=pipeline_path) if options.data_file is not None: cpprefs.set_data_file(os.path.abspath(options.data_file)) from cellprofiler.utilities.version import version_string, version_number logging.root.info("Version: %s / %d" % (version_string, version_number)) if options.run_pipeline and not options.pipeline_filename: raise ValueError("You must specify a pipeline filename to run") if options.output_directory: if not os.path.exists(options.output_directory): os.makedirs(options.output_directory) cpprefs.set_default_output_directory(options.output_directory) if options.image_directory: cpprefs.set_default_image_directory(options.image_directory) if options.show_gui: if options.run_pipeline: app.frame.pipeline_controller.do_analyze_images() app.MainLoop() return elif options.run_pipeline: run_pipeline_headless(options, args) except Exception, e: logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True) exit_code = -1
self.classifier_cache[classifier_name] = algorithm else: algorithm = self.classifier_cache[classifier_name] return algorithm.predict_proba(sample) def run_pipeline(self, filter_bank_name, classifier_name, sample): filtered = self.use_filter_bank(filter_bank_name, sample) return self.predict_proba(classifier_name, filtered) def config_final_pipeline(self, filter_bank_name, classifier_name): self.root.attrs["FilterBankName"] = filter_bank_name self.root.attrs["ClassifierName"] = classifier_name def run_final_pipeline(self, sample): return self.run_pipeline(self.root.attrs["FilterBankName"], self.root.attrs["ClassifierName"], sample) if __name__ == "__main__": logging.basicConfig() logging.root.setLevel(logging.DEBUG) import cellprofiler.pipeline as cpp import cellprofiler.preferences as cpprefs cpprefs.set_default_output_directory("c:/temp/output/classify") pipeline = cpp.Pipeline() pipeline.load("c:/temp/output/classify/classify.cpproj") module = pipeline.modules()[-1] module.post_group(None, None) from cellprofiler.utilities.cpjvm import cp_stop_vm cp_stop_vm()