simplest conversion of gff to jalview annotation format files.
[jalview.git] / utils / gff2annot.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my %annotLines;
7
8 my @fields;
9 while (<>) {
10     my @fields = split /\s+/, $_;
11     if (scalar @fields) {
12         (defined $annotLines{$fields[1]}) or $annotLines{$fields[1]}=[];
13         my $line = [$fields[2],$fields[0], "ID_NOT_SPECIFIED", $fields[3], $fields[4], $fields[2]];
14         my $attribs = {};
15         if (scalar @fields>5) {
16             $attribs->{"gff:score"}=$fields[5];
17             (scalar @fields>6) and $attribs->{"gff:strand"}=$fields[6];
18             (scalar @fields>7) and $attribs->{"gff:frame"}=$fields[7];
19             if (scalar @fields>8) {
20                 for (my $i=7; ($i+1)<(scalar @fields); $i+=2) {
21                     $attribs->{"gff:".$fields[$i]} = $fields[$i+1];
22                 }
23             }
24         }
25         push @{$annotLines{$fields[1]}}, [$line, $attribs];
26     }
27 }
28
29 foreach my $labels (keys %annotLines) {
30     print "startgroup\t".$labels."\n";
31     foreach my $annot (@{$annotLines{$labels}}) {
32         print "".(join "\t",@{$annot->[0]})."\n";
33     }
34     print "endgroup\t".$labels."\n";
35 }