Preparation

Load packages and set options

Setup the default knitr options for the R code sections below.

Load the packages used in this analysis.

setwd("/share/users/Mike/AutismPaper/RNASeq/R")
suppressMessages({
  library('tidyverse')
  library('rbokeh')
  library('trelliscopejs')
  options(tibble.print_max=100)
})

Load data and create trelliscope display

load(file = '/share/users/Mike/AutismPaper/RNASeq/R/genes.up.trajectories.RData')
obs <- obs %>% mutate(grp = fct_recode(grp, "1-FetalControl" = "FetalControl", "2-ChildAutism" = "ChildAutism", "3-ChildControl" = "ChildControl"))
by_target_id <- obs %>% 
  ungroup() %>%
  group_by(target_id, symbol, description, padj) %>%
  nest()

# add in a plot column with map_plot

by_target_id <- by_target_id %>% mutate(
  panel = map_plot(data,
                   ~ figure(ylim = c(min(log(obs$mean_est_counts)), max(log(obs$mean_est_counts))), 
                            width = 500, height = 400, 
                            xlab = "Group", ylab = "log(counts)", tools = NULL) %>%
                     ly_points(grp, log(mean_est_counts), data = .x, 
                               hover = data_frame(Group = .x$grp,
                                                  Counts = .x$mean_est_counts)) %>% 
                     ly_lines(grp, log(mean_est_counts), data = .x)
  )
)

by_target_id %>%
  trelliscope(name = "counts_vs_groups", panel_col = 'panel', nrow = 2, ncol = 4, 
              self_contained = TRUE, 
              state = list(sort = list(sort_spec("padj")), 
                           labels = c('symbol', 'description', 'padj')) 
  )