restrand_nmatlist: Re-strand coverage matrix data by inferred strandedness

restrand_nmatlistR Documentation

Re-strand coverage matrix data by inferred strandedness

Description

Re-strand coverage matrix data by inferred strandedness

Usage

restrand_nmatlist(
  nmatlist,
  restrand_heatmap = 1,
  restrand_range = NULL,
  restrand_buffer = NULL,
  restrand_invert = FALSE,
  empty_value = 0,
  transform = NULL,
  verbose = FALSE,
  ...
)

Arguments

nmatlist

list of normalizedMatrix objects

restrand_heatmap

numeric (default 1) index with one or more entries in nmatlist to use for re-stranding.

restrand_range

numeric (default NULL) with optional maximum distance from the target (center) of coverage in nmatlist. For example, if nmatlist data spans -50kb to +50kb, but peaks are no wider than 1kb, consider using recenter_range=1000 so that the recentering will only use coverage data -1000bp to +1000bp at most.

restrand_buffer

numeric not yet implemented, intended to enforce a "buffer" distance away from the center before calculating coverage.

restrand_invert

logical indicating whether to invert the coverage, therefore effectively taking the minimum signal. This value is recycled to length(restrand_heatmap) such that each heatmap can individually be inverted as relevant.

empty_value

numeric value used for empty values created by the "edges" of recentered matrix data. Default is 0, other values may not be well-supported.

transform

character or function applied to restrand_heatmap to transform the data prior to calculating the coverage.

  • When using transform with nmatlist2heatmaps() it is recommended to use it here also.

verbose

logical indicating whether to print verbose output.

...

additional arguments are ignored.

Details

Coverage matrix data is provided as nmatlist which is a list of normalizedMatrix objects (see EnrichmentHeatmap). One or more restrand_heatmap are defined, and the side with higher coverage "wins" such that the downstream signal is always higher within the specified range.

Value

object in format nmatlist, a list of normalizedMatrix objects.

See Also

Other jam coverage heatmap functions: coverage_matrix2nmat(), get_nmat_ceiling(), nmathm_row_order(), nmatlist2heatmaps(), recenter_nmatlist(), validate_heatmap_params(), zoom_nmatlist(), zoom_nmat()

Examples

cov_file1 <- system.file("data", "tss_coverage.matrix", package="platjam");
cov_file2 <- system.file("data", "h3k4me1_coverage.matrix", package="platjam");
cov_files <- c(cov_file1, cov_file2);
names(cov_files) <- gsub("[.]matrix",
   "",
   basename(cov_files));
nmatlist <- coverage_matrix2nmat(cov_files, verbose=FALSE);

# scramble the strandedness
new_k <- sample(c(TRUE, FALSE), size=nrow(nmatlist[[1]]), replace=TRUE)
nmatlist1 <- lapply(nmatlist, function(nmat){
   nmat[new_k, ] <- nmat[new_k, rev(colnames(nmat)), drop=FALSE]
   nmat;
})

nmatlist2heatmaps(nmatlist1,
   title="Test data\n(mixed strandedness)",
   transform=c("log2signed", "sqrt"));

nmatlist2heatmaps(nmatlist1,
   title="Test data,\nrestranded by TSS",
   restrand_heatmap=1,
   transform=c("log2signed", "sqrt"));

nmatlist2heatmaps(nmatlist1,
   title="Test data,\nrecentered by H3K4me1",
   recenter_heatmap=2, recenter_invert=TRUE,
   transform=c("log2signed", "sqrt"));

nmatlist2heatmaps(nmatlist1,
   title="Test data, recentered by H3K4me1,\nrestranded by TSS",
   recenter_heatmap=2, recenter_invert=TRUE,
   restrand_heatmap=1,
   transform=c("log2signed", "sqrt"));

nmatlist_c <- restrand_nmatlist(nmatlist, restrand_invert=FALSE,
   transform=c("log2signed"), restrand_heatmap=1,
   restrand_range=600, restrand_buffer=100)
nmhm <- nmatlist2heatmaps(nmatlist_c,
   title="Re-stranded using tss signal",
   transform=c("log2signed", "sqrt"));
   k_clusters=8, k_method="euclidean", min_rows_per_k=10, k_heatmap=1,

nmatlist2i <- recenter_nmatlist(nmatlist, recenter_heatmap=1, recenter_range=1000, restrand_invert=TRUE)
nmatlist2heatmaps(nmatlist2i,
   title="Test data, centered on inverted tss signal",
   transform=c("log2signed", "sqrt"));

nmatlist2 <- recenter_nmatlist(nmatlist, recenter_heatmap=1, recenter_range=1000)
nmatlist2heatmaps(nmatlist2,
   title="Test data, centered on tss signal",
   transform=c("log2signed", "sqrt"));

nmatlist4 <- restrand_nmatlist(nmatlist2, restrand_invert=FALSE,
   transform=c("log2signed"), restrand_heatmap=1,
   restrand_range=600, restrand_buffer=100)
nmhm <- nmatlist2heatmaps(nmatlist4,
   title="Test data, centered on tss signal\nRe-stranded on tss signal",
   transform=c("log2signed", "sqrt"));
   #k_clusters=8, k_method="euclidean", min_rows_per_k=10, k_heatmap=1,


jmw86069/platjam documentation built on Sept. 26, 2024, 3:31 p.m.