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

Function: group_classes (OR logic for rules) #8

Open
FelixTheStudent opened this issue Jun 10, 2021 · 4 comments
Open

Function: group_classes (OR logic for rules) #8

FelixTheStudent opened this issue Jun 10, 2021 · 4 comments

Comments

@FelixTheStudent
Copy link
Owner

Currently all rules are combined with AND, but there might be cases where OR is useful.

Motivation
Use-case 1: For example, markers a1 and a2 might have nice but imperfect overlap, and both mark cell type A. If A has subtypes it may well be we'd want to set the subtype's parent to either a1 OR a2. For this, introducing a group called "A" as a kind of virtual class (no own rules) would help.

Use-case 2: for plotting, we might want to have all myeloid cells in the same colors. Introducing the "myeloid" class could achieve this:

obj %>%
rule("mono", "CD14", .1) %>%
rule("DC",   "CD1C", .1) %>%
group_classes("myeloid"=c("mono","DC") %>%
rule("T",    "CD3E", .1) %>%
plot_classes( c("myeloid", "T"))

Since mono and DC have no common parent, this can not be achieved without the group_classes function.

How to implement
obj$classes currently has "class" and "parent" columns. parent is either a class name or the special key word "..root..". I propose to create the second key word "..group.." and the slot obj$class_groups; this could be a named list (name is group name, elements are classes belonging to the group.

@FelixTheStudent
Copy link
Owner Author

FelixTheStudent commented Mar 18, 2022

I thought more about the API. I think the most intuitive is a group argument in the rule function:
obj %>% rule("mono", "CD14", ">", 1e-4, group="myeloid").

More thoughts:

  • group=NULL will be the default, not creating a new group
  • groups can be parents. Does that mean I'd want to write them to obj$classes?
  • classify will use OR to combine rules from different group members.
  • plot_classes will ignore overlap between a group and its members, right? Just like ignoring overlap between classes and their parents?

This feature might be fun to implement! I'll save it for a rainy day, and then I'll be like git checkout -b group and coffee!

@FelixTheStudent
Copy link
Owner Author

Don't forget this check:

if(any(group %in% obj$classes$class)) stop( group ": You created a class AND a group for this cell type. That's ambiguous, please double-check your rules!")

@FelixTheStudent
Copy link
Owner Author

One more requirement:

has to be compatible with grouping existing labels, see #16 .

That probably means an argument to "rule" alone does not cut it, I'll need a separate function, right? Something like this: class_group(obj, group="lymphocytes", classes=c("T","B")

@FelixTheStudent
Copy link
Owner Author

I feel this might still be a relevant feature and should start collecting use-cases. Any ideas, anyone?

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

1 participant