axelalmet/flowsig

AttributeError: 'AnnData' object has no attribute 'flatten'

WangShuai-3 opened this issue · 4 comments

Hello, I encountered an error while running the following code:

fs.pp.construct_flows_from_cellchat(data,
cellchat_output_key,
gem_expr_key = 'X_gem',
scale_gem_expr = False,
model_organism = 'human',
flowsig_network_key = 'flowsig_network',
flowsig_expr_key = 'X_flow')

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [16], line 1
----> 1 fs.pp.construct_flows_from_cellchat(data,
      2                                 cellchat_output_key,
      3                                 gem_expr_key = 'X_gem',
      4                                 scale_gem_expr = False,
      5                                 model_organism = 'human',
      6                                 flowsig_network_key = 'flowsig_network',
      7                                 flowsig_expr_key = 'X_flow')

File /opt/conda/lib/python3.8/site-packages/flowsig/preprocessing/_flow_expressions.py:263, in construct_flows_from_cellchat(adata, cellchat_output_key, gem_expr_key, scale_gem_expr, model_organism, flowsig_network_key, flowsig_expr_key)
    260     flow_downstream_tfs[outflow_var] = adata_gem.var['downstream_tfs'].loc[gem]
    261     flow_interactions[outflow_var] = adata_gem.var['interactions'].loc[gem]
--> 263     flow_expressions[:, len(outflow_vars) + len(inflow_vars) + i] = adata_gem[:, gem].flatten()
    265 # Store the type, relevant downstream_TF, and received interactions for each variable
    266 # Store all the information on the flow variables
    267 adata.uns[flowsig_network_key] = {'flow_vars': flow_variables,
    268                                   'flow_var_types': flow_variable_types,
    269                                   'downstream_tfs': flow_downstream_tfs,
    270                                   'interactions': flow_interactions
    271                                   }

AttributeError: 'AnnData' object has no attribute 'flatten'

The issue seems to be at line 263 in _flow_expressions.py. The expression adata_gem[:, gem].flatten() should be modified to adata_gem[:, gem].X.flatten() because adata_gem is an AnnData object. Is that correct?

Hello,

This error seems to be from an older version of FlowSig, as you can see that, as you correctly pointed out, it is indeed adam_gem[:, gem].X.flatten() here.

I reinstalled flowsig and it works now. thanks!

HI, I just face the same problem as yours. And the flowsig i install just as the tutorial use the setup.py. Could you ples tell me how to update it? Any advice will be appreciated :) @WangShuai-3 @axelalmet

I used mirror.ghproxy.com to clone this repository before, but when I cloned it again without the mirror, the issue didn’t come up. I’m not sure if the problem is with mirror.ghproxy.com, but re-cloning the repository might fix it. @LJZYaaa