CahanLab / PySingleCellNet

singleCellNet in Python
https://pysinglecellnet.readthedocs.io/en/latest/
MIT License
14 stars 9 forks source link

Error with pySCN.scn_classify: "Data matrix has wrong shape(), need to be (x,y)." #2

Open kma2112 opened 3 years ago

kma2112 commented 3 years ago

I've been using the same code that worked for me previously, but just started getting an error at the pySCN.scn_classify step and was wondering what I might be doing wrong or if there is an incompatibility with one of the package versions I am using. It throws an error when ad._core.views.ArrayView is called.

My code is below, as well as a screenshot of my error report and session info. Files are too large to be uploaded here but are in my Dropbox under Cahan lab: Kathleen.Noller/forgithub/ (https://www.dropbox.com/s/k5hrbbflh32w56x/forgithub.zip?dl=0)

adRaw = sc.read_loom("../data/LLi-21-FT/velocyto/LLi-21-FT.loom")
adRaw.obs_names_make_unique()
adRaw.var_names_make_unique()

from joblib import dump, load

tspRF = load("../101520/tspRF_FallopianTube_Ahmed_101520.joblib")
cgenesA = load("../101520/cgenesA_FallopianTube_Ahmed_101520.joblib")
xpairs = load("../101520/xpairs_FallopianTube_Ahmed_101520.joblib")

adClassRes = pySCN.scn_classify(adRaw, cgenesA, xpairs, tspRF, nrand = 0)
Screen Shot 2021-04-22 at 8 38 35 PM Screen Shot 2021-04-22 at 8 38 43 PM

Thank you for your help!

Yves33 commented 3 years ago

Same issue here, with the files from tutorial (adLung_TabSen_100920.h5ad,...) adVal = pySCN.scn_classify(expVal, cgenesA, xpairs, tspRF, nrand = 0) (...)ValueError: Data matrix has wrong shape (), need to be (500, 16543).

(fedora 33/x86_64)

Edit:

solved by adding
if isinstance(aDat.X,np.ndarray): in scn_train.py, line 98 final code should be

def scn_predict(cgenes, xpairs, rf_tsp, aDat, nrand = 2):
    # in the case of aDat.X is a numpy array
    if isinstance(aDat.X,np.ndarray):
        aDat.X = ad._core.views.ArrayView(aDat.X)
###    expDat= pd.DataFrame(data=aDat.X, index= aDat.obs.index.values, columns= aDat.var.index.values)
    expDat= pd.DataFrame(data=aDat.X.toarray(), index= aDat.obs.index.values, columns= aDat.var.index.values)
    expValTrans=query_transform(expDat.reindex(labels=cgenes, axis='columns', fill_value=0), xpairs)
    classRes_val=rf_classPredict(rf_tsp, expValTrans, numRand=nrand)
    return classRes_val