plotly / dash-bio

Open-source bioinformatics components for Dash
https://dash-gallery.plotly.host/Portal/?search=Bioinformatics
MIT License
531 stars 191 forks source link

Clustergram "row_colors" and "column_colors" properties documentation not clear #735

Open birkanozer opened 1 year ago

birkanozer commented 1 year ago

While I was trying to colourise my Clustergram, I tried to assign a list of colour names and a list of rgb() annotations to the "row_color" and "column_color" properties. Each time I received the following error:

` ValueError: Invalid value of type 'builtins.list' received for the 'colorscale' property of heatmap Received value: [[0, 'gray'], [0.0333333333, 'gray'], [0.0333333333, 'gray'], [0.0666666666, 'gray'], [0.0666666666, 'gray'], [0.0999999999, 'gray'], [0.0999999999, 'gray'], [0.1333333332, 'gray'], [0.1333333332, 'v'], [0.1666666665, 'v'], [0.1666666665, 'gray'], [0.1999999998, 'gray'], [0.1999999998, 'gray'], [0.2333333331, 'gray'], [0.2333333331, 'gray'], [0.2666666664, 'gray'], [0.2666666664, 'gray'], [0.2999999997, 'gray'], [0.2999999997, 'gray'], [0.333333333, 'gray'], [0.333333333, 'gray'], [0.3666666663, 'gray'], [0.3666666663, 'gray'], [0.3999999996, 'gray'], [0.3999999996, 'gray'], [0.4333333329, 'gray'], [0.4333333329, 'gray'], [0.4666666662, 'gray'], [0.4666666662, 'gray'], [0.4999999995, 'gray'], [0.4999999995, 'gray'], [0.5333333328, 'gray'], [0.5333333328, 'gray'], [0.5666666661, 'gray'], [0.5666666661, 'gray'], [0.5999999994, 'gray'], [0.5999999994, 'gray'], [0.6333333327, 'gray'], [0.6333333327, 'gray'], [0.666666666, 'gray'], [0.666666666, 'gray'], [0.6999999993, 'gray'], [0.6999999993, 'gray'], [0.7333333326, 'gray'], [0.7333333326, 'gray'], [0.7666666659, 'gray'], [0.7666666659, 'gray'], [0.7999999992, 'gray'], [0.7999999992, 'gray'], [0.8333333325, 'gray'], [0.8333333325, 'gray'], [0.8666666658, 'gray'], [0.8666666658, 's'], [0.8999999991, 's'], [0.8999999991, 'gray'], [0.9333333324, 'gray'], [0.9333333324, 'gray'], [0.9666666657, 'gray'], [0.9666666657, 'h'], [1, 'h']]

The 'colorscale' property is a colorscale and may be
specified as:
  - A list of colors that will be spaced evenly to create the colorscale.
    Many predefined colorscale lists are included in the sequential, diverging,
    and cyclical modules in the plotly.colors package.
  - A list of 2-element lists where the first element is the
    normalized color level value (starting at 0 and ending at 1),
    and the second item is a valid color string.
    (e.g. [[0, 'green'], [0.5, 'red'], [1.0, 'rgb(0, 0, 255)']])
  - One of the following named colorscales:
        ['aggrnyl', 'agsunset', 'algae', 'amp', 'armyrose', 'balance',
         'blackbody', 'bluered', 'blues', 'blugrn', 'bluyl', 'brbg',
         'brwnyl', 'bugn', 'bupu', 'burg', 'burgyl', 'cividis', 'curl',
         'darkmint', 'deep', 'delta', 'dense', 'earth', 'edge', 'electric',
         'emrld', 'fall', 'geyser', 'gnbu', 'gray', 'greens', 'greys',
         'haline', 'hot', 'hsv', 'ice', 'icefire', 'inferno', 'jet',
         'magenta', 'magma', 'matter', 'mint', 'mrybm', 'mygbm', 'oranges',
         'orrd', 'oryel', 'oxy', 'peach', 'phase', 'picnic', 'pinkyl',
         'piyg', 'plasma', 'plotly3', 'portland', 'prgn', 'pubu', 'pubugn',
         'puor', 'purd', 'purp', 'purples', 'purpor', 'rainbow', 'rdbu',
         'rdgy', 'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar',
         'spectral', 'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn',
         'tealrose', 'tempo', 'temps', 'thermal', 'tropic', 'turbid',
         'turbo', 'twilight', 'viridis', 'ylgn', 'ylgnbu', 'ylorbr',
         'ylorrd'].
    Appending '_r' to a named colorscale reverses it.

`

Based on that error I tried the second and the third options. I keep receiving the same error. I dig out the both "dash_bio" and "plotly" codebase and I found the reason.

The Clustergram class only accepts a list of HEX colour codes, which does not mention at any point in the documentation. After it receives this list, it calls "plotly.graph_objects.Heatmap" class and passes the colour list to the "colorscale" property. The "colorscale" is much more flexible in terms of receiving colour, hence giving it's own possible values on the error note. This makes the confusion.

Propose: The documentation about "row_color" and "column_color" according to current status or change this library to accept the same values as the underlying "Heatmap" class accepts.

adikondepudi commented 1 year ago

I have the same issue as well. I think looking at seaborn's implemention of colors under their clustermap would help significantly.

Sameerpython commented 1 year ago

Hi,

I had the same issue. I was able to solve the issue by adding: color_map= 'rdylbu'.

You can select any of the following colorscale you have provided above.