Skip to content
Laurent Jourdren edited this page Mar 26, 2015 · 2 revisions

Reading and writing files with GFF3 data

WARNING: This documentation is outdated and will soon be updated.

Introduction

GFF3 files are read with the GFFReader class and written with the GFFWriter class.

Read a GFF3 file

As the GFFReader extends the Iterable and Iterator interface, it is quite easy to read the entries of a GFF3 file using a for loop:


GFFReader reader = new GFFReader(new File("annotation.gff");

for (GFFEntry entry : reader) {
  System.out.println(entry);
}
// Throw an exception if an error has occurred while reading data
reader.throwException();

reader.close();

Write a GFF3 file

Writing a GFF3 file is also very easy, you just have to create the GFFWriter and call the write(GFFEntry) method to add the sequences to the file. Don't forget to close the file after adding the last sequence of the file.


GFFEntry gffEntry = new GFFEntry();


GFFWriter writer = new GFFWriter(new File("annotation.gff"); 

gffEntry.parsing("ctg123\t.\tgene\t1000\t9000\t.\t+\t.\tID=gene00001;Name=EDEN")
writer.write(gffEntry);

gffEntry.parsing("ctg123\t.\tTF_binding_site\t1000\t1012\t.\t+\t.\t ID=tfbs00001;Parent=gene00001")
writer.write(gffEntry);

writer.close();