Shifts start or end of fragments by a fixed amount, which can be useful to correct the Tn5 offset.
Details
The correct Tn5 offset is +/- 4bp since the Tn5 cut sites on opposite strands are offset by 9bp. However, +4/-5 bp is often applied to bed-format files, since the end coordinate in bed files is 1 past the last basepair of the sequenced DNA fragment. This results in a bed-like format except with inclusive end coordinates.
Examples
## Prep data
frags <- tibble::tibble(
chr = "chr1",
start = seq(10, 260, 50),
end = start + 30,
cell_id = paste0("cell1")
) %>% as("GRanges")
frags
#> GRanges object with 6 ranges and 1 metadata column:
#> seqnames ranges strand | cell_id
#> <Rle> <IRanges> <Rle> | <character>
#> [1] chr1 10-40 * | cell1
#> [2] chr1 60-90 * | cell1
#> [3] chr1 110-140 * | cell1
#> [4] chr1 160-190 * | cell1
#> [5] chr1 210-240 * | cell1
#> [6] chr1 260-290 * | cell1
#> -------
#> seqinfo: 1 sequence from an unspecified genome; no seqlengths
frags <- frags %>% convert_to_fragments()
## Shift fragments
shift_fragments(frags, shift_start = 4, shift_end = -4) %>% as("GRanges")
#> GRanges object with 6 ranges and 1 metadata column:
#> seqnames ranges strand | cell_id
#> <Rle> <IRanges> <Rle> | <factor>
#> [1] chr1 14-36 * | cell1
#> [2] chr1 64-86 * | cell1
#> [3] chr1 114-136 * | cell1
#> [4] chr1 164-186 * | cell1
#> [5] chr1 214-236 * | cell1
#> [6] chr1 264-286 * | cell1
#> -------
#> seqinfo: 1 sequence from an unspecified genome; no seqlengths