proseg icon indicating copy to clipboard operation
proseg copied to clipboard

Compatibility with squidpy?

Open jamesboot opened this issue 1 year ago • 2 comments

Hi,

Thanks for creating such a great tool, love the pre-print.

I'm thinking about applying this method to some CosMx data. I already have a pipeline for importing CosMx data into squidpy and then using some of the tools available there to perform spatial analysis. I was just wondering if it is possible to generate an AnnData object from the proseg outputs, or if you have any recommendations for analysis tools/packages downstream of proseg?

Cheers James

jamesboot avatar Sep 17 '24 10:09 jamesboot

Thanks! It's tricky to add support directly to proseg, because h5ad is a pretty complex format, but I ought to include python code to do this in the future. In the mean time, something like this should do the trick:

import pandas as pd
import numpy as np
from anndata import AnnData

# Or, `pd.read_csv` if csv files were generated by proseg
df_counts = pd.read_parquet("expected-counts.parquet")
df_metadata = pd.read_parquet("cell-metadata.parquet")

X = np.asarray(df_counts, dtype=np.float32)
xys = np.stack([df_metadata.centroid_x, df_metadata.centroid_y], 1)

adata = AnnData(
    X=X,
    obs=df_metadata,
    obsm={"spatial": xys},
    var=pd.DataFrame(index=df_counts.columns))

dcjones avatar Sep 17 '24 20:09 dcjones

Thanks! Will give that a go

jamesboot avatar Oct 02 '24 10:10 jamesboot