ventolab/CellphoneDB

cellphonedb does not work

Closed this issue · 4 comments

Hello! I installed cellphonedb with python3.8,conda-env. I am getting the same issue. Running the following command shows error message.

from cellphonedb.src.core.methods import cpdb_analysis_method

means, deconvoluted = cpdb_analysis_method.call(
cpdb_file_path = '../SaveData/cellphonedb-data-4.1.0/cellphonedb.zip',
meta_file_path = '../SaveData/test_meta.txt',
counts_file_path = '../SaveData/test_counts.txt',
counts_data = 'ensembl',
output_path = '../SaveData/')

Output:
[ ][CORE][14/07/23-19:06:42][INFO] [Non Statistical Method] Threshold:0.1 Precision:3
Reading user files...
The following user files were loaded successfully:
../SaveData/test_counts.txt
../SaveData/test_meta.txt
[ ][CORE][14/07/23-19:06:43][INFO] Running Real Analysis
[ ][CORE][14/07/23-19:06:43][INFO] Building results

OSError Traceback (most recent call last)
Cell In[62], line 3
1 from cellphonedb.src.core.methods import cpdb_analysis_method
----> 3 means, deconvoluted = cpdb_analysis_method.call(
4 cpdb_file_path = '../SaveData/cellphonedb-data-4.1.0/cellphonedb.zip',
5 meta_file_path = '../SaveData/test_meta.txt',
6 counts_file_path = '../SaveData/test_counts.txt',
7 counts_data = 'ensembl',
8 output_path = '../SaveData/')

File c:\users\wjr\anaconda3\envs\cpdb\lib\site-packages\cellphonedb\src\core\methods\cpdb_analysis_method.py:161, in call(cpdb_file_path, meta_file_path, counts_file_path, counts_data, output_path, microenvs_file_path, separator, threshold, result_precision, debug, output_suffix)
158 significant_means['rank'] = significant_means['rank'].apply(lambda rank: rank if rank != 0 else (1 + max_rank))
159 significant_means.sort_values('rank', inplace=True)
--> 161 file_utils.save_dfs_as_tsv(output_path, output_suffix, "simple_analysis",
162 {"means_result" : means_result,
163 "deconvoluted_result" : deconvoluted_result} )
164 return means_result, deconvoluted_result

File c:\users\wjr\anaconda3\envs\cpdb\lib\site-packages\cellphonedb\utils\file_utils.py:212, in save_dfs_as_tsv(out, suffix, analysis_name, name2df)
210 for name, df in name2df.items():
211 file_path = os.path.join(out, "{}{}{}.{}".format(analysis_name, name, suffix, "txt"))
--> 212 df.to_csv(file_path, sep = '\t', index=False)
213 print("Saved {} to {}".format(name, file_path))

File ~\anaconda3\Lib\site-packages\pandas\core\generic.py:3772, in NDFrame.to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, lineterminator, chunksize, date_format, doublequote, escapechar, decimal, errors, storage_options)
3761 df = self if isinstance(self, ABCDataFrame) else self.to_frame()
3763 formatter = DataFrameFormatter(
3764 frame=df,
3765 header=header,
(...)
3769 decimal=decimal,
3770 )
-> 3772 return DataFrameRenderer(formatter).to_csv(
3773 path_or_buf,
3774 lineterminator=lineterminator,
3775 sep=sep,
3776 encoding=encoding,
3777 errors=errors,
3778 compression=compression,
3779 quoting=quoting,
3780 columns=columns,
3781 index_label=index_label,
3782 mode=mode,
3783 chunksize=chunksize,
3784 quotechar=quotechar,
3785 date_format=date_format,
3786 doublequote=doublequote,
3787 escapechar=escapechar,
3788 storage_options=storage_options,
3789 )

File ~\anaconda3\Lib\site-packages\pandas\io\formats\format.py:1186, in DataFrameRenderer.to_csv(self, path_or_buf, encoding, sep, columns, index_label, mode, compression, quoting, quotechar, lineterminator, chunksize, date_format, doublequote, escapechar, errors, storage_options)
1165 created_buffer = False
1167 csv_formatter = CSVFormatter(
1168 path_or_buf=path_or_buf,
1169 lineterminator=lineterminator,
(...)
1184 formatter=self.fmt,
1185 )
-> 1186 csv_formatter.save()
1188 if created_buffer:
1189 assert isinstance(path_or_buf, StringIO)

File ~\anaconda3\Lib\site-packages\pandas\io\formats\csvs.py:240, in CSVFormatter.save(self)
236 """
237 Create the writer & save.
238 """
239 # apply compression and byte/text conversion
--> 240 with get_handle(
241 self.filepath_or_buffer,
242 self.mode,
243 encoding=self.encoding,
244 errors=self.errors,
245 compression=self.compression,
246 storage_options=self.storage_options,
247 ) as handles:
248 # Note: self.encoding is irrelevant here
249 self.writer = csvlib.writer(
250 handles.handle,
251 lineterminator=self.lineterminator,
(...)
256 quotechar=self.quotechar,
257 )
259 self._save()

File ~\anaconda3\Lib\site-packages\pandas\io\common.py:859, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
854 elif isinstance(handle, str):
855 # Check whether the filename is to be opened in binary mode.
856 # Binary mode does not support 'encoding' and 'newline'.
857 if ioargs.encoding and "b" not in ioargs.mode:
858 # Encoding
--> 859 handle = open(
860 handle,
861 ioargs.mode,
862 encoding=ioargs.encoding,
863 errors=errors,
864 newline="",
865 )
866 else:
867 # Binary mode
868 handle = open(handle, ioargs.mode)

OSError: [Errno 22] Invalid argument: '../SaveData/simple_analysis_means_result_07_14_2023_19:06:43.txt'

The test_meta.txt and test_counts.txt comes from example_data of CellphoneDB.
https://github.com/ventolab/CellphoneDB/tree/master/example_data

Hi.

It seems you are running CellPhoneDB on a windows machine. Can you provide the input/output files/dirs as full path rather than as a relative path.

Thanks

@ktroule Thank you for your response!

My input/output files/dirs is:

from cellphonedb.src.core.methods import cpdb_analysis_method

means, deconvoluted = cpdb_analysis_method.call(
cpdb_file_path = 'F:/DataAnalysis/LLMus/SaveData/cellphonedb-data-master/cellphonedb.zip',
meta_file_path = 'F:/DataAnalysis/LLMus/SaveData/test_meta.txt',
counts_file_path = 'F:/DataAnalysis/LLMus/SaveData/test_counts.txt',
counts_data = 'ensembl',
output_path = 'F:/DataAnalysis/LLMus/',
)

Many thanks.

Hi @Teich2233,
If I may just chime in - this issue was fixed and commented on in #102 when the user was calling Python via Reticulate from R Studio on Windows. Would you mind doing "pip install --force-reinstall "git+https://github.com/ventolab/CellphoneDB.git" and trying again?
Thanks and good luck,
Robert.