Skip to content

Commit

Permalink
Add to documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomrrr1 committed Apr 8, 2024
1 parent 07f04c3 commit d574967
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 44 deletions.
16 changes: 8 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
Package: MotifStats
Title: Uncover the relationship between peaks and motifs
Version: 0.0.0.9000
Authors@R:
person(given = "Thomas", family = "Roberts",
email = "[email protected]",
Authors@R:
person(given = "Thomas", family = "Roberts",
email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0009-0006-6244-8670"))
Description: This package calculates metrics to quantify the relationship
Description: This package calculates metrics to quantify the relationship
between peaks and motifs.
URL: https://github.com/Tomrrr1/MotifStats
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
Depends:
Depends:
R (>= 4.2.0)
Imports:
Biostrings,
BSgenome,
BSgenome.Hsapiens.UCSC.hg19,
BSgenome.Hsapiens.UCSC.hg38,
GenomicRanges,
ggplot2,
memes,
rGADEM,
rtracklayer,
universalmotif
Suggests:
Suggests:
BSgenome.Hsapiens.UCSC.hg19,
BSgenome.Hsapiens.UCSC.hg38,
knitr,
rmarkdown,
rworkflows,
Expand Down
8 changes: 8 additions & 0 deletions R/creb_motif.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' CREB Motif
#'
#' This dataset contains the MA0018.5 CREB1 motif from JASPAR2024.
#'
#' @format A universalmotif object produced by the \code{read_motif_file}
#' function.
#' @source JASPAR2024 \link{https://jaspar.elixir.no/matrix/MA0018.5/}
"creb_motif"
8 changes: 8 additions & 0 deletions R/creb_peaks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' CREB Peaks
#'
#' This dataset contains a set of CREB1 TIP-seq peaks (narrowPeak) produced by
#' MACS3.
#'
#' @format A GRanges peak object outputted by \code{read_peak_file}
#' function.
"creb_peaks"
38 changes: 6 additions & 32 deletions R/de_novo_motif.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Perform de novo motif discovery
#'
#' \code{de_novo_motif()} is a wrapper of several de novo motif discovery
#' methods, including Streme (meme suite), meme and rGADEM.
#' methods, including Streme, meme and rGADEM.
#'
#' Streme is preferable over Meme, except when you have a small number of
#' input sequences (< 50).
Expand All @@ -16,6 +16,8 @@
#' q-value) and the remaining 0.9 peaks as the background. If you wish to
#' supply your own control sequences, these must be passed as a DNAStringSet
#' object.
#' @param genome_build The genome build to use. The peak sequences will be
#' extracted from this genome.
#' @param ... Additional parameters to be passed to Streme, Meme or rGADEM. See
#' the respective documentation for more details.
#'
Expand Down Expand Up @@ -65,9 +67,9 @@ de_novo_motif <- function(peak_input,

if (control == "weak_peaks") {
top_index <- round(length(peaks) * 0.1)
ordered_peaks <- peaks[order(peaks$qValue, decreasing = TRUE), ]
top_peaks <- ordered_peaks[seq_len(top_index), ]
bottom_peaks <- ordered_peaks[!seq_len(top_index), ]
ordered_peaks <- peaks[order(peaks$qValue, decreasing = TRUE),]
top_peaks <- ordered_peaks[seq_len(top_index),]
bottom_peaks <- ordered_peaks[!seq_len(top_index),]

input_peak_sequences <-
BSgenome::getSeq(genome_build,
Expand Down Expand Up @@ -114,31 +116,3 @@ de_novo_motif <- function(peak_input,

return(motifs)
}

# de_novo_motif(peak_file = peak_file)
#
# peak_file <- "./rep1_peaks.narrowPeak"
# peaks <- read_peak_file(peak_file)
# peak_sequences <-
# BSgenome::getSeq(BSgenome.Hsapiens.UCSC.hg38::BSgenome.Hsapiens.UCSC.hg38,
# peaks)
# #
# #
# # fa <- system.file("extdata/fasta_ex/fa1.fa", package = "memes")
# # dreme_out <- memes::runDreme(fa, "shuffle", evalue = 39, outdir = tempdir())
# # ?memes::runStreme()
# #
# # BiocManager::install("rGADEM")
# # library(rGADEM)
# # peak_file <- "./rep1_peaks.narrowPeak"
# # peaks <- read_peak_file(peak_file)
# # peak_sequences <-
# # BSgenome::getSeq(BSgenome.Hsapiens.UCSC.hg38::BSgenome.Hsapiens.UCSC.hg38,
# # peaks)
# # gad <- rGADEM::GADEM(Sequences = peak_sequences)
# # rGADEM::getPWM(gad
# # )
#
# ?memes::runStreme()


12 changes: 10 additions & 2 deletions R/density_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
#'
#' @import ggplot2
#'
#' @param distance_vec A vector of summit-to-motif distances. This is an
#' output of the \code{summit_to_motif} function.
#' @param plot_title Title for the density plot.
#' @param x_label X-axis label.
#' @param y_label Y-axis label.
#' @param limits A vector of length 2 denoting the lower and upper bounds of the
#' x-axis. The default is \code{c(-400, 400)}.
#'
#' @returns NULL
#' @export
density_plot <- function(distance_vec,
Expand All @@ -13,9 +21,9 @@ density_plot <- function(distance_vec,
y_label = NULL,
limits = c(-400, 400)){
df <- as.data.frame(distance_vec)
colnames(df) <- "dist"
colnames(df) <- "distance"

ggplot(df, aes(x = dist)) +
ggplot(df, aes(x = distance)) +
geom_line(stat = "density", linetype = "solid", linewidth = 1) +
labs(x = x_label,
y = y_label,
Expand Down
20 changes: 20 additions & 0 deletions man/creb_motif.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions man/creb_peaks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/de_novo_motif.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions man/density_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/testthat/test-density_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ test_that("the density_plot function outputs a ggplot", {
out_dir = temp_dir,
genome_build = BSgenome.Hsapiens.UCSC.hg38::BSgenome.Hsapiens.UCSC.hg38
)
res <- density_plot(summit_to_motif_out$distance_to_summit)
res <- density_plot(
distance_vec = summit_to_motif_out$distance_to_summit)

expect_true(is.ggplot(res))
})

0 comments on commit d574967

Please sign in to comment.