def test_pixel_expansion_ring_plots(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.pixel_expansion_ring_plots(n_expansions=1,
                                                       expansions=[1])

            test_path = "%s/Ring Plots/%s%s Expansion/Point%s.png" % (temp_dir,
                                                                      str(round_to_nearest_half(
                                                                          1 *
                                                                          config.pixel_interval *
                                                                          config.pixels_to_distance)),
                                                                      config.data_resolution_units,
                                                                      str(1))

            assert path.exists(test_path)
    def test_removed_vessel_expression_boxplot(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir,
                             n_points=2,
                             resolution=(2048, 2048),
                             n_pseudo_vessel_size=(1, 50))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2,
                brain_region_point_ranges=[(1, 2)],
                brain_region_names=["Test Region"],
                data_resolution_size=(5000, 5000)
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.removed_vessel_expression_boxplot()

            test_path = "%s/Kept Vs. Removed Vessel Boxplots/Test/All Points/All_Points.png" % temp_dir

            assert path.exists(test_path)
    def test_vessel_images_by_categorical_variable(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.vessel_images_by_categorical_variable(primary_categorical_analysis_variable="Vessel Size")

            test_path = "%s/Vessel Size Vessel Images/Test/Large/Point_Num_1_Vessel_ID_5.png" % temp_dir

            assert path.exists(test_path)
    def test_box_plot_brain_expansions(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.box_plot_brain_expansions(n_expansions=1)

            test_path = "%s/Expansion Box Plots/Per Marker/0.5μm Expansion/SMA.png" % temp_dir

            assert path.exists(test_path)
    def test_spatial_probability_maps(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.spatial_probability_maps(mask_size=(2048, 2048))

            test_path = "%s/Pixel Expression Spatial Maps/Test/Vessels/Point1.png" % temp_dir

            assert path.exists(test_path)
    def test_categorical_violin_plot(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.categorical_violin_plot(primary_categorical_analysis_variable="Vessel Size",
                                                    mask_type="mask_and_expansion")

            test_path = "%s/Categorical Violin Plots/Test/By Vessel Size/Vessels/SMA.png" % temp_dir

            assert path.exists(test_path)
Beispiel #7
0
def create_test_data(test_dir,
                     n_points=48,
                     resolution=(2048, 2048),
                     n_pseudo_vessel_size=(10, 50)):
    config = Config()

    mask_dir = os.path.join(test_dir, "masks")
    data_dir = os.path.join(test_dir, "data")

    mkdir_p(mask_dir)
    mkdir_p(data_dir)

    for point_idx in range(n_points):
        directory_name = "Point" + str(point_idx + 1)

        point_data_dir = os.path.join(data_dir, directory_name, "TIFs")
        point_mask_dir = os.path.join(mask_dir, directory_name)

        mkdir_p(point_data_dir)
        mkdir_p(point_mask_dir)

        for cluster in config.marker_clusters.keys():
            for marker in config.marker_clusters[cluster]:
                data = generate_random_data(resolution)
                write_tif_data(data, marker, point_data_dir)

        mask = generate_random_mask(resolution, n_pseudo_vessel_size=n_pseudo_vessel_size)
        write_tif_data(mask, "allvessels", point_mask_dir)
    def test_vessel_nonvessel_masks(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2,
                brain_region_point_ranges=[(1, 2)],
                brain_region_names=["Test Region"]
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.vessel_nonvessel_masks()

            test_path = "%s/Associated Area Masks/Test/2.5μm Expansion/Point 1.png" % temp_dir

            assert path.exists(test_path)
    def test_dimensionality_reduction_clustering(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(feed_data_loc="%s/data" % temp_dir,
                                        feed_mask_loc="%s/masks" % temp_dir,
                                        feed_name="Test",
                                        n_points=2)

            pipe = MIBIPipeline(config,
                                temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False)
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            analyzer = DimensionalityReductionClusteringAnalyzer(
                pipe.config, pipe.all_expansions_features, pipe.marker_names,
                pipe.all_feeds_contour_data, pipe.all_feeds_metadata,
                pipe.all_feeds_data)

            analyzer.analyze(temp_dir)

            self.assertIn("UMAP0", pipe.all_expansions_features.columns)
            self.assertIn("UMAP1", pipe.all_expansions_features.columns)
            self.assertIn("K-Means", pipe.all_expansions_features.columns)
            self.assertIn("Hierarchical", pipe.all_expansions_features.columns)
Beispiel #10
0
def hires_example():
    conf = Config()

    results_dir = "/media/aswin/large_storage/results/experiment_%s/" % datetime.now().strftime("%d_%m_%Y_%H:%M:%S")
    mkdir_p(results_dir)

    hires_feed = MIBIDataFeed(
        feed_data_loc="/media/aswin/large_storage/oliveria_data/data/hires",
        feed_mask_loc="/media/aswin/large_storage/oliveria_data/masks/hires",
        feed_name="Hires",
        n_points=48,
        brain_region_point_ranges=[(1, 16), (17, 32), (33, 48)],
        brain_region_names=["MFG", "HIP", "CAUD"]
    )

    pipe = MIBIPipeline(conf, results_dir,
                        csv_loc="/media/aswin/large_storage/results/5um_impansion_5um_expansion.csv"
                        )
    pipe.add_feed(hires_feed)
    pipe.load_preprocess_data()

    pipe.add_analyzer(ShapeQuantificationAnalyzer)
    # pipe.add_analyzer(PositiveVesselSummaryAnalyzer)
    # pipe.add_analyzer(DimensionalityReductionClusteringAnalyzer)

    shape_quantification_method = {
        "Name": "Solidity",
        "Metric": solidity
    }

    pipe.analyze_data(marker_settings="all_markers",
                      shape_quantification_method=shape_quantification_method)
    def test_brain_region_expansion_heatmap(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2,
                brain_region_point_ranges=[(1, 2)],
                brain_region_names=["Test Region"]
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.brain_region_expansion_heatmap(n_expansions=1,
                                                           primary_categorical_analysis_variable=None)

            test_path = "%s/Expansion Heatmaps & Clustermaps/Test/Expansion Clustermaps/0.5μm Expansion/All_Points.png" % temp_dir

            assert path.exists(test_path)
    def test_load_preprocess_data(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(feed_data_loc="%s/data" % temp_dir,
                                        feed_mask_loc="%s/masks" % temp_dir,
                                        feed_name="Test",
                                        n_points=2)

            pipe = MIBIPipeline(config,
                                temp_dir,
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False)
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            actual_features = pd.read_csv("data/dummy_test_data.csv",
                                          index_col=[0, 1, 2, 3],
                                          skipinitialspace=True)

            assert_frame_equal(actual_features, pipe.all_expansions_features)
            self.assertIsNotNone(pipe.visualizer)
Beispiel #13
0
    def test_positive_vessel_summary(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(feed_data_loc="%s/data" % temp_dir,
                                        feed_mask_loc="%s/masks" % temp_dir,
                                        feed_name="Test",
                                        n_points=2)

            pipe = MIBIPipeline(config,
                                temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False)
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            analyzer = PositiveVesselSummaryAnalyzer(
                pipe.config, pipe.all_expansions_features, pipe.marker_names,
                pipe.all_feeds_contour_data, pipe.all_feeds_metadata,
                pipe.all_feeds_data)

            analyzer.analyze(temp_dir)

            self.assertTrue(
                os.path.isfile(
                    os.path.join(temp_dir, "vessel_positive_proportion.csv")))
    def test_obtain_embedded_vessel_masks(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.obtain_embedded_vessel_masks(n_points=2)

            test_path = "%s/Embedded Vessel Masks/29.5 μm/Test/Original Mask Excluded/Point1.tif" % temp_dir

            assert path.exists(test_path)
    def test_scatter_plot_umap_marker_projection(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            umap_analyzer = DimensionalityReductionClusteringAnalyzer(
                pipe.config,
                pipe.all_expansions_features,
                pipe.marker_names,
                pipe.all_feeds_contour_data,
                pipe.all_feeds_metadata,
                pipe.all_feeds_data
            )

            umap_analyzer.analyze(temp_dir)

            shape_quant_analyzer = ShapeQuantificationAnalyzer(
                pipe.config,
                pipe.all_expansions_features,
                pipe.marker_names,
                pipe.all_feeds_contour_data,
                pipe.all_feeds_metadata,
                pipe.all_feeds_data
            )

            shape_quant_analyzer.analyze(temp_dir,
                                         mask_type="expansion_only",
                                         marker_settings="all_markers",
                                         shape_quantification_method={
                                             "Name": "Solidity",
                                             "Metric": solidity
                                         },
                                         img_shape=(2048, 2048))

            pipe.visualizer.scatter_plot_umap_marker_projection(mask_type="mask_only",
                                                                primary_continuous_analysis_variable="Solidity Score")

            test_path = "%s/UMAP Scatter Plot Projection/Test/Marker Clusters/Vessels.png" % temp_dir

            assert path.exists(test_path)
Beispiel #16
0
    def test_init(self):
        conf = Config()
        mask = generate_random_mask((2048, 2048, 1))

        object_extractor = ObjectExtractor(conf, None)

        mibi_contours = MIBIPointContours(mask, 1, conf, object_extractor)

        self.assertIsNotNone(mibi_contours.contours)
        self.assertIsNotNone(mibi_contours.removed_contours)
        self.assertIsNotNone(mibi_contours.removed_areas)
    def test_pseudo_time_heatmap(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2,
                brain_region_point_ranges=[(1, 2)],
                brain_region_names=["Test Region"]
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            analyzer = ShapeQuantificationAnalyzer(
                pipe.config,
                pipe.all_expansions_features,
                pipe.marker_names,
                pipe.all_feeds_contour_data,
                pipe.all_feeds_metadata,
                pipe.all_feeds_data
            )

            analyzer.analyze(temp_dir,
                             mask_type="expansion_only",
                             marker_settings="all_markers",
                             shape_quantification_method={
                                 "Name": "Solidity",
                                 "Metric": solidity
                             },
                             img_shape=(2048, 2048))

            pipe.visualizer.pseudo_time_heatmap()

            test_path1 = "%s/Pseudo-Time Heatmaps/Test/Test Region/" \
                         "Solidity Score_pseudo_time_heatmap_Test Region.png" % temp_dir
            test_path2 = "%s/Pseudo-Time Heatmaps/Test/Test Region/" \
                         "Solidity Score_pseudo_time_heatmap_binned_Test Region.png" % temp_dir
            test_path3 = "%s/Pseudo-Time Heatmaps/Test/Solidity Score_pseudo_time_heatmap_all_points.png" % temp_dir

            assert path.exists(test_path1)
            assert path.exists(test_path2)
            assert path.exists(test_path3)
    def test_add_feed(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=1, resolution=(2048, 2048))

            config = Config()
            loader = MIBILoader(config)
            example_feed = MIBIDataFeed(feed_data_loc="%s/data" % temp_dir,
                                        feed_mask_loc="%s/masks" % temp_dir,
                                        feed_name="Test",
                                        n_points=1)

            loader.add_feed(example_feed)

            self.assertEqual(loader.feeds[example_feed.name], example_feed)
Beispiel #19
0
def medres_example():
    conf = Config()

    medres_feed = MIBIDataFeed(
        feed_data_loc="/media/large_storage/oliveria_data/data/medres",
        feed_mask_loc="/media/large_storage/oliveria_data/masks/medres",
        feed_name="Medres",
        n_points=300,
        points_per_dir=100,
        brain_region_point_ranges=[(1, 100), (101, 200), (201, 300)]
    )

    loader = MIBILoader(conf)
    loader.add_feed(medres_feed)
    loader.read()
    def test_categorical_violin_plot_with_images(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            analyzer = ShapeQuantificationAnalyzer(
                pipe.config,
                pipe.all_expansions_features,
                pipe.marker_names,
                pipe.all_feeds_contour_data,
                pipe.all_feeds_metadata,
                pipe.all_feeds_data
            )

            analyzer.analyze(temp_dir,
                             mask_type="expansion_only",
                             marker_settings="all_markers",
                             shape_quantification_method={
                                 "Name": "Solidity",
                                 "Metric": solidity
                             },
                             img_shape=(2048, 2048))

            pipe.visualizer.categorical_violin_plot_with_images(primary_categorical_analysis_variable="Solidity",
                                                                mask_size=(2048, 2048),
                                                                order=["25%", "50%", "75%", "100%"])

            test_path = "%s/Categorical Violin Plots with Images/Test/By Solidity/Vessels/SMA.png" % temp_dir

            assert path.exists(test_path)
    def test_line_plots(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(
                feed_data_loc="%s/data" % temp_dir,
                feed_mask_loc="%s/masks" % temp_dir,
                feed_name="Test",
                n_points=2
            )

            pipe = MIBIPipeline(config, temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False
                                )
            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            pipe.visualizer.expansion_line_plots_per_vessel(n_expansions=1,
                                                            vessel_line_plots_points=[1])

            assert path.exists("%s/%s%s Expansion" % ("%s/Line Plots Per Vessel" % temp_dir,
                                                      str(round_to_nearest_half(config.pixel_interval *
                                                                                config.pixels_to_distance)),
                                                      config.data_resolution_units))

            pipe.visualizer.expansion_line_plots_per_point(n_expansions=1,
                                                           n_points=2)

            assert path.exists("%s/%s%s Expansion" % ("%s/Line Plots Per Point" % temp_dir,
                                                      str(round_to_nearest_half(1 *
                                                                                config.pixel_interval *
                                                                                config.pixels_to_distance)),
                                                      config.data_resolution_units))

            pipe.visualizer.expansion_line_plots_all_points(n_expansions=1)

            assert path.exists("%s/%s%s Expansion" % ("%s/Line Plots All Points Average" % temp_dir,
                                                      str(round_to_nearest_half(1 *
                                                                                config.pixel_interval *
                                                                                config.pixels_to_distance)),
                                                      config.data_resolution_units))
    def test_read(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=1, resolution=(2048, 2048))

            config = Config()
            loader = MIBILoader(config)
            example_feed = MIBIDataFeed(feed_data_loc="%s/data" % temp_dir,
                                        feed_mask_loc="%s/masks" % temp_dir,
                                        feed_name="Test",
                                        n_points=1)

            loader.add_feed(example_feed)

            all_feeds_metadata, all_feeds_data, all_feeds_mask, marker_names = loader.read(
            )

            self.assertEqual(len(all_feeds_data), 1)
Beispiel #23
0
    def test_vessel_asymmetry_analyzer(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            create_test_data(temp_dir, n_points=2, resolution=(2048, 2048))

            config = Config()
            example_feed = MIBIDataFeed(feed_data_loc="%s/data" % temp_dir,
                                        feed_mask_loc="%s/masks" % temp_dir,
                                        feed_name="Test",
                                        n_points=2)

            pipe = MIBIPipeline(config,
                                temp_dir,
                                csv_loc="data/dummy_test_data.csv",
                                max_inward_expansions=1,
                                max_outward_expansions=1,
                                expansions=[1],
                                n_workers=1,
                                run_async=False)

            pipe.add_feed(example_feed)
            pipe.load_preprocess_data()

            analyzer = ShapeQuantificationAnalyzer(
                pipe.config, pipe.all_expansions_features, pipe.marker_names,
                pipe.all_feeds_contour_data, pipe.all_feeds_metadata,
                pipe.all_feeds_data)

            analyzer.analyze(temp_dir,
                             mask_type="expansion_only",
                             marker_settings="all_markers",
                             shape_quantification_method={
                                 "Name": "Solidity",
                                 "Metric": solidity
                             },
                             img_shape=(2048, 2048))

            self.assertIn("Solidity", pipe.all_expansions_features.columns)
Beispiel #24
0
    def test_normalize_expression_data(self):
        config = Config()

        marker_names = [
            "HH3",
            "CD45",
            "HLADR",
            "Iba1",
            "CD47",
            "ABeta42",
            "polyubiK48",
            "PHFTau",
            "8OHGuanosine",
            "SMA",
            "CD31",
            "CollagenIV",
            "TrkA",
            "GLUT1",
            "Desmin",
            "vWF",
            "CD105",
            "S100b",
            "GlnSyn",
            "Cx30",
            "EAAT2",
            "CD44",
            "GFAP",
            "Cx43",
            "CD56",
            "Synaptophysin",
            "VAMP2",
            "PSD95",
            "MOG",
            "MAG",
            "Calretinin",
            "Parvalbumin",
            "MAP2",
            "Gephyrin",
        ]

        test_raw_data = pd.read_csv("data/dummy_test_data_unnormalized.csv",
                                    index_col=[0, 1, 2, 3],
                                    skipinitialspace=True)

        scaling_factor = config.scaling_factor
        transformation = config.transformation_type
        normalization = config.normalization_type
        n_markers = config.n_markers

        hh3_data = test_raw_data["HH3"].to_numpy()
        hh3_data = hh3_data * scaling_factor
        hh3_data = arcsinh(hh3_data)
        percentile_99 = np.percentile(hh3_data, 99, axis=0)
        normalized_hh3 = hh3_data / percentile_99

        all_expansions_features = normalize_expression_data(
            config,
            test_raw_data,
            marker_names,
            transformation=transformation,
            normalization=normalization,
            scaling_factor=scaling_factor,
            n_markers=n_markers)

        test_normalized_hh3 = all_expansions_features["HH3"].to_numpy()

        assert_array_equal(normalized_hh3, test_normalized_hh3)