Find differentially expressed between multiple subsets of cells based on certain barcodes

Dear Scanpy lab, I have two questions for you, and would very much appreciate your help!

My overall goal is to find differentially expressed genes between five different groups of cells based on specific barcodes (so not between Leiden clusters).

My five groups are specified as filtered_barcodes_group_1 etc. (to keep things more compact, here I only include 2 barcodes per group):

adata.obs[‘filtered_barcodes_group_1’] = data.obs_names.isin([‘TTGGAACCAGCGTCCA-1’, ‘TTGGCAAAGCTCCCAG-1’])
adata.obs[‘filtered_barcodes_group_2’] = data.obs_names.isin([‘TTGGTTCCAGCGTCCA-1’, ‘TTGGCAATTCTCCCAG-1’])
Etc. for the other 3 remaining groups.

1. What would be the best way to rank the genes between for example filtered_barcodes_group_1 and filtered_barcodes_group_2?

I am planning on using an ‘if else syntax’ - however it throws an error saying: ‘str’ object has no attribute ‘isin’:

#(Etc. for group 3-5)

adata.obs[‘barcodes’] = [‘filtered_barcodes_group_1’ if id.isin(barcode_group1) else ‘filtered_barcodes_group_2’ if id.isin(barcode_group2) else ‘filtered_barcodes_group_3’ if id.isin(barcode_group3) else ‘filtered_barcodes_group_4’ if id.isin(barcode_group4) else ‘filtered_barcodes_group_5’ if id.isin(barcode_group5) for id in adata.obs_names], ‘filtered_barcodes_group_1’, groups=[‘True’], reference=[‘filtered_barcodes_group_2’])

2. How can I rank genes between two groups consisting of 1) filtered_barcodes_group_1 and filtered_barcodes_group_2 and 2) filtered_barcodes_group_3 and filtered_barcodes_group_4?

Thanks in advance,

Josine :slight_smile:

(The second bit of code under question 1 was kindly provided by your colleague LuckyMD @ Theis Lab.)