Split Regions into Windows

makeWindows(query, w = NULL, k = NULL, direction = c("normal", "reverse"),
    short.keep = FALSE)

Arguments

query

A GRanges-class object.

w

Window size. A value larger than 1 means the number of base pairs and a value between 0 and 1 is the percent to the current region.

k

Number of partitions for each region. If it is set, all other arguments are ignored.

direction

Where to start the splitting? See 'Details' section.

short.keep

If the the region can not be split equally under the window size, the argument controls whether to keep the windows that are smaller than the window size. See 'Details' section.

Details

Following illustrates the meaning of direction and short.keep:

    -->-->-->-  one region, split by 3bp window (">" represents the direction of the sequence)
    aaabbbccc   direction = "normal",  short.keep = FALSE
    aaabbbcccd  direction = "normal",  short.keep = TRUE
     aaabbbccc  direction = "reverse", short.keep = FALSE
    abbbcccddd  direction = "reverse", short.keep = TRUE  

Value

A GRanges-class object with two additional columns attached:

  • .i_query which contains the correspondance between small windows and original regions in query

  • .i_window which contains the index of the small window on the current region.

Examples

query = GRanges(seqnames = "chr1", ranges = IRanges(start = c(1, 11, 21), end = c(10, 20, 30))) makeWindows(query, w = 2)
#> GRanges object with 15 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-2 * | 1 1 #> [2] chr1 3-4 * | 1 2 #> [3] chr1 5-6 * | 1 3 #> [4] chr1 7-8 * | 1 4 #> [5] chr1 9-10 * | 1 5 #> ... ... ... ... . ... ... #> [11] chr1 21-22 * | 3 1 #> [12] chr1 23-24 * | 3 2 #> [13] chr1 25-26 * | 3 3 #> [14] chr1 27-28 * | 3 4 #> [15] chr1 29-30 * | 3 5 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, w = 0.5)
#> GRanges object with 6 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-5 * | 1 1 #> [2] chr1 6-10 * | 1 2 #> [3] chr1 11-15 * | 2 1 #> [4] chr1 16-20 * | 2 2 #> [5] chr1 21-25 * | 3 1 #> [6] chr1 26-30 * | 3 2 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, w = 3)
#> GRanges object with 9 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-3 * | 1 1 #> [2] chr1 4-6 * | 1 2 #> [3] chr1 7-9 * | 1 3 #> [4] chr1 11-13 * | 2 1 #> [5] chr1 14-16 * | 2 2 #> [6] chr1 17-19 * | 2 3 #> [7] chr1 21-23 * | 3 1 #> [8] chr1 24-26 * | 3 2 #> [9] chr1 27-29 * | 3 3 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, w = 3, direction = "reverse")
#> GRanges object with 9 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 2-4 * | 1 1 #> [2] chr1 5-7 * | 1 2 #> [3] chr1 8-10 * | 1 3 #> [4] chr1 12-14 * | 2 1 #> [5] chr1 15-17 * | 2 2 #> [6] chr1 18-20 * | 2 3 #> [7] chr1 22-24 * | 3 1 #> [8] chr1 25-27 * | 3 2 #> [9] chr1 28-30 * | 3 3 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, w = 3, short.keep = TRUE)
#> GRanges object with 12 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-3 * | 1 1 #> [2] chr1 4-6 * | 1 2 #> [3] chr1 7-9 * | 1 3 #> [4] chr1 10 * | 1 4 #> [5] chr1 11-13 * | 2 1 #> ... ... ... ... . ... ... #> [8] chr1 20 * | 2 4 #> [9] chr1 21-23 * | 3 1 #> [10] chr1 24-26 * | 3 2 #> [11] chr1 27-29 * | 3 3 #> [12] chr1 30 * | 3 4 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, w = 3, direction = "reverse", short.keep = TRUE)
#> GRanges object with 12 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1 * | 1 1 #> [2] chr1 2-4 * | 1 2 #> [3] chr1 5-7 * | 1 3 #> [4] chr1 8-10 * | 1 4 #> [5] chr1 11 * | 2 1 #> ... ... ... ... . ... ... #> [8] chr1 18-20 * | 2 4 #> [9] chr1 21 * | 3 1 #> [10] chr1 22-24 * | 3 2 #> [11] chr1 25-27 * | 3 3 #> [12] chr1 28-30 * | 3 4 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, w = 12)
#> GRanges object with 0 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, w = 12, short.keep = TRUE)
#> GRanges object with 3 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-10 * | 1 1 #> [2] chr1 11-20 * | 2 1 #> [3] chr1 21-30 * | 3 1 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, k = 2)
#> GRanges object with 6 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-5 * | 1 1 #> [2] chr1 6-10 * | 1 2 #> [3] chr1 11-15 * | 2 1 #> [4] chr1 16-20 * | 2 2 #> [5] chr1 21-25 * | 3 1 #> [6] chr1 26-30 * | 3 2 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, k = 3)
#> GRanges object with 9 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-3 * | 1 1 #> [2] chr1 4-6 * | 1 2 #> [3] chr1 7-10 * | 1 3 #> [4] chr1 11-13 * | 2 1 #> [5] chr1 14-16 * | 2 2 #> [6] chr1 17-20 * | 2 3 #> [7] chr1 21-23 * | 3 1 #> [8] chr1 24-26 * | 3 2 #> [9] chr1 27-30 * | 3 3 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
query = GRanges(seqnames = "chr1", ranges = IRanges(start = c(1, 11, 31), end = c(10, 30, 70))) makeWindows(query, w = 2)
#> GRanges object with 35 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-2 * | 1 1 #> [2] chr1 3-4 * | 1 2 #> [3] chr1 5-6 * | 1 3 #> [4] chr1 7-8 * | 1 4 #> [5] chr1 9-10 * | 1 5 #> ... ... ... ... . ... ... #> [31] chr1 61-62 * | 3 16 #> [32] chr1 63-64 * | 3 17 #> [33] chr1 65-66 * | 3 18 #> [34] chr1 67-68 * | 3 19 #> [35] chr1 69-70 * | 3 20 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths
makeWindows(query, w = 0.2)
#> GRanges object with 15 ranges and 2 metadata columns: #> seqnames ranges strand | .i_query .i_window #> <Rle> <IRanges> <Rle> | <integer> <integer> #> [1] chr1 1-2 * | 1 1 #> [2] chr1 3-4 * | 1 2 #> [3] chr1 5-6 * | 1 3 #> [4] chr1 7-8 * | 1 4 #> [5] chr1 9-10 * | 1 5 #> ... ... ... ... . ... ... #> [11] chr1 31-38 * | 3 1 #> [12] chr1 39-46 * | 3 2 #> [13] chr1 47-54 * | 3 3 #> [14] chr1 55-62 * | 3 4 #> [15] chr1 63-70 * | 3 5 #> ------- #> seqinfo: 1 sequence from an unspecified genome; no seqlengths