# \dontshow{
options(gmax.processes = 2)
# }
gdb.init_examples()
# Basic intervals
intervs1 <- giterator.intervals("dense_track",
gintervals(1, 0, 4000),
iterator = 233
)
intervs2 <- giterator.intervals(
"sparse_track",
gintervals(1, 0, 2000)
)
# Original behavior - no strand considerations
gintervals.neighbors(intervs1, intervs2, 10,
mindist = -300,
maxdist = 500
)
# Add strand to intervals2 - affects distance directionality (original behavior)
intervs2$strand <- c(1, 1, -1, 1)
gintervals.neighbors(intervs1, intervs2, 10,
mindist = -300,
maxdist = 500
)
# TSS analysis example - use intervals1 (TSS) strand for directionality
tss <- data.frame(
chrom = c("chr1", "chr1", "chr1"),
start = c(1000, 2000, 3000),
end = c(1001, 2001, 3001),
strand = c(1, -1, 1), # +, -, +
gene = c("GeneA", "GeneB", "GeneC")
)
features <- data.frame(
chrom = "chr1",
start = c(500, 800, 1200, 1800, 2200, 2800, 3200),
end = c(600, 900, 1300, 1900, 2300, 2900, 3300),
feature_id = paste0("F", 1:7)
)
# Use TSS strand for distance directionality
result <- gintervals.neighbors(tss, features,
maxneighbors = 2,
mindist = -1000, maxdist = 1000,
use_intervals1_strand = TRUE
)
# Convenience functions for common TSS analysis
# Find upstream neighbors (negative distances for + strand genes)
upstream <- gintervals.neighbors.upstream(tss, features,
maxneighbors = 2, maxdist = 1000
)
# Find downstream neighbors (positive distances for + strand genes)
downstream <- gintervals.neighbors.downstream(tss, features,
maxneighbors = 2, maxdist = 1000
)
# Find both directions
both_directions <- gintervals.neighbors.directional(tss, features,
maxneighbors_upstream = 1,
maxneighbors_downstream = 1,
maxdist = 1000
)
Run the code above in your browser using DataLab