Hi Everyone,

I have the data from a ChIP-Seq experiment. I used EDD to call the domains. I am interested in knowing out what genes are present just a few bp outside of the domains. I extended each of the peaks in the bed file I got from edd by 250 bp on both ends using bedtools slop. But what I need now is two rows for each feature of length 500bp centered around the ends. For instance, 

Input

    chr1    1000  2000
    chr1     2500 3500

Output

    chr1   750    1250
    chr1   1750   2250
    chr1    2250  2750
    chr1    3250  3750

Using bedtools slop to extend and subtracting the old bed file from new file with extended coordinates will give me the 250bp region exactly outside the two ends of the peak. But I want the ends of the peak to be in the centre. How can I do that ?

Thanks
A bed file is just a table, so you can do this quickly in R or the language of your choice.

    shiftPosition <- function(record, size){
    first <- c(record[1], as.numeric(record[2]) - size, as.numeric(record[2]) + size)
    second <- c(record[1], as.numeric(record[3]) - size, as.numeric(record[3]) + size)
    result <- c(first, second)
    return(result)
    }
    
    bed <- read.table("your_bed_file.bed", header=FALSE, stringsAsFactors=FALSE)
    
    final <- data.frame(matrix(apply(bed, 1, shiftPosition, 250), ncol=3, byrow=TRUE))

    write.table(final, file="your_new_bed.bed", quote=FALSE, row.names=FALSE, col.names=FALSE)

This converts

        V1      V2      V3
    1 chr1 3680371 3681212
    2 chr1 4344252 4350391
    3 chr1 4351710 4353125
    4 chr1 4491516 4493706
    5 chr1 4773006 4777948

to 

    1  chr1 3680121 3680621
    2  chr1 3680962 3681462
    3  chr1 4344002 4344502
    4  chr1 4350141 4350641
    5  chr1 4351460 4351960
    6  chr1 4352875 4353375
    7  chr1 4491266 4491766
    8  chr1 4493456 4493956
    9  chr1 4772756 4773256
    10 chr1 4777698 4778198

