Question: Output The Overlapping Regions To New File
0
gravatar for raj.karthik437
5.3 years ago by
raj.karthik43740 wrote:

Hi i have 2 files file1

contig1 10037203    10038203    blah
contig1    10037203    10038203    blah
contig1    10037203    10038203    blah

file2

contig1    997329    938329    blab11
contig1    10037329    10038329    blah11
contig1    10037329    10038329    blah11

i want to get my output as below

contig1 10037203    10038203    blah
contig1    10037203    10038203    blah
contig1    10037203    10038203    blah
contig1    10037329    10038329    blah11
contig1    10037329    10038329    blah11

i,e., if the overlap exists first output all the overlapping ones of file1 and then of file2 . can anybody help me know how to do that

bed • 1.4k views
ADD COMMENTlink modified 5.3 years ago by sjneph600 • written 5.3 years ago by raj.karthik43740
2

http://bedtools.readthedocs.org/en/latest/content/example-usage.html

ADD REPLYlink written 5.3 years ago by Pierre Lindenbaum120k
2

no pierre i have already checked with bedtools. it gives nn lines i dont want that. for eg if 3 lines in file 1 overlap with 2 lines in file 2 the output that bedtools produce is 32=6 lines but i want only 5 3 from firstfile followed by 2 from second

ADD REPLYlink modified 5.3 years ago • written 5.3 years ago by raj.karthik43740
1

You just need to modify the options, -w -a -o to get what you need.

ADD REPLYlink written 5.3 years ago by Vivek2.2k
2
gravatar for sjneph
5.3 years ago by
sjneph600
sjneph600 wrote:
sort-bed file1 > file1.sorted
sort-bed file2 > file2.sorted
bedops -e -1 file1.sorted file2.sorted > answer.bed    
bedops -e -1 file2.sorted file1.sorted >> answer.bed

The answer.bed file will not be sorted per sort-bed since you catted on the results. If you want to maintain sorted order, then change the final line above to:

bedops -e -1 file2.sorted file1.sorted | bedops -u - answer.bed > final.answer.bed
ADD COMMENTlink modified 5.3 years ago by Alex Reynolds28k • written 5.3 years ago by sjneph600
2

Thank you very much it worked

ADD REPLYlink written 5.3 years ago by raj.karthik43740
0
gravatar for Alex Reynolds
5.3 years ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

Use BEDOPS bedmap and bedops set operations for this problem:

$ sort-bed file1 > file1.sorted
$ sort-bed file2 > file2.sorted
$ bedmap --echo-map file1.sorted file2.sorted > 2_overlapped_by_1
$ bedmap --echo-map file2.sorted file1.sorted > 1_overlapped_by_2
$ bedops --everything 1_overlapped_by_2 2_overlapped_by_1 > answer.bed
ADD COMMENTlink modified 5.3 years ago • written 5.3 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: 2286 users visited in the last hour