ventolab / CellphoneDB

CellPhoneDB can be used to search for a particular ligand/receptor, or interrogate your own HUMAN single-cell transcriptomics data.
https://www.cellphonedb.org/
MIT License
322 stars 51 forks source link

call() got an unexpected keyword argument 'cpdb_file_path' #95

Closed renyuan1988 closed 10 months ago

renyuan1988 commented 1 year ago

Hi, I was trying to perform the degs analysis on the jupyter lab and I did my job strictly according to example notebook. however, there was an error keep showing :TypeError: call() got an unexpected keyword argument 'cpdb_file_path'. I checked my codes several times but still didn't find out the reason.

Here are my codes:

import pandas as pd
import sys
import os

from cellphonedb.src.core.methods import cpdb_degs_analysis_method

cpdb_file_path = '/home/data/t090350/CellphoneDB/cellphonedb.zip'
meta_file_path = '/home/data/t090350/CellphoneDB/meta.tsv'
counts_file_path = '/home/data/t090350/CellphoneDB/counts.mtx'
degs_file_path = '/home/data/t090350/CellphoneDB/CP_DEGs.tsv'
output_path = '/home/data/t090350/CellphoneDB/'

 from cellphonedb.src.core.methods import cpdb_degs_analysis_method
deconvoluted, means, relevant_interactions, significant_means =cpdb_degs_analysis_method.call(
    cpdb_file_path = cpdb_file_path,                           
    meta_file_path = meta_file_path,                         
    counts_file_path = counts_file_path,                      
    degs_file_path = degs_file_path,
    output_path = output_path)

And then the error showed:

TypeError                                 Traceback (most recent call last)
Input In [433], in <cell line: 3>()
      1 from cellphonedb.src.core.methods import cpdb_degs_analysis_method
----> 3 deconvoluted, means, relevant_interactions, significant_means =cpdb_degs_analysis_method.call(
      4    cpdb_file_path = cpdb_file_path,                           
      5    meta_file_path = meta_file_path,                         
      6    counts_file_path = counts_file_path,                      
      7    degs_file_path = degs_file_path)

TypeError: call() got an unexpected keyword argument 'cpdb_file_path'

Could you tell me why? Many many thanks!

ktroule commented 1 year ago

Hi @renyuan1988

Thanks for using CellPhoneDB and for pointing out this, we are going to investigate this issue.

In the meantime, Could I ask you to install CellPhoneDB in a new conda environment with python>=3.8 and then pip install "git+https://github.com/ventolab/CellphoneDB.git@master" and try again?

Have you tried to run the notebook/T01_Method3.ipynb with the data provided in notebook/data_tutorial.zip, if yes, what was the result?

We will follow this issue, kind regards.

renyuan1988 commented 1 year ago

Thanks a lot for your quick response. I have installed the "git+https://github.com/ventolab/CellphoneDB.git@master" and repeat my job, the previous error disappeared but a new issue presented:

SystemError                               Traceback (most recent call last)
Input In [24], in <cell line: 1>()
----> 1 from cellphonedb.src.core.methods import cpdb_degs_analysis_method
      2 deconvoluted, means, relevant_interactions, significant_means =cpdb_degs_analysis_method.call(
      3     cpdb_file_path = cpdb_file_path, 
      4     meta_file_path = meta_file_path,
      5     counts_file_path = counts_file_path, 
      6     degs_file_path = degs_file_path, 
      7     output_path = output_path)

File ~/.local/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_degs_analysis_method.py:10, in <module>
      8 from cellphonedb.src.core.exceptions.NoInteractionsFound import NoInteractionsFound
      9 from cellphonedb.src.core.exceptions.MissingRequiredArgumentsException import MissingRequiredArgumentsException
---> 10 from cellphonedb.src.core.methods import cpdb_statistical_analysis_helper, cpdb_statistical_analysis_complex_method
     11 from cellphonedb.src.core.models.complex import complex_helper
     12 from cellphonedb.utils import db_utils, file_utils

File ~/.local/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py:10, in <module>
      8 import pandas as pd
      9 import numpy as np
---> 10 import numpy_groupies as npg
     11 from cellphonedb.src.core.core_logger import core_logger
     12 from cellphonedb.src.core.models.complex import complex_helper

File ~/.local/lib/python3.8/site-packages/numpy_groupies/__init__.py:38, in <module>
     34     aggregate = aggregate_wv
     37 try:
---> 38     import numba
     39 except ImportError:
     40     aggregate_nb = None

File ~/.local/lib/python3.8/site-packages/numba/__init__.py:42, in <module>
     38 from numba.core.decorators import (cfunc, generated_jit, jit, njit, stencil,
     39                                    jit_module)
     41 # Re-export vectorize decorators and the thread layer querying function
