diff --git a/NAMESPACE b/NAMESPACE index cccbf98..9ea82d6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -85,6 +85,7 @@ export(named_group_split) export(normalise_counts) export(normalised_matrix_to_rpm) export(parcutils_chip) +export(plot_chip_pairwise_correlation_heatmap) export(plot_deASE_venn) export(plot_deg_upsets) export(plot_deg_venn) diff --git a/R/chip_related.R b/R/chip_related.R index 46181af..c47c3ca 100644 --- a/R/chip_related.R +++ b/R/chip_related.R @@ -1,11 +1,11 @@ #' Construct a parcutils_chip object -#' @description This function creates an object of the {.cls parcutils_chip.} parcutils_chip is an extension of the the {.cls RangedSummarizedExperiment}. +#' @description This function creates an object of the \code{parcutils_chip}. parcutils_chip is an extension of the the \code{RangedSummarizedExperiment}. #' This object make sure that it contains necessary elements to perform downstream chipseq analysis. Downstream exploratory and visualization functions will be based on this object. -#' @param x a list of the object(s) of {.cls normalisedMatrix}. +#' @param x a list of the object(s) of \code{normalisedMatrix}. #' @param row_ranges an object of the class GenomicRanges. Each range must be identified by an unique id stored in a column \code{name}, #' @details RPM is calculated by the function RowSums applied on the each row of the -#' {.arg normalized_matrix}. +#' \code{normalized_matrix}. #' @return an object of the class parcutils_chip. Class parcutils_chip extends to RangedSummarizedExperiment. It contains data in the below format #' \itemize{ #' \item{"assay"} {These is the object of NormalisedMatrix for the sample.} @@ -86,11 +86,10 @@ parcutils_chip <- setClass(Class = "parcutils_chip", contains="RangedSummarizedE #' Convert normalised matrix into RPM signal -#' -#' @param x a list of the object(s) of {.class normalisedMatrix}. -#' @details RPM is calculated by the function RowSums applied on the each row of the -#' {.arg x}. -#' @return a dataframe of RPM values. Rows are the features and columns are samples. Row names will be set from the rownames of the {.arg x}. Column names are the attribute {.code names} the list {.arg x}. +#' @param x a list of the object(s) of \code{normalisedMatrix}. +#' @details RPM is calculated by the function RowSums which is applied on the each row of the +#' \code{x}. +#' @return a dataframe of RPM values. Rows are the features and columns are samples. Row names will be set from the rownames of the \code{x}. Column names are the attribute \code{names} the list \code{x}. #' @export #' #' @examples @@ -103,7 +102,9 @@ normalised_matrix_to_rpm <- function(x){ # prepare RPM for each peak - df_rpm <- furrr::future_map(norm_mats , ~ ..1 %>% rowSums() %>% set_names(rownames(..1))) %>% + df_rpm <- furrr::future_map(norm_mats , ~ ..1 %>% + rowSums() %>% + set_names(rownames(..1))) %>% # make it wide format tibble::enframe() %>% tidyr::unnest(cols = c(value)) %>% @@ -131,15 +132,14 @@ normalised_matrix_to_rpm <- function(x){ #' Validate a list of normalised matrix. #' -#' @param x a list of the object(s) of {.class normalisedMatrix}. -#' @return a list of the object(s) of {.class normalisedMatrix}. +#' @param x a list of the object(s) of \code{normalisedMatrix}. +#' @return a list of the object(s) of \code{normalisedMatrix}. #' @export -#' @keywords {internal} +#' @keywords internal #' @examples #' \dontrun{ #' // TODO - #' } .validate_a_list_of_normalised_matrix <- function(x){ @@ -242,10 +242,10 @@ normalised_matrix_to_rpm <- function(x){ #' Import top features (ranked by score) from a bed file. #' #' @param bed_feature_file a character string denoting a valid bed file. -#' @param topn a numeric value, default 5000, denoting number of top features to keep. Features are ranked by a column {.code score}. +#' @param topn a numeric value, default 5000, denoting number of top features to keep. Features are ranked by a column \code{score}. #' @param center logical, denoting whether to align each feature by central position. If TRUE, default, it will return a ranges of single nucleotide (width = 0) denting a central position of each feature. #' @param ... Other arguments pass to the function [rtracklayer::import.bed()]. -#' @return an object of the {.class GRanges} containing {.arg topn} features. +#' @return an object of the \code{GRanges} containing \code{topn} features. #' @export #' #' @examples @@ -721,3 +721,103 @@ get_three_prime_flank_motif <- function(x, return(list(logo= m1, seq = for_motif)) } + + + + + +#' Validate a class parcutils_chip +#' +#' @param x an object of the class \code{parcutils_chip} +#' +#' @keywords internal +.validate_parcutils_chip <- function(x){ + if (!is(x, "parcutils_chip")) { + cli::cli_abort("x must be an object of {.cls parcutils_chip}") + } +} + + + +#' Generate a pairwise correlation for chipseq data. +#' @description Given an object of the class \code{parcutils_chip} it generates correlation heatmap for selected samples and observations (peaks). +#' @param x an object of the class \code{parcutils_chip}. +#' @param samples a character vector denoting samples to show in the plot. Values must be a subset of \code{names(assays(x))}. +#' @param peaks a character vector denoting peaks (observations) to use for correlation. Values must be a subset of \code{rownames(RowData(x))}. +#' @param rename_samples a character vector denoting sample names to show in the plot. Values must be of same order and length of values given as an argument \code{sample}. +#' @param scale_min a numeric value denoting a minimum value for the scale. +#' @param scale_max a numeric value denoting a maximum value for the scale. +#' @param col a character string of valid colors. Number of colors are not restricted. +#' @param cor_method a character string denoting a method to calculate correlation values. Values can be one of \code{"pearson"} (default), \code{"kendall"}, or \code{"spearman"}. +#' @param plot_title a character string denoting a plot title. +#' @param ... other arguments pass to the function [ggcorrplot::ggcorrplot()]. +#' +#' @return a plot +#' @export +#' @import ggcorrplot +#' @examples +#' \dontrun{ +#' +#' } +#' +plot_chip_pairwise_correlation_heatmap <- function(x, + samples=NULL, + peaks = NULL, + rename_samples = NULL, + scale_min = 0, + scale_max =1, + col = c("blue","white","red"), + cor_method = c("pearson"), + plot_title = "title",...){ + + + # validate x + .validate_parcutils_chip(x) + + # validate samples + rpm_sample_names <- rowData(x) %>% colnames() + rpm_sample_names <- rpm_sample_names[grepl("^RPM-", rpm_sample_names)] + + if (is.null(samples)) { + samples = rpm_sample_names + } else if(!all(samples %in% rpm_sample_names)) { + cli::cli_abort("{.arg samples} must be either {.cls NULL} or a {.cls character} vector of {.code colnames(rowData(x))} ") + } + + + # validate peaks + all_peaks <- rowData(x) %>% rownames() + + if (is.null(peaks)) { + peaks = all_peaks + } else if(!all(peaks %in% all_peaks)) { + cli::cli_abort("{.arg peaks} must be either {.cls NULL} or a {.cls character} vector of {.code rownames(rowData(x))} ") + } + + # validate rename samples + # rename_samples must be unique and have identical length to samples + + if(!is.null(rename_samples)){ + if(any(duplicated(rename_samples))){ + cli::cli_abort("{.arg rename_samples} must be either {.cls NULL} or a {.cls character} vector of the length {.code samples}.") + } else if (!(length(rename_samples) == length(samples))){ + cli::cli_abort("{.arg rename_samples} must be either {.cls NULL} or a {.cls character} vector of the length {.code samples}.") + } + } else { # default names + rename_samples = samples + } + + rowData(x)[peaks, samples] %>% + tibble::as_tibble() %>% + dplyr::rename_all(.funs = ~ rename_samples) %>% + # remove rows with NA values + TidyWrappers::tbl_remove_rows_NA_any() %>% + # convert Log2 + TidyWrappers::tbl_convert_log2(frac = 1) %>% + cor(method = cor_method) %>% + ggcorrplot::ggcorrplot(lab = T,...) + + scale_fill_gradientn(colours = col, + limits = c(scale_min, scale_max) , oob=scales::squish, name = "Cor") + + ggtitle(plot_title) + +} diff --git a/_pkgdown.yml b/_pkgdown.yml index cd0da8f..cb40736 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -68,6 +68,7 @@ reference: - get_chip_signal_over_control_heatmap - get_five_prime_flank_motif - get_three_prime_flank_motif + - plot_chip_pairwise_correlation_heatmap # figures: # dev: ragg::agg_png diff --git a/docs/reference/dot-validate_a_list_of_normalised_matrix.html b/docs/reference/dot-validate_a_list_of_normalised_matrix.html index 225b002..951f63e 100644 --- a/docs/reference/dot-validate_a_list_of_normalised_matrix.html +++ b/docs/reference/dot-validate_a_list_of_normalised_matrix.html @@ -54,14 +54,14 @@

