zhengrongbin / MEBOCOST

A python-based package and software to predict metabolite mediated cell-cell communications by single-cell RNA-seq data
BSD 3-Clause "New" or "Revised" License
59 stars 10 forks source link

TypeError: get_xlmhg_stat() takes from 3 to 4 positional arguments but 6 were given #6

Closed semenko closed 1 year ago

semenko commented 2 years ago

Thanks for this great package!

I'm trying it out, and ran into a bug following your second notebook (on pathway inference).

When applied to my dataset, this starts generating output, but fails near the end:

mebo_obj.infer_pathway(
                    pval_method='permutation_test_fdr',
                    pval_cutoff=0.05,
                    commu_score_cutoff=0,
                    commu_score_column='Commu_Score',
                    min_term=15,
                    max_term=500,
                    thread=None,
                    sender_focus=[],
                    metabolite_focus=[],
                    sensor_focus=[],
                    receiver_focus=[],
                    Return_res=False
                    )

Traceback:

[July 07, 2022 13:02:11]: Read gene set from GMT file
[July 07, 2022 13:02:11]: Weight gene expression by gene network score of sensor
[July 07, 2022 13:03:38]: Weighted expression deconvolution to metabolite-sensor events
[July 07, 2022 13:03:38]: 205 sensor-receiver pairs
[July 07, 2022 13:10:02]: Weighted expression deconvolution to sender-receiver events
[July 07, 2022 13:10:02]: 476 sender-receiver pairs
[July 07, 2022 13:10:13]: Enrichment for significant sensor in receiver cell
[July 07, 2022 13:10:13]: Thread: 24
[July 07, 2022 13:10:23]: ABCB1 ~ 21
[July 07, 2022 13:10:27]: ABCC1 ~ 22
....
[July 07, 2022 13:14:14]: VDR ~ 22
---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/nsemenkovich/.local/miniconda3/envs/jupyter/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/home/nsemenkovich/.local/miniconda3/envs/jupyter/lib/python3.10/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/home/nsemenkovich/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/mebocost-1.0.1-py3.10.egg/mebocost/pathway_enrichment.py", line 251, in _excu_sensor_enrich_
    resobjs, res = self._link_mHG(w_e, self.gmt, 500)
  File "/home/nsemenkovich/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/mebocost-1.0.1-py3.10.egg/mebocost/pathway_enrichment.py", line 223, in _link_mHG
    res = pd.DataFrame(map(lambda x: self.getmHG(indices[x], N=int(N), X = 1, L = L), indices),
  File "/home/nsemenkovich/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/pandas/core/frame.py", line 710, in __init__
    data = list(data)
  File "/home/nsemenkovich/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/mebocost-1.0.1-py3.10.egg/mebocost/pathway_enrichment.py", line 223, in <lambda>
    res = pd.DataFrame(map(lambda x: self.getmHG(indices[x], N=int(N), X = 1, L = L), indices),
  File "/home/nsemenkovich/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/mebocost-1.0.1-py3.10.egg/mebocost/pathway_enrichment.py", line 171, in getmHG
    res = xlmhg.get_xlmhg_test_result(N, go_indices, X=X, L=L)
  File "/home/nsemenkovich/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/xlmhg/test.py", line 207, in get_xlmhg_test_result
    stat, cutoff = mhg_cython.get_xlmhg_stat(indices, N, K, X, L, tol)
TypeError: get_xlmhg_stat() takes from 3 to 4 positional arguments but 6 were given
"""

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
Input In [28], in <cell line: 1>()
----> 1 mebo_obj.infer_pathway(
      2                     pval_method='permutation_test_fdr',
      3                     pval_cutoff=0.05,
      4                     commu_score_cutoff=0,
      5                     commu_score_column='Commu_Score',
      6                     min_term=15,
      7                     max_term=500,
      8                     thread=None,
      9                     sender_focus=[],
     10                     metabolite_focus=[],
     11                     sensor_focus=[],
     12                     receiver_focus=[],
     13                     Return_res=False
     14                     )

File ~/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/mebocost-1.0.1-py3.10.egg/mebocost/mebocost.py:824, in create_obj.infer_pathway(self, pval_method, pval_cutoff, commu_score_cutoff, commu_score_column, min_term, max_term, thread, sender_focus, metabolite_focus, sensor_focus, receiver_focus, Return_res)
    811         ## start a object                      
    812         eobj = PE.PathwayEnrich(commu_res = good_commu,
    813                                 gene_network=self.gene_network,
    814                                 avg_exp = self.avg_exp,
   (...)
    821                                 thread = self.thread if thread is None else thread
    822                                 )
--> 824         self.enrich_result = eobj._pred_(pval_method = pval_method, 
    825                             sensor_in_receiver = True, 
    826                             sender_to_receiver = True,
    827                             sender_focus = sender_focus,
    828                             metabolite_focus = metabolite_focus,
    829                             sensor_focus = sensor_focus,
    830                             receiver_focus = receiver_focus,
    831                             Return = True
    832                            )
    834 #         ## add
    835 #         self.enrich_result = vars(eobj)
    837         toc  = time.time()

File ~/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/mebocost-1.0.1-py3.10.egg/mebocost/pathway_enrichment.py:465, in PathwayEnrich._pred_(self, pval_method, sensor_in_receiver, sender_to_receiver, Return, sender_focus, metabolite_focus, sensor_focus, receiver_focus)
    462 sensor_res = collections.defaultdict()
    463 if sensor_in_receiver:
    464     ## iterate for each sensor in receivers
--> 465     sensor_res = self._sensor_enrich_()
    467 ## pathway enrichment for significant sender-receiver pairs
    468 cellpair_res = collections.defaultdict()

File ~/.local/miniconda3/envs/jupyter/lib/python3.10/site-packages/mebocost-1.0.1-py3.10.egg/mebocost/pathway_enrichment.py:283, in PathwayEnrich._sensor_enrich_(self)
    281 info('Thread: %s'%(self.thread))
    282 pool = multiprocessing.Pool(self.thread)
--> 283 res_col = pool.map(self._excu_sensor_enrich_, sr)
    284 pool.close()
    285 ## collect

File ~/.local/miniconda3/envs/jupyter/lib/python3.10/multiprocessing/pool.py:364, in Pool.map(self, func, iterable, chunksize)
    359 def map(self, func, iterable, chunksize=None):
    360     '''
    361     Apply `func` to each element in `iterable`, collecting the results
    362     in a list that is returned.
    363     '''
--> 364     return self._map_async(func, iterable, mapstar, chunksize).get()

File ~/.local/miniconda3/envs/jupyter/lib/python3.10/multiprocessing/pool.py:771, in ApplyResult.get(self, timeout)
    769     return self._value
    770 else:
--> 771     raise self._value

TypeError: get_xlmhg_stat() takes from 3 to 4 positional arguments but 6 were given
zhengrongbin commented 2 years ago

Hi - could you please downgrade your Python from 3.10 to 3.8? The required package xlmhg was maintained at python 3.8. a similar question refer to #2