awk script

Hi,

I wrote an awk script to compare intervals between two files

awk 'FNR==NR {a[$1]; next} $1 in a'

My input files I am comparing for overlaps are arranged like this:

chr1    23110    23140 
chr1    23120    23371    MIR    SINE/MIR

But my script only gives the overlap of one file over the other.
What do I have to do to get an output like this:

chr1    23110    23140  chr1    23120    23371    MIR  SINE/MIR

regards.

Hi,
The input files are attached

---------- Post updated at 10:43 AM ---------- Previous update was at 10:42 AM ----------

Hi,

I am trying to find out overlapping regions in two given files, so I wrote a awk script

 awk 'FNR==NR {a[$1]; next} $1 in a' 

My first input file is arranged like this:

 
chr7 751143 766356
chr7 825291 826114
chr7 826118 857092
chr7 912969 916281
chr7 935060 938556
chr7 995044 1009012
chr7 1015146 1022846
chr7 1028459 1037259

and the second input file like this:

 
chr1 10001 10468 (CCCTAA)n Simple_repeat
chr1 10469 11447 TAR1 Satellite/telo
chr1 11505 11675 L1MC5a LINE/L1
chr1 11678 11780 MER5B DNA/hAT-Charlie
chr1 15265 15355 MIR3 SINE/MIR
chr1 16713 16749 (TGG)n Simple_repeat
chr1 18907 19048 L2a LINE/L2
chr1 19972 20405 L3 LINE/CR1
chr1 20531 20679 Plat_L3 LINE/CR1

If I want to find out the overlapping regions between the two files having an output like this which contains elements from the first and the second file :

chr7 751143 766356 chr7 751143 766356 MIR3 SINE/MIR

How should I write the script ?
The output is just an example I have given to illustrate the overlaps between two files

Hello genebuster,

Kindly use code tags while using commands/codes in your posts. Not clear still, could you please let me know what is the common attribute between 2 files which we will take and start making our code? Also let us know on what basis you want output too?

Thanks,
R. Singh

This is already implemented in the bedtools package, see tutorials below...

Bedtools intersect

I'm sorry, I can't see any overlap between the numbers in the two files nor can I see how the desired output is obtained...