---> 42 from numba.np.ufunc import (vectorize, guvectorize, threading_layer,
     43                             get_num_threads, set_num_threads,
     44                             set_parallel_chunksize, get_parallel_chunksize,
     45                             get_thread_id)
     47 # Re-export Numpy helpers
     48 from numba.np.numpy_support import carray, farray, from_dtype

File ~/.local/lib/python3.8/site-packages/numba/np/ufunc/__init__.py:3, in <module>
      1 # -*- coding: utf-8 -*-
----> 3 from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize
      4 from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One
      5 from numba.np.ufunc import _internal, array_exprs

File ~/.local/lib/python3.8/site-packages/numba/np/ufunc/decorators.py:3, in <module>
      1 import inspect
----> 3 from numba.np.ufunc import _internal
      4 from numba.np.ufunc.parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder
      6 from numba.core.registry import DelayedRegistry

SystemError: initialization of _internal failed without raising an exception

I guess this should be the incompability of the higher version of numpy(1.24.2), so I reinstalled the numpy of version 1.23.5, but still failed. Looking forward to your further instructions.

ktroule commented 1 year ago

Thanks. In my case, CellPhoneDB works with numpy 1.24.2.

Could you please indicate: 1) Is this error happening with your data or with the tutorial? 2) In which OS are you installing CellPhoneDB? 3) Report the output of pip list | grep num when installing CellPhoneDB in a new environment?

Thanks

renyuan1988 commented 1 year ago

Thanks.

  1. The error happened with my own data, I kept failing in downloading the turorial data.
  2. I installed CellPhoneDB on linux system.
  3. The out put of gre num ara as follows: numba 0.56.4
    numpy 1.23.5
    numpy-groupies 0.9.20 .
ktroule commented 1 year ago

To download the tutorial, click on the View raw in the centre of the page and the data should download to your computer.

The version of the libraries that you display should cause no issue.

We will keep looking at this, in the meantime confirm if you can run the tutorial.

Thanks

ktroule commented 1 year ago

Just in case, after updating any package, make sure you restart your kernel and you start from a new environment.

renyuan1988 commented 1 year ago

Hi,I have tried the tutorial data in cloned git, unfortunatly,it failed again, with the error: MissingRequiredArgumentsException. Here are my codes and outpus: pip install "git+https://github.com/ventolab/CellphoneDB.git@master"

import pandas as pd
import sys
import os

print(sys.version)
3.8.10 (default, Nov 14 2022, 12:59:47) 
[GCC 9.4.0]

cpdb_file_path = '/home/data/t090350/CellphoneDB/cellphonedb.zip'
meta_file_path = '/home/data/t090350/data_tutorial/metadata.tsv'
counts_file_path = '/home/data/t090350/data_tutorial/normalised_log_counts.h5ad'
degs_file_path = '/home/data/t090350/data_tutorial/DEGs_inv_trophoblast.tsv'
output_path = '/home/data/t090350/CellphoneDB/'

from cellphonedb.src.core.methods import cpdb_degs_analysis_method
deconvoluted, means, relevant_interactions, significant_means =cpdb_degs_analysis_method.call(
    cpdb_file_path = cpdb_file_path, 
    meta_file_path = meta_file_path,
    counts_file_path = counts_file_path, 
    degs_file_path = degs_file_path, 
    output_path = output_path)
MissingRequiredArgumentsException         Traceback (most recent call last)
Input In [6], in <cell line: 2>()
      1 from cellphonedb.src.core.methods import cpdb_degs_analysis_method
----> 2 deconvoluted, means, relevant_interactions, significant_means =cpdb_degs_analysis_method.call(
      3     cpdb_file_path = cpdb_file_path, 
      4     meta_file_path = meta_file_path,
      5     counts_file_path = counts_file_path, 
      6     degs_file_path = degs_file_path, 
      7     output_path = output_path)

File ~/.local/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_degs_analysis_method.py:82, in call(cpdb_file_path, meta_file_path, counts_file_path, degs_file_path, counts_data, output_path, microenvs_file_path, separator, threshold, result_precision, debug, output_suffix)
     80 required_arguments = [cpdb_file_path, meta_file_path, counts_file_path, degs_file_path, counts_data, output_path]
     81 if None in required_arguments or '' in required_arguments:
---> 82     raise MissingRequiredArgumentsException(description="All of the following arguments need to be provided: {}".format( \
     83     "cpdb_file_path, meta_file_path, counts_file_path, degs_file_path, counts_data, output_path"))
     85 # Load into memory CellphoneDB data
     86 interactions, genes, complex_compositions, complexes, gene_synonym2gene_name = \
     87     db_utils.get_interactions_genes_complex(cpdb_file_path)

