I have gff files and files containing intergenic regions for different bacterial genomes. I want to extract the adjacent genes and their co-ordinate which corresponding those intergenic regions for all of these genomes. Are there any scripts or tools are available?

Example:

For *Bacillus anthracis*, I have two files:

1. gff file
2. files containing coordinates of intergenic regions:

`intergenic_region.txt`

```
185457-185562
320958-321064
1146951-1147049
1285399-1285500
3894344-3894451
4075706-4075815
```

I want to extract the coordinate of adjacent genes for each of those intergenic regions from gff files.

I have to do such kind of process for 300+ bacterial genomes.
Convert the GFF file to BED with <a href="http://bedops.readthedocs.org/en/latest/content/reference/file-management/conversion/gff2bed.html">BEDOPS *gff2bed*</a>:

    $ gff2bed < annotations.gff > annotations.bed

Convert the intergenic regions to BED. Assuming they are all on chromosome `chr1` and 0-indexed:

    $ awk 'BEGIN { FS = "-"; } { print "chr1\t"$1"\t"$2; }' intergenic_region.txt > intergenic_region.bed

You may need to modify the name used for the chromosome, depending on the naming scheme used in the annotations file. You could browse through the first column of `annotations.bed` to see what the chromosome naming scheme looks like.

Once you have the annotations and intergenic regions in BED format, you can use <a href="http://bedops.readthedocs.org/en/latest/content/reference/set-operations/closest-features.html">BEDOPS *closest-features*</a> to find the nearest annotations to the regions:

    $ closest-features intergenic_region.bed annotations.bed > answer.bed