monarch-initiative / monarchr

R package for easy access, manipulation, and analysis of Monarch KG data
Other
9 stars 1 forks source link

monarch plot theme #40

Open bschilder opened 2 months ago

bschilder commented 2 months ago

I think it would be nice to have a theme_monarch function that gives plots some useful attributes. Relates to #24.

1.

For example

immune <- monarch_search("immune system",  category = "biolink:Disease")|>
    expand(predicates = "biolink:subclass_of") |>
    expand(predicates = "biolink:has_phenotype",
         categories = "biolink:PhenotypicFeature") |>
    expand(categories = "biolink:Gene")
immune|>
    activate(nodes)|> 
    filter(pcategory %in% c("biolink:Disease", "biolink:PhenotypicFeature")) |> 
    activate(edges)|>
  filter(tidygraph::edge_is_between(which(nodes(g)$pcategory=="biolink:Disease"),
                                                                    which(nodes(g)$pcategory=="biolink:Disease"), 
                                                                    ignore_dir=TRUE)) |>
    activate(nodes) |>
    filter(!node_is_isolated()) |>
    plot(layout="fr")

PhenotypicFeature is turquoise: image

immune|>
    activate(nodes)|> 
    sample_n(1000) |>
    activate(edges)|>
  filter(tidygraph::edge_is_between(which(nodes(g)$pcategory=="biolink:Disease"),
                                                                    which(nodes(g)$pcategory=="biolink:Disease"), 
                                                                    ignore_dir=TRUE)) |>
    activate(nodes) |>
    filter(!node_is_isolated()) |>
    plot(layout="fr")

PhenotypicFeature is now blue: image

2.

3.

4.

Screenshot 2024-08-23 at 11 35 38

5.

oneilsh commented 2 months ago

Very much agreed and great ideas, thanks for working on this! One challenge might be that different KGs have different category/relationship labels, so hard-coding a palette against them could be tricky. One option is to use the kg prefs feature (I'm starting to wonder how much to lean on that...).

Another trick I've used in the past for similar issues is to generate a largish palette, and then hash labels and map them to an int mod the palette size to identify a psuedo-random color choice that is repeatable.

bschilder commented 4 weeks ago

Very much agreed and great ideas, thanks for working on this! One challenge might be that different KGs have different category/relationship labels, so hard-coding a palette against them could be tricky. One option is to use the kg prefs feature (I'm starting to wonder how much to lean on that...).

Very true, I was thinking of only using the hard-coded palette when the KG is the official Monarch KG.

Another trick I've used in the past for similar issues is to generate a largish palette, and then hash labels and map them to an int mod the palette size to identify a psuedo-random color choice that is repeatable.

For all other KGs, doing something like this seems like the best way to go.