Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
 def test_01_01_get_from_image_set(self):
     image = numpy.zeros((10,10),dtype=float)
     image_set_list = cellprofiler.cpimage.ImageSetList()
     ii = InjectImage("my_image", image)
     pipeline = cellprofiler.pipeline.Pipeline()
     ii.prepare_run(cpw.Workspace(pipeline, ii, None, None,
                                  cpmeas.Measurements(), image_set_list))
     ii.prepare_group(pipeline, image_set_list, {}, [1])
     image_set = image_set_list.get_image_set(0)
     self.assertTrue(image_set,"No image set returned from ImageSetList.GetImageSet")
     my_image = image_set.get_image("my_image")
     self.assertTrue(my_image, "No image returned from ImageSet.GetImage")
     self.assertEqual(my_image.image.shape[0],10,"Wrong image shape")
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
Ejemplo n.º 4
0
 def test_01_01_get_from_image_set(self):
     image = numpy.zeros((10,10),dtype=float)
     ii = InjectImage("my_image", image)
     pipeline = cellprofiler.pipeline.Pipeline()
     measurements = cpmeas.Measurements()
     workspace = cpw.Workspace(pipeline, ii, measurements, None,
                               measurements,
                               cellprofiler.cpimage.ImageSetList())
     ii.prepare_run(workspace)
     ii.prepare_group(workspace, {}, [1])
     ii.run(workspace)
     image_set = workspace.image_set
     self.assertTrue(image_set,"No image set returned from ImageSetList.GetImageSet")
     my_image = image_set.get_image("my_image")
     self.assertTrue(my_image, "No image returned from ImageSet.GetImage")
     self.assertEqual(my_image.image.shape[0],10,"Wrong image shape")
Ejemplo n.º 5
0
    def make_workspace(self, input_image, input_mask=None,
                       reference_image=None, reference_mask=None,
                       measurement=None):
        pipeline = cpp.Pipeline()

        def callback(caller, event):
            self.assertFalse(isinstance(event, cpp.RunExceptionEvent))

        pipeline.add_listener(callback)
        object_set = cpo.ObjectSet()
        image_set_list = cpi.ImageSetList()
        image_set = image_set_list.get_image_set(0)
        measurements = cpmeas.Measurements()
        module_number = 1
        module = R.RescaleIntensity()
        module.image_name.value = INPUT_NAME
        if isinstance(input_image, (tuple, list)):
            first_input_image = input_image[0]
        else:
            first_input_image = input_image
        if isinstance(input_mask, (tuple, list)):
            first_input_mask = input_mask[0]
        else:
            first_input_mask = input_mask
        if first_input_mask is None:
            image = cpi.Image(first_input_image)
        else:
            image = cpi.Image(first_input_image, first_input_mask)
        ii = InjectImage(INPUT_NAME, input_image, input_mask)
        ii.module_num = module_number
        module_number += 1
        pipeline.add_module(ii)
        image_set.add(INPUT_NAME, image)
        module.rescaled_image_name.value = OUTPUT_NAME
        if reference_image is not None:
            module.matching_image_name.value = REFERENCE_NAME
            if reference_mask is None:
                image = cpi.Image(reference_image)
            else:
                image = cpi.Image(reference_image, mask=reference_mask)
            image_set.add(REFERENCE_NAME, image)
            ii = InjectImage(REFERENCE_NAME, reference_image, reference_mask)
            ii.module_num = module_number
            module_number += 1
            pipeline.add_module(ii)
        module.module_num = module_number
        pipeline.add_module(module)
        if measurement is not None:
            module.divisor_measurement.value = MEASUREMENT_NAME
            measurements.add_image_measurement(MEASUREMENT_NAME, measurement)
        workspace = cpw.Workspace(pipeline,
                                  module,
                                  image_set,
                                  object_set,
                                  measurements,
                                  image_set_list)
        return workspace, module
Ejemplo n.º 6
0
 def test_00_00_init(self):
     image = numpy.zeros((10,10),dtype=float)
     x = InjectImage("my_image", image)