maximilianh / cellBrowser

main repo: https://github.com/ucscGenomeBrowser/cellBrowser/ - Python pipeline and Javascript scatter plot library for single-cell datasets, http://cellbrowser.rtfd.org
https://github.com/ucscGenomeBrowser/cellBrowser/
GNU General Public License v3.0
104 stars 41 forks source link

Custom colors for each attribute #256

Closed cancerGen closed 1 year ago

cancerGen commented 1 year ago

Hi,

I was just curious if you already have in place the ease of assigning and storing colors for each attribute. For instance, I want to always color all the microglia cells purple or green, etc. Currently, every time I restart the browser I have to manually set colors for each attribute. Maybe there's a slot somewhere in the json file that will allow me to assign and store colors?

maximilianh commented 1 year ago

Yes! There is the “colors” file in the sample cellbrowser.conf file. It’s a table, comma or tab sep. Two columns, first the value then the color as a six digit hex value. Can you see it in the sample config file ? Otherwise let me know, I can add more examples.

On Sun 6 Nov 2022 at 18:27, cancerGen @.***> wrote:

Hi,

I was just curious if you already have in place the ease of assigning and storing colors for each attribute. For instance, I want to always color all the microglia cells purple or green, etc. Currently, every time I restart the browser I have to manually set colors for each attribute. Maybe there's a slot somewhere in the json file that will allow me to assign and store colors?

— Reply to this email directly, view it on GitHub https://github.com/maximilianh/cellBrowser/issues/256, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL4TO7FLKTSVWL5WIJ3VDWG7S7VANCNFSM6AAAAAARYQTTO4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

maximilianh commented 1 year ago

Hi @cancerGen, can you tell me why you didn't see this? I need to make options like this easier to understand. The sample config has this particular statement, but maybe I should highlight these things more in the documentation?

On Mon, Nov 7, 2022 at 7:39 AM cancerGen @.***> wrote:

Closed #256 https://github.com/maximilianh/cellBrowser/issues/256 as completed.

— Reply to this email directly, view it on GitHub https://github.com/maximilianh/cellBrowser/issues/256#event-7749485466, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL4TNGTXXDGZQZ56PA4JDWHCP3LANCNFSM6AAAAAARYQTTO4 . You are receiving this because you commented.Message ID: @.***>

cancerGen commented 1 year ago

Sorry for the inconvenience, but the colors parameter is allowing me to assign colors to just one attribute. I was looking specifically to have pre-assigned colors for clusters/mutations/Gender. I tried providing multiple color files but that doesn't seem to work. I also tried providing colors for all possible attributes in a single file but that doesn't work either.

maximilianh commented 1 year ago

Sorry, I don't understand what you mean with "attribute" - do you mean that the coloring works only for the cell-type meta data field? It should work for any field, as long as the field values match exactly to your colors file...

On Mon, Nov 7, 2022 at 2:12 PM cancerGen @.***> wrote:

Sorry for the inconvenience, but the colors parameter is allowing me to assign colors to just one attribute. I was looking specifically to have pre-assigned colors for clusters/mutations/Gender. I tried providing multiple color files but that doesn't seem to work. I also tried providing colors for all possible attributes in a single file but that doesn't work either.

— Reply to this email directly, view it on GitHub https://github.com/maximilianh/cellBrowser/issues/256#issuecomment-1305597330, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL4TPJBDNK5F6JROK7EO3WHD527ANCNFSM6AAAAAARYQTTO4 . You are receiving this because you commented.Message ID: @.***>

cancerGen commented 1 year ago

Sorry for the confusion. I mean I want to have pre-assigned colors for multiple fields at the same time. For instance, I have three fields: clusters, mutation, and Gender. Currently, the cell browser allows me to pre-assign colors only for any one of the mentioned fields. My objective is to assign colors to all the fields in the metafile.

I hope this clears my question.

maximilianh commented 1 year ago

I'm sorry that I dropped the ball on this! I was traveling and then forgot. Oops.

Colors defined in the colors file apply to all fields. It's not just the label field.

This is defined in cellbrowser.py line 1180:

    if colors!=None:
        colArr = []
        foundColors = 0
        notFound = set()
        for val, _ in valCounts:
            if val in colors:
                colArr.append(colors[val])
                foundColors +=1
            else:
                notFound.add(val)
                colArr.append(None) # maybe I should fail hard here?

        if foundColors > 0:
            fieldMeta["colors"] = colArr
            if len(notFound)!=0:
                logging.warn("No default color found for field values

%s. They were set to defaults." % notFound)

This code is run for every field not just the label field.

This may not be very intuitive but it's simple enough. If you have the same value in different field but want different colors for it, then you'd have to use different values, for now. I can change the system, but I think this system should work for you?

Now yes, it would have been better if I had replied a month ago...

On Mon, Nov 7, 2022 at 6:07 PM cancerGen @.***> wrote:

Sorry for the confusion. I mean I want to have pre-assigned colors for multiple fields at the same time. For instance, I have three fields: clusters, mutation, and Gender. Currently, the cell browser allows me to pre-assign colors only for any one of the mentioned fields. My objective is to assign colors to all the fields in the metafile.

I hope this clears my question.

— Reply to this email directly, view it on GitHub https://github.com/maximilianh/cellBrowser/issues/256#issuecomment-1305922837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL4TOS4F6HEDQNJCEB3LTWHEZMLANCNFSM6AAAAAARYQTTO4 . You are receiving this because you commented.Message ID: @.***>

cancerGen commented 1 year ago

Thanks for the solution.

maximilianh commented 1 year ago

Hi @cancerGen do you have a publicly visible instance so I could have a look? I’m always interested in how people show things.

If I don’t reply in the future don’t hesitate to ping me again.

On Thu 15 Dec 2022 at 22:24, cancerGen @.***> wrote:

Closed #256 https://github.com/maximilianh/cellBrowser/issues/256 as completed.

— Reply to this email directly, view it on GitHub https://github.com/maximilianh/cellBrowser/issues/256#event-8053766044, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL4TNT47K2UJTEH6QLGPLWNQDKBANCNFSM6AAAAAARYQTTO4 . You are receiving this because you commented.Message ID: @.***>