daler / gffutils

GFF and GTF file manipulation and interconversion
http://daler.github.io/gffutils
MIT License
282 stars 76 forks source link

How to get closest features? #226

Closed YeHW closed 3 months ago

YeHW commented 4 months ago

After creating the db, I want to query the closest features given a location (seq: pos). I found that there was a test related to this but seemed to be only in a previous version: https://github.com/daler/gffutils/blob/955fb41a32022e11683a873a7bdc78444d5628cc/gffutils/test/from-prev-version#L415

Is there a similar API for this purpose in the current version? Thanks!

daler commented 3 months ago

I believe this was originally added before the pybedtools_integration module. For getting the closest features, nowadays I would use pybedtools/bedtools directly on the original GTF/GFF file (e.g., bedtools closest). I didn't want to start down the rabbit hole of implementing all of the bedtools operations on the db!

If you wanted to restrict the features going into bedtools/pybedtools, you can extract the locus of interest from the db and convert that into a subsetted GTF file to feed to bedtools/pybedtools. Alternatively, bypassing gffutils altogether you could make a single-feature bed file with your region of interest and intersect that with the full GTF to get a subset.