Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-gregoricchio committed Feb 20, 2021
1 parent 34c190c commit ec15cc8
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 186 deletions.
12 changes: 9 additions & 3 deletions DESCRIPTION
@@ -1,15 +1,21 @@
Package: Rseb
Type: Package
Title: A package for NGS data managing and visualization
Version: 0.1.6
Version: 0.1.7
Author: Sebastian Gregoricchio
Maintainer: Sebastian Gregoricchio <sebastian.gregoricchio@gmail.com>
Description: An R-package for daily tasks required to handle biological data as well as avoid re-coding of small functions for quick but necessary data managing.
License: GNU GENERAL PUBLIC LICENSE version 3
Depends:
R (>= 3.2.0), BiocManager, Biostrings, biomaRt, GO.db, rtracklayer, cowplot, data.table, ggplot2 (>= 3.3.3), ggrepel, matrixStats, plyr, dplyr, purrr, robustbase, stringr, tidyr, tools, labeling, devtools, rvcheck, curl
R (>= 4.0.0)
Imports:
BiocManager, Biostrings, biomaRt, GO.db, rtracklayer, cowplot, data.table, ggplot2 (>= 3.3.3), ggrepel, ggpubr, matrixStats, plyr, dplyr, tidyr, purrr, robustbase, stringr, tools, devtools, rvcheck, curl
biocViews:
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
git_url: https://github.com/sebastian-gregoricchio/Rseb/
URL:
https://sebastian-gregoricchio.github.io/Rseb/
https://github.com/sebastian-gregoricchio/Rseb/
https://sebastian-gregoricchio.github.io/
BugReports: https://github.com/sebastian-gregoricchio/Rseb/issues
18 changes: 18 additions & 0 deletions NEWS.md
Expand Up @@ -53,6 +53,24 @@ First releasing
* Optimization for different labeling and better handle of Y-axis autoscale in `plot.density.profile` function
* Optimization of `uniform.x.axis` and `uniform.y.axis` with the new functions `floating.ceiling` and `floating.floor` and to support a given number of digits

<br />

#### [v0.1.7](https://github.com/sebastian-gregoricchio/Rseb/releases/tag/0.1.7) - February 20th 2021
* Updated information in DESCRIPTION file
* Updated the dependencies to require an R version >= 4.0.0
* Moved all "depending" packages in "imports" to avoid attaching of all packages. Morover, added `ggpubr` and removed `labeling`
* Bug fixing in `actualize` and `uniform.x.axis` functions
* Optimization for better definition of the breaks in the functions `uniform.x.axis` and `uniform.y.axis`
* Optimization of package handling for `plot.density.summary` and `plot.density.profile`
* Optimized color handling for summary plots in `plot.density.summary` function
* Now computation and plot of the statistical mean comparisons is available for `plot.density.summary`
* In the `plot.density.summary` function a density profile corresponding to the summary plot subset range is generated
* The data.table of `plot.density.summary` now contains also the orignal positions used to generate the matrix
* Optimization of `IGVsnap` function and improvment of relative manual information
* `IGVsnap` allows the addiction of a delay time between snap generation



<br />
<br />

Expand Down
20 changes: 14 additions & 6 deletions R/IGVsnap.R
Expand Up @@ -6,14 +6,15 @@
#' @param input_type Define the input type. Allowed values are \code{genes} and \code{regions}.
#' @param biomart Defines the \code{biomart} parameter for \code{biomaRt} package, by default \code{ensembl}.
#' @param dataset Defines the \code{dataset} parameter for \code{biomaRt} package, by default \code{mmusculus_gene_ensembl}.
#' @param reference_genome [optional] Defines the genome to use, e.g. "mm10", "hg19", ... . By default \code{NULL}.
#' @param fivePrime Numeric value to define how many bases [bp] exapand from full gene position at it's 5'-end, default 1000bp.
#' @param threePrime Numeric value to define how many bases [bp] exapand from full gene position at it's 3'-end, default 1000bp.
#' @param reference_genome [optional] Defines the genome to use, e.g. "mm9", "mm10", "hg19", "hg38", ... . By default \code{NULL}.
#' @param fivePrime Numeric value to define of how many base-pairs (bp) expand from full gene position at it's 5'-end, default 1000bp.
#' @param threePrime Numeric value to define of how many base-pairs (bp) expand from full gene position at it's 3'-end, default 1000bp.
#' @param snap_names [optional] String vector to define the names of images (without extention), by default uses \code{loci_vector}.
#' @param IGV_batch_file String for the batch_script_file_name/path, by default \code{<working_directory>/IGV_batch.txt}.
#' @param snap_image_format String to define the format of the images, e.g. "png", "jpeg", "svg", ... . By default \code{png}.
#' @param snap_directory String for the output directory for the snapshoots. By default <working_directory>.
#' @param maxPanelHeight Numeric value to define the height in pixel of the IGV pannel that will be captured on IGV.
#' @param maxPanelHeight Numeric value to define the height in pixel of the IGV pannel that will be captured on IGV. By default \code{1000}.
#' @param delay.interval Sets a delay (sleep) time in milliseconds. The sleep interval is invoked between successive commands. By default \code{10}. helps to give the time to IGV to adapt the view before the snap (such as the autoscale).
#' @param session [optional] FULL path to an IGV session file (session.xml) to use for the images. By default \code{NULL}.
#' @param exit Logical value to indicate whether exit IGV after image capture ended. By default \code{FALSE}.
#'
Expand Down Expand Up @@ -41,6 +42,7 @@ IGVsnap = function(loci_vector,
snap_image_format = "png",
snap_directory = getwd(),
maxPanelHeight = 1000,
delay.interval = 10,
session = NULL,
exit = FALSE) {

Expand All @@ -64,6 +66,7 @@ IGVsnap = function(loci_vector,
"snap_image_format image format such as 'png', 'jpeg', 'svg', ..., by default 'png'. \n",
" snap_directory output directory for snapshoots, by default <working_directory>. \n",
" maxPanelHeight heigth in pixel of the IGV pannel that will be captured. \n",
" delay.interval Sets a delay (sleep) time in milliseconds. The sleep interval is invoked between successive commands, default 10. \n",
" session [optional] define an IGV session file .xml to use for the images, 'NULL' by default - USE FULL PATH -. \n",
" exit logical to indicate whether exit IGV after image capture ended, FALSE by default. \n",
" help logical to indicate whether display the help, FALSE by default. \n",
Expand Down Expand Up @@ -116,7 +119,7 @@ IGVsnap = function(loci_vector,

} else if (input_type == "regions") {
if (is.null(snap_names)) {snap_names = loci_vector}
list = unique(loci_vector)
list = loci_vector
}

# Initialization/Creation of the batch_file
Expand All @@ -130,7 +133,7 @@ IGVsnap = function(loci_vector,
append = T)
} else if (!is.null(reference_genome)){
write(file = IGV_batch_file,
x = paste("genome", reference_genome),
x = paste("genome", tolower(reference_genome)),
append = T)
}

Expand All @@ -152,6 +155,11 @@ IGVsnap = function(loci_vector,
x = paste("goto", list[i]),
append = T)

# Write the command to delay interval
write(file = IGV_batch_file,
x = paste("setSleepInterval", delay.interval),
append = T)

# Write the command to take a snapshot with the name of the gene/position with the chosen extension
write(file = IGV_batch_file,
x = paste("snapshot ", snap_names[i], "_snapshot.", snap_image_format, sep =""),
Expand Down
97 changes: 56 additions & 41 deletions R/actualize.R
@@ -1,41 +1,56 @@
#' @title \code{Rseb} updates verification
#'
#' @description It verifies if \code{Rseb} is up-to-date and installs it when required.
#'
#' @param update Logical value to define whether update the \code{Rseb} package. By default \code{TRUE}.
#' @param verbose Logical value to define whether print messages. By default \code{TRUE}.
#' @param force Logical value to define whether to force the installation of \code{Rseb} even though already up-to-date. Parameter passed to \code{devtools::install_github()}. By default \code{FALSE}.
#'
#' @return Warnings and/or messages. Installation of the latest version of \code{Rseb} if required.
#'
#' @details This function will check for internet availability.
#'
#' @export actualize


actualize = function(update = TRUE,
verbose = TRUE,
force = FALSE) {

# Check internet connection
if (isFALSE(curl::has_internet())) {return(invisible(NULL))}

# Store Rseb package versions
check = suppressMessages(rvcheck::check_github("sebastian-gregoricchio/Rseb"))
# When up-to-date == NA it means that it is a developmental version higher then the last release
if (is.na(check$up_to_date)) {return(invisible(NULL))}

# Check if Rseb is up-to-date
if (check$up_to_date == FALSE) {
return(warning(paste("The Rseb package is not up-to-date. Installed version",
check$installed_version, "-->", check$latest_version,
"available. \nTo update Rseb type: Rseb::actualize()")))
}

# Update Rseb if required
if (check$up_to_date == FALSE & update == TRUE) {
devtools::install_github("sebastian-gregoricchio/Rseb", force = force)
} else if (verbose == T) {
return(message(paste("Rseb's latest version (v", check$installed_version, ") is already installed.", sep = "")))}

} # END function
#' @title \code{Rseb} updates verification
#'
#' @description It verifies if \code{Rseb} is up-to-date and installs it when required.
#'
#' @param update Logical value to define whether update the \code{Rseb} package. By default \code{TRUE}.
#' @param verbose Logical value to define whether print messages. By default \code{TRUE}.
#' @param force Logical value to define whether to force the installation of \code{Rseb} even though already up-to-date. Parameter passed to \code{devtools::install_github()}. By default \code{FALSE}.
#'
#' @return Warnings and/or messages. Installation of the latest version of \code{Rseb} if required.
#'
#' @details This function will check for internet availability.
#'
#' @export actualize


actualize = function(update = TRUE,
verbose = TRUE,
force = FALSE) {

# Check internet connection
if (isFALSE(curl::has_internet())) {return(invisible(NULL))}

# Store Rseb package versions
check = suppressMessages(rvcheck::check_github("sebastian-gregoricchio/Rseb"))
# When up-to-date == NA it means that it is a developmental version higher then the last release
if (is.na(check$up_to_date)) {return(invisible(NULL))}

# Check if Rseb is up-to-date and return a message if not up-to-date
if (check$up_to_date == FALSE) {
message = paste("| The 'Rseb' package is not up-to-date. Installed version",
check$installed_version, "-->", check$latest_version,
"available. |")
command = "| To update Rseb type: Rseb::actualize()"

return(message(paste("\033[0;37;44m",
paste(rep("-", nchar(message)), collapse = ""),
"\n", message, "\n",
command, paste(rep(" ", (nchar(message) - nchar(command)) - 1), collapse = ""), "|",
"\n", paste(rep("-", nchar(message)), collapse = ""),
"\033[0m",
sep = "")))
}



# Update Rseb if required
if (check$up_to_date == F & update == T) {devtools::install_github("sebastian-gregoricchio/Rseb")}
else if (check$up_to_date == T) {
if (force == T) {devtools::install_github("sebastian-gregoricchio/Rseb", force = force)}
else if (verbose == T) {return(message(paste("Rseb's latest version (v", check$installed_version, ") is already installed.", sep = "")))}
}




} # END function
2 changes: 0 additions & 2 deletions R/plot.density.profile.R
Expand Up @@ -58,7 +58,6 @@
#'
#' @export plot.density.profile
#'
# @import tidyr
# @import dplyr
# @import ggplot2
# @importFrom data.table fread
Expand Down Expand Up @@ -107,7 +106,6 @@ plot.density.profile = function(
##############################################################################

# Load all libraries
require(tidyr)
require(dplyr)
require(ggplot2)
# require(data.table)
Expand Down
46 changes: 41 additions & 5 deletions R/plot.density.summary.R
Expand Up @@ -55,6 +55,7 @@
#' \item \code{data.table} with the computed values used for the plot;
#' \item \code{metadata} table with the information obtained from the matrix_file.gz;
#' \item \code{plot.list} with a plot for each list element;
#' \item \code{density.profile} with the density profile of the mean signal generated by \link{plot.density.profile} corresponding to the regions/samples for which the summary multiplot have been generated;
#' \item \code{multiplot} with the image of all the plots together;
#' \item \code{summary.plot.samples} with a plot showing the scores of all regions per each sample;
#' \item \code{summary.plot.regions} with a plot showing the scores of all samples per each region;
Expand All @@ -66,7 +67,6 @@
#'
#' @export plot.density.summary
#'
# @import tidyr
# @import dplyr
# @import ggplot2
# @importFrom data.table fread
Expand All @@ -77,7 +77,6 @@
# @importFrom purrr reduce
# @importFrom cowplot plot_grid
# @importFrom tools toTitleCase
# @importFrom labeling extended

plot.density.summary = function(
matrix.file,
Expand Down Expand Up @@ -127,7 +126,6 @@ plot.density.summary = function(
##############################################################################

# Load all libraries
require(tidyr)
require(dplyr)
require(ggplot2)
# require(ggpubr)
Expand All @@ -138,7 +136,6 @@ plot.density.summary = function(
# require(purrr)
# require(cowplot)
# require(tools)
# require(labeling)

# Check if Rseb is up-to-date #
Rseb::actualize(update = F, verbose = F)
Expand Down Expand Up @@ -953,10 +950,48 @@ plot.density.summary = function(

##############################################################################
# RETURN a list of data
## generate the table with regions (from the matrix, equivalent to the bed used) to add then to the full.stat.table

# Bed files from original matrix
regions.position = m$matrix.data[, 1:6]
names(regions.position) = c("chr", "start", "end", "name", "score", "strand")

# Repeating the regions n times as the number of samples
regions.position = purrr::reduce(.x = replicate(n = length(unique(full.stat.table$sample)),
expr = regions.position,
simplify = F),
.f = rbind)


# Generation of density profile
density.profile = Rseb::plot.density.profile(matrix.file = matrix.file,
plot.by.group = plot.by.group,
missing.data.as.zero = missing.data.as.zero,
sample.names = sample.names,
region.names = region.names,
signal.type = "mean",
error.type = error.type,
plot.error = T,
x.lim = subset.range,
y.lim = y.lim,
y.identical.auto = F,
y.ticks.interval = ,
y.digits = y.digits,
text.size = text.size,
legend.position = legend.position,
plot.vertical.lines = T,
write.reference.points = F,
colors = colors,
n.row.multiplot = n.row.multiplot,
by.row = by.row,
print.multiplot = F)

# Build the output list
if (show.stat.multiplot == T) {
return(list(data.table = full.stat.table,
return(list(data.table = cbind(regions.position, full.stat.table),
metadata = metadata,
plot.list = plot.list,
density.profile = density.profile$multiplot,
multiplot = multiplot,
summary.plot.samples = summary.plot.samples,
summary.plot.regions = summary.plot.groups,
Expand All @@ -965,6 +1000,7 @@ plot.density.summary = function(
return(list(data.table = full.stat.table,
metadata = metadata,
plot.list = plot.list,
density.profile = density.profile$multiplot,
multiplot = multiplot,
summary.plot.samples = summary.plot.samples,
summary.plot.regions = summary.plot.groups,
Expand Down
15 changes: 6 additions & 9 deletions R/substract.bw.R
Expand Up @@ -4,9 +4,8 @@
#'
#' @param bw1 Full path to the first bigWig (the second one will be substracted to this one).
#' @param bw2 Full path to the second bigWig (it will be substracted to the first one).
#' @param return.substracted.bw Logic value to define whether return the resulting bigWig as GRanges object. By default \code{FALSE}.
#' @param export.substracted.bw Logic value to define whether export the resulting bigWig. By default \code{TRUE}.
#' @param substracted.bw.file String for the path of the resulting bigwig file to be exported. \cr By default \code{<working.directory>/subtraction.bw}.
#' @param return.substracted.bw Logic value to define whether return the resulting bigWig as GRanges object. By default \code{TRUE}.
#' @param substracted.bw.file String for the path of the resulting bigwig file to be exported. \cr By default \code{NULL}, any file will be exported.
#'
#' @return If required a subtraction bigWig is returned as GRanges object. The resulting bigWig can be also directly exported.
#'
Expand All @@ -17,10 +16,8 @@

substract.bw = function(bw1,
bw2,
wd = getwd(),
return.substracted.bw = F,
export.substracted.bw = T,
substracted.bw.file = paste(getwd(), "subtraction.bw", sep = "/")) {
return.substracted.bw = T,
substracted.bw.file = NULL) {

#-----------------------------#
# Check if Rseb is up-to-date #
Expand Down Expand Up @@ -63,9 +60,9 @@ substract.bw = function(bw1,
score(bws[[1]]) = score(bws[[1]]) - score(bws[[2]])

# Export the subtracted file if required
if (export.substracted.bw == T) {
if (!is.null(substracted.bw.file)) {
export(bws[[1]], substracted.bw.file)
message("The result was exported has", substracted.bw.file)
message("The resulting bigWig was exported has", substracted.bw.file)
}

# Return the subtracted bigWig if required
Expand Down

0 comments on commit ec15cc8

Please sign in to comment.