Usage

Arguments

x
-

a list of the object(s) of .class normalisedMatrix.

+

a list of the object(s) of normalisedMatrix.

Value

-

a list of the object(s) of .class normalisedMatrix.

+

a list of the object(s) of normalisedMatrix.

diff --git a/docs/reference/dot-validate_parcutils_chip.html b/docs/reference/dot-validate_parcutils_chip.html new file mode 100644 index 0000000..d149f8f --- /dev/null +++ b/docs/reference/dot-validate_parcutils_chip.html @@ -0,0 +1,80 @@ + +Validate a class parcutils_chip — .validate_parcutils_chip • parcutils + Skip to contents + + +
+
+
+ +
+

Validate a class parcutils_chip

+
+ +
+

Usage

+
.validate_parcutils_chip(x)
+
+ +
+

Arguments

+
x
+

an object of the class parcutils_chip

+ +
+ +
+ + +
+ + + +
+ + + + + + + diff --git a/docs/reference/import_topn_bed_features.html b/docs/reference/import_topn_bed_features.html index 2a9ef62..0fde0de 100644 --- a/docs/reference/import_topn_bed_features.html +++ b/docs/reference/import_topn_bed_features.html @@ -58,7 +58,7 @@

ArgumentsArgumentsValue

-

an object of the .class GRanges containing .arg topn features.

+

an object of the GRanges containing topn features.

diff --git a/docs/reference/index.html b/docs/reference/index.html index 6421ed3..222751d 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -348,6 +348,11 @@
diff --git a/docs/reference/make_parcutils_chip.html b/docs/reference/make_parcutils_chip.html index 9babc37..d301ae0 100644 --- a/docs/reference/make_parcutils_chip.html +++ b/docs/reference/make_parcutils_chip.html @@ -1,6 +1,6 @@ -Construct a parcutils_chip object — make_parcutils_chip • parcutilsConstruct a parcutils_chip object — make_parcutils_chip • parcutilsGenerate a pairwise correlation for chipseq data. — plot_chip_pairwise_correlation_heatmap • parcutils + Skip to contents + + +
+
+
+ +
+

Given an object of the class parcutils_chip it generates correlation heatmap for selected samples and observations (peaks).

+
+ +
+

Usage

+
plot_chip_pairwise_correlation_heatmap(
+  x,
+  samples = NULL,
+  peaks = NULL,
+  rename_samples = NULL,
+  scale_min = 0,
+  scale_max = 1,
+  col = c("blue", "white", "red"),
+  cor_method = c("pearson"),
+  plot_title = "title",
+  ...
+)
+
+ +
+

Arguments

+
x
+

an object of the class parcutils_chip.

+ + +
samples
+

a character vector denoting samples to show in the plot. Values must be a subset of names(assays(x)).

+ + +
peaks
+

a character vector denoting peaks (observations) to use for correlation. Values must be a subset of rownames(RowData(x)).

