zhengrongbin / MEBOCOST

A python-based package and software to predict metabolite mediated cell-cell communications by single-cell RNA-seq data
BSD 3-Clause "New" or "Revised" License
59 stars 10 forks source link

KeyError: "None of [Index(['met', 'hmdbID'], dtype='object')] are in the [columns]" #21

Closed KunFang93 closed 2 months ago

KunFang93 commented 2 months ago

Hi Rongbin,

Thanks for providing this wonderful tool! I tried to follow the tutorial but got error when run section 2.3 of tutorial

update_commu_res, efflux_mat, influx_mat = _update_commu_res_(mebo_obj, 
                                                              compass_folder='your_folder/compass_res', 
                                                              efflux_cut = 'auto', influx_cut='auto')

After I digged in, the bug came from this line in _get_compassflux function.

efflux_mat = pd.merge(secretion, compass_met_ann[['met', 'hmdbID']],
                            left_index = True, right_on = 'met').dropna()

The compass_met_anno seems not have 'met' and 'hmdbID' columns. I wondered if you could shed some lights on this? Thank you very much for your time and help!

Best, Kun

KunFang93 commented 2 months ago

Hi Rongbin,

Thanks for providing this wonderful tool! I tried to follow the tutorial but got error when run section 2.3 of tutorial

update_commu_res, efflux_mat, influx_mat = _update_commu_res_(mebo_obj, 
                                                              compass_folder='your_folder/compass_res', 
                                                              efflux_cut = 'auto', influx_cut='auto')

After I digged in, the bug came from this line in _get_compassflux function.

efflux_mat = pd.merge(secretion, compass_met_ann[['met', 'hmdbID']],
                            left_index = True, right_on = 'met').dropna()

The compass_met_anno seems not have 'met' and 'hmdbID' columns. I wondered if you could shed some lights on this? Thank you very much for your time and help!

Best, Kun

I thought I find the reason. In mebocos.conf, these two lines should switch the files

compass_rxt_ann_path = /data/kfang/software/MEBOCOST/data/Compass/met_md.csv
compass_met_ann_path = /data/kfang/software/MEBOCOST/data/Compass/rxn_md.csv

To

compass_rxt_ann_path = /data/kfang/software/MEBOCOST/data/Compass/rxn_md.csv
compass_met_ann_path = /data/kfang/software/MEBOCOST/data/Compass/met_md.csv
zhengrongbin commented 2 months ago

Thank you for pointing out the bug. I will correct it soon.

KunFang93 commented 2 months ago

Hi Rongbin,

Sorry for re-openning this issue, but I found another bug resulted from the code one line below the before one

KeyError: "None of [Index(['Secondary_HMDB_ID', 'metabolite'], dtype='object')] are in the [columns]"

caused by

 efflux_mat = pd.merge(efflux_mat, met_ann[['Secondary_HMDB_ID', 'metabolite']],
                        left_on='hmdbID', right_on='Secondary_HMDB_ID')

However, the met_ann is not defined in the function, I wondered if you could help on this? Thanks!

Best, Kun

zhengrongbin commented 2 months ago

Thanks again, I believe that this can be resolved by adding:

met_ann = pd.read_csv(mebocost._read_config(mebo_obj.config_path)['common']['hmdb_info_path'])

I will correct the tutorial later.

KunFang93 commented 2 months ago

Thanks again, I believe that this can be resolved by adding:

met_ann = pd.read_csv(mebocost._read_config(mebo_obj.config_path)['common']['hmdb_info_path'])

I will correct the tutorial later.

Thanks for your prompt response. Appreciated a lot!

I noticed the met_ann is .tsv file so it might need a minor change to read_table

met_ann = pd.read_table(mebocost._read_config(mebo_obj.config_path)['common']['hmdb_info_path'])

It works and I closed the thread. Thanks again!