aristoteleo / spateo-release

Spatiotemporal modeling of spatial transcriptomics
https://spateo-release.readthedocs.io/
BSD 2-Clause "Simplified" License
159 stars 27 forks source link

Microenvironment modeling analysis (patsy.PatsyError: categorical data cannot be >1-dimensional) #234

Open heziqing opened 5 months ago

heziqing commented 5 months ago

Hello everyone,

I re-run the analysis https://spateo-release.readthedocs.io/en/latest/tutorials/notebooks/3_cci/2_microenvironment_modeling_analysis.html#, but I got an error when running the following code

niche_interp = st.tl.Niche_Model(
    adata,
    group_key='Annotation',
    genes=targets,
    smooth=False,
    normalize=False,
    log_transform=False,
    weights_mode="knn",
    distr="poisson",
    data_id="axolotl",
)

File "/share/home/heziqing/miniconda3/envs/Spateo/lib/python3.9/site-packages/patsy/categorical.py", line 157, in _categorical_shape_fix raise PatsyError("categorical data cannot be >1-dimensional") patsy.PatsyError: categorical data cannot be >1-dimensional

屏幕截图 2024-03-31 180243

I also check the scripts, and I found the main steps are the following codes:

group_name = adata.obs['Annotation']
db = pd.DataFrame({"group": group_name})
categories = np.array(adata.obs['Annotation'].unique().tolist())
db["group"] = pd.Categorical(db["group"], categories=categories)
X = pd.get_dummies(data=db, drop_first=False)
X = X.reindex(sorted(X.columns), axis=1)
adata.obsm["adj"] = pd.read_csv("/neighbors/axolotl_neighbors.csv",index_col=0).values
adj = adata.obsm["adj"]
dmat_neighbors = (adj > 0).astype("int").dot(X.values)
data = {"categories": X, "dmat_neighbours": dmat_neighbors}
connections = np.asarray(dmatrix("categories:dmat_neighbours-1", data))

Could anyone help me how to fix this error? Thanks in advance!

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days

Sichao25 commented 1 month ago

Hi, thanks for reporting this issue. The Niche_Model and the related tutorial have been deprecated, so it could be difficult to debug. We’ve integrated the related functionality into a new class called MuSIC. Feel free to try it out for cell-cell interaction analysis. Let me know if you meet the same issue.