MissingRequiredArgumentsException: All of the following arguments need to be provided: cpdb_file_path, meta_file_path, counts_file_path, degs_file_path, counts_data, output_path
renyuan1988 commented 1 year ago

Besides, I have tried to run the degs_analysis in the Linux terminal, which also failed. Below are my codes and outputs: cellphonedb method degs_analysis final.tsv counts.mtx N_DEGs.tsv --counts-data=gene_name --threshold 0.1 --threads 32

[ ][CORE][11/03/23-11:57:38][INFO] Initializing SqlAlchemy CellPhoneDB Core
[ ][CORE][11/03/23-11:57:38][INFO] Using custom database at /home/data/t090328/.cpdb/releases/v4.0.0/cellphone.db
[ ][APP][11/03/23-11:57:38][INFO] Launching Method cpdb_degs_analysis_local_method_launcher
[ ][APP][11/03/23-11:57:38][INFO] Launching Method _set_paths
[ ][APP][11/03/23-11:57:38][INFO] Launching Method _load_meta_counts
[ ][APP][11/03/23-12:02:48][INFO] Launching Method _check_counts_data
[ ][APP][11/03/23-12:02:48][INFO] Launching Method _load_degs
[ ][CORE][11/03/23-12:02:48][INFO] Launching Method cpdb_degs_analysis_launcher
[ ][CORE][11/03/23-12:02:48][INFO] Launching Method _counts_validations
[ ][CORE][11/03/23-12:03:34][INFO] Launching Method get_interactions_genes_complex
[ ][CORE][11/03/23-12:03:34][INFO] [Cluster DEGs Analysis] Threshold:0.1 Iterations:1000 Debug-seed:-1 Threads:32 Precision:3
[ ][CORE][11/03/23-12:03:34][WARNING] 
***********************************
DEGs ANALYSIS IS AN EXPERIMENTAL METHOD STILL UNDER DEVELOPMENT!
***********************************
[ ][CORE][11/03/23-12:03:41][INFO] Running Real Analysis
[ ][CORE][11/03/23-12:03:41][INFO] Running DEGs-based Analysis
[ ][APP][11/03/23-12:03:42][ERROR] Unexpected error
Traceback (most recent call last):
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/cellphonedb/src/api_endpoints/terminal_api/method_terminal_api_endpoints/method_terminal_commands.py", line 300, in degs_analysis
    debug
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/cellphonedb/src/local_launchers/local_method_launcher.py", line 176, in cpdb_degs_analysis_local_method_launcher
    output_path
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/cellphonedb/src/core/methods/method_launcher.py", line 212, in cpdb_degs_analysis_launcher
    output_path)
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/cellphonedb/src/core/methods/cpdb_degs_analysis_method.py", line 153, in call
    counts_data)
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/cellphonedb/src/core/methods/cpdb_degs_analysis_method.py", line 362, in build_degs_matrix
    d = d.groupby(d.index).max()
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 1560, in max
    numeric_only=numeric_only, min_count=min_count, alias="max", npfunc=np.max
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 1001, in _agg_general
    how=alias, alt=npfunc, numeric_only=numeric_only, min_count=min_count,
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/pandas/core/groupby/generic.py", line 1022, in _cython_agg_general
    how, alt=alt, numeric_only=numeric_only, min_count=min_count
  File "/home/data/t090328/miniconda3/envs/cpdb/lib/python3.7/site-packages/pandas/core/groupby/generic.py", line 1135, in _cython_agg_blocks
    assert len(locs) == result.shape[1]
AssertionError

Then I ran the statistical_analysis method and succeeded. I have checked my deg file, there was no NA or unmached cluster names with the meta file, so what could be reason? I have attached my deg and meta files in txt format (converted from the original tsv format since the uploading didn't support ), I thought it might help.

ktroule commented 1 year ago

For errors such All of the following arguments need to be provided: cpdb_file_path, meta_file_path, counts_file_path, degs_file_path, counts_data, output_path you might be missing the argument counts_data, run it as:

from cellphonedb.src.core.methods import cpdb_degs_analysis_method

deconvoluted, means, relevant_interactions, significant_means = cpdb_degs_analysis_method.call(
    cpdb_file_path = cpdb_file_path,                            
    meta_file_path = meta_file_path,                        
    counts_file_path = counts_file_path,                       
    degs_file_path = degs_file_path,
    output_path = out_path,
    counts_data = 'hgnc_symbol')

Replace counts_data value accordingly.

renyuan1988 commented 1 year ago

Thanks for the reminding, it works well for my own data in the cloned git now, but still failed in my own jupyter lab or in the linux terminal.

ktroule commented 1 year ago

I'm not able to reproduce your error. Provide the exact failing command and all the inputs (downsampled) you use so I can try to reproduce the error with your data.