def _gene_color_dict(model):
    """
    Helper function to match genes to colors based on COG. Used by
    imdb_gene_scatter_df.

    Parameters
    ----------
    model : :class:`~pymodulon.core.IcaData`
        IcaData object

    Returns
    -------
    dict
        Dictionary associating gene names to colors

    """

    try:
        gene_cogs = model.gene_table.cog.to_dict()
    except AttributeError:
        return {k: "dodgerblue" for k in model.gene_table.index}

    try:
        return {k: model.cog_colors[v] for k, v in gene_cogs.items()}
    except (KeyError, AttributeError):
        # previously, this would call the setter using:
        # data.cog_colors = None
        cogs = sorted(model.gene_table.cog.unique())
        model.cog_colors = dict(
            zip(
                cogs,
                [
                    "red",
                    "pink",
                    "y",
                    "orchid",
                    "mediumvioletred",
                    "green",
                    "lightgray",
                    "lightgreen",
                    "slategray",
                    "blue",
                    "saddlebrown",
                    "turquoise",
                    "lightskyblue",
                    "c",
                    "skyblue",
                    "lightblue",
                    "fuchsia",
                    "dodgerblue",
                    "lime",
                    "sandybrown",
                    "black",
                    "goldenrod",
                    "chocolate",
                    "orange",
                ],
            )
        )
        return {k: model.cog_colors[v] for k, v in gene_cogs.items()}