forked from gustavo11/GFFLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgff_sort.pl
executable file
·49 lines (29 loc) · 1 KB
/
gff_sort.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/env perl
# Sort GFF file based on the numerical part of contig/scaffolds names
# and then by the start coord. of genes
use strict;
use FindBin;
use lib "$FindBin::Bin";
use GFFFile;
my $usage =
"gff_sort.pl <GFF file> <output: sorted GFF file>\n\n";
die $usage if scalar(@ARGV) != 2;
my $in_gff = $ARGV[0];
my $out_gff = $ARGV[1];
my $gffFile = GFFFile::new($in_gff);
$gffFile->read();
my $gffGenes = $gffFile->get_genes_hash();
# Ordering genes based on template name and start coord
my @gffGenesArray = values %{$gffGenes};
# Sort by the numerical part of chrom and then start coord of gene
@gffGenesArray =
sort {
my ($a_num_chrom) = ( $a->get_chrom() =~ /(\d+)/ );
my ($b_num_chrom) = ( $b->get_chrom() =~ /(\d+)/ );
return $a_num_chrom <=> $b_num_chrom || $a->get_start() <=> $b->get_start() }
@gffGenesArray;
open OUT, ">$out_gff" or die "Unable to write on file $out_gff\n";
for my $currGene (@gffGenesArray) {
print OUT $currGene->toGFF();
}
close(OUT);