public static Genome buildGenome(String gtffilename,
                                     String compartmentPrefix, int resolution) {

        Genome genome = new Genome(ChromatinLocation.NUM_CHROMOSOMES,
                                   compartmentPrefix, resolution);

        System.out.println("Building genome from GTF");

        // Open file for read
        int lines = 0;
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(gtffilename));

            HashMap<String, Gene> genes = new HashMap<String, Gene>();

            // For each line
            String line = null;
            while ((line = reader.readLine()) != null) {
                // Parse the GTF line
                String[] parts = line.split("\t");
                if (parts.length == 9) {

                    // Get gene name
                    String geneName = getGeneNameFromAnnotation(parts[8]);
                    long start = Long.parseLong(parts[3]);
                    long end = Long.parseLong(parts[4]);

                    if (geneName != null) {

                        // Check if we've seen this gene before
                        Gene newGene = genes.get(geneName);
                        if (newGene == null) {
                            // Create a new gene
                            int chromosome = parseChromosome(parts[0]);
                            String classification = parts[1];

                            if (chromosome != 0) {
                                newGene = new Gene(chromosome, geneName,
                                                   classification);
                                // Set start and end
                                newGene.setStart(start);
                                newGene.setEnd(end);

                                genes.put(geneName, newGene);
                                genome.getChromosome(chromosome)
                                      .addGene(start, newGene);
                            }
                        } else {
                            if (newGene.getStart() > start) {
                                newGene.setStart(start);
                            }
                            if (newGene.getEnd() < end) {
                                newGene.setEnd(end);
                            }
                        }
                    }

                } else {
                    System.err.println("Error reading GTF line " + lines
                                       + ": not enough fields");
                }
                lines++;
            }
            System.out.println("Completed Genome parsing: " + lines + " -> "
                               + genes.size());
            // Close the file
            reader.close();
        } catch (FileNotFoundException e1) {
            System.err.println("Failed to find GTF file: " + gtffilename);
        } catch (IOException e) {
            System.err.println("Got stuck while trying to read GTF file @line "
                               + lines);
        }

        return genome;
    }