Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting colors for obsSets? #339

Open
srivarra opened this issue Apr 26, 2024 · 2 comments
Open

Setting colors for obsSets? #339

srivarra opened this issue Apr 26, 2024 · 2 comments

Comments

@srivarra
Copy link

srivarra commented Apr 26, 2024

If I have an AnnData object, is it possible to manually assign colors for the different cell categories? I tried taking a look at obsSetColor but I wasn't able to figure out how to utilize it.

If it is obsSetColor is it used with with add_coordination_by_dict? Something like below?

vc.add_coordination_by_dict({
    ct.OBS_COLOR_ENCODING: {
        "obs_set_one": ["0", "12" "123"],
		"obs_set_two": ["240", "123", "58"],
    }
})

As a ease of use functionality, It would be handy if colors could be manually set with the adata.uns["<obs_category_column>_colors" which is a list of RGB values sorted by adata.obs["<obs_category_column>"].categories.cat. Many scanpy functions take into account these manual color settings as well when plotting.

Thank you!!

@keller-mark
Copy link
Member

keller-mark commented Apr 29, 2024

vc.link_views_by_dict([spatial_view, another_view], {
    ct.OBS_COLOR_ENCODING: "cellSetSelection",
    ct.OBS_SET_SELECTION: [
        ["colname", "obs_set_one"],
        ["colname", "obs_set_two"],
    ],
    ct.OBS_SET_COLOR: [
        {
          "path": ["colname", "obs_set_one"],
           "color": [0, 12, 123],
        },
        {
          "path": ["colname", "obs_set_two"],
           "color": [240, 123, 58],
        },
    ]
}, meta=False)

Hi @srivarra this can be done with the above. The OBS_COLOR_ENCODING tells Vitessce whether to use the sets (categorical) vs. the gene expression values (quantitative) for colors. (For historical reasons the accepted values for this are the strings cellSetSelection or geneSelection despite moving to the more general obs prefix everywhere else). The OBS_SET_SELECTION is a list of paths for currently-selected sets. The OBS_SET_COLOR is a list of objects like { path, color } where color is an array of [r, g, b] values.

Thanks for the suggestion about using the adata.uns option, I did not know about the _colors convention in scanpy. I will make a new issue to track that

@srivarra
Copy link
Author

srivarra commented Apr 29, 2024

@keller-mark Thank you very much! I'll go ahead and give this a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants