gr_distance_overlap: gr_distance

View source: R/functions_GR_ovlerlaps.R

gr_distance_overlapR Documentation

gr_distance

Description

Find items in b within a certain distance (max_dist) all items in a.

Usage

gr_distance_overlap(a, b, max_dist)

Arguments

a

The left side of output, regions that get extended when applying max_dist.

b

The right side of output

max_dist

Maximum distance allowed from a to b.

Details

Items in a will be repeated for every item in b they overlap with.

a is the left side of output and the regions that extended when applying max_dist.

Value

a GRanges of b appended to regions they overlap with from a.

Examples


max_distance = 5e4
np_file = "/slipstream/galaxy/uploads/working/qc_framework/output/MCF7_H3K4ME3_R1/MCF7_H3K4ME3_R1_peaks.narrowPeak"
np_gr = seqsetvis::easyLoad_narrowPeak(np_file)[[1]]

ref_gr = rtracklayer::import.gff("~/gencode.v36.annotation.gtf", feature.type = "gene")
pr_gr = GenomicRanges::promoters(ref_gr, 1)

olap_gr = gr_distance_overlap(pr_gr, np_gr, max_distance)
#not the impact of reversing the inputs
olap_gr.flip = gr_distance_overlap(np_gr, pr_gr, max_distance)

wd = "/slipstream/home/sophiakogut/IK_peaks"
np_file2 = file.path(wd, "IK_common.narrowPeak")
mir_file = file.path(wd, "DE_mirna_primary.txt")

# This ain't a narrowPeak file!
np_gr2 = seqsetvis::easyLoad_bed(np_file2)[[1]]
mir_gr = seqsetvis::easyLoad_bed(mir_file)[[1]]
mir_olaps = gr_distance_overlap(mir_gr, np_gr2, 5e4)
mir_olaps

# writing the output
df = as.data.frame(mir_olaps)
df = df[, colnames(df)[c(1:3, 6, 7, 5, seq(8, ncol(df)))]]
# this file is very similar to a bed file and will work with bedtools if you remove the first line with column names
# the first 6 columns are standard bed format
write.table(df, "mir_nearby_peaks.txt", sep = "\t", quote = FALSE, row.names = FALSE)

# load it back into R like this
loaded_gr = GRanges(read.table("mir_nearby_peaks.txt", header = TRUE))

jrboyd/ssvRecipes documentation built on May 22, 2022, 7:07 a.m.