Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Passing a set as an indexer is not supported. Use a list instead. #49

Open
Fanyu000 opened this issue Mar 25, 2024 · 5 comments

Comments

@Fanyu000
Copy link

Hello, I encoutered a warning today with this code
interactions = c2c.analysis.SingleCellInteractions(rnaseq_data=rnaseq.to_df().T,
ppi_data=lr_pairs,
metadata=meta,
interaction_columns=('ligand_symbol', 'receptor_symbol'),
communication_score='expression_thresholding',
expression_threshold=0.1, # values after aggregation
cci_score='bray_curtis',
cci_type='undirected',
aggregation_method='nn_cell_fraction',
barcode_col='index',
celltype_col='celltype',
complex_sep='&',
verbose=False)

And it warns me like that

TypeError Traceback (most recent call last)
Cell In[12], line 1
----> 1 interactions = c2c.analysis.SingleCellInteractions(rnaseq_data=rnaseq.to_df().T,
2 ppi_data=lr_pairs,
3 metadata=meta,
4 interaction_columns=('ligand2', 'receptor2'),
5 communication_score='expression_thresholding',
6 expression_threshold=0.1, # values after aggregation
7 cci_score='bray_curtis',
8 cci_type='undirected',
9 aggregation_method='nn_cell_fraction',
10 barcode_col='index',
11 celltype_col='cell_type',
12 complex_sep='&',
13 verbose=False)

File D:\anaconda\Lib\site-packages\cell2cell\analysis\cell2cell_pipelines.py:693, in SingleCellInteractions.init(self, rnaseq_data, ppi_data, metadata, interaction_columns, communication_score, cci_score, cci_type, expression_threshold, aggregation_method, barcode_col, celltype_col, complex_sep, complex_agg_method, verbose)
685 self.aggregated_expression = rnaseq.aggregate_single_cells(rnaseq_data=self.rnaseq_data,
686 metadata=self.metadata,
687 barcode_col=self.index_col,
688 celltype_col=self.group_col,
689 method=self.aggregation_method,
690 transposed=self.__adata)
692 # Interaction Space
--> 693 self.interaction_space = initialize_interaction_space(rnaseq_data=self.aggregated_expression,
694 ppi_data=self.ppi_data,
695 cutoff_setup=self.cutoff_setup,
696 analysis_setup=self.analysis_setup,
697 complex_sep=self.complex_sep,
698 complex_agg_method=self.complex_agg_method,
699 interaction_columns=self.interaction_columns,
700 verbose=verbose)

File D:\anaconda\Lib\site-packages\cell2cell\analysis\cell2cell_pipelines.py:940, in initialize_interaction_space(rnaseq_data, ppi_data, cutoff_setup, analysis_setup, excluded_cells, complex_sep, complex_agg_method, interaction_columns, verbose)
936 excluded_cells = []
938 included_cells = sorted(list((set(rnaseq_data.columns) - set(excluded_cells))))
--> 940 interaction_space = ispace.InteractionSpace(rnaseq_data=rnaseq_data[included_cells],
941 ppi_data=ppi_data,
942 gene_cutoffs=cutoff_setup,
943 communication_score=analysis_setup['communication_score'],
944 cci_score=analysis_setup['cci_score'],
945 cci_type=analysis_setup['cci_type'],
946 complex_sep=complex_sep,
947 complex_agg_method=complex_agg_method,
948 interaction_columns=interaction_columns,
949 verbose=verbose)
950 return interaction_space

File D:\anaconda\Lib\site-packages\cell2cell\core\interaction_space.py:381, in InteractionSpace.init(self, rnaseq_data, ppi_data, gene_cutoffs, communication_score, cci_score, cci_type, cci_matrix_template, complex_sep, complex_agg_method, interaction_columns, verbose)
374 self.ppi_data = self.ppi_data.assign(score=1.0)
376 self.modified_rnaseq = integrate_data.get_modified_rnaseq(rnaseq_data=rnaseq_data,
377 cutoffs=cutoff_values,
378 communication_score=self.communication_score,
379 )
--> 381 self.interaction_elements = generate_interaction_elements(modified_rnaseq=self.modified_rnaseq,
382 ppi_data=self.ppi_data,
383 cci_matrix_template=cci_matrix_template,
384 cci_type=self.cci_type,
385 complex_sep=complex_sep,
386 complex_agg_method=complex_agg_method,
387 verbose=verbose)
389 self.interaction_elements['ppi_score'] = self.ppi_data['score'].values

