cNMF
cNMF copied to clipboard
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
Hi, I am getting this error, I tried reinstalling but couldn't resolve this issue. I have removed all the low counts and even tried giving TPMs, but failed in running this successfully. Please let me know how best I can resolve this, I am not a programmer, I am a cancer biologist and trust me I have gone through each line of the code but failed to understand where I am going wrong. I request you to have a look at this, it's a beautiful tool and will help us in resolving so many things. Thank you. Dr Ateeq
sc.pp.filter_cells(adata, min_genes=200) # filter cells with fewer than 200 genes
sc.pp.filter_cells(adata, min_counts=200) # This is a weaker threshold than above. It is just to population the n_counts column in adata
sc.pp.filter_genes(adata, min_cells=3) # filter genes detected in fewer than 3 cells
sc.pp.normalize_per_cell(adata, counts_per_cell_after=1e6) # TPM normalisation
python /Users/akhaliq/Desktop/nmf/script/cnmf.py prepare --output-dir ./ --name cNMF_epi -c tpm_counts.tsv -k 5 6 7 8 9 10 11 --n-iter 500 --seed 14 --numgenes 2000 --tpm tpm_counts.tsv
/Users/akhaliq/Desktop/nmf/script/cnmf.py:806: FutureWarning: X.dtype being converted to np.float32 from int64. In the next version of anndata (0.9) conversion will not be automatic. Pass dtype explicitly to avoid this warning. Pass `AnnData(X, dtype=X.dtype, ...)` to get the future behavour.
var=pd.DataFrame(index=input_counts.columns))
/Users/akhaliq/Desktop/nmf/script/cnmf.py:831: FutureWarning: X.dtype being converted to np.float32 from int64. In the next version of anndata (0.9) conversion will not be automatic. Pass dtype explicitly to avoid this warning. Pass `AnnData(X, dtype=X.dtype, ...)` to get the future behavour.
var=pd.DataFrame(index=tpm.columns))
/Users/akhaliq/miniconda3/envs/cnmf_env/lib/python3.7/site-packages/scanpy/preprocessing/_simple.py:843: UserWarning: Received a view of an AnnData. Making a copy.
view_to_actual(adata)
Traceback (most recent call last):
File "/Users/akhaliq/Desktop/nmf/script/cnmf.py", line 853, in <module>
high_variance_genes_filter=highvargenes)
File "/Users/akhaliq/Desktop/nmf/script/cnmf.py", line 328, in get_norm_counts
examples = norm_counts.obs.index[zerocells]
File "/Users/akhaliq/miniconda3/envs/cnmf_env/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 4307, in __getitem__
result = getitem(key)
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
Best, Dr AMK
Did you resolve this? I am getting the same issue.
@rpauly, No I have not. Our lab got in touch with the authors but they are also clueless about it. So we decided to move on with other methods.
Best! AMK
@AteeqMKhaliq : What other method did you use?
Hi I think the issue occurs when you have cells that have 0 counts of the high variance genes selected by cNMF. Could you check if this is indeed the case, perhaps by providing your own list of high variance genes where you can check this ahead of time?
OK, I finally fixed the bug in the prepare step that was stopping it from printing out the problematic cells that end up with 0 counts of the overdispersed genes. If you clone the development branch of the repo and run src/cnmf.py from there you should get the more informative error message telling you which cells are the problem.
Thanks the author for provide the development version, I tried install the development branch by
pip install https://github.com/dylkot/cNMF/archive/refs/heads/development.zip
and increase the number of over-dispersed genes to 6000, this bug solved. However, I wonder the higher number of viriable genes would cause other issues?
Here's a small suggestion: you can check if the data matrix has genes as column names and cell names as row names.