grassp.pp.set_sensible_compartment_colors#
- set_sensible_compartment_colors(data, columns=None, cutoff=0.3, verbose=False, plot_mapping=False)[source]#
Assign colors to compartment annotation columns in
.obsusing the built-in color dictionary.Scans columns in
.obsand identifies those that look like compartment annotation columns by checking what fraction of their unique values appear in the built-inMARKER_COLORSdictionary. Matching is case-insensitive and treats underscores as spaces (e.g."endoplasmic_reticulum"matches"Endoplasmic Reticulum").Columns where at least
cutofffraction of unique values are recognised compartments receive a'{col}_colors'entry in.uns, following scanpy plotting conventions. Known compartments get their canonical color fromMARKER_COLORS; unknown categories receive distinct colors drawn from matplotlib’stab20/tab20b/tab20cpalettes. All assigned colors are deduplicated so that every category in a column maps to a unique color.- Parameters:
- data
AnnData AnnData object whose
.obscolumns are scanned for compartment annotations.- columns
list[str] |None(default:None) List of column names in
.obsto process. IfNone(default), all columns in.obsare scanned.- cutoff
float(default:0.3) Minimum fraction of unique values in a column that must be recognised compartments for that column to receive a
'{col}_colors'entry in.uns. Default is0.3.- verbose
bool(default:False) If
True, print diagnostic information for each processed column, including the matched fraction, assigned colors, and any fallback assignments.- plot_mapping
bool(default:False) If
True, display a grid plot showing the color assigned to each category for every processed column, with fallback colors visually distinguished.
- data
- Return type: