Teichlab / celltypist

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

Getting error when running predictions follow tutorial #52

Closed WhaleGe closed 1 year ago

WhaleGe commented 1 year ago

Thank you for providing such a useful tool, but when I run your the tutorial of Best practice in large-scale cross-dataset label transfer using CellTypist, why can't I read the locally saved model_from_Elmentaite_2021.pkl.

predictions = celltypist.annotate(adata_James, model = 'model_from_Elmentaite_2021.pkl' , majority_voting = True,mode = 'best match')
🔎 No available models. Downloading...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/site-packages/celltypist/annotate.py", line 77, in annotate
    lr_classifier = model if isinstance(model, Model) else Model.load(model)
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/site-packages/celltypist/models.py", line 90, in load
    if model in get_all_models():
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/site-packages/celltypist/models.py", line 359, in get_all_models
    download_if_required()
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/site-packages/celltypist/models.py", line 372, in download_if_required
    download_models()
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/site-packages/celltypist/models.py", line 432, in download_models
    models_json = get_models_index(force_update)
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/site-packages/celltypist/models.py", line 394, in get_models_index
    return json.load(f)
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/jdfssz1/USER/hw/2.software/mn3/envs/celltypist/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

image

ChuanXu1 commented 1 year ago

@WhaleGe, seems you have some problem fetching the json, can you confirm you can access https://celltypist.cog.sanger.ac.uk/models/models.json

To use your own model, you can provide a path to the model. here, ./model_from_Elmentaite_2021.pkl

WhaleGe commented 1 year ago

@WhaleGe, seems you have some problem fetching the json, can you confirm you can access https://celltypist.cog.sanger.ac.uk/models/models.json

To use your own model, you can provide a path to the model. here, ./model_from_Elmentaite_2021.pkl

Yes, I can't fetch the json. So, I provide a path to the model. But I found that I have to modify the /home/hw/.celltypist/data/models/models.json file. Like this, the program to run.

{
    "description": "CellTypist model list",
    "last_update": "2022-12-20 19:43:06.565435",
    "models": [
      {
        "filename": "model_from_Elmentaite_2021.pkl",
        "url": "",
        "version": "v1",
        "date": "2022-12-20 19:43:06.565435",
        "details": "",
        "No_celltypes": 134,
        "source": "",
        "default": true
      }
    ]
}

image

ChuanXu1 commented 1 year ago

@WhaleGe, the error comes from your inability to access the json file. It's better to solve the url issue at your end such that you can use a number of built-in models.

Another way to solve your problem (if you really have problem fetching the json) is to put your model in /home/hw/.celltypist/data/models/, and use celltypist.annotate(adata_James, model = 'model_from_Elmentaite_2021.pkl')

WhaleGe commented 1 year ago

@WhaleGe, the error comes from your inability to access the json file. It's better to solve the url issue at your end such that you can use a number of built-in models.

Another way to solve your problem (if you really have problem fetching the json) is to put your model in /home/hw/.celltypist/data/models/, and use celltypist.annotate(adata_James, model = 'model_from_Elmentaite_2021.pkl')

Ok I got it, thanks for your help