Error: 'numpy.ndarray' object has no attribute 'A'
tingxie2020 opened this issue · comments
Could you please help?
import scvelo as scv
from mousipy import translate
humanized_mdata = translate(mdata)
AttributeError Traceback (most recent call last)
Input In [219], in <cell line: 3>()
1 import scvelo as scv
2 from mousipy import translate
----> 3 humanized_mdata = translate(mdata)
File ~/ENTER/lib/python3.9/site-packages/mousipy/mousipy.py:196, in translate(adata, stay_sparse)
193 # for those with an entry but no ortholog we assume that there really is no known ortholog
194 # which means we ignore genes in m2h_no_hit
195 bdata = translate_direct(adata, direct, no_index)
--> 196 bdata = translate_multiple(bdata, adata, multiple, stay_sparse=stay_sparse)
197 bdata = collapse_duplicate_genes(bdata, stay_sparse=stay_sparse)
198 return bdata
File ~/ENTER/lib/python3.9/site-packages/mousipy/mousipy.py:122, in translate_multiple(adata, original_data, multiple, stay_sparse)
106 """Adds the counts of multiple-hit genes to ALL their orthologs.
107 Parameters
108 ----------
(...)
119 Updated original adata.
120 """
121 from scipy.sparse import csr_matrix, hstack
--> 122 X = adata.X.copy() if stay_sparse else adata.X.A.copy()
123 var = adata.var.copy()
124 for mgene, hgenes in tqdm(multiple.items(), leave=False):
AttributeError: 'numpy.ndarray' object has no attribute 'A'
mdata is AnnData object with n_obs × n_vars = 2040 × 20771
mdata.var_names:
Index(['Mrpl15', 'Lypla1', 'Tcea1', 'Atp6v1h', 'Rb1cc1', '4732440D04Rik',
'Pcmtd1', 'Gm26901', 'Rrs1', 'Adhfe1',
...
'Gm14862', 'Hypm', 'Gm14493', 'Hsf3', 'Dgat2l6', 'Dmrtc1a', 'Il1rapl2',
'Kcne1l', 'Dcx', 'Usp51'],
dtype='object', length=20771)
mdata.X
array([[4., 0., 7., ..., 0., 0., 0.],
[1., 0., 2., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 4., 1., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[2., 0., 3., ..., 0., 0., 0.]], dtype=float32)
after I transform mdata.X asmatrix, mdata.X = np.matrix(mdata.X), it still has the error.
matrix([[4., 0., 7., ..., 0., 0., 0.],
[1., 0., 2., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 4., 1., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[2., 0., 3., ..., 0., 0., 0.]], dtype=float32)
AttributeError: 'numpy.ndarray' object has no attribute 'A'
Hi,
thanks for posting an issue!
I just updated the code on github so your code will work.
Try to install with
pip install -U git+https://github.com/stefanpeidli/mousipy.git@dev
and please run your code again! Tell me if it worked or not :)
Hi Stefanpeidli,
Thank you. I still encountered error when I pip install the updated code.
Collecting git+https://github.com/stefanpeidli/mousipy.git@dev
Cloning https://github.com/stefanpeidli/mousipy.git (to revision dev) to /tmp/pip-req-build-qfjpqnes
Running command git clone --filter=blob:none --quiet https://github.com/stefanpeidli/mousipy.git /tmp/pip-req-build-qfjpqnes
WARNING: Did not find branch or tag 'dev', assuming revision or ref.
Running command git checkout -q dev
error: pathspec 'dev' did not match any file(s) known to git
error: subprocess-exited-with-error
× git checkout -q dev did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× git checkout -q dev did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Ah sorry, please try
pip install -U git+https://github.com/stefanpeidli/mousipy.git
This is the same install command as before but without the "@dev", since this branch does not exist. Basically what this command does is tell pip to install the current version of mousipy on github (which has the bug fix for your problem). Once we solve this I will update the version on PyPI as well. Thanks for your patience!
Hi Stefanpeidli,
Thanks.
I pip installed follow your instruction. This time the installation was successful. But the translate() still results the same error as before:
AttributeError: 'numpy.ndarray' object has no attribute 'A'.
Hi tingxie,
Oh that's weird. Can you please show me the full error message like when you opened this issue?
The full error message was the same as before.
AttributeError Traceback (most recent call last)
Input In [246], in <cell line: 3>()
1 import scvelo as scv
2 from mousipy import translate
----> 3 humanized_mdata= translate(mdata)
File ~/ENTER/lib/python3.9/site-packages/mousipy/mousipy.py:196, in translate(adata, stay_sparse)
193 # for those with an entry but no ortholog we assume that there really is no known ortholog
194 # which means we ignore genes in m2h_no_hit
195 bdata = translate_direct(adata, direct, no_index)
--> 196 bdata = translate_multiple(bdata, adata, multiple, stay_sparse=stay_sparse)
197 bdata = collapse_duplicate_genes(bdata, stay_sparse=stay_sparse)
198 return bdata
File ~/ENTER/lib/python3.9/site-packages/mousipy/mousipy.py:122, in translate_multiple(adata, original_data, multiple, stay_sparse)
106 """Adds the counts of multiple-hit genes to ALL their orthologs.
107 Parameters
108 ----------
(...)
119 Updated original adata.
120 """
121 from scipy.sparse import csr_matrix, hstack
--> 122 X = adata.X.copy() if stay_sparse else adata.X.A.copy()
123 var = adata.var.copy()
124 for mgene, hgenes in tqdm(multiple.items(), leave=False):
AttributeError: 'numpy.ndarray' object has no attribute 'A'
Hi I am having the same issue as well. Anyone able to fix it ?
Try to update to v0.0.6 using
pip install mousipy --upgrade
. You might have to restart your python kernel after the upgrade.
Try to update to v0.0.6 using
pip install mousipy --upgrade
. You might have to restart your python kernel after the upgrade.
I just tried still having same issues.
@stefanpeidli , Working perfectly fine now. Thanks for the update.
Glad to hear that!
I'll close the issue then.
@tingxie2020 if you still have problems feel free to comment!