Question: intersection of two files
0
gravatar for a.rex
2.4 years ago by
a.rex180
a.rex180 wrote:

Is there an efficient way of joining two files in the following way - i.e. using BedTools?

For example, FILE 1:

scaffold1          0        206        transcript_loc.00001      exon    
scaffold1         262      749       transcript_loc.00001      exon    
scaffold1         1391    1549     transcript_loc.00001      exon

FILE2:

scaffold1        517     540     Simple_repeat   
scaffold1        1063    1162    LTR/Gypsy        
scaffold1        1400     1498   LTR

Resultant file:

 scaffold1          0        206        transcript_loc.00001      exon    
 scaffold1         262      749       transcript_loc.00001      exon          517     540     Simple_repeat   
 scaffold1         1391    1549     transcript_loc.00001      exon          1400     1498   LTR

In this way, wherever the two files intersect, the intersection is appended to a new column on the first file. The non-intersect is discarded.

Many thanks.

bedtools • 736 views
ADD COMMENTlink modified 2.4 years ago by Alex Reynolds28k • written 2.4 years ago by a.rex180
2

This can be done with intersectBed option from BedTools. Check wa, wb, wo options. Before using bedtools change your file formats to actual BED format.

ADD REPLYlink written 2.4 years ago by venu6.1k
3
gravatar for Alex Reynolds
2.4 years ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

Sure, you can use BEDOPS bedmap to map overlaps in one file to elements in another file:

$ bedmap --echo --echo-map --delim '\t' file1.bed file2.bed > answer.bed

So long as your files are sorted, they are BED and can be used as-is. If not:

$ sort-bed file1.unsorted.bed > file1.bed
$ sort-bed file2.unsorted.bed > file2.bed

Then use bedmap, as described.

If you want to discard rows without overlaps between the first and second inputs, add the --skip-unmapped option:

$ bedmap --echo --echo-map --delim '\t' --skip-unmapped file1.bed file2.bed > answer.bed
ADD COMMENTlink modified 2.3 years ago • written 2.4 years ago by Alex Reynolds28k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1888 users visited in the last hour