Our Sponsors



Download BioinformaticsOnline(BOL) Apps in your chrome browser.




Python script to parse GFF file

  • Public
By LEGE 273 days ago
def parse_gff(gff_file): features = [] with open(gff_file, 'r') as f: for line in f: if not line.startswith('#'): # Ignore comment lines fields = line.strip().split('\t') feature = { 'seqid': fields[0], 'source': fields[1], 'type': fields[2], 'start': int(fields[3]), 'end': int(fields[4]), 'score': fields[5], 'strand': fields[6], 'phase': fields[7], 'attributes': dict(item.split('=') for item in fields[8].split(';')) } features.append(feature) return features # Usage example gff_file = 'example.gff' parsed_features = parse_gff(gff_file) for feature in parsed_features: print(feature)