For a given query set of genomic regions, and a given feature set of regions, this function will return the distance for each query region to its closest feature. It ignores strand and returns the distance as positive or negative, depending on whether the feature is upstream or downstream

calcFeatureDist(query, features)

Arguments

query

A GRanges or GRangesList object with query sets

features

A GRanges object with features to test distance to

Value

A vector of genomic distances for each query region relative to its closest feature.

Details

This function is similar to the bioconductor distanceToNearest function, but returns negative values for downstream distances instead of absolute values. This allows you to assess the relative location.

Examples

vistaSftd = GenomicRanges::shift(vistaEnhancers, 100000)
calcFeatureDist(vistaEnhancers, vistaSftd) 
#>    [1] 100000 100000 100000 -38929 -64482  51103   6276  26407 -13765 100000
#>   [11] 100000 100000  -6641 100000  34288  32503   3698  -2524  -8261 -29241
#>   [21]  34400  16785 100000  43928   1401 100000 100000 100000 100000 100000
#>   [31] 100000  71285   7325 -30573 100000 100000 100000 100000 100000 -27817
#>   [41] -35678 100000  25913   5122 100000 100000  -6086  -7225 100000  68317
#>   [51]   9811   6900  -8186   -440 100000 100000  91651  73613  73613 100000
#>   [61]  63233  20278 -18522 100000 -33200  58877  41370  20747 -10367  -8731
#>   [71] -55505  65952  14761 100000 100000 100000 100000 100000 100000 100000
#>   [81]  17471  33840 100000  16440 -74771 100000  82295  51393  47104  19710
#>   [91] 100000 100000 100000 100000  24148 100000 100000 100000 100000 100000
#>  [101]    878 100000 100000 100000 100000  84783 100000 100000 100000  81047
#>  [111] 100000 100000 100000 100000 100000   1131 100000 100000 -90653 100000
#>  [121] 100000 100000 100000 100000 -16943 -43080 100000  56804 100000 -66902
#>  [131] -26156 -44680  -7442 100000 100000 100000 100000 100000 -27622 -29594
#>  [141]  57964  53785  25177    691  -3889 100000 -15788 -50812 -72312 100000
#>  [151]  87189 100000 100000 100000  98460 100000  96686 -78252 100000 100000
#>  [161] 100000  76153  24812 100000  19325 100000 100000 100000 100000 100000
#>  [171] 100000  96925  54878 -10815 -76463 100000 100000  52629  10397 100000
#>  [181] 100000 100000  63131 100000 -20578 -25225 -36732  33804   3738 100000
#>  [191] -20875  37350   -204 -31316 -72161  36651 -45166 100000 100000 100000
#>  [201] 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
#>  [211] 100000 100000 100000 100000 100000  -4847 -54386  28709   7648 100000
#>  [221] 100000  47622 -14847 -37981 100000 100000  42890 100000 100000 100000
#>  [231] 100000 100000   1796 100000 100000 100000 100000  73993  38884 -65103
#>  [241]  57558 100000 100000 100000 100000  99007 100000 100000 100000 100000
#>  [251] 100000 100000 100000 100000 100000  85439 -74816 -90095  48602  29703
#>  [261]  29332 100000 -92841 -92868  54546  22185   9333   7191 100000  74593
#>  [271]   -641  -3496 -67168  37674  33183 -28249  22842  19467  14151  18450
#>  [281]  24388 100000 100000  -9147 100000 100000  55507 100000  99959 100000
#>  [291] 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
#>  [301] 100000 100000  28195   1903 -30612 -16811 -50262  49522  33288    191
#>  [311]  -3142 100000  69992 100000 100000 100000 100000  46003  20063 -83450
#>  [321] 100000  77197 100000 100000  21297   6742 -18721 100000 100000 100000
#>  [331]  88610  44110 100000  71626 100000 100000 100000 100000 100000 -16485
#>  [341] 100000 100000 100000 100000 100000 -45601 -46974 -64149 100000  73717
#>  [351]  50363  -7128 -30782 -41182 -49954 -31234 100000 100000 100000  99110
#>  [361] 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
#>  [371] 100000 100000 100000 100000  86832 100000 -28090 100000  -5320 -92943
#>  [381]  72653 100000 100000 100000 100000 100000 100000 100000 100000 100000
#>  [391] -81374 100000 100000  78611  73720  -2320  -7074 -35863  34922  20654
#>  [401]   4520  12927  -5143  -1985 -58266  -2404  31851  14998   2298   5804
#>  [411]  25382    545 -15165  15012   3454  -4725 100000 -93472  90172  66670
#>  [421]  32435   5560  -5572 -11452 100000  85245 -48427  66209 -68791  80495
#>  [431]  42107  34518   1633 -38303 -45036  49007  -6013  26495   -642 -34956
#>  [441] -38292 -55545  46720  43431  11670   6997   3999  -1385 -10366 -16875
#>  [451]  10608    277  -5216 -19717 100000  94884 -43900 -61400  -6291  11568
#>  [461]   4948 100000  44988 100000 100000 -85227 100000 100000 100000 100000
#>  [471]  79201 -30067 100000 -10734 -14917   -984 -48695   9760   6331 100000
#>  [481]  89898 100000 100000 -77297 -87831  50795 -12889 -32747 -88865  -1081
#>  [491]   6607 100000 100000  80133 100000  49176 100000 100000 100000 100000
#>  [501]  97361 100000 100000 100000 100000 100000 100000  53893 100000  92987
#>  [511] -11215 -37945 100000 100000 100000  71236  35013 100000 100000 100000
#>  [521] 100000  79312 100000 100000 100000 100000 100000 100000 100000 100000
#>  [531] 100000 100000 100000   3867 100000  65061  33949   9947   1546  -9778
#>  [541] -11756  14982   2262 100000 100000 -63800 100000 100000 100000 -14685
#>  [551] 100000 100000  61683 100000 100000 100000 100000 -90893  64605 100000
#>  [561] 100000  81766 100000 100000 100000 -16472 100000  62924 100000 100000
#>  [571] 100000  94539 -45764  40652 -68529 100000 100000  70278  22547  -2517
#>  [581] 100000  97413  42978  36383 100000 100000  92184  58919 100000 -14953
#>  [591]  28576  20185 -72979  80187   5935   5663 -25301 -10635 100000 100000
#>  [601] 100000 100000 100000 100000 100000 100000 -62401  66030 100000 100000
#>  [611] 100000  62965  24364   2948 100000 100000 -74022 100000  47331  25775
#>  [621]  -3596 -14132 -15618  -9078   9961   8345   9007  15396 -26299 -32057
#>  [631] -57382  39497  23109   3008   -112  -1157   -567  -2051 -71346  35991
#>  [641] 100000 -43404 -49191 -51214  42306  -1098  -8639  -8516  21090  17441
#>  [651]  14344  26304   6702 -28545  11053  41970  24911 100000  39566 100000
#>  [661]  88099  25728 100000    128 -12933 100000 -75174 -27092 100000 -33471
#>  [671] -47401 100000 100000 100000 100000 100000  88600 100000  77515 -17216
#>  [681]  -7945 -51358  53530 100000 100000  99107  27467   7487 -10024  12339
#>  [691] 100000  14890 -40147 -21924 -12641 -52571  35958 -80071 100000 100000
#>  [701] 100000 100000 100000 -89821  92423  88891 100000 100000  87926 -39537
#>  [711] 100000  45025 100000 100000  96789  91383   -444 100000  61458  11924
#>  [721] -17130  26609 100000  97071 -81794  25904  32365  -3156 100000 100000
#>  [731]  -8802  39178 -40649  61499  -5777 100000 100000 100000 -68842   -556
#>  [741] -23782  17193  12714 -82271 100000 100000 -16544 -27673 -35626 -37506
#>  [751] 100000 100000  96955  44553 -54627 -65825 100000 -86033 100000 100000
#>  [761] 100000 100000 100000 100000 100000 100000  43403 100000  28581 100000
#>  [771] 100000  -7879   6002 100000 100000 100000 100000 100000 100000 100000
#>  [781] 100000 100000 100000 100000 100000  86882  66694  60880   5339    566
#>  [791] -10229  -2430 100000 100000 100000 -83894 100000 -13353 100000 -54819
#>  [801] 100000  82312 100000 100000 100000 100000 100000 100000  91750 100000
#>  [811] 100000 100000  98080  87802  85348  50242  37610  33425 100000 100000
#>  [821] 100000 -81511 100000  45644  27859 -11530 -17188 100000 100000 100000
#>  [831] 100000  91005  44265 100000 100000 -36150 -69940 -54360 -62773  73686
#>  [841]  26493  12516  33146   9353  -4013 -56317  47594  39646  26150   8382
#>  [851] 100000 100000 100000 100000 100000 -41078  63279 100000  35034  15168
#>  [861]  22334 -18141 -74979 100000 100000  80681   5259 100000  85890 100000
#>  [871]  94333  55070  47206  45826 100000 100000 -87076  25343  -6263 -27106
#>  [881]  -6905  -6202 -22588 -75377  55726 100000 -26672 100000 100000  74843
#>  [891] 100000 100000 100000 100000 100000  82803 100000 100000 100000  48242
#>  [901]  -9906 -17106 100000 100000 100000 100000 100000 100000 100000  19442
#>  [911] 100000 100000 100000  95716 100000 100000 100000 100000 100000 100000
#>  [921] 100000  51924   8336 -64880  18858 -20523   5078 100000 -35029 -11726
#>  [931] 100000 100000 100000 100000 100000 100000 100000 100000  73889 100000
#>  [941] 100000 100000 100000 100000   6324 100000  97278  92840  81619  53220
#>  [951] 100000 100000 100000 100000 100000 -33123 -46128 100000 -46943  -5521
#>  [961] 100000 100000 100000  94629  14189 -18675 -26533 -20205 100000 100000
#>  [971]  14959  28130 100000 100000 100000 -24502 100000  82641 -42453  -8975
#>  [981] -57049  22612  -3646  -4763 -24234 100000  35222  -3464 -27918 -12769
#>  [991]   9340   5255  -6296  22033   5059 -12058  49516    780  -9377 100000
#> [1001]  30781 100000 100000  25361 100000   4005 100000 100000 100000  13031
#> [1011] 100000  68512  43312 100000 100000 100000 100000 100000 100000 100000
#> [1021] 100000 -63709 100000 -25657  15476 -13188 -45022  68459 100000 100000
#> [1031]  58453  46086 -12146  54953 -20819 100000 100000 100000 100000 100000
#> [1041] 100000  85735 100000 100000  23703 -25967 100000 100000 100000 100000
#> [1051] 100000 100000  45962  43618  11625 100000 100000 100000 100000 -32418
#> [1061] 100000  27519 100000 100000 100000 100000 -94651 -67085   2998 -45870
#> [1071]  33777   -718  -3457    471  -9338 -21851 -10458 -47046   5860 -11924
#> [1081]  11000   7308  -3422 100000 100000 100000 100000 100000 100000 100000
#> [1091] 100000  98071 100000 100000 100000 100000 100000 100000  97236 100000
#> [1101] 100000 100000  44578 100000 100000 100000 100000  96634 -70750  83639
#> [1111]  19114 -55448 100000 100000 100000 -27678 100000 100000 100000  61578
#> [1121] 100000 100000 100000 100000  82509  68447  61698  16790   5746  -5401
#> [1131]  -4544 -12979   6066   3920    392   8775  14641 100000  93872  32859
#> [1141] -79120 100000 -13880 -38264   8329 100000 -97745  -5302 -79302 -88712
#> [1151]   1270 -22772 100000 100000 100000 100000 100000 100000 100000 100000
#> [1161]  96668  95004  89484  80729   9922  33199 -19252  20359  16194  13889
#> [1171] -18712   7076   -139  18066 100000  97672  79419 -29131 -61303  49613
#> [1181] -39017 -29208 100000 100000 100000 100000 100000 100000 100000 100000
#> [1191] 100000 100000 100000  99959 100000 100000 100000 100000 100000 100000
#> [1201] -88462 100000 100000 100000 100000 100000 100000 100000 100000  55201
#> [1211] 100000 100000 -81251 100000   8094 100000 100000 100000 100000 100000
#> [1221] 100000 100000 100000 100000  18895 -40071 100000 100000  93183 -32710
#> [1231] 100000 100000 100000 100000 100000 100000  95084 100000 100000 100000
#> [1241] 100000 100000 -89199 100000 100000 100000  91010 100000  84966  80278
#> [1251]  70394  59612 100000 100000 100000  63680  14247 100000 100000 100000
#> [1261]  70825 100000 100000 100000  52559 100000 -25804 -46580 -55328 -57351
#> [1271] 100000   9764 100000 100000 100000  84487 100000 100000  65909 -39105
#> [1281] 100000  68762 100000 100000 100000 100000 100000 100000  12008  10735
#> [1291] 100000 100000 100000 100000 100000 100000  89449 -10753 -14923 -19381
#> [1301]  33434  10218 -14465  17237  11785   5079 -84386  74317 100000 100000
#> [1311] -86520 100000  36009  -5359  28404   6787  18374   8097  -1085  -2875
#> [1321] 100000 100000 100000 100000   8210 -89703  -3440 100000 100000 100000
#> [1331] 100000 100000 100000 -62293  51197 100000  19187 100000 100000