This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extracting Sequences from a FASTA File Using Exon Coordinates from a GTF File

I have a .gtf file containing exon coordinates for all chromosomes of a species and a corresponding .fa file. I need to extract the correct sequences from the FASTA file based on the exon start and end positions provided in the .gtf file.

Can anyone suggest the best way to do this? Are there any existing tools or scripts that can help with this process?

gtf fasta

3 answers

awk -F '\t' '($3=="exon") {printf("%s\t%d\t%s\n",$1,int($4)-1,$5);}' in.gtf | sort | uniq > exons.bed

bedtools getfasta -fi ref.fa -bed exons.bed

Could also consider using the AGAT tool kit . (specifically the extract_sequences sub part)

gffread is a decent option here. I'd choose that over custom awk scripts for speed and consistency. https://github.com/gpertea/gffread

Log in to answer this question.