1
$\begingroup$

I have two files of genomic coordinates. I am trying to output only the overlapping region of fileA if it intersects with fileB. Not the original fileA coordinates.

fileA

chr1 25 50
chr1 75 200

fileB

chr1 10 60
chr1 80 90

desired output

chr1 25 50
chr1 80 90
$\endgroup$
1
  • $\begingroup$ Please provide a small reproducible example using dput so we can help you. All you need to do is run dput(fileA) in R and, paste the output in the terminal. $\endgroup$
    – h3ab74
    Jul 9 '19 at 20:33
3
$\begingroup$

bedtools is my go-to program for operations on genomic intervals. In particular, the bedtools intersect operation is what you're looking for here.

$ cat fileA
chr1    25      50
chr1    75      200
$ cat fileB
chr1    10      60
chr1    80      90
$ bedtools intersect -a fileA -b fileB                                                           
chr1    25      50
chr1    80      90

Make sure that the values are separated by tabs rather than spaces, or bedtools will have trouble reading the files.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.