From c23d96eeb065020cf53dfa54969d0260a5d65dc8 Mon Sep 17 00:00:00 2001 From: jlanej Date: Fri, 29 Mar 2024 13:40:35 -0500 Subject: [PATCH] initial file stub --- .gitignore | 2 +- Dockerfile | 9 +++++++++ bamRUtils.R | 29 +++++++++++++++++++++++++++++ longReadPlot.R | 3 +++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 bamRUtils.R create mode 100644 longReadPlot.R diff --git a/.gitignore b/.gitignore index e75435c..cc7ff3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # History files .Rhistory .Rapp.history - +*.Rproj # Session Data files .RData .RDataTmp diff --git a/Dockerfile b/Dockerfile index 5d41ea8..aa34328 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,10 @@ FROM r-base + +RUN R -e "install.packages('optparse',dependencies=TRUE, repos='http://cran.rstudio.com/')" +RUN R -e "install.packages('Rsamtools',dependencies=TRUE, repos='http://cran.rstudio.com/')" +ENV BASE=/app/ + +WORKDIR ${BASE} +COPY ./ ${BASE} +CMD ["Rscript", "longReadPlot.R"] + diff --git a/bamRUtils.R b/bamRUtils.R new file mode 100644 index 0000000..4f7f2d3 --- /dev/null +++ b/bamRUtils.R @@ -0,0 +1,29 @@ +require(Rsamtools) + + +.unlist <- function (x) +{ + ## do.call(c, ...) coerces factor to integer, which is undesired + x1 <- x[[1L]] + if (is.factor(x1)) { + structure(unlist(x), class = "factor", levels = levels(x1)) + } else { + do.call(c, x) + } +} + +convertBam <- function(bam, param) { + bam <- unname(bam) # names not useful in unlisted result + elts <- setNames(bamWhat(param), bamWhat(param)) + lst <- lapply(elts, function(elt) + .unlist(lapply(bam, "[[", elt))) + lst = lst[lengths(lst) != 0] + df <- do.call("data.frame", bam) + return(df) +} + +loadBam <- function(bamFile, param) { + bam = scanBam(bamFile, param = param) + bam = convertBam(bam = bam, param = param) + return(bam) +} diff --git a/longReadPlot.R b/longReadPlot.R new file mode 100644 index 0000000..3450a83 --- /dev/null +++ b/longReadPlot.R @@ -0,0 +1,3 @@ +library(optparse) +source("bamRUtils.R") +print("hi") \ No newline at end of file