R/plotCombinedResults.R

#' Plot of combined results
#'
#' Uses scatter3D package to generate an interactive scatter plot of the combined results
#'
#' @param con A \code{SQLiteConnection} object
#' @param highlighted_gene Highlight the provided gene on the plot.  Default NULL - ie don't highlight anything
#' @param pi_value_th Set a PI value threshold.  Default 0.2
#' @param bisep_pval_th Set a BISEP p-value threshold.  Default 0.1
#' @return A ggplot2 object
#' @export
plotCombinedResults <- function(con, highlighted_gene=NULL, pi_value_th=0.2, bisep_pval_th=0.1) {

    #get the BISEP output data
    bisep_output <- dplyr::src_sqlite(con@dbname) %>%
        dplyr::tbl('bisep_results') %>%
        dplyr::collect()

    #all_genes <- DBI::dbReadTable(con, 'human_genes')

    plot_data <- bisep_output %>%
        dplyr::mutate(selected=pi_value <= pi_value_th & bisep_pval <= bisep_pval_th)

    num_filtered_genes <- plot_data %>% dplyr::filter(selected) %>% nrow()

    #bisep_pval vs pi_val plot
    scatterD3::scatterD3(x=plot_data$pi_value,
                         y=log10(plot_data$bisep_pval),
                         tooltips=TRUE,
                         transitions=TRUE,
                         tooltip_text=plot_data$gene_name,
                         point_size = 15, point_opacity = 0.5,
                         key_var=plot_data$gene_id)


    #p1 <- ggplot(plot_data, aes(x=pi_value, y=bisep_pval, colour=selected)) +
    #    geom_point(size=rel(0.3)) +
    #    geom_vline(xintercept=pi_value_th, colour='blue') +
    #    geom_hline(yintercept=bisep_pval_th, colour='blue') +
    #    scale_y_log10() +
    #    theme_bw() +
    #    ggtitle(sprintf("%s genes @ pi_value < %s and bisep_pval < %s", num_filtered_genes, pi_value_th, bisep_pval_th))

    #highlight the selected gene if provided
    #if(!is.null(highlighted_gene)) {
    #    highlight_data <- plot_data %>%
    #        dplyr::filter(gene_id == highlighted_gene)
    #    p1 <- p1 + geom_point(data=highlight_data, shape=1, colour='black', size=rel(2))
    #}


    #return(p1)

}
chapmandu2/CollateralVulnerability2016 documentation built on May 13, 2019, 3:27 p.m.