Teichlab / celltypist

A tool for semi-automatic cell type classification
https://www.celltypist.org/
MIT License
254 stars 40 forks source link

Update plot.py #93

Open milescsmith opened 8 months ago

milescsmith commented 8 months ago

Fixes KeyError: [...] not in index when running celltypist.plot.dotplot()

ChuanXu1 commented 8 months ago

@milescsmith, can you provide more details on why this change is needed? Thank you!

milescsmith commented 8 months ago

Sure. The problem is that if prediction_order is not passed to celltypist.plot.dotplot() (and thus to celltypist.plot._get_fraction_prob_df()), prediction_order is set to all possible categories in the passed AnnotationResult.predicted_labels; however, the dot_color_df is derived from the sliced pred = predictions.predicted_labels[use_as_prediction], so that by the time you get to dot_color_df = dot_color_df.loc[prediction_order], the values in prediction_order may be larger than the possible values in dot_color_df and thus _get_fraction_prob_df() and dotplot() fail due to a KeyError. The bit of code I added ensures the values match or that prediction_order is a subset.

ChuanXu1 commented 8 months ago

@milescsmith, I think dot_color_df is not sliced, so their values should be matched. Do you any code to produce the scenario you mentioned?