Matching column and search closest elements

Hi all
I have a great challenge 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 (cloumn 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 match).
Moreover i would like to take in consideration only the element in file two in which the 4th column is "yes"(or at least I can have the possibility to decide this parameter) and the 5th column match with the entry in file1(or also in this case I have the possibility to decide this).

The output file for the example above should be (if I have 4th columns muast matches) 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 and, for example for entry1, that the closest feature "yes" is the second met.

I really hope that my explanation wa good.

If you need furthr information let me know.

What have you tried so far?

I am not really able neither to try something like that!
:frowning: