Skip to content

Commit 73b6b4a

Browse files
committed
Add d XGR, RR ROADMAP
1 parent 1f87557 commit 73b6b4a

File tree

191 files changed

+22614
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+22614
-49
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LazyData: true
2727
Depends: R (>= 4.1)
2828
SystemRequirements: Python (>= 3.7.0)
2929
biocViews:
30-
Imports:
30+
Imports:
3131
echodata,
3232
echotabix,
3333
dplyr,
@@ -50,7 +50,8 @@ Imports:
5050
S4Vectors,
5151
GenomeInfoDb,
5252
biomaRt,
53-
IRanges
53+
IRanges,
54+
XGR
5455
Suggests:
5556
markdown,
5657
rmarkdown,

NAMESPACE

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,39 @@
33
export(CORCES_2020.get_HiChIP_FitHiChIP_overlap)
44
export(CS_bin_plot)
55
export(CS_counts_plot)
6+
export(ROADMAP.construct_reference)
7+
export(ROADMAP.query)
8+
export(ROADMAP.query_and_plot)
9+
export(XGR.download_and_standardize)
10+
export(XGR.enrichment)
11+
export(merge_celltype_specific_epigenomics)
612
export(merge_finemapping_results)
713
export(peak_overlap_plot)
814
export(plot_dataset_overlap)
915
export(super_summary_plot)
10-
import(ggplot2)
16+
import(ggplot2, except = c(geom_rect, ggsave))
17+
import(ggplot2, except = geom_rect)
18+
import(ggplot2, except = ggsave)
1119
importFrom(DescTools,Divisors)
20+
importFrom(DescTools,RoundTo)
1221
importFrom(GenomeInfoDb,seqlevelsStyle)
1322
importFrom(GenomicRanges,GRanges)
23+
importFrom(GenomicRanges,GRangesList)
1424
importFrom(GenomicRanges,elementMetadata)
1525
importFrom(GenomicRanges,end)
1626
importFrom(GenomicRanges,findOverlaps)
1727
importFrom(GenomicRanges,makeGRangesFromDataFrame)
1828
importFrom(GenomicRanges,mcols)
29+
importFrom(GenomicRanges,seqnames)
1930
importFrom(GenomicRanges,start)
2031
importFrom(IRanges,IRanges)
32+
importFrom(IRanges,overlapsAny)
33+
importFrom(R.utils,gzip)
2134
importFrom(RColorBrewer,brewer.pal)
2235
importFrom(S4Vectors,queryHits)
2336
importFrom(S4Vectors,subjectHits)
37+
importFrom(XGR,xGRviaGenomicAnno)
38+
importFrom(XGR,xRDataLoader)
2439
importFrom(biomaRt,getBM)
2540
importFrom(biomaRt,useMart)
2641
importFrom(data.table,as.data.table)
@@ -30,6 +45,7 @@ importFrom(data.table,fwrite)
3045
importFrom(data.table,melt.data.table)
3146
importFrom(data.table,merge.data.table)
3247
importFrom(data.table,rbindlist)
48+
importFrom(data.table,transpose)
3349
importFrom(dplyr,"%>%")
3450
importFrom(dplyr,arrange)
3551
importFrom(dplyr,case_when)
@@ -39,12 +55,15 @@ importFrom(dplyr,group_by)
3955
importFrom(dplyr,mutate)
4056
importFrom(dplyr,n_distinct)
4157
importFrom(dplyr,rename)
58+
importFrom(dplyr,sample_n)
4259
importFrom(dplyr,select)
4360
importFrom(dplyr,slice)
4461
importFrom(dplyr,summarise)
4562
importFrom(dplyr,summarise_at)
63+
importFrom(dplyr,tally)
4664
importFrom(dplyr,top_n)
4765
importFrom(dplyr,vars)
66+
importFrom(echotabix,query_tabular)
4867
importFrom(ggbio,autoplot)
4968
importFrom(ggbio,geom_arch)
5069
importFrom(ggbio,geom_rect)
@@ -53,9 +72,18 @@ importFrom(ggbio,ggsave)
5372
importFrom(ggbio,plotGrandLinear)
5473
importFrom(ggbio,scale_x_sequnit)
5574
importFrom(ggbio,theme_genome)
75+
importFrom(ggplot2,aes)
76+
importFrom(ggplot2,element_text)
77+
importFrom(ggplot2,ggplot_build)
78+
importFrom(ggplot2,guide_legend)
79+
importFrom(ggplot2,guides)
80+
importFrom(ggplot2,scale_y_continuous)
81+
importFrom(ggplot2,theme)
82+
importFrom(ggplot2,theme_classic)
5683
importFrom(grDevices,dev.off)
5784
importFrom(grDevices,png)
5885
importFrom(haploR,queryRegulome)
86+
importFrom(methods,is)
5987
importFrom(parallel,mclapply)
6088
importFrom(patchwork,plot_layout)
6189
importFrom(patchwork,plot_spacer)
@@ -65,6 +93,7 @@ importFrom(scales,alpha)
6593
importFrom(stats,as.formula)
6694
importFrom(stats,formula)
6795
importFrom(stats,median)
96+
importFrom(stats,p.adjust)
6897
importFrom(stats,setNames)
6998
importFrom(tidyr,separate)
7099
importFrom(utils,head)