+ + +
rename_samples
+

a character vector denoting sample names to show in the plot. Values must be of same order and length of values given as an argument sample.

+ + +
scale_min
+

a numeric value denoting a minimum value for the scale.

+ + +
scale_max
+

a numeric value denoting a maximum value for the scale.

+ + +
col
+

a character string of valid colors. Number of colors are not restricted.

+ + +
cor_method
+

a character string denoting a method to calculate correlation values. Values can be one of "pearson" (default), "kendall", or "spearman".

+ + +
plot_title
+

a character string denoting a plot title.

+ + +
...
+

other arguments pass to the function ggcorrplot::ggcorrplot().

+ +
+
+

Value

+ + +

a plot

+
+ +
+

Examples

+
if (FALSE) {
+
+}
+
+
+
+
+ + +
+ + + + + + + diff --git a/man/dot-validate_a_list_of_normalised_matrix.Rd b/man/dot-validate_a_list_of_normalised_matrix.Rd index f7292b6..f91a72b 100644 --- a/man/dot-validate_a_list_of_normalised_matrix.Rd +++ b/man/dot-validate_a_list_of_normalised_matrix.Rd @@ -7,10 +7,10 @@ .validate_a_list_of_normalised_matrix(x) } \arguments{ -\item{x}{a list of the object(s) of {.class normalisedMatrix}.} +\item{x}{a list of the object(s) of \code{normalisedMatrix}.} } \value{ -a list of the object(s) of {.class normalisedMatrix}. +a list of the object(s) of \code{normalisedMatrix}. } \description{ Validate a list of normalised matrix. @@ -20,4 +20,4 @@ Validate a list of normalised matrix. // TODO } } -\keyword{{internal}} +\keyword{internal} diff --git a/man/dot-validate_parcutils_chip.Rd b/man/dot-validate_parcutils_chip.Rd new file mode 100644 index 0000000..e988155 --- /dev/null +++ b/man/dot-validate_parcutils_chip.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/chip_related.R +\name{.validate_parcutils_chip} +\alias{.validate_parcutils_chip} +\title{Validate a class parcutils_chip} +\usage{ +.validate_parcutils_chip(x) +} +\arguments{ +\item{x}{an object of the class \code{parcutils_chip}} +} +\description{ +Validate a class parcutils_chip +} +\keyword{internal} diff --git a/man/import_topn_bed_features.Rd b/man/import_topn_bed_features.Rd index d19f020..20a8a8e 100644 --- a/man/import_topn_bed_features.Rd +++ b/man/import_topn_bed_features.Rd @@ -9,14 +9,14 @@ import_topn_bed_features(bed_feature_file, topn = 5000, center = TRUE, ...) \arguments{ \item{bed_feature_file}{a character string denoting a valid bed file.} -\item{topn}{a numeric value, default 5000, denoting number of top features to keep. Features are ranked by a column {.code score}.} +\item{topn}{a numeric value, default 5000, denoting number of top features to keep. Features are ranked by a column \code{score}.} \item{center}{logical, denoting whether to align each feature by central position. If TRUE, default, it will return a ranges of single nucleotide (width = 0) denting a central position of each feature.} \item{...}{Other arguments pass to the function \code{\link[rtracklayer:BEDFile-class]{rtracklayer::import.bed()}}.} } \value{ -an object of the {.class GRanges} containing {.arg topn} features. +an object of the \code{GRanges} containing \code{topn} features. } \description{ Import top features (ranked by score) from a bed file. diff --git a/man/make_parcutils_chip.Rd b/man/make_parcutils_chip.Rd index e3ad449..86fdcb0 100644 --- a/man/make_parcutils_chip.Rd +++ b/man/make_parcutils_chip.Rd @@ -7,7 +7,7 @@ make_parcutils_chip(x, row_ranges) } \arguments{ -\item{x}{a list of the object(s) of {.cls normalisedMatrix}.} +\item{x}{a list of the object(s) of \code{normalisedMatrix}.} \item{row_ranges}{an object of the class GenomicRanges. Each range must be identified by an unique id stored in a column \code{name},} } @@ -20,12 +20,12 @@ an object of the class parcutils_chip. Class parcutils_chip extends to RangedSum } } \description{ -This function creates an object of the {.cls parcutils_chip.} parcutils_chip is an extension of the the {.cls RangedSummarizedExperiment}. +This function creates an object of the \code{parcutils_chip}. parcutils_chip is an extension of the the \code{RangedSummarizedExperiment}. This object make sure that it contains necessary elements to perform downstream chipseq analysis. Downstream exploratory and visualization functions will be based on this object. } \details{ RPM is calculated by the function RowSums applied on the each row of the -{.arg normalized_matrix}. +\code{normalized_matrix}. } \examples{ diff --git a/man/normalised_matrix_to_rpm.Rd b/man/normalised_matrix_to_rpm.Rd index 4477032..71e15ed 100644 --- a/man/normalised_matrix_to_rpm.Rd +++ b/man/normalised_matrix_to_rpm.Rd @@ -7,17 +7,17 @@ normalised_matrix_to_rpm(x) } \arguments{ -\item{x}{a list of the object(s) of {.class normalisedMatrix}.} +\item{x}{a list of the object(s) of \code{normalisedMatrix}.} } \value{ -a dataframe of RPM values. Rows are the features and columns are samples. Row names will be set from the rownames of the {.arg x}. Column names are the attribute {.code names} the list {.arg x}. +a dataframe of RPM values. Rows are the features and columns are samples. Row names will be set from the rownames of the \code{x}. Column names are the attribute \code{names} the list \code{x}. } \description{ Convert normalised matrix into RPM signal } \details{ -RPM is calculated by the function RowSums applied on the each row of the -{.arg x}. +RPM is calculated by the function RowSums which is applied on the each row of the +\code{x}. } \examples{ \dontrun{ diff --git a/man/plot_chip_pairwise_correlation_heatmap.Rd b/man/plot_chip_pairwise_correlation_heatmap.Rd new file mode 100644 index 0000000..545a4f0 --- /dev/null +++ b/man/plot_chip_pairwise_correlation_heatmap.Rd @@ -0,0 +1,52 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/chip_related.R +\name{plot_chip_pairwise_correlation_heatmap} +\alias{plot_chip_pairwise_correlation_heatmap} +\title{Generate a pairwise correlation for chipseq data.} +\usage{ +plot_chip_pairwise_correlation_heatmap( + x, + samples = NULL, + peaks = NULL, + rename_samples = NULL, + scale_min = 0, + scale_max = 1, + col = c("blue", "white", "red"), + cor_method = c("pearson"), + plot_title = "title", + ... +) +} +\arguments{ +\item{x}{an object of the class \code{parcutils_chip}.} + +\item{samples}{a character vector denoting samples to show in the plot. Values must be a subset of \code{names(assays(x))}.} + +\item{peaks}{a character vector denoting peaks (observations) to use for correlation. Values must be a subset of \code{rownames(RowData(x))}.} + +\item{rename_samples}{a character vector denoting sample names to show in the plot. Values must be of same order and length of values given as an argument \code{sample}.} + +\item{scale_min}{a numeric value denoting a minimum value for the scale.} + +\item{scale_max}{a numeric value denoting a maximum value for the scale.} + +\item{col}{a character string of valid colors. Number of colors are not restricted.} + +\item{cor_method}{a character string denoting a method to calculate correlation values. Values can be one of \code{"pearson"} (default), \code{"kendall"}, or \code{"spearman"}.} + +\item{plot_title}{a character string denoting a plot title.} + +\item{...}{other arguments pass to the function \code{\link[ggcorrplot:ggcorrplot]{ggcorrplot::ggcorrplot()}}.} +} +\value{ +a plot +} +\description{ +Given an object of the class \code{parcutils_chip} it generates correlation heatmap for selected samples and observations (peaks). +} +\examples{ +\dontrun{ + +} + +}