Example #1
0
    def test_reproducibility(self, adata: AnnData, n_jobs: int):
        spatial_neighbors(adata)

        res1 = nhood_enrichment(adata,
                                cluster_key=_CK,
                                seed=42,
                                n_jobs=n_jobs,
                                n_perms=20,
                                copy=True)
        res2 = nhood_enrichment(adata,
                                cluster_key=_CK,
                                seed=42,
                                n_jobs=n_jobs,
                                n_perms=20,
                                copy=True)
        res3 = nhood_enrichment(adata,
                                cluster_key=_CK,
                                seed=43,
                                n_jobs=n_jobs,
                                n_perms=20,
                                copy=True)

        assert len(res1) == len(res2)
        assert len(res2) == len(res3)

        for key in range(len(res1)):
            np.testing.assert_array_equal(res2[key], res1[key])
            if key == 0:  # z-score
                with pytest.raises(AssertionError):
                    np.testing.assert_array_equal(res3[key], res2[key])
            else:  # counts
                np.testing.assert_array_equal(res3[key], res2[key])
Example #2
0
    def test_plot_nhood_enrichment_dendro(self, adata: AnnData):
        gr.spatial_neighbors(adata)
        gr.nhood_enrichment(adata, cluster_key=C_KEY)

        # use count to avoid nan for scipy.cluster.hierarchy
        pl.nhood_enrichment(adata,
                            cluster_key=C_KEY,
                            mode="count",
                            method="single")
Example #3
0
    def test_parallel_works(self, adata: AnnData, backend: str):
        spatial_neighbors(adata)

        nhood_enrichment(adata,
                         cluster_key=_CK,
                         n_jobs=2,
                         n_perms=20,
                         backend=backend)

        self._assert_common(adata)
Example #4
0
    def test_plot_cbar_kwargs(self, adata: AnnData):
        gr.spatial_neighbors(adata)
        gr.nhood_enrichment(adata, cluster_key=C_KEY)

        pl.nhood_enrichment(adata,
                            cluster_key=C_KEY,
                            cbar_kwargs={
                                "label": "FOOBARBAZQUUX",
                                "filled": False
                            })
Example #5
0
    def test_nhood_enrichment(self, adata: AnnData):
        spatial_neighbors(adata)
        nhood_enrichment(adata, cluster_key=_CK)

        self._assert_common(adata)
Example #6
0
    def test_plot_cbar_vmin_vmax(self, adata: AnnData):
        gr.spatial_neighbors(adata)
        gr.nhood_enrichment(adata, cluster_key=C_KEY)

        pl.nhood_enrichment(adata, cluster_key=C_KEY, vmin=10, vmax=20)
Example #7
0
    def test_plot_nhood_enrichment(self, adata: AnnData):
        gr.spatial_neighbors(adata)
        gr.nhood_enrichment(adata, cluster_key=C_KEY)

        pl.nhood_enrichment(adata, cluster_key=C_KEY)