Skip to content

Commit

Permalink
allow subseting by significance catagory
Browse files Browse the repository at this point in the history
  • Loading branch information
KatrionaGoldmann committed Feb 4, 2021
1 parent 160897c commit 2c85745
Show file tree
Hide file tree
Showing 26 changed files with 1,347 additions and 298 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(polar_grid)
export(radial_ggplot)
export(radial_plotly)
export(show_grid)
export(significance_subset)
export(volcano3D)
export(volcano_plot)
export(volcano_trio)
Expand Down Expand Up @@ -47,6 +48,7 @@ importFrom(grDevices,col2rgb)
importFrom(grDevices,hsv)
importFrom(grDevices,rgb)
importFrom(graphics,text)
importFrom(methods,slot)
importFrom(plotly,"%>%")
importFrom(plotly,add_markers)
importFrom(plotly,add_text)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ News
# volcano3D 1.1.0
###### 04/02/2021
* allow colour coding to be based on pvalue or adjusted pvalue according to cutoff_criteria
* allow subsetting by significance groups with the significance_subset function

# volcano3D 1.0.3
###### 15/08/2020
Expand Down
59 changes: 59 additions & 0 deletions R/significance_subset.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#' Extract a subset population
#'
#' Subsets data according to the significance groups.
#' @param polar A polar object including expression data from groups of
#' interest. Created by \code{\link{polar_coords}}.
#' @param significance Which significance factors to subset to. If NULL
#' levels(syn_polar@polar$sig)[1] is selected.
#' @param output What object to return. Options are "pvalues", "expression",
#' "polar_df" for subset data frames or "polar" for subset polar class object.
#' @references
#' Lewis, Myles J., et al. (2019).
#' \href{https://www.cell.com/cell-reports/fulltext/S2211-1247(19)31007-1}{
#' Molecular portraits of early rheumatoid arthritis identify clinical and
#' treatment response phenotypes.}
#' \emph{Cell reports}, \strong{28}:9
#' @importFrom methods slot
#' @export
#' @examples
#' data(example_data)
#' syn_polar <- polar_coords(sampledata = syn_example_meta,
#' contrast = "Pathotype",
#' groups = NULL,
#' pvalues = syn_example_p,
#' expression = syn_example_rld,
#' p_col_suffix = "pvalue",
#' padj_col_suffix = "padj",
#' non_sig_name = "Not Significant",
#' multi_group_prefix = "LRT",
#' significance_cutoff = 0.01,
#' fc_col_suffix='log2FoldChange',
#' fc_cutoff = 0.3)
#'
#' subset <- significance_subset(syn_polar, "Lymphoid+", "polar_df")

significance_subset <- function(polar,
significance = NULL,
output = "pvalues"){

if(is.null(significance)) significance <- levels(polar@polar$sig)[1]
if(! all(significance %in% levels(polar@polar$sig))){
stop("Significance must be in levels(polar@polar$sig)")
}
if(class(polar) != "polar") stop("polar must be a polar class object")
if(! output %in% c("pvalues", "expression", "polar_df", "polar")){
stop("return must be one of 'pvalues', 'expression', 'polar_df', 'polar'")
}

rows <- polar@polar$Name[polar@polar$sig %in% significance]
polar@pvalues <- polar@pvalues[rows, ]
polar@expression <- polar@expression[rows, ]
polar@polar <- polar@polar[rows, ]

if(output == "polar"){
return(polar)
} else {
return(slot(polar, gsub("_df", "", output)))
}
}

Loading

0 comments on commit 2c85745

Please sign in to comment.