Teichlab / celltypist

A tool for semi-automatic cell type classification
https://www.celltypist.org/
MIT License
254 stars 40 forks source link

ValueError in celltypist.annotate #108

Closed katecycho closed 2 months ago

katecycho commented 4 months ago

Hello! Thank you so much for this useful tool. I am encountering an error in the first annotate step and am unsure what I am doing wrong.

I export the raw counts matrix from Seurat as csv (seuratobj@assays$RNA$counts) and read it in python pd.read_csv. When I run celltypist.annotate, this is my error:

ValueError                                Traceback (most recent call last)
<ipython-input-11-109c12bae0f8> in ?()
----> 1 predictions_Immune_All_Low = celltypist.annotate(df, model = 'Immune_All_Low.pkl', transpose_input = True)

[~/anaconda3/lib/python3.11/site-packages/celltypist/annotate.py](https://untitled+.vscode-resource.vscode-cdn.net//~/anaconda3/lib/python3.11/site-packages/celltypist/annotate.py) in ?(filename, model, transpose_input, gene_file, cell_file, mode, p_thres, majority_voting, over_clustering, min_prop)
     75     """
     76     #load model
     77     lr_classifier = model if isinstance(model, Model) else Model.load(model)
     78     #construct Classifier class
---> 79     clf = classifier.Classifier(filename = filename, model = lr_classifier, transpose = transpose_input, gene_file = gene_file, cell_file = cell_file)
     80     #predict
     81     predictions = clf.celltype(mode = mode, p_thres = p_thres)
     82     if not majority_voting:

[~/anaconda3/lib/python3.11/site-packages/celltypist/classifier.py](https://untitled+.vscode-resource.vscode-cdn.net//~/anaconda3/lib/python3.11/site-packages/celltypist/classifier.py) in ?(self, filename, model, transpose, gene_file, cell_file)
    261     def __init__(self, filename: Union[AnnData,str] = "", model: Union[Model,str] = "", transpose: bool = False, gene_file: Optional[str] = None, cell_file: Optional[str] = None):
    262         if isinstance(model, str):
    263             model = Model.load(model)
    264         self.model = model
--> 265         if not filename:
    266             logger.warn(f"📭 No input file provided to the classifier")
    267             return
    268         if isinstance(filename, str):

[~/anaconda3/lib/python3.11/site-packages/pandas/core/generic.py](https://untitled+.vscode-resource.vscode-cdn.net//~/anaconda3/lib/python3.11/site-packages/pandas/core/generic.py) in ?(self)
   1517     @final
   1518     def __nonzero__(self) -> NoReturn:
-> 1519         raise ValueError(
   1520             f"The truth value of a {type(self).__name__} is ambiguous. "
   1521             "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
   1522         )

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Do you have any idea what I am doing wrong? Sorry if I missed anything, I appreciate the help!

katecycho commented 4 months ago

It works fine on command line with the same input file so may be something with python package compatibility

ChuanXu1 commented 4 months ago

@katecycho, you can directly provide the csv table as predictions_Immune_All_Low = celltypist.annotate("NNN.csv", ...); there is no need to read it as a df

ChuanXu1 commented 2 months ago

This should have been resolved. Please reopen the issue if you still have questions.