Bedtools intersect with index
Hello everyone, I wonder are there any ways that bedtools intersect can display index of the matched pairs. For example: a.bed
chr1 10 20
chr1 30 40
chr1 50 80
b.bed
chr1 12 15
chr1 16 19
chr1 22 27
chr1 31 37
The results:
chr1 10 20 chr1 12 15 1 <- here is the index of the corresponding line index in b.bed file
chr1 10 20 chr1 16 19 2
chr1 30 40 chr1 31 37 4
Your help is really appreciated!
• 1,780 views
•
link
1 answer
Via BEDOPS bedmap:
$ bedmap --echo --echo-map --delim '\t' a.bed <(awk '{ print $0"\t"NR }' b.bed) > answer.bed
Just make sure your BED files are sorted per BEDOPS sort-bed. Hope this helps!
• 1 views
•
link
Log in to answer this question.