JinmiaoChenLab / GraphST

GNU Affero General Public License v3.0
91 stars 13 forks source link

Question with horizontal integration #10

Open RubyLiu-2 opened 1 year ago

RubyLiu-2 commented 1 year ago

Hi everyone,

I ran the tutorial of horizontal integration. Here is my question, the tutorial used processed data I assume: adata = sc.read_h5ad('data/mouse_anterior_posterior_brain_merged.h5ad'). I tried with separate data from 10X ( mouse brain sagittal anterior and posterior) by:

sc.set_figure_params(facecolor="white", figsize=(8, 8))
sc.settings.verbosity = 3
adata_anterior = sc.datasets.visium_sge(
    sample_id="V1_Mouse_Brain_Sagittal_Anterior"
)
adata_posterior = sc.datasets.visium_sge(
    sample_id="V1_Mouse_Brain_Sagittal_Posterior"
)
adata_anterior.var_names_make_unique()
adata_posterior.var_names_make_unique()
# merge into one dataset
library_names = ["V1_Mouse_Brain_Sagittal_Anterior", "V1_Mouse_Brain_Sagittal_Posterior"]

adata_spatial= adata_anterior.concatenate(
    adata_posterior,
    batch_key="library_id",
    uns_merge="unique",
    batch_categories=library_names
)
adata_spatial

And I ran the integration by:


def horizontal_ST_pipeline(adata_spatial, n_clusters):
"""
pre integration visualization 
"""
clusters_colors = dict(
zip([str(i) for i in range(len(adata_spatial.obs.clusters.cat.categories))], adata_spatial.uns["clusters_colors"]))

fig, axs = plt.subplots(1, 2, figsize=(15, 10))

for i, library in enumerate(
    ["V1_Mouse_Brain_Sagittal_Anterior", "V1_Mouse_Brain_Sagittal_Posterior"]
):
    ad = adata_spatial[adata_spatial.obs.library_id == library, :].copy()
    sc.pl.spatial(
        ad,
        img_key="hires",
        library_id=library,
        color="clusters",
        size=1.5,
        palette=[
            v
            for k, v in clusters_colors.items()
            if k in ad.obs.clusters.unique().tolist()
        ],
        legend_loc=None,
        show=False,
        ax=axs[i],
    )

plt.tight_layout()

# define model
model = GraphST.GraphST(adata_spatial,  device="cpu", random_seed=50)
# run model
adata_spatial = model.train()
if tool == 'mclust':
   clustering(adata_spatial, n_clusters, method=tool)
elif tool in ['leiden', 'louvain']:
   clustering(adata_spatial, n_clusters, method=tool, start=0.1, end=2.0, increment=0.01)

fig, axs = plt.subplots(1, 2, figsize=(15, 10))

adata_spatial.obsm['spatial'][:,1] = -1*adata_spatial.obsm['spatial'][:,1]
rgb_values = sns.color_palette("tab20", len(adata_spatial.obs['domain'].unique()))
color_fine = dict(zip(list(adata_spatial.obs['domain'].unique()), rgb_values))

for i, library in enumerate(
    ["V1_Mouse_Brain_Sagittal_Anterior", "V1_Mouse_Brain_Sagittal_Posterior"]
):
    ad = adata_spatial[adata_spatial.obs.library_id == library, :].copy()
    print(ad)
    sc.pl.spatial(
        ad,
        img_key="hires",
        library_id=library,
        color="domain",
        size=1.5,
        palette=color_fine,
        legend_loc=None,
        show=False,
        ax=axs[i],
    )

plt.tight_layout()

return adata_spatial

vertical_integrated_adata = horizontal_ST_pipeline(adata_spatial_processed_1, n_clusters=26)



However, I encountered with some coordinate issue, as you can see in the image. two parts are identical with each other which should not be. Could you please tell me how to tweak, or anything incorrect? 
![image](https://github.com/JinmiaoChenLab/GraphST/assets/134301167/1ed91d9e-8acc-4322-9c3a-1b2b5f971ad1)
longyahui commented 1 year ago

Hi RubyLiu,

 Sorry for the late reply.

 We just need to reverse the 'y' coordinates by code "adata.obsm['spatial][:,1]=-1*adata.obsm['spatial][:,1]" before the input or visualization. Thank you for your attention on our work.

 Best regards,
 Yahui