JCVenterInstitute / NSForest

A machine learning method for the discovery of the minimum marker gene combinations for cell type identification from single-cell RNA sequencing
MIT License
53 stars 20 forks source link

TypeError: 'NoneType' object is not callable #1

Closed giuseppedelnapalle closed 5 years ago

giuseppedelnapalle commented 5 years ago

Hi,

I had an error when I ran the codes in cell 3 of the script 'NS_Forest_v2.ipynb' on Jupyter Notebook. Codes in cell 1 & 2 went smoothly. The following messages were printed on the screen.

RTN1 5.4558917988718 GPM6A 6.5202792613131395 HSPB1 6.68820560318182 PHGDH 4.81677071212406 ANXA5 4.08874724866395 CLU 4.61930439015417 ...

D:\Anaconda3\envs\py27\lib\site-packages\ipykernel_launcher.py:98: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy D:\Anaconda3\envs\py27\lib\site-packages\pandas\core\indexing.py:543: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self.obj[item] = s

RTN1 8.321140985238856 GPM6A 8.261602044663064 HSPB1 3.103076840680365 PHGDH 2.4805289343488903 ANXA5 2.4805289343488903 ...


TypeError Traceback (most recent call last)

in () 74 max_grouped.df.to_csv('NSForest_v2_maxF-scores.csv') 75 ---> 76 NSForest_Results_Table_Fin["f-measureRank"] = NSForest_Results_Table_Fin.groupby(by="clusterName")["f-measure"].rank(ascending=False) 77 topResults = NSForest_Results_Table_Fin["f-measureRank"] < 50 78 NSForest_Results_Table_top = NSForest_Results_Table_Fin[topResults] D:\Anaconda3\envs\py27\lib\site-packages\pandas\core\groupby\groupby.pyc in rank(self, method, ascending, na_option, pct, axis) 1904 return self._cython_transform('rank', numeric_only=False, 1905 ties_method=method, ascending=ascending, -> 1906 na_option=na_option, pct=pct, axis=axis) 1907 1908 @Substitution(name='groupby') D:\Anaconda3\envs\py27\lib\site-packages\pandas\core\groupby\groupby.pyc in _cython_transform(self, how, numeric_only, **kwargs) 1023 try: 1024 result, names = self.grouper.transform(obj.values, how, -> 1025 **kwargs) 1026 except NotImplementedError: 1027 continue D:\Anaconda3\envs\py27\lib\site-packages\pandas\core\groupby\groupby.pyc in transform(self, values, how, axis, **kwargs) 2628 2629 def transform(self, values, how, axis=0, **kwargs): -> 2630 return self._cython_operation('transform', values, how, axis, **kwargs) 2631 2632 def _aggregate(self, result, counts, values, comp_ids, agg_func, D:\Anaconda3\envs\py27\lib\site-packages\pandas\core\groupby\groupby.pyc in _cython_operation(self, kind, values, how, axis, min_count, **kwargs) 2588 result = self._transform( 2589 result, values, labels, func, is_numeric, is_datetimelike, -> 2590 **kwargs) 2591 2592 if is_integer_dtype(result) and not is_datetimelike: D:\Anaconda3\envs\py27\lib\site-packages\pandas\core\groupby\groupby.pyc in _transform(self, result, values, comp_ids, transform_func, is_numeric, is_datetimelike, **kwargs) 2662 comp_ids, is_datetimelike, **kwargs) 2663 else: -> 2664 transform_func(result, values, comp_ids, is_datetimelike, **kwargs) 2665 2666 return result D:\Anaconda3\envs\py27\lib\site-packages\pandas\core\groupby\groupby.pyc in wrapper(*args, **kwargs) 2477 2478 def wrapper(*args, **kwargs): -> 2479 return f(afunc, *args, **kwargs) 2480 2481 # need to curry our sub-function D:\Anaconda3\envs\py27\lib\site-packages\pandas\core\groupby\groupby.pyc in (func, a, b, c, d, **kwargs) 2429 kwargs.get('ascending', True), 2430 kwargs.get('pct', False), -> 2431 kwargs.get('na_option', 'keep') 2432 ) 2433 } TypeError: 'NoneType' object is not callable

What I did: I followed the Prerequisites in the README.md to install the modules and create the input file. A glance of the input file was shown below.

In [3]: dataFull.head() Out[3]: AAK1 AARS ABCD3 ABHD12 ... YWHAH YWHAQ YWHAZ Clusters AMP358_sc11 5.318264 5.854272 2.480529 6.184276 ... 5.204884 7.599972 6.350880 Cl_1 AMP358_sc18 2.480529 2.480529 2.480529 4.379044 ... 3.193956 7.510237 5.710166 Cl_1 AMP358_sc7 6.228200 2.996529 3.206476 3.890947 ... 2.996529 8.167026 6.861036 Cl_1 AMP358_sc1 3.233557 3.320131 3.534038 4.060293 ... 2.860235 6.999525 6.781777 Cl_1 AMP358_sc11 3.219218 2.480529 2.480529 3.005682 ... 2.480529 7.919291 8.287178 Cl_1

[5 rows x 1255 columns]

Software information: OS: Windows 10 Python version: 2.7.15

In addition, I tried running the script in CentOS 7 system and got the same error.

Would anyone help solve the issue? Any suggestion is welcome. Thanks!

e-sollier commented 5 years ago

Hi,

I tried to use NSForest and I encountered the same issue.

In the dataframe NSForest_Results_Table_Fin, the column f-measure has type str, instead of float64, which results in the ranking function to fail in the following line:

NSForest_Results_Table_Fin["f-measureRank"] = NSForest_Results_Table_Fin.groupby(by="clusterName")["f-measure"].rank(ascending=False)

I solved this by not casting this column to str, ie I replaced the line

f1_store_1D_df = pd.DataFrame.from_dict(f1_store_1D, orient='index', dtype=str)

with

f1_store_1D_df = pd.DataFrame.from_dict(f1_store_1D, orient='index')
BAevermann commented 5 years ago

Thank you @Etienne92 for resolving this issue! I wasn't paying attention to the issues section, and I wasnt notified by email strangely. This issue was brought to my attention as well by co-worker, and it seems that the behavior of python2.7 when used as virtual env in python3 seems to not be identical to having an independent python 2.7 install. I am releasing a newer version of NS-Forest thats in python3 in an attempt to avoid these types of issues.