Exemple #1
0
def test_load_v3():
    with open("./tests/resources/modules/flagimages/v3.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    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"),
                ("Intensity_MinIntensity_Cytoplasm", 0.05, None, "bar.txt"),
                ("Intensity_MeanIntensity_DNA", 0.1, 0.9, "baz.txt"),
            ),
        ),
        (
            "HighCytoplasmIntensity",
            None,
            True,
            (("Intensity_MeanIntensity_Cytoplasm", None, 0.8, "dunno.txt"), ),
        ),
    )
    assert len(expected) == module.flag_count.value
    for flag, (feature_name, combine, skip,
               measurements) in zip(module.flags, expected):
        assert isinstance(flag, cellprofiler_core.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)) in zip(flag.measurement_settings,
                                               measurements):
            assert isinstance(measurement,
                              cellprofiler_core.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 == "1"
def test_load_v2():
    path = tests.modules.get_test_resources_directory(
        "calculatestatistics/v2.pipeline")
    with open(path, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(six.moves.StringIO(data))
    assert len(pipeline.modules()) == 1
    module = pipeline.modules()[0]
    assert isinstance(
        module, cellprofiler.modules.calculatestatistics.CalculateStatistics)
    assert module.grouping_values == "Metadata_Controls"
    assert len(module.dose_values) == 1
    dv = module.dose_values[0]
    assert dv.measurement == "Metadata_SBS_Doses"
    assert not dv.log_transform
    assert dv.wants_save_figure
    assert dv.figure_name == "DoseResponsePlot"
    assert (dv.pathname.dir_choice ==
            cellprofiler_core.preferences.DEFAULT_OUTPUT_FOLDER_NAME)
    assert dv.pathname.custom_path == "Test"
def test_load_v2():
    file = tests.modules.get_test_resources_directory(
        "measureobjectneighbors/v2.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    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_load_v4():
    with open("./tests/resources/modules/loaddata/v4.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    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_core.preferences.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"
Exemple #5
0
def test_load_v4():
    file = tests.modules.get_test_resources_directory("imagemath/v4.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(six.moves.StringIO(data))
    module = pipeline.modules()[-1]
    assert isinstance(module, cellprofiler.modules.imagemath.ImageMath)
    assert module.operation == cellprofiler.modules.imagemath.O_LOG_TRANSFORM
    assert module.exponent == 1.5
    assert module.after_factor == 0.5
    assert module.addend == 0.1
    assert module.truncate_low
    assert not module.truncate_high
    assert module.ignore_mask
    assert module.output_image_name == "LogTransformed"
    assert (module.images[0].image_or_measurement ==
            cellprofiler.modules.imagemath.IM_IMAGE)
    assert module.images[0].image_name == "DNA"
    assert module.images[0].factor == 1.2
    assert (module.images[1].image_or_measurement ==
            cellprofiler.modules.imagemath.IM_MEASUREMENT)
    assert module.images[1].measurement == "Count_Nuclei"
    assert module.images[1].factor == 1.5
Exemple #6
0
def test_load_v1():
    file = tests.modules.get_test_resources_directory(
        "maskobjects/v1.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    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
Exemple #7
0
def test_load_v3():
    with open("./tests/resources/modules/resize/v3.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    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
Exemple #8
0
def test_load_v1():
    file = tests.modules.test_resources_directory("tile/v1.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    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
Exemple #9
0
def test_load_v5():
    with open("./tests/resources/modules/displaydataonimage/v5.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    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_v3():
    file = tests.modules.get_test_resources_directory(
        "measuregranularity/v3.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(six.moves.StringIO(data))
    assert len(pipeline.modules()) == 1
    module = pipeline.modules()[0]
    assert isinstance(
        module, cellprofiler.modules.measuregranularity.MeasureGranularity)
    assert len(module.images_list.value) == 2
    for image_name, subsample_size, bsize, elsize, glen, objs in (
        ("DNA", 0.25, 0.25, 10, 16, ("Nuclei", "Cells")),
        ("Actin", 0.33, 0.50, 12, 20, ("Nuclei", "Cells", "Cytoplasm")),
    ):
        assert image_name in module.images_list.value
        assert module.subsample_size.value == 0.25
        assert module.image_sample_size.value == 0.25
        assert module.element_size.value == 10
        assert module.granular_spectrum_length.value == 16
        assert len(module.objects_list.value) == 3
        assert all([obj in module.objects_list.value for obj in objs])
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_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    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_load_v6():
    with open("./tests/resources/modules/loaddata/v6.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    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_core.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_core.preferences.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_v2():
    file = tests.modules.test_resources_directory("maskobjects/v2.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(six.moves.StringIO(data))
    assert len(pipeline.modules()) == 1

    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 module.wants_inverted_mask
def test_load_v3():
    file = tests.modules.test_resources_directory("filterobjects/v3.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(io.StringIO(data))
    assert len(pipeline.modules()) == 1
    module = pipeline.modules()[-1]
    assert isinstance(module, cellprofiler.modules.filterobjects.FilterObjects)
    assert module.x_name == "Things"
    assert module.y_name == "FilteredThings"
    assert module.mode == cellprofiler.modules.filterobjects.MODE_MEASUREMENTS
    assert (
        module.rules_directory.dir_choice
        == cellprofiler_core.preferences.DEFAULT_OUTPUT_FOLDER_NAME
    )
    assert module.rules_file_name == "myrules.txt"
    assert module.measurements[0].measurement == "Intensity_MeanIntensity_DNA"
    assert module.filter_choice == cellprofiler.modules.filterobjects.FI_MINIMAL
def test_load_v3():
    with open("./tests/resources/modules/graytocolor/v3.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(six.moves.StringIO(data))
    assert len(pipeline.modules()) == 1
    module = pipeline.modules()[0]
    assert isinstance(module, cellprofiler.modules.graytocolor.GrayToColor)
    assert module.scheme_choice == cellprofiler.modules.graytocolor.SCHEME_COMPOSITE
    assert module.rgb_image_name == "myimage"
    assert module.red_image_name == "1"
    assert module.green_image_name == "2"
    assert module.blue_image_name == "3"
    assert module.cyan_image_name == "4"
    assert module.magenta_image_name == "5"
    assert module.yellow_image_name == "6"
    assert module.gray_image_name == "7"
    assert numpy.round(numpy.abs(module.red_adjustment_factor.value - 2.1), 7) == 0
    assert numpy.round(numpy.abs(module.green_adjustment_factor.value - 2.2), 7) == 0
    assert numpy.round(numpy.abs(module.blue_adjustment_factor.value - 2.3), 7) == 0
    assert numpy.round(numpy.abs(module.cyan_adjustment_factor.value - 1.1), 7) == 0
    assert numpy.round(numpy.abs(module.magenta_adjustment_factor.value - 1.2), 7) == 0
    assert numpy.round(numpy.abs(module.yellow_adjustment_factor.value - 1.3), 7) == 0
    assert numpy.round(numpy.abs(module.gray_adjustment_factor.value - 1.4), 7) == 0
    assert len(module.stack_channels) == 2
    assert module.stack_channels[0].image_name == "DNA"
    assert module.stack_channels[1].image_name == "GFP"
    assert module.stack_channels[0].color.to_rgb() == (127, 0, 255)
    assert module.stack_channels[1].color.to_rgb() == (127, 255, 0)
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_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    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 len(module.images_list.value) == 2
    assert module.thr == 25.0
    for name in module.images_list.value:
        assert name in ["DNA", "Cytoplasm"]

    assert len(module.objects_list.value) == 2
    for name in module.objects_list.value:
        assert name in ["Nuclei", "Cells"]
Exemple #17
0
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_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    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"
Exemple #18
0
def test_load_v1():
    file = tests.modules.test_resources_directory("labelimages/v1.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    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
Exemple #19
0
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_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    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
Exemple #20
0
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_core.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_core.measurement.Measurements()

    workspace = cellprofiler_core.workspace.Workspace(
        pipeline, module, m, cellprofiler_core.object.ObjectSet, m, None)

    module.prepare_run(workspace)
Exemple #21
0
def test_load_v2():
    with open("./tests/resources/modules/makeprojection/v2.pipeline",
              "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    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_v4():
    file = tests.modules.get_test_resources_directory("displaydataonimage/v4.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    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 module.wants_image
def test_load_v1():
    file = tests.modules.test_resources_directory("straightenworms/v1.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    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_core.preferences.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
Exemple #24
0
def test_load_v5():
    pipeline_file = os.path.join(get_data_directory(),
                                 "modules/metadata/v5.pipeline")
    with open(pipeline_file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(io.StringIO(data))
    assert len(pipeline.modules()) == 1
    module = pipeline.modules()[0]

    em0, em1 = module.extraction_methods

    assert (em0.csv_location.get_dir_choice() ==
            cellprofiler_core.preferences.ABSOLUTE_FOLDER_NAME)
    assert em0.csv_location.get_custom_path() == "/imaging/analysis"
    assert em0.csv_filename.value == "metadata.csv"

    assert (em1.csv_location.get_dir_choice() ==
            cellprofiler_core.preferences.URL_FOLDER_NAME)
    assert em1.csv_location.get_custom_path() == "https://cellprofiler.org"
    assert em1.csv_filename.value == "metadata.csv"
Exemple #25
0
def test_load_v4():
    pipeline_file = os.path.join(get_data_directory(),
                                 "modules/metadata/v4.pipeline")
    with open(pipeline_file, "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(io.StringIO(data))
    assert len(pipeline.modules()) == 1
    module = pipeline.modules()[0]
    assert isinstance(module, cellprofiler_core.modules.metadata.Metadata)
    assert module.wants_metadata
    assert (module.data_type_choice ==
            cellprofiler_core.constants.modules.metadata.DTC_CHOOSE)
    d = cellprofiler_core.setting.DataTypes.decode_data_types(
        module.data_types.value_text)
    for k, v in (
        ("Index", cellprofiler_core.setting.DataTypes.DT_NONE),
        ("WellRow", cellprofiler_core.setting.DataTypes.DT_TEXT),
        ("WellColumn", cellprofiler_core.setting.DataTypes.DT_FLOAT),
        ("ChannelNumber", cellprofiler_core.setting.DataTypes.DT_INTEGER),
    ):
        assert k in d
        assert d[k] == v
    assert len(module.extraction_methods) == 2
    em0, em1 = module.extraction_methods
    assert (em0.extraction_method ==
            cellprofiler_core.constants.modules.metadata.X_MANUAL_EXTRACTION)
    assert em0.source == cellprofiler_core.constants.modules.metadata.XM_FILE_NAME
    assert (
        em0.file_regexp.value ==
        r"^Channel(?P<ChannelNumber>[12])-(?P<Index>[0-9]+)-(?P<WellRow>[A-H])-(?P<WellColumn>[0-9]{2}).tif$"
    )
    assert em0.folder_regexp.value == r"(?P<Date>[0-9]{4}_[0-9]{2}_[0-9]{2})$"
    assert (em0.filter_choice ==
            cellprofiler_core.constants.modules.metadata.F_ALL_IMAGES)
    assert em0.filter == 'or (file does contain "Channel2")'
    assert not em0.wants_case_insensitive

    assert (em1.extraction_method ==
            cellprofiler_core.constants.modules.metadata.X_IMPORTED_EXTRACTION)
    assert em1.source == cellprofiler_core.constants.modules.metadata.XM_FOLDER_NAME
    assert (em1.filter_choice ==
            cellprofiler_core.constants.modules.metadata.F_FILTERED_IMAGES)
    assert (em1.csv_location.get_dir_choice() ==
            cellprofiler_core.preferences.ABSOLUTE_FOLDER_NAME)
    assert em1.csv_location.get_custom_path() == "/imaging/analysis"
    assert em1.csv_filename.value == "metadata.csv"
    assert (
        em1.csv_joiner.value ==
        "[{'Image Metadata': u'ChannelNumber', 'CSV Metadata': u'Wavelength'}]"
    )
    assert em1.wants_case_insensitive
Exemple #26
0
def test_load_v3():
    data = """CellProfiler Pipeline: http://www.cellprofiler.org
Version:1
SVNRevision:10865

MeasureTexture:[module_num:1|svn_version:\'1\'|variable_revision_number:3|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
Angles to measure:Horizontal,Vertical
Texture scale to measure:5
Angles to measure:Diagonal,Anti-diagonal
Measure Gabor features?:Yes
Number of angles to compute for Gabor:6

MeasureTexture:[module_num:2|svn_version:\'1\'|variable_revision_number:3|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
Angles to measure:Horizontal,Vertical
Texture scale to measure:5
Angles to measure:Diagonal,Anti-diagonal
Measure Gabor features?:No
Number of angles to compute for Gabor:6
"""
    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(io.StringIO(data))
    assert len(pipeline.modules()) == 2
    for i, wants_gabor in enumerate((True, False)):
        module = pipeline.modules()[i]
        assert isinstance(module,
                          cellprofiler.modules.measuretexture.MeasureTexture)
        assert len(module.image_groups) == 2
        assert module.image_groups[0].image_name.value == "rawDNA"
        assert module.image_groups[1].image_name.value == "rawGFP"
        assert len(module.object_groups) == 2
        assert module.object_groups[0].object_name.value == "Cells"
        assert module.object_groups[1].object_name.value == "Nuclei"
        assert len(module.scale_groups) == 2
        assert module.scale_groups[0].scale == 3
        assert module.scale_groups[1].scale == 5
        assert module.images_or_objects == cellprofiler.modules.measuretexture.IO_BOTH
Exemple #27
0
def test_load_v2():
    data = """CellProfiler Pipeline: http://www.cellprofiler.org
Version:2
DateRevision:20120126174947

MeasureObjectIntensityDistribution:[module_num:8|svn_version:\'Unknown\'|variable_revision_number:2|show_window:True|notes:\x5B\x5D|batch_state:array(\x5B\x5D, dtype=uint8)]
Hidden:2
Hidden:2
Hidden:2
Select an image to measure:EnhancedGreen
Select an image to measure:OrigBlue
Select objects to measure:Nuclei
Object to use as center?:These objects
Select objects to use as centers:Cells
Select objects to measure:Nuclei
Object to use as center?:Other objects
Select objects to use as centers:Cells
Scale bins?:No
Number of bins:4
Maximum radius:200
Scale bins?:Yes
Number of bins:5
Maximum radius:50
"""
    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event,
                              cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(io.StringIO(data))
    assert len(pipeline.modules()) == 1
    module = pipeline.modules()[0]
    assert isinstance(
        module,
        cellprofiler.modules.measureobjectintensitydistribution.
        MeasureObjectIntensityDistribution,
    )
    assert module.image_count.value == 2
    assert module.object_count.value == 2
    assert module.bin_counts_count.value == 2
    assert module.images[0].image_name == "EnhancedGreen"
    assert module.images[1].image_name == "OrigBlue"
    assert module.objects[0].object_name == "Nuclei"
    assert (module.objects[0].center_choice ==
            cellprofiler.modules.measureobjectintensitydistribution.C_SELF)
    assert module.objects[0].center_object_name == "Cells"
    assert (module.objects[1].center_choice == cellprofiler.modules.
            measureobjectintensitydistribution.C_CENTERS_OF_OTHER)
    assert module.objects[1].center_object_name == "Cells"
    assert module.bin_counts[0].bin_count == 4
    assert not module.bin_counts[0].wants_scaled
    assert module.bin_counts[0].maximum_radius == 200
    assert module.bin_counts[1].bin_count == 5
    assert module.bin_counts[1].wants_scaled
    assert module.bin_counts[1].maximum_radius == 50
def test_load_v3():
    with open("./tests/resources/modules/measureimagequality/v3.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    pipeline.add_listener(callback)
    pipeline.load(io.StringIO(data))
    assert len(pipeline.modules()) == 1
    module = pipeline.modules()[0]
    assert isinstance(
        module, cellprofiler.modules.measureimagequality.MeasureImageQuality
    )
    assert len(module.image_groups) == 2

    group = module.image_groups[0]
    thr = group.threshold_groups[0]
    assert group.image_names.value_text == "Alpha"
    assert group.check_blur
    assert group.scale_groups[0].scale == 25
    assert group.check_saturation
    assert group.calculate_threshold
    assert thr.threshold_method == centrosome.threshold.TM_OTSU
    assert round(abs(thr.object_fraction.value - 0.2), 7) == 0
    assert thr.two_class_otsu == cellprofiler_core.modules.identify.O_THREE_CLASS
    assert (
        thr.use_weighted_variance
        == cellprofiler_core.modules.identify.O_WEIGHTED_VARIANCE
    )
    assert (
        thr.assign_middle_to_foreground
        == cellprofiler_core.modules.identify.O_FOREGROUND
    )

    group = module.image_groups[1]
    thr = group.threshold_groups[0]
    assert group.image_names.value_text == "Beta"
    assert not group.check_blur
    assert group.scale_groups[0].scale == 15
    assert not group.check_saturation
    assert not group.calculate_threshold
    assert thr.threshold_method == centrosome.threshold.TM_MOG
    assert round(abs(thr.object_fraction.value - 0.3), 7) == 0
    assert thr.two_class_otsu == cellprofiler_core.modules.identify.O_TWO_CLASS
    assert thr.use_weighted_variance == cellprofiler_core.modules.identify.O_ENTROPY
    assert (
        thr.assign_middle_to_foreground
        == cellprofiler_core.modules.identify.O_BACKGROUND
    )
def test_load_with_extracted_operations():
    file = tests.modules.get_test_resources_directory("morph/extracted_operations.pipeline")
    with open(file, "r") as fd:
        data = fd.read()

    def callback(caller, event):
        assert not isinstance(event, cellprofiler_core.pipeline.event.LoadException)

    pipeline = cellprofiler_core.pipeline.Pipeline()
    pipeline.add_listener(callback)
    pipeline.load(io.StringIO(data))

    module = pipeline.modules()[-1]
    with pytest.raises(cellprofiler_core.setting.ValidationError):
        module.test_valid(pipeline)
def test_load_v02():
    with open("./tests/resources/modules/smooth/v2.pipeline", "r") as fd:
        data = fd.read()

    pipeline = cellprofiler_core.pipeline.Pipeline()
    pipeline.load(io.StringIO(data))
    assert len(pipeline.modules()) == 1
    smooth = pipeline.modules()[0]
    assert isinstance(smooth, cellprofiler.modules.smooth.Smooth)
    assert smooth.image_name == "InputImage"
    assert smooth.filtered_image_name == "OutputImage"
    assert smooth.wants_automatic_object_size
    assert smooth.object_size == 19
    assert smooth.smoothing_method == cellprofiler.modules.smooth.MEDIAN_FILTER
    assert not smooth.clip