You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any plan to add the option to use features in .obs for li.mt.bivariate? For example, if I calculate two gene set scores and want to check their spatial relationship?
The text was updated successfully, but these errors were encountered:
Apologies for the delayed response. You could transfer categorical variables or else from .obs to adata.X, but for that you would need to create a new AnnData object. From then on, applying the bivariate scores would be as usual.
Essentially, in relatively realistic pseudocode what you need to do is
import pandas as pd
from anndata import AnnData
# define new X
# your variables of interest where, rows are the same shape as adata.n_obs, and columns can be as many as you need
# say you have columns of interest in adata.obs
X = adata.obs[['column1', 'column2', 'column3']].values
var = pd.DataFrame(X.columns)
obs = adata.obs # I guess you still might need this e.g. for visualizations
obsp = adata.obsp # this is where the spatial connectivities are stored
uns = adata.uns # you need this for the image data typically
obsm = adata.obsm
adata2 = AnnData(X=X, var=var, obs=obs, obsp=obsp, uns=uns, obsm=obsm)
# then, you just need to provide a list of tupples for your interactions of interest:
li.mt.bivariate(... # as usual
interactions=[('column1', 'column2),
('column2', 'column3'), ...]
)
PS. For categorical variables (e.g. cell types), you would need to do dummy (one-hot) encoding (e.g. via pd.get_dummies), and then you would need to use a bivariate score which weights before doing correlations such as Moran's R or the products.
Hi,
Is there any plan to add the option to use features in .obs for li.mt.bivariate? For example, if I calculate two gene set scores and want to check their spatial relationship?
The text was updated successfully, but these errors were encountered: