This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Comparison between two files with chromosomes and positions

Hi I am trying to compare two files with chromosome numbers and positions.

For example;

File 1:

I 1000 
I 9009
I 187902

File 2:

I 1080
I 8995
II 578022

I would like to check if the positions of file1 are present in file2 in and around the range of +/- 100 bases and add a third column with "YES/NO".

I tried using awk but i am able to only compare the exact positions.

My output file should look like

I 1080 Yes 
I 8995 Yes
II 578022 No

Any help would be appreciated. Thanks in advance.

awk

1 answer

convert both file to bed using awk, and sort on chrom/pos e.g.:

awk '{X=100;P=int($2);printf("%s\t%d\t%d\t%s\n",$1,(P<X?0:P-X),P+X,$0);}' input.txt | sort -t $'\t' -k1,1 -k2,2n > sorted1.bed

and then find the intersection using bedtools intersect

Log in to answer this question.