R/CS_bin_plot.R

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#' @examples
55
#' bin_plot <- CS_bin_plot(merged_DT = echodata::Nalls2019_merged)
66
#' @export
7-
#' @import ggplot2
87
#' @importFrom RColorBrewer brewer.pal
8+
#' @importFrom stats setNames
99
CS_bin_plot <- function(merged_DT,
1010
show_plot = TRUE) {
1111
Method <- bin <- ..count.. <- NULL
@@ -17,40 +17,40 @@ CS_bin_plot <- function(merged_DT,
1717
custom_colors <- RColorBrewer::brewer.pal(
1818
n = length(levels(bin_counts$bin)), "GnBu"
1919
)
20-
custom_colors_dict <- setNames(
20+
custom_colors_dict <- stats::setNames(
2121
custom_colors[seq(1, length(used_bins))],
2222
rev(used_bins)
2323
)
2424
custom_colors_dict[names(custom_colors_dict) == "0"] <- "lightgray"
2525

26-
bin_plot <- ggplot(
26+
bin_plot <- ggplot2::ggplot(
2727
subset(bin_counts, Method != "mean"),
28-
aes(x = Method, fill = bin)
28+
ggplot2::aes(x = Method, fill = bin)
2929
) +
30-
geom_bar(
30+
gggplot2::eom_bar(
3131
stat = "count", show.legend = TRUE,
32-
position = position_stack(reverse = FALSE), color = "white"
32+
position = ggplot2::position_stack(reverse = FALSE), color = "white"
3333
) +
3434
# scale_fill_brewer(palette = "Spectral", direction = -1) +
35-
scale_fill_manual(values = custom_colors_dict) +
35+
ggplot2::scale_fill_manual(values = custom_colors_dict) +
3636
# geom_text(aes(label = paste(bin,"SNPs")),
3737
# position = position_stack(vjust = .5), vjust=-1, stat = "count") +
38-
geom_text(aes(label = ..count..),
39-
position = position_stack(vjust = .5),
38+
ggplot2::geom_text(ggplot2::aes(label = ..count..),
39+
position = ggplot2::position_stack(vjust = .5),
4040
vjust = .5, stat = "count"
4141
) +
42-
theme_bw() +
43-
labs(x = NULL, y = "Loci", fill = "CS size") +
44-
coord_flip() +
45-
theme(
46-
panel.grid.major = element_blank(),
47-
panel.grid.minor = element_blank(),
48-
rect = element_blank(),
49-
axis.text.x = element_blank(),
50-
axis.ticks = element_blank(),
42+
ggplot2::theme_bw() +
43+
ggplot2::labs(x = NULL, y = "Loci", fill = "CS size") +
44+
ggplot2::coord_flip() +
45+
ggplot2::theme(
46+
panel.grid.major = ggplot2::element_blank(),
47+
panel.grid.minor = ggplot2::element_blank(),
48+
rect = ggplot2::element_blank(),
49+
axis.text.x = ggplot2::element_blank(),
50+
axis.ticks = ggplot2::element_blank(),
5151
legend.position = "top"
5252
) +
53-
guides(fill = guide_legend(nrow = 1, reverse = TRUE))
53+
ggplot2::guides(fill = ggplot2::guide_legend(nrow = 1, reverse = TRUE))
5454
if (show_plot) print(bin_plot)
5555
return(list(
5656
plot = bin_plot,

R/CS_counts_plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @examples
66
#' gg_CS <- CS_counts_plot(merged_DT = echodata::Nalls2019_merged)
77
#' @export
8-
#' @import ggplot2
8+
#' @rawNamespace import(ggplot2, except = c(geom_rect, ggsave))
99
#' @importFrom dplyr %>% mutate arrange
1010
CS_counts_plot <- function(merged_DT,
1111
show_numbers = TRUE,

R/GR.name_filter_convert.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#' GR.name_filter_convert
2+
#'
3+
#' @family plot
4+
#' @keywords internal
5+
GR.name_filter_convert <- function(GR.final,
6+
GR.names,
7+
min_hits = 1) {
8+
names(GR.final) <- GR.names
9+
grl <- GR.final[!as.logical(lapply(GR.final, is.null))]
10+
# Filter to those that had at least N hits
11+
grl <- grl[as.logical(lapply(grl, function(g, min_hits. = min_hits) {
12+
length(GenomicRanges::seqnames(g)) >= min_hits.
13+
}))]
14+
# Convert to GRangesList (important)
15+
grl <- GenomicRanges::GRangesList(grl)
16+
return(grl)
17+
}

R/NOTT_2019.epigenomic_histograms.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
#' return_assay_track = TRUE,
1515
#' save_annot = FALSE
1616
#' )
17-
#' @import ggplot2
17+
#' @rawNamespace import(ggplot2, except = c(geom_rect, ggsave))
1818
#' @importFrom ggbio autoplot geom_rect scale_x_sequnit plotGrandLinear
1919
#' @importFrom ggbio theme_genome ggsave
2020
#' @importFrom stats formula
21+
#' @importFrom GenomeInfoDb seqlevelsStyle
2122
NOTT_2019.epigenomic_histograms <- function(finemap_dat,
2223
locus_dir,
2324
show_plot = TRUE,
@@ -45,15 +46,20 @@ NOTT_2019.epigenomic_histograms <- function(finemap_dat,
4546
# library(BiocGenerics)
4647
# library(GenomicRanges)
4748
# library(ggbio)
48-
# show_plot=T;save_plot=T;full_data=T;return_assay_track=F;binwidth=2500; geom="histogram"; plot_formula="Cell_type ~."; show_regulatory_rects=T; bigwig_dir=NULL; verbose=T; nThread=1;
49-
# finemap_dat=echoannot::LRRK2; plot.zoom=500000; fill_var="Assay"; density_adjust=.2; strip.text.y.angle=0;
49+
# show_plot=T;save_plot=T;full_data=T;return_assay_track=F;
50+
# binwidth=2500; geom="histogram"; plot_formula="Cell_type ~.";
51+
# show_regulatory_rects=T; bigwig_dir=NULL; verbose=T; nThread=1;
52+
# finemap_dat=echoannot::LRRK2; plot.zoom=500000; fill_var="Assay";
53+
# density_adjust=.2; strip.text.y.angle=0;
5054

5155
# Import BigWig annotation files
5256
bigWigFiles <- echoannot::NOTT_2019.bigwig_metadata
53-
# Some bigWig files were initially loaded to UCSC GB, but then later taken down by the authors....
57+
# Some bigWig files were initially loaded to UCSC GB,
58+
# but then later taken down by the authors....
5459
# However I saved these files on Minerva beforehand.
5560
bigWigFiles <- subset(bigWigFiles, UCSC_available == "T")
56-
bigWigFiles <- dplyr::mutate(bigWigFiles, cell_type = gsub(" ", ".", cell_type))
61+
bigWigFiles <- dplyr::mutate(bigWigFiles,
62+
cell_type = gsub(" ", ".", cell_type))
5763
# Convert finemap data to granges
5864
dat <- finemap_dat
5965
dat$seqnames <- dat$CHR

R/NOTT_2019.plac_seq_plot.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#' # Zoom in
1414
#' trks_plus_lines <- NOTT_2019.plac_seq_plot(finemap_dat = BST1, locus_dir = file.path("~/Desktop", locus_dir), zoom_window = 500000, highlight_plac = TRUE)
1515
#' }
16-
#' @import ggplot2
16+
#' @rawNamespace import(ggplot2, except = geom_rect)
17+
#' @rawNamespace import(ggplot2, except = ggsave)
1718
#' @importFrom ggbio ggbio geom_arch geom_rect scale_x_sequnit ggsave
1819
#' @importFrom IRanges IRanges
1920
NOTT_2019.plac_seq_plot <- function(finemap_dat = NULL,

R/PLOT.get_max_histogram_height.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
#' PLOT.get_max_histogram_height
2+
#'
3+
#' @keywords internal
4+
#' @importFrom methods is
5+
#' @importFrom ggplot2 ggplot_build
6+
#' @importFrom DescTools RoundTo
17
PLOT.get_max_histogram_height <- function(gg,
28
round_to = NULL,
39
verbose = TRUE) {
4-
if (tolower(class(gg)[1]) == "ggbio") gg <- gg@ggplot
5-
printer("+ PLOT:: Calculating max histogram height", v = verbose)
10+
if (methods::is(gg,"ggbio")) {gg <- gg@ggplot}
11+
messager("+ PLOT:: Calculating max histogram height", v = verbose)
612
dat <- ggplot2::ggplot_build(gg)$data[[1]]
7-
max_height <- max(dat$ymax)
13+
max_height <- max(dat$ymax, na.rm = TRUE)
814
if (!is.null(round_to)) {
915
max_height <- DescTools::RoundTo(max_height, round_to)
1016
}

R/PLOT.get_window_limits.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PLOT.get_window_limits <- function(finemap_dat,
2626
.index_as_center = index_as_center,
2727
.genomic_units = genomic_units,
2828
.verbose = verbose) {
29-
printer("+ Inferring genomic limits for window:", pz, v = .verbose)
29+
messager("+ Inferring genomic limits for window:", pz, v = .verbose)
3030
# Zoom #x as input
3131
if (.index_as_center) {
3232
middle_pos <- subset(.finemap_dat, leadSNP)$POS[1]

R/ROADMAP.construct_reference.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#' Gather Roadmap annotation metadata
2+
#'
3+
#' @param ref_path Where the ROADMAP metadata is stored.
4+
#' @param keyword_query Search all columns in the Roadmap annotations metadata
5+
#' and only query annotations that contain your keywords.
6+
#' Can provide multiple keywords in list form:
7+
#' \code{c("placenta","liver","monocytes")}
8+
#'
9+
#' @examples
10+
#' ref <- ROADMAP.construct_reference(keyword_query = c(
11+
#' "placenta",
12+
#' "liver",
13+
#' "monocytes"
14+
#' ))
15+
#' @family ROADMAP
16+
#' @export
17+
#' @importFrom data.table transpose fread
18+
ROADMAP.construct_reference <- function(ref_path =
19+
system.file(
20+
"extdata/ROADMAP",
21+
"ROADMAP_Epigenomic.js",
22+
package = "echoannot"
23+
),
24+
keyword_query = NULL) {
25+
# %like% is from data.table
26+
ref <- suppressWarnings(data.table::fread(ref_path))
27+
colnames(ref)[1] <- "EID"
28+
if (!is.null(keyword_query)) {
29+
rows <- grep(paste(keyword_query, collapse = "|"),
30+
data.table::transpose(ref),
31+
ignore.case = TRUE
32+
)
33+
ref <- ref[rows, ]
34+
messager(
35+
"+ ROADMAP::", nrow(ref),
36+
"annotation(s) identified that match `keyword_query`."
37+
)
38+
}
39+
return(ref)
40+
}

R/ROADMAP.merge_and_process_grl.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#' Standardize Roadmap query
2+
#'
3+
#' @param grl.roadmap Roadmap query results
4+
#' @param n_top_tissues The number of top tissues to include,
5+
#' sorted by greatest number of rows
6+
#' (i.e. the number of genomic ranges within the window).
7+
#' @family ROADMAP
8+
#' @importFrom IRanges overlapsAny
9+
#' @importFrom dplyr %>% group_by tally n_distinct
10+
ROADMAP.merge_and_process_grl <- function(grl.roadmap,
11+
gr.snp,
12+
n_top_tissues = 5,
13+
sep = " ") {
14+
grl.roadmap.merged <- unlist(grl.roadmap)
15+
grl.roadmap.merged$Source <- names(grl.roadmap.merged)
16+
grl.roadmap.merged$Source <- gsub("_", sep, grl.roadmap.merged$Source)
17+
grl.roadmap.merged$ChromState <-
18+
lapply(
19+
grl.roadmap.merged$State,
20+
function(ROW) {
21+
base::strsplit(ROW, "_")[[1]][2]
22+
}
23+
) %>% unlist()
24+
grl.roadmap.filt <- grl.roadmap.merged[unlist(lapply(
25+
grl.roadmap, function(e) {
26+
IRanges::overlapsAny(e, gr.snp, minoverlap = 1)
27+
}
28+
))]
29+
if (!is.null(n_top_tissues)) {
30+
top_tissues <- data.frame(grl.roadmap.filt) %>%
31+
dplyr::group_by(Source) %>%
32+
dplyr::tally(sort = TRUE)
33+
grl.roadmap.filt <- subset(
34+
grl.roadmap.filt,
35+
Source %in% unique(top_tissues$Source[
36+
seq(1, min(
37+
n_top_tissues,
38+
dplyr::n_distinct(top_tissues$Source)
39+
))
40+
])
41+
)
42+
}
43+
return(grl.roadmap.filt)
44+
}

0 commit comments

Comments
 (0)