vanallenlab / comut

CoMut is a Python library for visualizing genomic and phenotypic information via comutation plots
MIT License
87 stars 26 forks source link

add_side_bar_data errors with pandas 2.0.0 or higher #22

Open seunghun23 opened 10 months ago

seunghun23 commented 10 months ago

Hi Jett,

It seems that add_side_bar_data errors with TypeError: Passing a set as an indexer is not supported. Use a list instead. if I use pandas version 2.0.0 or higher. I tested with the toy dataset included in the tutorial as well, and it failed with the same error. I could get it to working again once I downgraded pandas to version 1.5.3. I'm not sure whether you are still maintaining the package but it would be nice if you could fix this.

Thanks, Seunghun

jett-crowdis commented 10 months ago

Hi Seunghun,

Would you mind posting a minimum reproducible example? Using a set as an indexer is unexpected, so I'm curious what's going on here.

seunghun23 commented 10 months ago

I simply ran what's in your documentation.ipynb and got the error I mentioned above

# import other data
cat_data = pd.read_csv('tutorial_data/tutorial_mutation_data.tsv', sep = '\t')
purity_data = pd.read_csv('tutorial_data/tutorial_purity.tsv', sep = '\t')
mut_burden_df = pd.read_csv('tutorial_data/tutorial_mutation_burden.tsv', sep = '\t')

# import side bar data
mutsig_df = pd.read_csv('tutorial_data/tutorial_mutsig_qvals.tsv', sep = '\t')
mutsig_df.head()
# make CoMut
toy_comut = comut.CoMut()
toy_comut.samples = ['Sample' + str(i) for i in range(1,51)]

toy_comut.add_categorical_data(cat_data, name = 'Mutation type')
toy_comut.add_continuous_data(purity_data, name = 'Purity', mapping = 'Purples', value_range = (0, 1))
toy_comut.add_bar_data(mut_burden_df, stacked = True, name = 'Mutation burden')

# create mapping for side bar data, make the bars thinner with bar_kwargs
side_mapping = {'-log(Q)': 'darkgrey'}
bar_kwargs = {'height': 0.8}
toy_comut.add_side_bar_data(mutsig_df, paired_name = 'Mutation type', name = 'Mutsig',
                            mapping = side_mapping, xlabel = 'Mutsig -log(Q)', position = 'right', bar_kwargs = bar_kwargs)

toy_comut.plot_comut(figsize = (12, 5), x_padding = 0.04, y_padding = 0.04, tri_padding = 0.03, hspace = 0.1, wspace = 0.03)
toy_comut.add_unified_legend(axis_name = 'Mutsig')
vincentx42 commented 3 months ago

Hi Jett and seunghun,

I met this issue as well. Python just raised me an error the same as seunghun mentioned TypeError: Passing a set as an indexer is not supported. Use a list instead.

The reason might be the feature update by Pandas and I just simply fixed to use that function CoMut.add_side_bar_data().

-----Below is the modified part of original function-----
# add missing categories and assign them a value of 0 for all rows
missing_categories = list(paired_cats - side_cats)    #Fix may work: add a wrapper <list()> to avoid Pandas TypeError
data_indexed = data_indexed.reindex(list(paired_plot['data'].index))
data.loc[missing_categories, :] = 0      # the indexer caused the error: 'missing_categories'

It works from my end and hope it makes sense.

here0009 commented 3 weeks ago

Hi guys, I got the same issue, I edited line 1002 of comut.py from

missing_categories = paired_cats - side_cats

to

missing_categories = list(paired_cats - side_cats)

It worked for me