I am new on this forum and I have a problem that I am not able to resolve.
Briefly, I have a file like this:
ID_1 chr1 100 -
ID_2 chr2 300 +
and another file like this:
name_1 chr1 150 no -
name_2 chr1 250 yes -
name_3 chr2 350 yes +
name_4 chr2 280 yes +
Well, for each entry in file1 I would like to find the closest (considering column 3) feature in file2.
So, for instance for entry1 in file1, I would like to check in file2 which is the element that is closest to "chr1 100" (the second column must matchand the 3th column must be the closest).
Moreover i would like to take in consideration only the elements in file2 in which the 4th column is "yes"(or at least I can have the possibility to decide this parameter) and the 5th column must match with the entry in file1(or also in this case I should have the possibility to decide this).
The output file for the example above should be (if I have 4th columns must match) like this:
ID_1 chr1 100 - name2 chr1 250 yes - 150 2
ID_2 chr2 300 + name4 chr2 280 yes + -20 1
So I would like to output all entry in file1 with the closest feature in file2 and report (last 2 column) the distance between column 3 (taken from the 2 files) and, for example for entry1, that the closest feature (reported) "yes" is the second met.
I really hope that my explanation wa good.
If you need further information let me know.