amc-heme / scExploreR

Shiny app for single cell omics data visualization
https://amc-heme.github.io/scExploreR/
MIT License
2 stars 0 forks source link

Sort plots by feature expression #288

Open wish1832 opened 1 week ago

wish1832 commented 1 week ago

Plots can currently be sorted in alphanumeric order by group names, but it is often desirable to sort plots by expression of one of the features, and this application is frequently used in the lab. This should be added so users do not have to do this manually, which is both time-intensive and error-prone.

wish1832 commented 1 week ago

Below is guidance for implementing the back-end, in the specific case of dot plots.

First, the dot plot function should be ran under the hood to get the mean expression data per group. The underlying table is extracted with $data.

summary_table <- 
    SCUBA::plot_dot(
        # Subset used in plots tab
        object = subset, 
        features = features, 
        group_by = group_by
        )$data

Next, sort the table in descending order and pull the id column (which has all the groups)

order <- 
        summary_table %>% 
        arrange(avg.exp.scaled) # or desc(avg.exp.scaled), after adding a menu to sort in ascending or descending order %>% 
        pull(id)

Next, set the factor levels of the group to order.

Code already exists for the setting of factor levels before plotting (R/shiny_dot.R), and a menu exists for sorting groups (R/modules-plot_module.R, id: "sort_groups_menu"). The current choices are "Ascending", "Descending", or "custom". Something like "Feature Expression" should be added, and when that is selected, a new set of menus should appear beneath the menu with a feature choice from the ones currently entered, and a menu to sort in ascending or descending order. The current "Ascending" and "Descending" display values should be modified to specify that those choices are for alphanumeric sorting of group values.