From dedb472d231b540cc1907fe13cd6cc87aff23091 Mon Sep 17 00:00:00 2001 From: jcalendo Date: Tue, 15 Oct 2024 15:46:12 -0400 Subject: [PATCH] Add normalized avg by default --- R/{pileup_profile.R => pileup-profile.R} | 11 +++++------ man/dot-pileup2dt.Rd | 2 +- man/pileup_profile.Rd | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) rename R/{pileup_profile.R => pileup-profile.R} (93%) diff --git a/R/pileup_profile.R b/R/pileup-profile.R similarity index 93% rename from R/pileup_profile.R rename to R/pileup-profile.R index 31c64e3..d0ed5d1 100644 --- a/R/pileup_profile.R +++ b/R/pileup-profile.R @@ -79,12 +79,10 @@ pileup_profile <- function(bamfile, x, scan_bam_flag, sample_size = NULL, if (!is.null(sample_size)) { n <- floor(sample_size / 2) - if (n > length(pos_gr) || n > length(neg_gr)) { n <- min(c(length(pos_gr), length(neg_gr))) message("subsample size > length of ranges on either strand. Setting n to ", n) } - pos_gr <- pos_gr[sample.int(length(pos_gr), size = n)] neg_gr <- neg_gr[sample.int(length(neg_gr), size = n)] } @@ -96,12 +94,13 @@ pileup_profile <- function(bamfile, x, scan_bam_flag, sample_size = NULL, np <- .pileup2dt(Rsamtools::pileup(bamfile, scanBamParam = neg_bparam, pileupParam = pparam)) # Start counting from the 5' end - pp[, RelativePosition := pos - start] - np[, RelativePosition := end - pos] + pp[, relative_position := pos - start] + np[, relative_position := end - pos] df <- rbind(pp, np) - result <- df[, .(Sum = sum(count), Avg = mean(count), N = .N), by = RelativePosition] - data.table::setorder(result, RelativePosition) + result <- df[, .(n = .N, total = sum(count), avg = mean(count)), by = relative_position] + result[, normalized := coriell::minmax(avg)] + data.table::setorder(result, relative_position) return(result) } diff --git a/man/dot-pileup2dt.Rd b/man/dot-pileup2dt.Rd index 356ed13..fe6a144 100644 --- a/man/dot-pileup2dt.Rd +++ b/man/dot-pileup2dt.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pileup_profile.R +% Please edit documentation in R/pileup-profile.R \name{.pileup2dt} \alias{.pileup2dt} \title{Convert pileups to data.tables} diff --git a/man/pileup_profile.Rd b/man/pileup_profile.Rd index 0e56118..2d140c1 100644 --- a/man/pileup_profile.Rd +++ b/man/pileup_profile.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pileup_profile.R +% Please edit documentation in R/pileup-profile.R \name{pileup_profile} \alias{pileup_profile} \title{Return the pileup of reads over a set of GRanges}