import re


def fetch_geneid(fn):
    """
    fetch gene id from GTF records
    gene_id "FBgn0267431"; gene_name "Myo81F"; gene_source "FlyBase"; gene_biotype "protein_coding";
    """
    assert isinstance(fn, str)
    ps = fn.split(';')
    dn = {}
    for i in fn.split(';'):
        if len(i) < 8: # shortest field
            continue
        id = i.strip().split(' ')
        id = re.sub('"', '', id[1])
        if 'gene_id' in i:
            dn['gene_id'] = id
        elif 'gene_name' in i:
            dn['gene_name'] = id
        elif 'transcript_id' in i:
            dn['transcript_id'] = id
        elif 'transcript_name' in i:
            dn['transcript_name'] = id
        elif 'exon_id' in i:
            dn['exon_id'] = id
        elif 'gene_biotype' in i:
            dn['gene_biotype'] = id
        else:
            pass
    return dn