|
a |
|
b/ATAC/Functions/FindRegion.R |
|
|
1 |
# convert region argument to genomic coordinates |
|
|
2 |
# region can be a string, name of a gene, or GRanges object |
|
|
3 |
FindRegion <- function( |
|
|
4 |
object, |
|
|
5 |
region, |
|
|
6 |
sep = c("-", "-"), |
|
|
7 |
assay = NULL, |
|
|
8 |
extend.upstream = 0, |
|
|
9 |
extend.downstream = 0 |
|
|
10 |
) { |
|
|
11 |
if (!is(object = region, class2 = "GRanges")) { |
|
|
12 |
# if separators are present in the string and we can convert the |
|
|
13 |
# start to a number, assume we're using genomic coordinates |
|
|
14 |
if (all(sapply(X = sep, FUN = grepl, x = region))) { |
|
|
15 |
region <- StringToGRanges(regions = region, sep = sep) |
|
|
16 |
} else { |
|
|
17 |
region <- LookupGeneCoords(object = object, assay = assay, gene = region) |
|
|
18 |
if (is.null(x = region)) { |
|
|
19 |
stop("Gene not found") |
|
|
20 |
} |
|
|
21 |
} |
|
|
22 |
} |
|
|
23 |
region <- suppressWarnings(expr = Extend( |
|
|
24 |
x = region, |
|
|
25 |
upstream = extend.upstream, |
|
|
26 |
downstream = extend.downstream |
|
|
27 |
) |
|
|
28 |
) |
|
|
29 |
return(region) |
|
|
30 |
} |