File D:\anaconda\Lib\site-packages\cell2cell\core\interaction_space.py:146, in generate_interaction_elements(modified_rnaseq, ppi_data, cci_type, cci_matrix_template, complex_sep, complex_agg_method, interaction_columns, verbose)
141 if complex_sep is not None:
142 col_a_genes, complex_a, col_b_genes, complex_b, complexes = get_genes_from_complexes(ppi_data=ppi_data,
143 complex_sep=complex_sep,
144 interaction_columns=interaction_columns
145 )
--> 146 modified_rnaseq = add_complexes_to_expression(rnaseq_data=modified_rnaseq,
147 complexes=complexes,
148 agg_method=complex_agg_method
149 )
151 # Cells
152 cell_instances = list(modified_rnaseq.columns) # @erick, check if position 0 of columns contain index header.

File D:\anaconda\Lib\site-packages\cell2cell\preprocessing\rnaseq.py:179, in add_complexes_to_expression(rnaseq_data, complexes, agg_method)
177 for k, v in complexes.items():
178 if all(g in tmp_rna.index for g in v):
--> 179 df = tmp_rna.loc[v, :]
180 if agg_method == 'min':
181 tmp_rna.loc[k] = df.min().values.tolist()

File D:\anaconda\Lib\site-packages\pandas\core\indexing.py:1091, in _LocationIndexer.getitem(self, key)
1089 @Final
1090 def getitem(self, key):
-> 1091 check_dict_or_set_indexers(key)
1092 if type(key) is tuple:
1093 key = tuple(list(x) if is_iterator(x) else x for x in key)

File D:\anaconda\Lib\site-packages\pandas\core\indexing.py:2618, in check_dict_or_set_indexers(key)
2610 """
2611 Check if the indexer is or contains a dict or set, which is no longer allowed.
2612 """
2613 if (
2614 isinstance(key, set)
2615 or isinstance(key, tuple)
2616 and any(isinstance(x, set) for x in key)
2617 ):
-> 2618 raise TypeError(
2619 "Passing a set as an indexer is not supported. Use a list instead."
2620 )
2622 if (
2623 isinstance(key, dict)
2624 or isinstance(key, tuple)
2625 and any(isinstance(x, dict) for x in key)
2626 ):
2627 raise TypeError(
2628 "Passing a dict as an indexer is not supported. Use a list instead."
2629 )

TypeError: Passing a set as an indexer is not supported. Use a list instead.

how can I deal with it.
my RANseq datafrme is like the screenshots show
image

Thanks

@earmingol
Copy link
Owner

earmingol commented Mar 25, 2024

I suggest doing this before calling cell2cell
meta.index.name = 'barcodes'

Then replace this barcode_col='index' by barcode_col='barcodes' when calling c2c.analysis.SingleCellInteractions()

In case this does not work, do you have a screenshot of the dataframe for the ligand-receptor pairs?
Also it would be useful if you check if you have repeated gene names in your data, for that use this:

rnaseq_df = rnaseq.to_df().T
rnaseq_df[~rnaseq_df.index.duplicated()]

Then pass rnaseq_df into

interactions = c2c.analysis.SingleCellInteractions(rnaseq_data=rnaseq_df,
ppi_data=lr_pairs,
metadata=meta,
interaction_columns=('ligand_symbol', 'receptor_symbol'),
communication_score='expression_thresholding',
expression_threshold=0.1, # values after aggregation
cci_score='bray_curtis',
cci_type='undirected',
aggregation_method='nn_cell_fraction',
barcode_col='barcodes',
celltype_col='celltype',
complex_sep='&',
verbose=False)

Also what version of pandas are you using? I think that could be also a reason for this error.

If this does not work, send me an email to erickarmingol [AT] gmail.com, and I would be happy to help.

@Fanyu000
Copy link
Author

@earmingol I have sent you the email with your needed information. It still can't work.

@earmingol
Copy link
Owner

earmingol commented Mar 26, 2024

I haven't got your email, but I think the error could be due to the version of pandas. From version 1.5 is not supporting sets to call indexes anymore. I need to push an update for fixing this. In the meantime, if your pandas version is 1.5 or higher, try installing an older version with pip install -U pandas<1.5

@Pangjing-Wu
Copy link

In another issue I found a way that may help you solve this error. Maybe you can try it.

@earmingol
Copy link
Owner

As @Pangjing-Wu pointed out, the issue was due to the lost of support for using sets for indexing in pandas. I just implemented a fix for this. Please update to v0.7.4 with pip install -U cell2cell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants