ImXman / MACA

MACA: Marker-based automatic cell-type annotation for single cell expression data
GNU General Public License v3.0
25 stars 10 forks source link

ValueError: shapes not aligned #3

Closed Edert closed 2 years ago

Edert commented 2 years ago

Hi,

I did use MACA for single-cell RNA-seq annotation successfully some time ago, however since the OS reinstallation of my machine it stopped working.

My workflow in python 3.10.4 looks like this:

import scanpy as sc
import anndata
import collections
import numpy as np
import pandas as pd
import scanpy as sc
import MACA as maca
import warnings
warnings.filterwarnings("ignore")

sc.settings.figdir = "/proj/canis_organoids_052019/analysis/02_seurat/plots/processing2/test_ribomito/maca/"
sc.set_figure_params(dpi=300, dpi_save=300,figsize=(8, 8), fontsize=10)

pg_df = pd.read_table("PanglaoDB_markers_27_Mar_2020.tsv")

cell_markers = {} ##cell_marker is dictionary that contains names of cell types and their marker genes
marker_list = []

for i in list(set(pg_df["cell type"].values.tolist())):
    genes = pg_df[pg_df["cell type"]==i]['official gene symbol'].values.tolist()
    if len(genes)>=5 and len(genes)<=500:
        cell_markers[i]=genes
        marker_list+= genes

marker_list = list(set(marker_list))

adata = sc.read_h5ad("sample1.h5ad")
marker_list = [i for i in marker_list if i in adata.var.index]
ad = adata.copy()
ad = ad[:,marker_list]
ad, annotation = maca.singleMACA(ad=ad, cell_markers=cell_markers, res=[1,1.5,2],n_neis=[3,5,10])

then singleMACA fails in the numpy percentile function:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eder/.local/lib/python3.10/site-packages/MACA/__init__.py", line 57, in singleMACA
    expr95 = np.percentile(X[:,ad.var.index == i],95)
  File "<__array_function__ internals>", line 180, in percentile
  File "/home/eder/.local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 4134, in percentile
    return _quantile_unchecked(
  File "/home/eder/.local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 4383, in _quantile_unchecked
    r, k = _ureduce(a,
  File "/home/eder/.local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 3702, in _ureduce
    r = func(a, **kwargs)
  File "/home/eder/.local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 4552, in _quantile_ureduce_func
    result = _quantile(arr,
  File "/home/eder/.local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 4669, in _quantile
    result = _lerp(previous,
  File "/home/eder/.local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 4488, in _lerp
    lerp_interpolation = asanyarray(add(a, diff_b_a * t, out=out))
  File "/home/eder/.local/lib/python3.10/site-packages/numpy/matrixlib/defmatrix.py", line 218, in __mul__
    return N.dot(self, asmatrix(other))
  File "<__array_function__ internals>", line 180, in dot
ValueError: shapes (1,8563) and (1,1) not aligned: 8563 (dim 1) != 1 (dim 0)

scanpy 1.9.1 anndata 0.8.0 scikit-learn 1.1.1 MACA-Python 1.0.1

What am I doing wrong?

Best, Thomas

ImXman commented 2 years ago

Hi Thomas,

My first guess would be issue of compatibility with scanpy 1.9.1.

Try: pip install scanpy==1.8.1

And see if it solves the problem. If not let me know.

Thank you for giving our tool a try!

Edert commented 2 years ago

Hi,

thanks for your quick reply, I manged to resolve this issue by using a conda environment with numpy 1.19 and scanpy 1.8.1 (it might also work with newer versions, however I did not test this):

conda create -n maca
conda activate maca

conda install numpy=1.19
conda install -c conda-forge scanpy=1.8.1
conda install -c conda-forge anndata
conda install -c conda-forge python-igraph
conda install -c conda-forge python-louvain
conda install -c conda-forge louvain
conda install -c conda-forge scikit-learn
conda install pip
pip install MACA-Python