def test_load_v3(): with open("./tests/resources/modules/measurecolocalization/v3.pipeline", "r") as fd: data = fd.read() fd = six.moves.StringIO(data) pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(fd) assert len(pipeline.modules()) == 1 module = pipeline.modules()[-1] assert (module.images_or_objects.value == cellprofiler.modules.measurecolocalization.M_IMAGES_AND_OBJECTS) assert module.image_count.value == 2 assert module.thr == 25.0 for name in [x.image_name.value for x in module.image_groups]: assert name in ["DNA", "Cytoplasm"] assert module.object_count.value == 2 for name in [x.object_name.value for x in module.object_groups]: assert name in ["Nuclei", "Cells"]
def test_load_v2(): data = """CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:10479 IdentifyDeadWorms:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D] Input image:BinaryWorms Objects name:DeadWorms Worm width:6 Worm length:114 Number of angles:180 Automatically calculate distance parameters?:No Spatial distance:6 Angular distance:45 """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.identifydeadworms.IdentifyDeadWorms) assert module.image_name == "BinaryWorms" assert module.object_name == "DeadWorms" assert module.worm_width == 6 assert module.worm_length == 114 assert module.angle_count == 180 assert not module.wants_automatic_distance assert module.space_distance == 6 assert module.angular_distance == 45
def write_schema(pipeline_filename): if pipeline_filename is None: raise ValueError( "The --write-schema-and-exit switch must be used in conjunction\nwith the -p or --pipeline switch to load a pipeline with an\n" "ExportToDatabase module.") pipeline = cellprofiler.pipeline.Pipeline() pipeline.load(pipeline_filename) pipeline.turn_off_batch_mode() for module in pipeline.modules(): if module.module_name == "ExportToDatabase": break else: raise ValueError( "The pipeline, \"%s\", does not have an ExportToDatabase module" % pipeline_filename) m = cellprofiler.measurement.Measurements() workspace = cellprofiler.workspace.Workspace(pipeline, module, m, cellprofiler.object.ObjectSet, m, None) module.prepare_run(workspace)
def test_load_v3(): with open("./tests/resources/modules/align/v3.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 3 for module, crop_method in zip( pipeline.modules(), ( cellprofiler.modules.align.C_SAME_SIZE, cellprofiler.modules.align.C_CROP, cellprofiler.modules.align.C_PAD, ), ): assert isinstance(module, cellprofiler.modules.align.Align) assert (module.alignment_method == cellprofiler.modules.align.M_MUTUAL_INFORMATION) assert module.crop_mode == crop_method assert module.first_input_image == "Image1" assert module.second_input_image == "Image2" assert module.first_output_image, "AlignedImage1" assert module.second_output_image, "AlignedImage2"
def test_load_v1(): with open("./tests/resources/modules/labelimages/v1.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 2 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.labelimages.LabelImages) assert module.site_count == 3 assert module.row_count == 32 assert module.column_count == 48 assert module.order == cellprofiler.modules.labelimages.O_COLUMN module = pipeline.modules()[1] assert isinstance(module, cellprofiler.modules.labelimages.LabelImages) assert module.site_count == 1 assert module.row_count == 8 assert module.column_count == 12 assert module.order == cellprofiler.modules.labelimages.O_ROW
def set_file_chooser_path(self, path): file_names = [] for file_name in os.listdir(path): ext = os.path.splitext(file_name)[1].lower() if len(ext) > 0 and ext[1:] in cellprofiler.preferences.EXT_PIPELINE_CHOICES: file_names.append(file_name) self.file_chooser.DeleteAllItems() module_count = [None] def on_pipeline_event(caller, event): if isinstance(event, cellprofiler.pipeline.LoadExceptionEvent): module_count[0] = None elif isinstance(event, cellprofiler.pipeline.PipelineLoadedEvent): module_count[0] = len(caller.modules()) pipeline = cellprofiler.pipeline.Pipeline() pipeline.add_listener(on_pipeline_event) for file_name in file_names: file_path = os.path.join(path, file_name) mtime = os.path.getmtime(file_path) mtime = datetime.datetime.fromtimestamp(mtime) mtime = mtime.ctime() pipeline.load(file_path) if module_count[0] is not None: index = self.file_chooser.InsertStringItem( sys.maxint, file_name) self.file_chooser.SetStringItem(index, FC_DATE_COLUMN, mtime) self.file_chooser.SetStringItem(index, FC_MODULE_COUNT_COLUMN, str(module_count[0])) self.file_chooser.SetColumnWidth(FC_FILENAME_COLUMN, wx.LIST_AUTOSIZE) self.file_chooser.SetColumnWidth(FC_DATE_COLUMN, wx.LIST_AUTOSIZE)
def set_file_chooser_path(self, path): file_names = [] for file_name in os.listdir(path): ext = os.path.splitext(file_name)[1].lower() if len(ext) > 0 and ext[ 1:] in cellprofiler.preferences.EXT_PIPELINE_CHOICES: file_names.append(file_name) self.file_chooser.DeleteAllItems() module_count = [None] def on_pipeline_event(caller, event): if isinstance(event, cellprofiler.pipeline.LoadExceptionEvent): module_count[0] = None elif isinstance(event, cellprofiler.pipeline.PipelineLoadedEvent): module_count[0] = len(caller.modules()) pipeline = cellprofiler.pipeline.Pipeline() pipeline.add_listener(on_pipeline_event) for file_name in file_names: file_path = os.path.join(path, file_name) mtime = os.path.getmtime(file_path) mtime = datetime.datetime.fromtimestamp(mtime) mtime = mtime.ctime() pipeline.load(file_path) if module_count[0] is not None: index = self.file_chooser.InsertStringItem( sys.maxint, file_name) self.file_chooser.SetStringItem(index, FC_DATE_COLUMN, mtime) self.file_chooser.SetStringItem(index, FC_MODULE_COUNT_COLUMN, str(module_count[0])) self.file_chooser.SetColumnWidth(FC_FILENAME_COLUMN, wx.LIST_AUTOSIZE) self.file_chooser.SetColumnWidth(FC_DATE_COLUMN, wx.LIST_AUTOSIZE)
def test_01_03_load_v3(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:9524 LoadSingleImage:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D] Folder containing the image file:Default Input Folder\x7CNone Filename of the image to load (Include the extension, e.g., .tif):foo.tif Name the image that will be loaded:DNA Filename of the image to load (Include the extension, e.g., .tif):bar.tif Name the image that will be loaded:Cytoplasm """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse( isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue( isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage)) self.assertEqual(len(module.file_settings), 2) fs = module.file_settings[0] self.assertEqual(fs.file_name, "foo.tif") self.assertEqual(fs.image_name, "DNA") fs = module.file_settings[1] self.assertEqual(fs.file_name, "bar.tif") self.assertEqual(fs.image_name, "Cytoplasm") self.assertTrue(fs.rescale)
def test_load_v6(): with open("./tests/resources/modules/loaddata/v6.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(io.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.loaddata.LoadData) assert module.csv_file_name == "1049_Metadata.csv" assert module.csv_directory.dir_choice == cellprofiler.setting.ABSOLUTE_FOLDER_NAME assert (module.csv_directory.custom_path == r"x:\projects\NightlyBuild\trunk\ExampleImages\ExampleSBSImages") assert module.wants_images assert (module.image_directory.dir_choice == cellprofiler.setting.DEFAULT_INPUT_FOLDER_NAME) assert module.rescale assert module.wants_image_groupings assert not module.wants_rows assert module.row_range.min == 1 assert module.row_range.max == 100000 assert len(module.metadata_fields.selections) == 2 assert module.metadata_fields.selections[0] == "Column" assert module.metadata_fields.selections[1] == "Row"
def test_load_v4(): with open("./tests/resources/modules/loaddata/v4.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(io.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.loaddata.LoadData) assert module.csv_file_name == "1049_Metadata.csv" assert (module.csv_directory.dir_choice == cellprofiler.setting.DEFAULT_INPUT_FOLDER_NAME) assert module.wants_images assert module.rescale assert not module.wants_image_groupings assert not module.wants_rows assert module.row_range.min == 10 assert module.row_range.max == 36 assert len(module.metadata_fields.selections) == 1 assert module.metadata_fields.selections[0] == "Well"
def test_load_v1(): data = ('eJztWNFO2zAUdUqBsUkr28v26Ee60aotQ4NqKu0oEtUIVLRiQohtpnXba' 'EkcOQlrNyHtcZ+0x33OHvcJs4NDUhMIbccmpqay2nt9zz3Xx0lsV600dy' 'qv4Wo2B9VKM9PRdAzrOnI6hBpFaDrLcJNi5OA2JGYRqsSEKhrAfB7mV4o' 'rheLqOizkcutgvEupqQ/Z19pjAObY9z3WEqJrVthKqHG7gR1HM7v2LEiC' 'p8L/g7UDRDV0ouMDpLvYDih8f83skObAuuhSSdvV8S4ywsHs2nWNE0ztv' 'Y4PFN11rY/1hvYZS0Pww/bxqWZrxBR4kV/2XvASR+LlOnyfD3RQJB24Lq' 'mQn8dvgyA+GaHbo1D8orA1s62dam0X6VAzUPeiCm8eYvLNS/m4rQ5qPI2' 'HL8fgFyU8b03cdzJbfdRyoIGcVu8meVJSnpRXx5bZQ2YLt4N6cjF5lKE8' 'CliZQAfBfiMd7kt4blcJNIkDXRsH8xFXf2IoTwLkX46H2yWXcXMSzr983' 'AII6oy7D59I4+V2FXeQqzvQmy1Y1ShuOYQOJqrjX+Kixj0zNO4ZcMietr' 'vK9zdwk75/bktX+T2R/4P6RPElh/iS7Pk08SR8X2P43oBhXbn9bmmj/op' 'vBHAp+zz9nltvsa7vk0+lo0qmfpz2PZtEdw2zdJTLrB9/yS8Xzs6DGxpD' 'es505LhHqb8XU/+aVD+3eQ2HGFFR2IuzdIa72AbG6QlfQfiqaBB4Jqnz5' '9xo6/e4POUYPaLWF2+x71LiWrfPH7XOB/yQbUGwdZfeS1PcFPc/4soh3P' 'Q5nuJGxS0qV6938jmDx38A199vz8Dw/cbtFttiWJTw/yVo1vAOz3ZWJ6h' '9fnrN7rCftdBBlvP0Y3i2JZ7tq3jw+aGOUNu1LIpt27Zw6yPvEce9PdoQ' 'PQ3RI+u5EMEf1iXBPqnk9fMg6x/My6+NcfgSymW+BzG4pFCS476B0eZ96' 'Zp4f2zjxv8G/FcCeg==') pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(zlib.decompress(base64.b64decode(data)))) assert len(pipeline.modules()) == 2 module = pipeline.modules()[1] assert module.module_name == 'EnhanceOrSuppressFeatures' assert module.x_name.value == 'MyImage' assert module.y_name.value == 'MyEnhancedImage' assert module.method.value == cellprofiler.modules.enhanceorsuppressfeatures.ENHANCE assert module.object_size == 17
def test_01_04_load_v4(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:9524 LoadSingleImage:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D] Folder containing the image file:Default Input Folder\x7CNone Filename of the image to load (Include the extension, e.g., .tif):foo.tif Name the image that will be loaded:DNA Rescale image?:No Filename of the image to load (Include the extension, e.g., .tif):bar.tif Name the image that will be loaded:Cytoplasm Rescale image?:Yes """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage)) self.assertEqual(len(module.file_settings), 2) fs = module.file_settings[0] self.assertEqual(fs.file_name, "foo.tif") self.assertEqual(fs.image_objects_choice, cellprofiler.modules.loadsingleimage.IO_IMAGES) self.assertEqual(fs.image_name, "DNA") self.assertFalse(fs.rescale) fs = module.file_settings[1] self.assertEqual(fs.file_name, "bar.tif") self.assertEqual(fs.image_name, "Cytoplasm") self.assertTrue(fs.rescale)
def test_01_02_load_v1(self): data = ('eJztWF9v0zAQd7vuH0ioiAd4tPayFdYo7TZpq9C2siJRWEu1VWPTNMBdndZS' 'EleJM1bQJB75WHykfQTsLmkSE5a03RBITRWld7nf/e7OzsVOrdzcL7+CG4oK' 'a+VmXiM6hg0dMY1aRgmabBXuWRgx3IbULMFm14FvHR0W12Bho1TcLBXWYVFV' 't8B4R6pae8Qv8AkAc/y6wM+0e2vWlVOBU8iHmDFiduxZkAHPXP1Pfh4hi6CW' 'jo+Q7mDbp/D0VVOjzX5veKtG246O68gIGvOj7hgtbNnvNQ/o3m6QS6wfkq9Y' 'SsEzO8AXxCbUdPGuf1k75KVM4hV1aCz4dUhJdRB1yQb0wv4N8O0zEXV7HLDP' 'ujIx2+SCtB2kQ2KgzjAK4U+N8TcT8jcDKvXyALcbg8uCcBzibOJLln99ic4Z' 'NBA77ybx80DyI+QDbPNBaYtQEueRCvlJgTUXdxyDW5b4l4f8sNWHCGo8G2pB' 'qkHWxZBapENMXmdhkKhOUflVKDQpg46Nk+eXCfnJAFUpbiTBpUO4NKjT8eZF' 'QVUTzc+nUr5CrmANOTqDVTE5YYVYWNS0P1EcQdychPMOD7cI/DrvxvBFzes6' 'Rha2Gaxj0um2qDVO3Cf8qZwk7n+NL8m8GoVvM4ZvDoTHRch7OjVFs/ubdfX6' '433xyX2sEIG7Sz65r9R5SSfh+x7D9w6Ex1HIH1d2Gi/FAgVvKy9yn4T0Aev6' 'Af2yfVrON85ynmaP6o5hbp+q+a2zb4XV4tWN8SHhyIEyF5n3KPF3Y+LflOIX' 'sojhhPcIN7D1q1xeqGrUZF1XV3R1FdT3NZPEeTw/2rrivvpl1PttsAjpWNTp' '3T9/VL/2+SFfGuHeXT0/U9wUN8X9H7jdAG7aN6a4UXHXAZz8fpXXv8L+M7h9' 'vj0H4fkm5HO+pOlZVHyfsRRj8BHBVnSK2je7eGWf/60GNvRJ9rNLEs/Sn3is' 'wSZXudnrRtdrMcJ/MO80/2Xnb6+zXF+/7tc74/DNpH7nexiDy7iVErgfYLRx' 'XbnF3sttXPtf+3UFIg==') pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(zlib.decompress(base64.b64decode(data)))) self.assertEqual(len(pipeline.modules()), 2) module = pipeline.modules()[1] self.assertEqual(module.x_name, 'DNA') self.assertEqual(module.y_name, 'ResizedDNA') self.assertEqual(module.size_method, cellprofiler.modules.resize.R_BY_FACTOR) self.assertAlmostEqual(module.resizing_factor.value, .25) self.assertEqual(module.interpolation, cellprofiler.modules.resize.I_NEAREST_NEIGHBOR)
def test_01_02_load_v2(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20120209212234 ModuleCount:1 HasImagePlaneDetails:False Images:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)] :{"ShowFiltered"\x3A false} Filter choice:%s Filter:or (directory does startwith "foo") (file does contain "bar") """ for fc, fctext in ((cellprofiler.modules.images.FILTER_CHOICE_CUSTOM, "Custom"), (cellprofiler.modules.images.FILTER_CHOICE_IMAGES, "Images only"), (cellprofiler.modules.images.FILTER_CHOICE_NONE, "No filtering")): pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(cStringIO.StringIO(data % fctext)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.images.Images)) self.assertEqual(module.filter_choice, fc) self.assertEqual(module.filter.value, 'or (directory does startwith "foo") (file does contain "bar")')
def test_01_02_load_v2(self): data = ('eJztVd1KwzAUTuv82QTxTi9zJV5oycTf3eimiAM3xQ3RK4lbOgJpM9J0bD6B' 'j+Jj+Cg+go9gMtKtrWOdeiPogZCc5PvOyfk4bWrl5mW5AvccBGvl5rZLGYHX' 'DEuXC68EfbkFTwXBkrQh90vwXFBYDjsQHcDifqmISmgX7iB0BL5nVrW2oqa3' 'RQAW1Lykhm2O5o1vxYb2G0RK6neCeZAD62b/VY1bLCh+ZOQWs5AE4xTRftV3' 'eXPQHR3VeDtkpI69OFhZPfQeiQiu3Ihojq9pn7AGfSKpEiLYDenRgHLf8E38' '9O4oL5epvFqHF3usgzVBh0JsX+MvwBifm4Bfi+FXjX9GXBwyCase7hB4RgVp' 'SS4Gw3goI56ViGcBx9zjMIO3BJL30H4R7R45raA3S965BH8O3CvtflP9WTw7' 'wbNBnf9At60i0vYT3U4yePlUXu03Ko2HNg9GXavj3H2xX+P3XUjhI4vw+X/e' 'n+c9g+n9Ff8eh/0Ipvf1Bkj2tfZbhLGu4PrdE443/DkHDuO4LUlfOpdq0VSL' 'z3XkJ8SP38dWq0JG/em6x3q8H38nnz0h33IGL2de3LR+s+i9OQUPUvgPhsiG' 'ig==') pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(zlib.decompress(base64.b64decode(data)))) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.loaddata.LoadText)) self.assertEqual(module.csv_file_name, "1049.csv") self.assertTrue(module.wants_images.value) self.assertTrue(module.wants_image_groupings.value) self.assertEqual(len(module.metadata_fields.selections), 1) self.assertEqual(module.metadata_fields.selections[0], "SBS_doses") self.assertEqual(module.image_directory.dir_choice, cellprofiler.setting.DEFAULT_INPUT_FOLDER_NAME) self.assertFalse(module.wants_rows.value)
def test_01_04_load_v4(self): data = """CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20141015195823 GitHash:051040e ModuleCount:1 HasImagePlaneDetails:False MeasureImageOverlap:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:4|show_window:False|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False] Compare segmented objects, or foreground/background?:Foreground/background segmentation Select the image to be used as the ground truth basis for calculating the amount of overlap:Foo Select the image to be used to test for overlap:Bar Select the objects to be used as the ground truth basis for calculating the amount of overlap:Cell2_0 Select the objects to be tested for overlap against the ground truth:Cell2_1 Calculate earth mover\'s distance?:Yes Maximum # of points:101 Point selection method:Skeleton Maximum distance:102 Penalize missing pixels:Yes """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.measureimageoverlap.MeasureImageOverlap)) self.assertEqual(module.ground_truth, "Foo") self.assertEqual(module.test_img, "Bar")
def test_01_03_load_v3(self): data = ('eJztVUtPg0AQXihtfCTGgwePezIelICv2F5MqzE2kWqE+Dhu28WSLGwDS338' 'An+CP9Of4FKX8pAUbT2Y6AQyO7PzzTczLGA0rfNmC+6rGjSa1rbtEAwvCWI2' '9d0G9NgWPPYxYrgPqdeAN1yf4B7UD/jV0Hcbe/twR9PqYDaR2sYKV68LANS4' '5grIYqsqbCl1R7aJGXO8+6AKFLAu/G/8vka+g7oEXyMS4iChiP1tz6bW03Cy' 'ZdB+SHAHuelgLp3Q7WI/uLBjoNi+dB4xMZ1nnGshDrvCIydwqCfwIn/eO+Gl' 'LMdrDujDqc/LyeVvIdYbmIw/gax/PDc5mZtUMLellD+KPwNJvFIQv5aKXxX2' 'CbZRSBhse8OQwVNK+tiP82kl+aRMPgmoAndYglsA2ToiW9f26movGH2Ft5LB' 'V8Adn/Vv6r8MJ2dwMujQOea2pWuRzMObxtVyuFhi3KLQEe72m+dzVp5/3N/E' 'vYDp5yv9/o3PI5h+/jdA9v2J7B4mZOjT6L/oq+744x2ohKI+w49MPecLiy8+' '97FYkD9dj8xXSyX95/tO5vF2NAtfpYBvuQSniD9yfn5fmffmlHhQEP/dfqQf' 'qCvhUSY1feT/kHfzN4ip') pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(zlib.decompress(base64.b64decode(data)))) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.loaddata.LoadText)) self.assertEqual(module.csv_file_name, "1049.csv") self.assertTrue(module.wants_images.value) self.assertFalse(module.wants_image_groupings.value)
def test_01_03_load_v3(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20131210175632 GitHash:63ec479 ModuleCount:1 HasImagePlaneDetails:False MeasureImageOverlap:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:3|show_window:False|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True] Compare segmented objects, or foreground/background?:Foreground/background segmentation Select the image to be used as the ground truth basis for calculating the amount of overlap:Foo Select the image to be used to test for overlap:Bar Select the objects to be used as the ground truth basis for calculating the amount of overlap:Cell2_0 Select the objects to be tested for overlap against the ground truth:Cell2_1 """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse( isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) module = pipeline.modules()[0] self.assertTrue( isinstance( module, cellprofiler.modules.measureimageoverlap.MeasureImageOverlap)) self.assertEqual(module.ground_truth, "Foo") self.assertEqual(module.test_img, "Bar") # self.assertEqual(module.object_name_GT, "Cell2_0") # self.assertEqual(module.object_name_ID, "Cell2_1") self.assertFalse(module.wants_emd)
def test_load_v5(): data = r'''CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20150414135713 GitHash:3bad577 ModuleCount:2 HasImagePlaneDetails:False EnhanceOrSuppressFeatures:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:5|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False] Select the input image:Dendrite Name the output image:EnhancedDendrite Select the operation:Enhance Feature size:10 Feature type:Neurites Range of hole sizes:1,10 Smoothing scale:2.0 Shear angle:0 Decay:0.95 Enhancement method:Tubeness Speed and accuracy:Slow / circular EnhanceOrSuppressFeatures:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:5|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False] Select the input image:Axon Name the output image:EnhancedAxon Select the operation:Enhance Feature size:10 Feature type:Neurites Range of hole sizes:1,10 Smoothing scale:2.0 Shear angle:0 Decay:0.95 Enhancement method:Line structures Speed and accuracy:Fast / hexagonal ''' pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) assert len(pipeline.modules()) == 2 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.enhanceorsuppressfeatures.EnhanceOrSuppressFeatures) assert module.x_name == "Dendrite" assert module.y_name == "EnhancedDendrite" assert module.method == cellprofiler.modules.enhanceorsuppressfeatures.ENHANCE assert module.enhance_method == cellprofiler.modules.enhanceorsuppressfeatures.E_NEURITES assert module.smoothing == 2.0 assert module.object_size == 10 assert module.hole_size.min == 1 assert module.hole_size.max == 10 assert module.angle == 0 assert module.decay == .95 assert module.neurite_choice == cellprofiler.modules.enhanceorsuppressfeatures.N_TUBENESS assert module.speckle_accuracy == cellprofiler.modules.enhanceorsuppressfeatures.S_SLOW module = pipeline.modules()[1] assert isinstance(module, cellprofiler.modules.enhanceorsuppressfeatures.EnhanceOrSuppressFeatures) assert module.speckle_accuracy == cellprofiler.modules.enhanceorsuppressfeatures.S_FAST
def test_load_v1(): with open("./tests/resources/modules/straightenworms/v1.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.straightenworms.StraightenWorms) assert module.objects_name == "OverlappingWorms" assert module.straightened_objects_name == "StraightenedWorms" assert module.width == 20 assert (module.training_set_directory.dir_choice == cellprofiler.setting.DEFAULT_OUTPUT_FOLDER_NAME) assert module.training_set_file_name == "TrainingSet.xml" assert module.image_count.value == 2 for group, input_name, output_name in ( (module.images[0], "Brightfield", "StraightenedBrightfield"), (module.images[1], "Fluorescence", "StraightenedFluorescence"), ): assert group.image_name == input_name assert group.straightened_image_name == output_name
def test_01_01_load_v1(self): data = ('eJztV01v2jAYdvgabBPith59mnrootANqeWyMtAEU6EVRdV2qlwwzJITR46' 'DYL9gP2nHHfdz9hNm06QkHiUQsXXSsGQlr/0+z/tlJ3a3MThvvIM104Ldxu' 'DVmFAMLykSY8btOnTEEWxyjAQeQebU4eCzDz/4DqyewGqt/vq4btXgsWWdg' 'nTN6HTL8nFYAaAgn0XZM8FUPpCNSFfyFRaCOBMvD3LgIBj/Lvs14gTdUnyN' 'qI+9pYlwvOOM2WDu3k912cinuIfsqLJsPd++xdy7GIfAYPqSzDC9Il+wFkK' 'o1sdT4hHmBPiAXx+9t8uEZlfl4aCwzIOh5SGrjSv9Nljq51bk7UVEvxLILT' 'xGPhWwY6MJhi3C8VAwPl/wWQl82RhfFrR6jQXuLAFX0vxQcnMumEuRZ0fiS' 'bJvxHgMYAa4kwRcEcTtK/m9rOdIBrCJ/2UNXw7xkSDS+lG13pyaQ2+6Cf6J' 'hldyk3G+aR1WxdG86PdvtDi2XQef5FrexP+CZl/JLTIlI7xZ/pLwu94PSfl' '8rvEpuccgx94QUfmRAkGOd8WTdn9EcQUNF7YQVwqeu8Kt8jMT8zMjY30cP1' 'Pt16Oqpdpj+Psjv93/Ia2ds4S8PNXyomSi9s+EM9/dPc+fiqOi2a/E7EPij' 'LC7S57/vR573B63xy1xX42Hv+f6OUvpfwTr9+9LEN+/Sh5iSl3O1L2Om/bi' '8uGZlKGRwDNhnsuXgXy5458l8Lc1/vZD/EN5KJXnKEKpbxMHCXkDukGuS+d' 'm826mE51pqJl/wX60jqUV9qP1yEipmM+vrb9e9+V6+Pk2jT3DMH47tzxLwO' 'UiPqmm8N/AduvucI1+GOPf0v8FsdkNYQ==') fd = StringIO.StringIO(zlib.decompress(base64.b64decode(data))) pipeline = cellprofiler.pipeline.Pipeline() pipeline.load(fd) self.assertEqual(len(pipeline.modules()), 3) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.loaddata.LoadText)) self.assertEqual(module.csv_directory.dir_choice, cellprofiler.setting.DEFAULT_INPUT_FOLDER_NAME) self.assertEqual(module.csv_file_name, "1049.csv") self.assertTrue(module.wants_images.value) self.assertFalse(module.wants_image_groupings.value) self.assertEqual(module.image_directory.dir_choice, cellprofiler.setting.DEFAULT_INPUT_FOLDER_NAME) self.assertFalse(module.wants_rows.value)
def test_04_02_load_saturation_blur(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:8925 FromMatlab:True MeasureImageSaturationBlur:[module_num:1|svn_version:\'8913\'|variable_revision_number:4|show_window:False|notes:\x5B\x5D] What did you call the image you want to check for saturation?:Image1 What did you call the image you want to check for saturation?:Image2 What did you call the image you want to check for saturation?:Image3 What did you call the image you want to check for saturation?:Do not use What did you call the image you want to check for saturation?:Do not use What did you call the image you want to check for saturation?:Do not use Do you want to also check the above images for image quality (called blur earlier)?:Yes If you chose to check images for image quality above, enter the window size of LocalFocusScore measurement (A suggested value is 2 times ObjectSize)?:25 """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, M.MeasureImageQuality)) self.assertEqual(len(module.image_groups), 3) for i in range(3): group = module.image_groups[i] self.assertEqual(group.image_names, "Image%d" % (i + 1)) self.assertTrue(group.check_blur) self.assertEqual(group.scale_groups[0].scale, 25) self.assertTrue(group.check_saturation) self.assertFalse(group.calculate_threshold)
def test_load_v4(): data = """CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20141015195823 GitHash:051040e ModuleCount:1 HasImagePlaneDetails:False MeasureImageOverlap:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:4|show_window:False|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False] Compare segmented objects, or foreground/background?:Foreground/background segmentation Select the image to be used as the ground truth basis for calculating the amount of overlap:Foo Select the image to be used to test for overlap:Bar Select the objects to be used as the ground truth basis for calculating the amount of overlap:Cell2_0 Select the objects to be tested for overlap against the ground truth:Cell2_1 Calculate earth mover\'s distance?:Yes Maximum # of points:101 Point selection method:Skeleton Maximum distance:102 Penalize missing pixels:Yes """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(io.StringIO(data)) module = pipeline.modules()[0] assert isinstance( module, cellprofiler.modules.measureimageoverlap.MeasureImageOverlap) assert module.ground_truth == "Foo" assert module.test_img == "Bar"
def test_load_v4(self): with open("./tests/resources/modules/loadsingleimage/v4.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage) assert len(module.file_settings) == 2 fs = module.file_settings[0] assert fs.file_name == "foo.tif" assert fs.image_objects_choice == cellprofiler.modules.loadsingleimage.IO_IMAGES assert fs.image_name == "DNA" assert not fs.rescale fs = module.file_settings[1] assert fs.file_name == "bar.tif" assert fs.image_name == "Cytoplasm" assert fs.rescale
def test_load_v5(): with open("./tests/resources/modules/displaydataonimage/v5.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance( module, cellprofiler.modules.displaydataonimage.DisplayDataOnImage) assert module.objects_or_image == cellprofiler.modules.displaydataonimage.OI_OBJECTS assert module.measurement == "AreaShape_Zernike_0_0" assert module.image_name == "DNA" assert module.text_color == "green" assert module.objects_name == "Nuclei" assert module.display_image == "Zernike" assert module.font_size == 10 assert module.decimals == 2 assert module.saved_image_contents == cellprofiler.modules.displaydataonimage.E_AXES assert module.offset == 5 assert module.color_or_text == cellprofiler.modules.displaydataonimage.CT_COLOR assert module.colormap == "jet" assert not module.wants_image assert (module.color_map_scale_choice == cellprofiler.modules.displaydataonimage.CMS_USE_MEASUREMENT_RANGE) assert module.color_map_scale.min == 0 assert module.color_map_scale.max == 1
def test_load_v2(): with open("./tests/resources/modules/makeprojection/v2.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.load(six.moves.StringIO(data)) methods = ( cellprofiler.modules.makeprojection.P_AVERAGE, cellprofiler.modules.makeprojection.P_MAXIMUM, cellprofiler.modules.makeprojection.P_MINIMUM, cellprofiler.modules.makeprojection.P_SUM, cellprofiler.modules.makeprojection.P_VARIANCE, cellprofiler.modules.makeprojection.P_POWER, cellprofiler.modules.makeprojection.P_BRIGHTFIELD, ) assert len(pipeline.modules()) == len(methods) for method, module in zip(methods, pipeline.modules()): assert isinstance(module, cellprofiler.modules.makeprojection.MakeProjection) assert module.image_name == "ch02" assert module.projection_type == method assert module.projection_image_name == "ProjectionCh00Scale6" assert module.frequency == 6
def test_load_v3(): with open("./tests/resources/modules/resize/v3.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(io.StringIO(data)) assert len(pipeline.modules()) == 2 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.resize.Resize) assert module.x_name == "DNA" assert module.y_name == "ResizedDNA" assert module.size_method == cellprofiler.modules.resize.R_TO_SIZE assert round(abs(module.resizing_factor.value - 0.25), 7) == 0 assert module.specific_width == 141 assert module.specific_height == 169 assert module.interpolation == cellprofiler.modules.resize.I_BILINEAR assert module.additional_image_count.value == 1 additional_image = module.additional_images[0] assert additional_image.input_image_name == "Actin" assert additional_image.output_image_name == "ResizedActin" module = pipeline.modules()[1] assert isinstance(module, cellprofiler.modules.resize.Resize) assert module.interpolation == cellprofiler.modules.resize.I_BICUBIC
def test_load_v3(): """ Tests a pipeline that was produced with module revision 3. The channel names are named according to the schema: Channel(#new_imagenumber)_(#channel_number), e.g. Channel3_2 would be the image number 3 that contains channel number 2. Thus it can be easily checked via the new image name, if the channel number is correctly parsed. """ with open("./tests/resources/modules/colortogray/v3.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.colortogray.ColorToGray) assert module.image_name == "DNA" assert module.channel_count.value == 8 for i in range(module.channel_count.value): c = module.channels[i].image_name.value.split("_")[1] assert module.channels[i].channel_choice.value == int(c) assert module.channels[6].image_name.value == "Channel7_7"
def test_01_02_load_v2(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:9063 OverlayOutlines:[module_num:5|svn_version:\'9000\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D] Display outlines on a blank image?:No Select image on which to display outlines:DNA Name the output image\x3A:PrimaryOverlay Select outline display mode\x3A:Color Select method to determine brightness of outlines\x3A:Max of image Line width\x3A:1.5 Select outlines to display\x3A:PrimaryOutlines Select outline color\x3A:Red Select outlines to display\x3A:SecondaryOutlines Select outline color\x3A:Green """ pipeline = cellprofiler.pipeline.Pipeline() pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.overlayoutlines.OverlayOutlines)) self.assertFalse(module.blank_image) self.assertEqual(module.image_name, "DNA") self.assertEqual(module.output_image_name, "PrimaryOverlay") self.assertEqual(module.wants_color, "Color") self.assertEqual(module.max_type, cellprofiler.modules.overlayoutlines.MAX_IMAGE) self.assertEqual(module.line_mode.value, "Inner") self.assertEqual(len(module.outlines), 2) for outline, name, color in zip(module.outlines, ("PrimaryOutlines", "SecondaryOutlines"), ("Red", "Green")): self.assertEqual(outline.objects_name.value, cellprofiler.setting.NONE) self.assertEqual(outline.color, color)
def test_load_v1(): with open("./tests/resources/modules/tile/v1.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.tile.Tile) assert module.input_image == "ResizedColorImage" assert module.output_image == "TiledImage" assert module.tile_method == cellprofiler.modules.tile.T_ACROSS_CYCLES assert module.rows == 2 assert module.columns == 12 assert module.wants_automatic_rows assert not module.wants_automatic_columns assert module.place_first == cellprofiler.modules.tile.P_TOP_LEFT assert module.tile_style == cellprofiler.modules.tile.S_ROW assert not module.meander assert len(module.additional_images) == 3 for g, expected in zip(module.additional_images, ("Cytoplasm", "ColorImage", "DNA")): assert g.input_image_name == expected
def test_01_03_load_v3(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20131210175632 GitHash:63ec479 ModuleCount:1 HasImagePlaneDetails:False MeasureImageOverlap:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:3|show_window:False|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True] Compare segmented objects, or foreground/background?:Foreground/background segmentation Select the image to be used as the ground truth basis for calculating the amount of overlap:Foo Select the image to be used to test for overlap:Bar Select the objects to be used as the ground truth basis for calculating the amount of overlap:Cell2_0 Select the objects to be tested for overlap against the ground truth:Cell2_1 """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.measureimageoverlap.MeasureImageOverlap)) self.assertEqual(module.ground_truth, "Foo") self.assertEqual(module.test_img, "Bar") # self.assertEqual(module.object_name_GT, "Cell2_0") # self.assertEqual(module.object_name_ID, "Cell2_1") self.assertFalse(module.wants_emd)
def test_01_02_load_v1(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:9169 MeasureImageOverlap:[module_num:1|svn_version:\'9000\'|variable_revision_number:1|show_window:True|notes:\x5B\x5D] Which image do you want to use as the basis for calculating the amount of overlap? :GroundTruth Which image do you want to compare for overlap?:Segmentation """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse( isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue( isinstance( module, cellprofiler.modules.measureimageoverlap.MeasureImageOverlap)) self.assertEqual(module.ground_truth, "GroundTruth") self.assertEqual(module.test_img, "Segmentation")
def test_01_01_01_load_v1(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:8957 MeasureObjectSizeShape:[module_num:1|svn_version:\'1\'|variable_revision_number:1|show_window:True|notes:\x5B\x5D] Select objects to measure:Nuclei Select objects to measure:Cells Calculate the Zernike features?:Yes """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse( isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue( isinstance( module, cellprofiler.modules.measureobjectsizeshape. MeasureObjectSizeShape)) self.assertEqual(len(module.object_groups), 2) for og, expected in zip(module.object_groups, ("Nuclei", "Cells")): self.assertEqual(og.name, expected) self.assertTrue(module.calculate_zernikes)
def test_04_02_load_saturation_blur(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:8925 FromMatlab:True MeasureImageSaturationBlur:[module_num:1|svn_version:\'8913\'|variable_revision_number:4|show_window:False|notes:\x5B\x5D] What did you call the image you want to check for saturation?:Image1 What did you call the image you want to check for saturation?:Image2 What did you call the image you want to check for saturation?:Image3 What did you call the image you want to check for saturation?:Do not use What did you call the image you want to check for saturation?:Do not use What did you call the image you want to check for saturation?:Do not use Do you want to also check the above images for image quality (called blur earlier)?:Yes If you chose to check images for image quality above, enter the window size of LocalFocusScore measurement (A suggested value is 2 times ObjectSize)?:25 """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse( isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, M.MeasureImageQuality)) self.assertEqual(len(module.image_groups), 3) for i in range(3): group = module.image_groups[i] self.assertEqual(group.image_names, "Image%d" % (i + 1)) self.assertTrue(group.check_blur) self.assertEqual(group.scale_groups[0].scale, 25) self.assertTrue(group.check_saturation) self.assertFalse(group.calculate_threshold)
def test_load_v2(): with open("./tests/resources/modules/measureobjectneighbors/v2.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance( module, cellprofiler.modules.measureobjectneighbors.MeasureObjectNeighbors) assert module.object_name == "glia" assert module.neighbors_name == "neurites" assert (module.distance_method == cellprofiler.modules.measureobjectneighbors.D_EXPAND) assert module.distance == 2 assert not module.wants_count_image assert module.count_image_name == "countimage" assert module.count_colormap == "pink" assert not module.wants_percent_touching_image assert module.touching_image_name == "touchingimage" assert module.touching_colormap == "purple"
def test_01_03_load_v3(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20140505183007 GitHash:c675ec6 ModuleCount:1 HasImagePlaneDetails:False OverlayOutlines:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False] Display outlines on a blank image?:No Select image on which to display outlines:DNA Name the output image:PrimaryOverlay Outline display mode:Color Select method to determine brightness of outlines:Max of image Width of outlines:1.5 Select outlines to display:PrimaryOutlines Select outline color:Red Load outlines from an image or objects?:Image Select objects to display:Nuclei Select outlines to display\x3A:SecondaryOutlines Select outline color\x3A:Green Load outlines from an image or objects?:Objects Select objects to display:Cells """ pipeline = cellprofiler.pipeline.Pipeline() pipeline.load(io.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue( isinstance(module, cellprofiler.modules.overlayoutlines.OverlayOutlines) ) self.assertFalse(module.blank_image) self.assertEqual(module.image_name, "DNA") self.assertEqual(module.output_image_name, "PrimaryOverlay") self.assertEqual(module.wants_color, "Color") self.assertEqual( module.max_type, cellprofiler.modules.overlayoutlines.MAX_IMAGE ) self.assertEqual(module.line_mode.value, "Inner") self.assertEqual(len(module.outlines), 2) for outline, name, color, choice, objects_name in ( ( module.outlines[0], "PrimaryOutlines", "Red", cellprofiler.modules.overlayoutlines.FROM_IMAGES, "Nuclei", ), ( module.outlines[1], "SecondaryOutlines", "Green", cellprofiler.modules.overlayoutlines.FROM_OBJECTS, "Cells", ), ): self.assertEqual(outline.color, color) self.assertEqual(outline.objects_name, objects_name)
def test_01_03_load_v3(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20120112154631 ModuleCount:1 HasImagePlaneDetails:False Metadata:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)] Extract metadata?:Yes Extraction method count:2 Metadata extraction method:Extract from file/folder names Metadata source:File name Regular expression:^Channel(?P<ChannelNumber>\x5B12\x5D)-(?P<Index>\x5B0-9\x5D+)-(?P<WellRow>\x5BA-H\x5D)-(?P<WellColumn>\x5B0-9\x5D{2}).tif$ Regular expression:(?P<Date>\x5B0-9\x5D{4}_\x5B0-9\x5D{2}_\x5B0-9\x5D{2})$ Extract metadata from:All images Select the filtering criteria:or (file does contain "Channel2") Metadata file location: Match file and image metadata:\x5B\x5D Case insensitive matching:No Metadata extraction method:Import from file Metadata source:Folder name Regular expression:^(?P<Plate>.*)_(?P<Well>\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P<Site>\x5B0-9\x5D)_w(?P<ChannelNumber>\x5B0-9\x5D) Regular expression:Example(?P<Project>\x5B^\\\\\\\\\x5D+)Images Extract metadata from:Images matching a rule Select the filtering criteria:or (file does contain "") Metadata file location\x3A:/imaging/analysis/metadata.csv Match file and image metadata:\x5B{\'Image Metadata\'\x3A u\'ChannelNumber\', \'CSV Metadata\'\x3A u\'Wavelength\'}\x5D Case insensitive matching:Yes """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(cStringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.metadata.Metadata)) self.assertTrue(module.wants_metadata) self.assertEqual(module.data_type_choice, cellprofiler.modules.metadata.DTC_TEXT) self.assertEqual(len(module.extraction_methods), 2) em0, em1 = module.extraction_methods self.assertEqual(em0.extraction_method, cellprofiler.modules.metadata.X_MANUAL_EXTRACTION) self.assertEqual(em0.source, cellprofiler.modules.metadata.XM_FILE_NAME) self.assertEqual(em0.file_regexp.value, r"^Channel(?P<ChannelNumber>[12])-(?P<Index>[0-9]+)-(?P<WellRow>[A-H])-(?P<WellColumn>[0-9]{2}).tif$") self.assertEqual(em0.folder_regexp.value, r"(?P<Date>[0-9]{4}_[0-9]{2}_[0-9]{2})$") self.assertEqual(em0.filter_choice, cellprofiler.modules.metadata.F_ALL_IMAGES) self.assertEqual(em0.filter, 'or (file does contain "Channel2")') self.assertFalse(em0.wants_case_insensitive) self.assertEqual(em1.extraction_method, cellprofiler.modules.metadata.X_IMPORTED_EXTRACTION) self.assertEqual(em1.source, cellprofiler.modules.metadata.XM_FOLDER_NAME) self.assertEqual(em1.filter_choice, cellprofiler.modules.metadata.F_FILTERED_IMAGES) self.assertEqual(em1.csv_location.get_dir_choice(), cellprofiler.setting.ABSOLUTE_FOLDER_NAME) self.assertEqual(em1.csv_location.get_custom_path(), "/imaging/analysis") self.assertEqual(em1.csv_filename.value, "metadata.csv") self.assertEqual(em1.csv_joiner.value, "[{'Image Metadata': u'ChannelNumber', 'CSV Metadata': u'Wavelength'}]") self.assertTrue(em1.wants_case_insensitive)
def test_load_v4(): with open("./tests/resources/modules/flagimages/v4.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 1 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.flagimage.FlagImage) expected = ( ( "QCFlag", cellprofiler.modules.flagimage.C_ANY, False, ( ("Intensity_MaxIntensity_DNA", None, 0.95, "foo.txt", "4"), ("Intensity_MinIntensity_Cytoplasm", 0.05, None, "bar.txt", "2"), ("Intensity_MeanIntensity_DNA", 0.1, 0.9, "baz.txt", "1"), ), ), ( "HighCytoplasmIntensity", None, True, (("Intensity_MeanIntensity_Cytoplasm", None, 0.8, "dunno.txt", "3"),), ), ) assert len(expected) == module.flag_count.value for flag, (feature_name, combine, skip, measurements) in zip( module.flags, expected ): assert isinstance(flag, cellprofiler.setting.SettingsGroup) assert flag.category == "Metadata" assert flag.feature_name == feature_name assert flag.wants_skip == skip if combine is not None: assert flag.combination_choice == combine assert len(measurements) == flag.measurement_count.value for ( measurement, (measurement_name, min_value, max_value, rules_file, rules_class), ) in zip(flag.measurement_settings, measurements): assert isinstance(measurement, cellprofiler.setting.SettingsGroup) assert measurement.source_choice == cellprofiler.modules.flagimage.S_IMAGE assert measurement.measurement == measurement_name assert measurement.wants_minimum.value == (min_value is not None) if measurement.wants_minimum.value: assert round(abs(measurement.minimum_value.value - min_value), 7) == 0 assert measurement.wants_maximum.value == (max_value is not None) if measurement.wants_maximum.value: assert round(abs(measurement.maximum_value.value - max_value), 7) == 0 assert measurement.rules_file_name == rules_file assert measurement.rules_class == rules_class
def test_01_05_load_v4(): data = r'''CellProfiler Pipeline: http://www.cellprofiler.org Version:2 DateRevision:20120516145742 EnhanceOrSuppressFeatures:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)] Select the input image:Dendrite Name the output image:EnhancedDendrite Select the operation:Enhance Feature size:10 Feature type:Neurites Range of hole sizes:1,10 Smoothing scale:2.0 Shear angle:0 Decay:0.95 Enhancement method:Tubeness EnhanceOrSuppressFeatures:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)] Select the input image:Axon Name the output image:EnhancedAxon Select the operation:Enhance Feature size:10 Feature type:Neurites Range of hole sizes:1,10 Smoothing scale:2.0 Shear angle:0 Decay:0.95 Enhancement method:Line structures ''' pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) assert len(pipeline.modules()) == 2 module = pipeline.modules()[0] assert isinstance( module, cellprofiler.modules.enhanceorsuppressfeatures. EnhanceOrSuppressFeatures) assert module.x_name == "Dendrite" assert module.y_name == "EnhancedDendrite" assert module.method == cellprofiler.modules.enhanceorsuppressfeatures.ENHANCE assert module.enhance_method == cellprofiler.modules.enhanceorsuppressfeatures.E_NEURITES assert module.smoothing == 2.0 assert module.object_size == 10 assert module.hole_size.min == 1 assert module.hole_size.max == 10 assert module.angle == 0 assert module.decay == .95 assert module.neurite_choice == cellprofiler.modules.enhanceorsuppressfeatures.N_TUBENESS module = pipeline.modules()[1] assert isinstance( module, cellprofiler.modules.enhanceorsuppressfeatures. EnhanceOrSuppressFeatures) assert module.neurite_choice == cellprofiler.modules.enhanceorsuppressfeatures.N_GRADIENT
def test_load_v2(): data = ('eJztW0Fv2zYUpl0nWFagS08dhhXgoYckiDXZq9E0KFo78boZqB2jNtoNadYx' 'Mm1zkEVDotK4Re/9qTvmuONEW7IlTolkS4qdVAIE+VH8+L33+PhIyVS90n5V' 'OYAlSYb1SjvfJSqGTRWxLtUH+1Bju/BQx4jhDqTaPmybGDboGSw+hoXifqm0' 'X5BhUZafgsWOTK1+z7pcPANg3bp+Y51Z+9aaLWdcJ5dbmDGi9Yw1kAPf2+UX' '1vkG6QSdqvgNUk1szCic8prWpe3RcHqrTjumihto4K5sHQ1zcIp146jrAO3b' 'TXKO1Rb5iAUTnGqv8RkxCNVsvN2+WDrlpUzgbfXph5e6pY7Q/gFiSr/FrB7w' 'lnO/bf0481tG8FvOOh+6ynn938Csfs7Hz/dd9TdtmWgdckY6JlIhGaDeVGve' 'nhzQ3h1Pe3dAtVEZ4/YCcOuCHlxumIqKSTTecgBuU+DlZxufs/wv50hhcMC7' 'Ig79g/BrAp7Lh1hVDbA4vqJYwwaE81/Gg8+AnyPwFuTdx7KND/L/XQHP5aZO' 'h6iHmDWIxuVh2vlWaIfLVQo1yqBp2OMoznbmjcc/rFEURz9GjaMgvbMefBY0' 'aDRckL/9+v+IGSb8VaWnSJ36O+r4C8qDDwQ8l6u4i0yVwRpPgrBKdKwwqo8i' '9f+8uIIk/w+3LuCcw8Ft2NcouHKAnmH7bZH5R5bk8bFbsH/EYM8y+8sPl/Pg' 'ctzmQpL2XTY+k+yfMHoU5GT7ddF8FqZ/QuJKqzh+N4C3X7lc0xjWDMJGrnYW' 'iY8WVqjWQfroyGQq0S5dPyZtz2EfaRpWC/kE/DJvXpBjzOPzrH/jGI9h4rxB' 'NZykfeL6tLAg7klIXJi8Ead9Yfw5z7xVDsD5zd/tDxQqKjIMe8RGsbcfwP9E' '4Ofyn1svms/4iwj8XNrZfs+lt9bS9flxJd88OZbzT08+FT9vvzf4jRaxao3L' 'tkPZ+53Ax+Wmbj3eurLUovnuLSa9Pn9dcsZfDGiK89gexX+/B+jxSNCDy9LO' '8bt3P51w91RtJ04LXpsalx/56RVnXPk9P72kOu7p1NQ60f0SxH/FPFB0zwNx' 'rAevYx5P+rl/VeycN48XF7Qvznl4FfJ/kvPwKuf7Zc7ftyGPLzP+k1z3ylJp' '6Xom/Z4lznXadeNWZX21av2c9Lpp1cftbctL4nqltCQ9v/www2UEnN//hdcZ' '3+M/F3mAD8O345cP6enfWGGzhuLU5zrznMsOSLQOHibY3rL9k+Juxji6LX67' 'bfamuBSX4lJc1Ly4Cbx5kZ+z+WSybLhJ9n5t/g3iT9dxKS4JXBksN+5T3NeJ' 'K4M07lJcOu+luBSX4lJciktxNwn3b2aGywg4Lrv3s/D6f7l4/Ob5HVf9TVtW' 'sKoOdcq/a9SlwfjjO0NSKepMvmaTXlk/a64P2zjPMICnLPCUL+MhHawx0h0N' '+eZCk9EBYkSRanYp33JYcUo5bz+Ad0/g3QviNZzN11PO6XZszncewHcg8B1c' 'xjfAyDB1PHmHTpwd0lJ9Unw0LhY2Totxs+HD7+7/rCU9eHh/7ap4A8AbZ7P4' 'u3ixCF8ul83eA959d3cDcDngjXuO/wfMF+dbV9R3bFzl+vP6OWMdUf0048lN' 'dZq0v5r1/wNnl0Vu') pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(zlib.decompress(base64.b64decode(data)))) assert len(pipeline.modules()) == 4 module = pipeline.modules()[-1] assert isinstance( module, cellprofiler.modules.measureobjectintensity.MeasureObjectIntensity) assert len(module.images) == 2 for expected, actual in zip(("DNA", "Actin"), [img.name for img in module.images]): assert expected == actual assert len(module.objects) == 2 for expected, actual in zip(("Cells", "Nuclei"), [obj.name for obj in module.objects]): assert expected == actual
def test_01_02_load_v2(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:9524 LoadSingleImage:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D] Folder containing the image file:Default Input Folder\x7CNone Filename of the image to load (Include the extension, e.g., .tif):foo.tif Name the image that will be loaded:DNA Filename of the image to load (Include the extension, e.g., .tif):bar.tif Name the image that will be loaded:Cytoplasm LoadSingleImage:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D] Folder containing the image file:Default Output Folder\x7CNone Filename of the image to load (Include the extension, e.g., .tif):baz.tif Name the image that will be loaded:GFP LoadSingleImage:[module_num:3|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D] Folder containing the image file:Elsewhere...\x7CNone Filename of the image to load (Include the extension, e.g., .tif):baz.tif Name the image that will be loaded:GFP LoadSingleImage:[module_num:4|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D] Folder containing the image file:URL\x7Chttps\x3A//svn.broadinstitute.org/CellProfiler/trunk/ExampleImages/ExampleSBSImages Filename of the image to load (Include the extension, e.g., .tif):Channel1-01-A-01.tif Name the image that will be loaded:DNA1 """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO(data)) self.assertEqual(len(pipeline.modules()), 4) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage)) self.assertEqual(len(module.file_settings), 2) fs = module.file_settings[0] self.assertEqual(fs.file_name, "foo.tif") self.assertEqual(fs.image_name, "DNA") fs = module.file_settings[1] self.assertEqual(fs.file_name, "bar.tif") self.assertEqual(fs.image_name, "Cytoplasm") module = pipeline.modules()[3] fs = module.file_settings[0] self.assertEqual( fs.file_name, "https://svn.broadinstitute.org/CellProfiler/trunk/ExampleImages/" "ExampleSBSImages/Channel1-01-A-01.tif") dir_choice = [ cellprofiler.setting.DEFAULT_INPUT_FOLDER_NAME, cellprofiler.setting.DEFAULT_OUTPUT_FOLDER_NAME, cellprofiler.setting.ABSOLUTE_FOLDER_NAME, cellprofiler.setting.URL_FOLDER_NAME] for i, module in enumerate(pipeline.modules()): self.assertTrue(isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage)) self.assertEqual(module.directory.dir_choice, dir_choice[i])
def test_01_03_load_v2(self): data = """CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:10865 MeasureTexture:[module_num:1|svn_version:\'1\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D] Hidden:2 Hidden:2 Hidden:2 Select an image to measure:rawDNA Select an image to measure:rawGFP Select objects to measure:Cells Select objects to measure:Nuclei Texture scale to measure:3 Texture scale to measure:5 Measure Gabor features?:Yes Number of angles to compute for Gabor:6 MeasureTexture:[module_num:2|svn_version:\'1\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D] Hidden:2 Hidden:2 Hidden:2 Select an image to measure:rawDNA Select an image to measure:rawGFP Select objects to measure:Cells Select objects to measure:Nuclei Texture scale to measure:3 Texture scale to measure:5 Measure Gabor features?:No Number of angles to compute for Gabor:6 """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 2) for i, wants_gabor in enumerate((True, False)): module = pipeline.modules()[i] self.assertTrue(isinstance(module, cellprofiler.modules.measuretexture.MeasureTexture)) self.assertEqual(len(module.image_groups), 2) self.assertEqual(module.image_groups[0].image_name, "rawDNA") self.assertEqual(module.image_groups[1].image_name, "rawGFP") self.assertEqual(len(module.object_groups), 2) self.assertEqual(module.object_groups[0].object_name, "Cells") self.assertEqual(module.object_groups[1].object_name, "Nuclei") self.assertEqual(len(module.scale_groups), 2) self.assertEqual(module.scale_groups[0].scale, 3) self.assertEqual(len(module.scale_groups[0].angles.get_selections()), 1) self.assertEqual(module.scale_groups[0].angles.get_selections()[0], cellprofiler.modules.measuretexture.H_HORIZONTAL) self.assertEqual(module.scale_groups[1].scale, 5) self.assertEqual(len(module.scale_groups[1].angles.get_selections()), 1) self.assertEqual(module.scale_groups[1].angles.get_selections()[0], cellprofiler.modules.measuretexture.H_HORIZONTAL) self.assertEqual(module.wants_gabor, wants_gabor) self.assertEqual(module.gabor_angles, 6)
def test_load_v1(): with open("./tests/resources/modules/maskobjects/v1.pipeline", "r") as fd: data = fd.read() pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(six.moves.StringIO(data)) assert len(pipeline.modules()) == 4 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.maskobjects.MaskObjects) assert module.object_name.value == "Nuclei" assert module.mask_choice.value == cellprofiler.modules.maskobjects.MC_OBJECTS assert module.masking_objects.value == "Wells" assert module.remaining_objects.value == "MaskedNuclei" assert (module.retain_or_renumber.value == cellprofiler.modules.maskobjects.R_RENUMBER) assert module.overlap_choice.value == cellprofiler.modules.maskobjects.P_MASK assert not module.wants_inverted_mask module = pipeline.modules()[1] assert isinstance(module, cellprofiler.modules.maskobjects.MaskObjects) assert module.object_name.value == "Cells" assert module.mask_choice.value == cellprofiler.modules.maskobjects.MC_IMAGE assert module.masking_image.value == "WellBoundary" assert module.remaining_objects.value == "MaskedCells" assert module.retain_or_renumber.value == cellprofiler.modules.maskobjects.R_RETAIN assert module.overlap_choice.value == cellprofiler.modules.maskobjects.P_KEEP assert not module.wants_inverted_mask module = pipeline.modules()[2] assert isinstance(module, cellprofiler.modules.maskobjects.MaskObjects) assert module.object_name.value == "Cytoplasm" assert module.mask_choice.value == cellprofiler.modules.maskobjects.MC_OBJECTS assert module.masking_objects.value == "Cells" assert module.remaining_objects.value == "MaskedCytoplasm" assert (module.retain_or_renumber.value == cellprofiler.modules.maskobjects.R_RENUMBER) assert module.overlap_choice.value == cellprofiler.modules.maskobjects.P_REMOVE assert not module.wants_inverted_mask module = pipeline.modules()[3] assert isinstance(module, cellprofiler.modules.maskobjects.MaskObjects) assert module.object_name.value == "Speckles" assert module.mask_choice.value == cellprofiler.modules.maskobjects.MC_OBJECTS assert module.masking_objects.value == "Cells" assert module.remaining_objects.value == "MaskedSpeckles" assert (module.retain_or_renumber.value == cellprofiler.modules.maskobjects.R_RENUMBER) assert (module.overlap_choice.value == cellprofiler.modules.maskobjects.P_REMOVE_PERCENTAGE) assert round(abs(module.overlap_fraction.value - 0.3), 7) == 0 assert not module.wants_inverted_mask
def test_01_01_load_v1(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:9524 LoadSingleImage:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:1|show_window:True|notes:\x5B\x5D] Folder containing the image file:Default Input Folder Name of the folder containing the image file:path1 Filename of the image to load (Include the extension, e.g., .tif):foo.tif Name the image that will be loaded:DNA Filename of the image to load (Include the extension, e.g., .tif):bar.tif Name the image that will be loaded:Cytoplasm LoadSingleImage:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:1|show_window:True|notes:\x5B\x5D] Folder containing the image file:Default Output Folder Name of the folder containing the image file:path2 Filename of the image to load (Include the extension, e.g., .tif):baz.tif Name the image that will be loaded:GFP LoadSingleImage:[module_num:3|svn_version:\'Unknown\'|variable_revision_number:1|show_window:True|notes:\x5B\x5D] Folder containing the image file:Custom folder Name of the folder containing the image file:path3 Filename of the image to load (Include the extension, e.g., .tif):baz.tif Name the image that will be loaded:GFP LoadSingleImage:[module_num:4|svn_version:\'Unknown\'|variable_revision_number:1|show_window:True|notes:\x5B\x5D] Folder containing the image file:Custom with metadata Name of the folder containing the image file:path4 Filename of the image to load (Include the extension, e.g., .tif):baz.tif Name the image that will be loaded:GFP """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO(data)) self.assertEqual(len(pipeline.modules()), 4) dir_choice = [ cellprofiler.setting.DEFAULT_INPUT_FOLDER_NAME, cellprofiler.setting.DEFAULT_OUTPUT_FOLDER_NAME, cellprofiler.setting.ABSOLUTE_FOLDER_NAME, cellprofiler.setting.ABSOLUTE_FOLDER_NAME] for i, module in enumerate(pipeline.modules()): self.assertTrue(isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage)) self.assertEqual(module.directory.dir_choice, dir_choice[i]) self.assertEqual(module.directory.custom_path, "path%d" % (i + 1)) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage)) self.assertEqual(len(module.file_settings), 2) fs = module.file_settings[0] self.assertEqual(fs.file_name, "foo.tif") self.assertEqual(fs.image_name, "DNA") fs = module.file_settings[1] self.assertEqual(fs.file_name, "bar.tif") self.assertEqual(fs.image_name, "Cytoplasm")
def test_01_05_load_v4(): data = r'''CellProfiler Pipeline: http://www.cellprofiler.org Version:2 DateRevision:20120516145742 EnhanceOrSuppressFeatures:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)] Select the input image:Dendrite Name the output image:EnhancedDendrite Select the operation:Enhance Feature size:10 Feature type:Neurites Range of hole sizes:1,10 Smoothing scale:2.0 Shear angle:0 Decay:0.95 Enhancement method:Tubeness EnhanceOrSuppressFeatures:[module_num:2|svn_version:\'Unknown\'|variable_revision_number:4|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)] Select the input image:Axon Name the output image:EnhancedAxon Select the operation:Enhance Feature size:10 Feature type:Neurites Range of hole sizes:1,10 Smoothing scale:2.0 Shear angle:0 Decay:0.95 Enhancement method:Line structures ''' pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) assert len(pipeline.modules()) == 2 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.enhanceorsuppressfeatures.EnhanceOrSuppressFeatures) assert module.x_name == "Dendrite" assert module.y_name == "EnhancedDendrite" assert module.method == cellprofiler.modules.enhanceorsuppressfeatures.ENHANCE assert module.enhance_method == cellprofiler.modules.enhanceorsuppressfeatures.E_NEURITES assert module.smoothing == 2.0 assert module.object_size == 10 assert module.hole_size.min == 1 assert module.hole_size.max == 10 assert module.angle == 0 assert module.decay == .95 assert module.neurite_choice == cellprofiler.modules.enhanceorsuppressfeatures.N_TUBENESS module = pipeline.modules()[1] assert isinstance(module, cellprofiler.modules.enhanceorsuppressfeatures.EnhanceOrSuppressFeatures) assert module.neurite_choice == cellprofiler.modules.enhanceorsuppressfeatures.N_GRADIENT
def test_01_03_load_v3(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:10104 Resize:[module_num:1|svn_version:\'10104\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D] Select the input image:DNA Name the output image:ResizedDNA Select resizing method:Resize by specifying desired final dimensions Resizing factor:0.25 Width of the final image, in pixels:141 Height of the final image, in pixels:169 Interpolation method:Bilinear Additional image count:1 Select the additional image?:Actin Name the output image:ResizedActin Resize:[module_num:2|svn_version:\'10104\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D] Select the input image:DNA Name the output image:ResizedDNA Select resizing method:Resize by specifying desired final dimensions Resizing factor:0.25 Width of the final image, in pixels:100 Height of the final image, in pixels:100 Interpolation method:Bicubic Additional image count:0 """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 2) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.resize.Resize)) self.assertEqual(module.x_name, "DNA") self.assertEqual(module.y_name, "ResizedDNA") self.assertEqual(module.size_method, cellprofiler.modules.resize.R_TO_SIZE) self.assertAlmostEqual(module.resizing_factor.value, 0.25) self.assertEqual(module.specific_width, 141) self.assertEqual(module.specific_height, 169) self.assertEqual(module.interpolation, cellprofiler.modules.resize.I_BILINEAR) self.assertEqual(module.additional_image_count.value, 1) additional_image = module.additional_images[0] self.assertEqual(additional_image.input_image_name, "Actin") self.assertEqual(additional_image.output_image_name, "ResizedActin") module = pipeline.modules()[1] self.assertTrue(isinstance(module, cellprofiler.modules.resize.Resize)) self.assertEqual(module.interpolation, cellprofiler.modules.resize.I_BICUBIC)
def test_test_load_v3(): data = r'''CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:10999 EnhanceOrSuppressFeatures:[module_num:1|svn_version:\'10591\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D] Select the input image:DNA Name the output image:EnhancedTexture Select the operation:Enhance Feature size:10 Feature type:Texture Range of hole sizes:1,10 Smoothing scale:3.5 Shear angle:45 Decay:0.90 EnhanceOrSuppressFeatures:[module_num:2|svn_version:\'10591\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D] Select the input image:EnhancedTexture Name the output image:EnhancedDIC Select the operation:Enhance Feature size:10 Feature type:DIC Range of hole sizes:1,10 Smoothing scale:1.5 Shear angle:135 Decay:0.99 ''' pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): assert not isinstance(event, cellprofiler.pipeline.LoadExceptionEvent) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) assert len(pipeline.modules()) == 2 module = pipeline.modules()[0] assert isinstance(module, cellprofiler.modules.enhanceorsuppressfeatures.EnhanceOrSuppressFeatures) assert module.x_name == "DNA" assert module.y_name == "EnhancedTexture" assert module.method == cellprofiler.modules.enhanceorsuppressfeatures.ENHANCE assert module.enhance_method == cellprofiler.modules.enhanceorsuppressfeatures.E_TEXTURE assert module.smoothing == 3.5 assert module.object_size == 10 assert module.hole_size.min == 1 assert module.hole_size.max == 10 assert module.angle == 45 assert module.decay == .9 assert module.speckle_accuracy == cellprofiler.modules.enhanceorsuppressfeatures.S_SLOW module = pipeline.modules()[1] assert isinstance(module, cellprofiler.modules.enhanceorsuppressfeatures.EnhanceOrSuppressFeatures) assert module.enhance_method == cellprofiler.modules.enhanceorsuppressfeatures.E_DIC
def test_01_05_load_v5(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:300 GitHash: ModuleCount:1 HasImagePlaneDetails:False Metadata:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:4|show_window:False|notes:\x5B\'The Metadata module optionally allows you to extract information describing your images (i.e, metadata) which will be stored along with your measurements. This information can be contained in the file name and/or location, or in an external file.\'\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False] Extract metadata?:Yes Metadata data type:Text Metadata types:{} Extraction method count:2 Metadata extraction method:Import from file Metadata source:File name Regular expression to extract from file name:^(?P<Plate>.*)_(?P<Well>\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P<Site>\x5B0-9\x5D)_w(?P<ChannelNumber>\x5B0-9\x5D) Regular expression to extract from folder name:(?P<Date>\x5B0-9\x5D{4}_\x5B0-9\x5D{2}_\x5B0-9\x5D{2})$ Extract metadata from:All images Select the filtering criteria:and (file does contain "") Metadata file location:/imaging/analysis/metadata.csv Match file and image metadata:\x5B{\'Image Metadata\'\x3A u\'FileLocation\', \'CSV Metadata\'\x3A u\'None\'}\x5D Use case insensitive matching?:No Metadata extraction method:Import from file Metadata source:File name Regular expression to extract from file name:^(?P<Plate>.*)_(?P<Well>\x5BA-P\x5D\x5B0-9\x5D{2})_s(?P<Site>\x5B0-9\x5D)_w(?P<ChannelNumber>\x5B0-9\x5D) Regular expression to extract from folder name:(?P<Date>\x5B0-9\x5D{4}_\x5B0-9\x5D{2}_\x5B0-9\x5D{2})$ Extract metadata from:All images Select the filtering criteria:and (file does contain "") Metadata file location:https\x3A//cellprofiler.org/metadata.csv Match file and image metadata:\x5B{\'Image Metadata\'\x3A u\'FileLocation\', \'CSV Metadata\'\x3A u\'None\'}\x5D Use case insensitive matching?:No """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(cStringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] em0, em1 = module.extraction_methods self.assertEqual(em0.csv_location.get_dir_choice(), cellprofiler.setting.ABSOLUTE_FOLDER_NAME) self.assertEqual(em0.csv_location.get_custom_path(), "/imaging/analysis") self.assertEqual(em0.csv_filename.value, "metadata.csv") self.assertEqual(em1.csv_location.get_dir_choice(), cellprofiler.setting.URL_FOLDER_NAME) self.assertEqual(em1.csv_location.get_custom_path(), "https://cellprofiler.org") self.assertEqual(em1.csv_filename.value, "metadata.csv")
def test_load_v3(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:300 GitHash: ModuleCount:1 HasImagePlaneDetails:False MeasureImageAreaOccupied:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False] Hidden:3 Measure the area occupied in a binary image, or in objects?:Binary Image Select objects to measure:None Retain a binary image of the object regions?:No Name the output binary image:Stain Select a binary image to measure:DNA Measure the area occupied in a binary image, or in objects?:Objects Select objects to measure:Cells Retain a binary image of the object regions?:Yes Name the output binary image:Stain Select a binary image to measure:None Measure the area occupied in a binary image, or in objects?:Objects Select objects to measure:Nuclei Retain a binary image of the object regions?:No Name the output binary image:Stain Select a binary image to measure:None """ def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline = cellprofiler.pipeline.Pipeline() pipeline.add_listener(callback) pipeline.load(six.StringIO(data)) module = pipeline.modules()[0] assert module.count.value == 3 assert module.operands[0].operand_choice == "Binary Image" assert module.operands[1].operand_choice == "Objects" assert module.operands[1].operand_objects == "Cells" assert module.operands[2].operand_choice == "Objects" assert module.operands[2].operand_objects == "Nuclei"
def test_01_01_load_matlab(self): data = ('eJzzdQzxcXRSMNUzUPB1DNFNy8xJ1VEIyEksScsvyrVSCHAO9/TTUXAuSk0s' 'SU1RyM+zUgjJKFXwKs1RMDJWMDS1MjWyAjKMDAwsFUgGDIyevvwMDAwBTAwM' 'FXPeTr/rd9tA5Li/V1CCc8fG2bFvlKbHMHh3a73dJKLGm3lazcFjctljNbWt' 'U26F2gUk6h9/KpfYv+H4DN6fW5zm1mWsFejTeW1ht7/4T3+y+m2Ggv3cF568' 'ZVvPW6HjlpTdqvWGW8a1pWoho9Ue71/vK/c6MTrWyscr2h9TTFF9a7/4+ptP' 'ZVPu/jp158ZxMykx9s9Jxw/b8R3Kv74yuei3tWTy/6Y7iRrTS25Y7lNUTDT5' '6P+jKF9sumvQndy4/znPrDIm8Vmtz+f+m1Qj/uljVWuedetHa8+9Rx6/eHBZ' 'wnKipctEYwEZ74OR2oXXHlyxa0v9sfLZ76hZ6zf4s3UEvdnOvyYs926cp0zi' '/McT7GvClwTN3qxauK3Ir3/9pbJYv6t7PtX0bar5d/2zRU551s9MVXveKONn' 'M48Fvwz5esdvpmdkyrHET4+4zrmzpsc+4tidGvl7z7l39x/+m2v5h/uj+NLm' 'ruCt9TckWC16fKSF8y+kO879meMhk/i9w18j/ewq936LwvkW3Fcfr/zWaj/T' '/q1dwZYnNfbaP/JV9m3gLD3JW5j8ZHZKx543X+a5T3fT9GPO2RYxl1/0Z6no' 'Hl9P9sRqxl28sk8ec93b8vPU7z/8615pvdR87m6/oNMm9Hf0/D+14THln/fx' '83df4Y6wiYr1i427ajnls8+/rEcXi5+dqLqaG/9I3/xfcb7u25d/fW5YTfm+' 'Wc9nf35N4glbbZkdTYt/xeV4ySTa/9Nf21b/8U6mVkl2QfZ1g57Ic/9X/V9r' '9ZHH9/KTylV/viz5//x3PP/0D/+5L6/t38v5+PKmVY//M5ac/+oEAKjKSvo=') pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(zlib.decompress(base64.b64decode(data)))) self.assertEqual(len(pipeline.modules()), 4) # # 4 modules - first resizes by factor, second resizes to a fixed size # interpolation is different for each # for module in pipeline.modules()[1:]: self.assertTrue(isinstance(module, cellprofiler.modules.resize.Resize)) module = pipeline.modules()[1] self.assertEqual(module.x_name, 'DNA') self.assertEqual(module.y_name, 'ResizedDNA') self.assertEqual(module.size_method, cellprofiler.modules.resize.R_BY_FACTOR) self.assertAlmostEqual(module.resizing_factor.value, .25) self.assertEqual(module.interpolation, cellprofiler.modules.resize.I_NEAREST_NEIGHBOR) module = pipeline.modules()[2] self.assertEqual(module.size_method, cellprofiler.modules.resize.R_TO_SIZE) self.assertEqual(module.specific_width.value, 150) self.assertEqual(module.specific_height.value, 150) self.assertEqual(module.interpolation, cellprofiler.modules.resize.I_BILINEAR) module = pipeline.modules()[3] self.assertEqual(module.interpolation, cellprofiler.modules.resize.I_BICUBIC)
def test_01_03_load_v3(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:3 DateRevision:20140505183007 GitHash:c675ec6 ModuleCount:1 HasImagePlaneDetails:False OverlayOutlines:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:3|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)|enabled:True|wants_pause:False] Display outlines on a blank image?:No Select image on which to display outlines:DNA Name the output image:PrimaryOverlay Outline display mode:Color Select method to determine brightness of outlines:Max of image Width of outlines:1.5 Select outlines to display:PrimaryOutlines Select outline color:Red Load outlines from an image or objects?:Image Select objects to display:Nuclei Select outlines to display\x3A:SecondaryOutlines Select outline color\x3A:Green Load outlines from an image or objects?:Objects Select objects to display:Cells """ pipeline = cellprofiler.pipeline.Pipeline() pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.overlayoutlines.OverlayOutlines)) self.assertFalse(module.blank_image) self.assertEqual(module.image_name, "DNA") self.assertEqual(module.output_image_name, "PrimaryOverlay") self.assertEqual(module.wants_color, "Color") self.assertEqual(module.max_type, cellprofiler.modules.overlayoutlines.MAX_IMAGE) self.assertEqual(module.line_mode.value, "Inner") self.assertEqual(len(module.outlines), 2) for outline, name, color, choice, objects_name in ( (module.outlines[0], "PrimaryOutlines", "Red", cellprofiler.modules.overlayoutlines.FROM_IMAGES, "Nuclei"), (module.outlines[1], "SecondaryOutlines", "Green", cellprofiler.modules.overlayoutlines.FROM_OBJECTS, "Cells")): self.assertEqual(outline.color, color) self.assertEqual(outline.objects_name, objects_name)
def test_01_00_load_matlab(self): data = ('eJzzdQzxcXRSMNUzUPB1DNFNy8xJ1VEIyEksScsvyrVSCHAO9/TTUXAuSk0s' 'SU1RyM+zUggpTVXwTSxSMDRTMDSxMjW3MrJQMDIwNFAgGTAwevryMzAwrGZk' 'YKiY8zbM1v+wgcDeFpapDEuFuIOvchpu3WDY9MJBVaNj0boTqn6pmp2LaxRO' '6Sc86S9JT3mSnrjd77VExqRLnF8XBX+ZU/1+nl78OqYDt80OqFmHR7wy4A1O' '8PXqq7bo67Tv8TF44LCmfsObxRMWNHb/PuFbwLLZ47r1Puf37gffXDLdKixe' 'PlFdfPMLtXsM7Rd7JwsdfRr9qeeuXOXBCb1b3vDZT+wIiP/Qum+X1Wvv5KX5' 'U5+utpzfvOxM4/mjk65V/jU887pX/tk2xavXJT5Fv/Dfc1lm3syHvoWbnwZo' '/dE7bJ/DG6DxI93yT2zr+Y1vF7M/WqiYd+yI5orNi18U3Hk3rzzG/GPLmaDi' 'FKnWZwGNOf+7rsz/rF/84zfX/MfHA32YxV3j0qSOPkvUrJLZnnl4eaFy5xHu' 'QJd074sPfyh9ZT1aGvY0fe3ma5FLPq+c/ltuuu3zn2s07Sr97t1L9Ji8wLFG' 'mn31lcjfv+//u/fw+/OZybKbzhfH3bddqn88XOSm7TbHZGu9dwlLrT79LzM+' 'vv8c32mtb/OvObxbf5Cz5rnoy3SJp5Vs1se+FtZu+t9c9P15hmOt1Olr9YzH' 'iy8IAQDsQ/za') pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO(zlib.decompress(base64.b64decode(data)))) self.assertEqual(len(pipeline.modules()), 2) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage)) self.assertEqual(module.directory.dir_choice, cellprofiler.setting.DEFAULT_INPUT_SUBFOLDER_NAME) self.assertEqual(module.directory.custom_path, "./foo") self.assertEqual(len(module.file_settings), 2) fs = module.file_settings[0] self.assertEqual(fs.file_name, "dna_image.tif") self.assertEqual(fs.image_name, "DNA") fs = module.file_settings[1] self.assertEqual(fs.file_name, "cytoplasm_image.tif") self.assertEqual(fs.image_name, "Cytoplasm") module = pipeline.modules()[1] self.assertTrue(isinstance(module, cellprofiler.modules.loadsingleimage.LoadSingleImage)) self.assertEqual(module.directory.dir_choice, cellprofiler.setting.DEFAULT_OUTPUT_SUBFOLDER_NAME) self.assertEqual(module.directory.custom_path, "./bar") self.assertEqual(len(module.file_settings), 1) fs = module.file_settings[0] self.assertEqual(fs.file_name, "DNAIllum.tif") self.assertEqual(fs.image_name, "DNAIllum")
def test_01_06_load_v6(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:10536 LoadData:[module_num:1|svn_version:\'Unknown\'|variable_revision_number:6|show_window:True|notes:\x5B\x5D] Input data file location:Elsewhere...\x7Cx\x3A\\projects\\NightlyBuild\\trunk\\ExampleImages\\ExampleSBSImages Name of the file:1049_Metadata.csv Load images based on this data?:Yes Base image location:Default Input Folder\x7C. Process just a range of rows?:No Rows to process:1,100000 Group images by metadata?:Yes Select metadata fields for grouping:Column,Row Rescale intensities?:Yes """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.loaddata.LoadData)) self.assertEqual(module.csv_file_name, "1049_Metadata.csv") self.assertEqual(module.csv_directory.dir_choice, cellprofiler.setting.ABSOLUTE_FOLDER_NAME) self.assertEqual(module.csv_directory.custom_path, r"x:\projects\NightlyBuild\trunk\ExampleImages\ExampleSBSImages") self.assertTrue(module.wants_images) self.assertEqual(module.image_directory.dir_choice, cellprofiler.setting.DEFAULT_INPUT_FOLDER_NAME) self.assertTrue(module.rescale) self.assertTrue(module.wants_image_groupings) self.assertFalse(module.wants_rows) self.assertEqual(module.row_range.min, 1) self.assertEqual(module.row_range.max, 100000) self.assertEqual(len(module.metadata_fields.selections), 2) self.assertEqual(module.metadata_fields.selections[0], "Column") self.assertEqual(module.metadata_fields.selections[1], "Row")
def test_load_v1(pipeline): data = ('eJztWltv2jAUNpeidpW6rnvYpL74cZvaKKFF2ngZFNaNqVy0ok57WxoM9WR' 'slDgU9kv2U/a4n7SfsBhCSbzQcGm5SIlkwXH8ne+c4xM7OXI5X7/In8GMos' 'Jyvn7cxATBGtF5k5ntLKT8CBZMpHPUgIxm4bmJ4WebQi0NtZOspmZPMzCtq' 'u/AfFesVN5zfn69BiDl/G47Le7e2nLlmKcJ+RJxjmnL2gJJ8NLt/+O0K93E' '+jVBVzqxkTWmGPWXaJPV+527W2XWsAmq6G3vYOeq2O1rZFrV5gjo3q7hHiK' 'X+CeSXBgN+4K62MKMunhXv9x7x8u4xCviAJ6P4xCT4pBw2qGnX4z/BMbjkw' 'Fxe+YZv+/KmDZwFzdsnUDc1lt3Vgh9b0P0bUv6hFw1cevMCfk0+JSETw3ib' 'RCEh/y5EPy+hBetjnr8+ENPNzhs69y4WYYdOxJeyAVESEkE1BNPNURPzKcn' 'Bk6mnIctiV/Imnp0qi6ALzDCTDCd/08kvJCLDFLGoW2h6f1P+PQkwDcnG+e' 'dv1tMOTKn44378HFQYQ+HS0m40TXC7YBxfMKe3xeSn0IuoqZuEw4HuQaL2E' 'QGZ2Z/oXjPa/+s+a2A6fJrV/JbyFVu2fAjYdc6CeR/SLvnzQ/ZX21N7ZTzQ' 'D3SHtXOpI8vCYr5WmkenKqo2iJ2Lrq/5ULwQftCyVmWqIV5f0K8lhHnTbO7' 'wiiaJ/81dT3tlNeFTADfOtj5mPvDLLhciJ17wJ+vQh6+v1VtTjAVL7WrsHt' 'T4hvZuVo7nX1sLZ+rZb53RXmwvnbK+6qSWc2850LsDMrX+i2DBtEty61srM' 'LusO+6oLrMV4RbN6LM1hUFJWpMqiOsQ9yDvv/PmYlaJrNpY3H+7wez1cGW6' 'eegaCYc7UyvJyhP2fUP58t9rGjZ+ebhh5g2UGeGuATV4cZxGapb9boW4SJc' 'hItwm4zLeXDROhzhItxqcWHvWQfA/zwKmQ0rUv+9aG2S3xEuwq3Dfjft99i' 'm+BvhIlyEWx2uFxvj5DqTXK8d1KU8PEHr0xvgX5+EbCBCOiYT5+pMpT04/G' 'UphOmN4ekr5cL5W/IcxBI8nRCenMSTm8SDG4hy3Ox3TIfN5qytc2woJbe35' 'vTmR72C9yaENy3xpifxGox2kck5GzipFIZinXkOSMnzthPA541/3JGeHibv' 'nW8A/PM8nv+/7+fhiydiAz7vuYHdEFzSY9PIz99gtjx7dc/4kY/LGv8PmsR' 'r2g==') fd = StringIO.StringIO(zlib.decompress(base64.b64decode(data))) pipeline.load(fd) assert len(pipeline.modules()) == 3 module = pipeline.modules()[2] assert isinstance(module, cellprofiler.modules.convertobjectstoimage.ConvertToImage) assert module.object_name.value == "Nuclei" assert module.image_name.value == "CellImage" assert module.image_mode.value == "Color" assert module.colormap.value == "winter"
def test_01_02_load_v1(self): data = r"""CellProfiler Pipeline: http://www.cellprofiler.org Version:1 SVNRevision:9169 MeasureImageOverlap:[module_num:1|svn_version:\'9000\'|variable_revision_number:1|show_window:True|notes:\x5B\x5D] Which image do you want to use as the basis for calculating the amount of overlap? :GroundTruth Which image do you want to compare for overlap?:Segmentation """ pipeline = cellprofiler.pipeline.Pipeline() def callback(caller, event): self.assertFalse(isinstance(event, cellprofiler.pipeline.LoadExceptionEvent)) pipeline.add_listener(callback) pipeline.load(StringIO.StringIO(data)) self.assertEqual(len(pipeline.modules()), 1) module = pipeline.modules()[0] self.assertTrue(isinstance(module, cellprofiler.modules.measureimageoverlap.MeasureImageOverlap)) self.assertEqual(module.ground_truth, "GroundTruth") self.assertEqual(module.test_img, "Segmentation")
def print_measurements(options): """Print the measurements that would be output by a pipeline This function calls Pipeline.get_measurement_columns() to get the measurements that would be output by a pipeline. This can be used in a workflow tool or LIMS to find the outputs of a pipeline without running it. For instance, someone might want to integrate CellProfiler with Knime and write a Knime node that let the user specify a pipeline file. The node could then execute CellProfiler with the --measurements switch and display the measurements as node outputs. """ if options.pipeline_filename is None: raise ValueError("Can't print measurements, no pipeline file") import cellprofiler.pipeline pipeline = cellprofiler.pipeline.Pipeline() def callback(pipeline, event): if isinstance(event, cellprofiler.pipeline.LoadExceptionEvent): raise ValueError("Failed to load %s" % options.pipeline_filename) pipeline.add_listener(callback) pipeline.load(os.path.expanduser(options.pipeline_filename)) columns = pipeline.get_measurement_columns() print "--- begin measurements ---" print "Object,Feature,Type" for column in columns: object_name, feature, data_type = column[:3] print "%s,%s,%s" % (object_name, feature, data_type) print "--- end measurements ---"
def test_load_matlab(pipeline): data = ('eJzzdQzxcXRSMNUzUPB1DNFNy8xJ1VEIyEksScsvyrVSCHAO9/TTUXAuSk0' 'sSU1RyM+zUnArylTwKs1TMDRSMDS2Mja3MjBUMDIwsFQgGTAwevryMzAwrG' 'BiYKiY8zbcMf+WgUiZgsI1v45A31uNzn3WJbI5l7c81rLK9ZAO0V5lkikuz' 'PP1yQ2NQoE307/umL/p9b+jSR5Nj5kMPa+8M/Ce9nXO933f9z6fLr6cj2FH' 'LlMA77UoA+8EW62FOR7BJ8I7in2Wx7HOeBC547/2jOsXjha4XDBVsfvkYLP' 'or9zcDQ+LxOx/HTpm51j74sSpgy9+n+PYeS9BSLKtX/8j00TtP8KNTzqu7F' 'tk+c1g8cLajvXvjtVJhv+51vzzd8ZkdueTzpYz1C/tu1DPb/br2bQ9pip/3' 'SzaMw7G10Q4zI7me/Kt90Dm8gdThC1SCy7ax/+sn54UHvonPPznVs5DDqf3' 'LbvBvbOaWdP1Sajgv8ufytfckD/+zZbdL7CGL/Lz9LR0tTc+H7598Y1Wf9d' '1KPpErNsM7qLneyer3st3XJveWe70IOT5HDnNmtY7sUVmyheKD9XK/l/K4s' 'f55eYtvU3+jwuXfBD4xLpZ4/G094q1crs/hZv0m8zJ/Wr/YF5+rUoOi2dP8' 'f2fhkIWbC9sBPi/zrm1fC5Lv/PjirWZy/epv91c9lzxVfLt6uuLZQL5Py89' 'oh5lv/SBbeCHlp6XEuc/3mg/cmjRyyqhuIt/Nn1r17E5V3uuid9gm/GHgNf' 'PdNztvn080WRe+vDSZkVHIb97ddOv2vXuf1e94LRydq3IWeez7LWc3Jbtey' 'o73kg/+1e97g77p29bQy/P2HVm/svHOb/fbbzIn/KZN+DePrWHkY79zpuZH' '90pW3//yM42bSH33vLrv+7Hb/z376rp2nuzFWayKxrPF/a5OLdpemH2sXf7' 'FnxbvubvA+Pmx/NKJl7ofL6ySfnJPYnAPvXT3uLWn8xD2sNjDwoXTb9oWfR' 'zQuv+aVnz1y57sljE46yw8fW/PwPqpx4/Nvf/SRNr4ys/70lt+bflWl3+wc' 'Tn/2r660zeef/XfzaV/REATdyFtA==') fd = StringIO.StringIO(zlib.decompress(base64.b64decode(data))) pipeline.load(fd) assert len(pipeline.modules()) == 3 module = pipeline.modules()[2] assert isinstance(module, cellprofiler.modules.convertobjectstoimage.ConvertToImage) assert module.object_name.value == "Nuclei" assert module.image_name.value == "NucleiImage" assert module.image_mode.value == "Color" assert module.colormap.value == "flag"