simplest conversion of gff to jalview annotation format files.
authorjprocter <Jim Procter>
Thu, 8 Jun 2006 13:56:37 +0000 (13:56 +0000)
committerjprocter <Jim Procter>
Thu, 8 Jun 2006 13:56:37 +0000 (13:56 +0000)
utils/gff2annot.pl [new file with mode: 0755]

diff --git a/utils/gff2annot.pl b/utils/gff2annot.pl
new file mode 100755 (executable)
index 0000000..f144df1
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my %annotLines;
+
+my @fields;
+while (<>) {
+    my @fields = split /\s+/, $_;
+    if (scalar @fields) {
+        (defined $annotLines{$fields[1]}) or $annotLines{$fields[1]}=[];
+        my $line = [$fields[2],$fields[0], "ID_NOT_SPECIFIED", $fields[3], $fields[4], $fields[2]];
+        my $attribs = {};
+        if (scalar @fields>5) {
+            $attribs->{"gff:score"}=$fields[5];
+            (scalar @fields>6) and $attribs->{"gff:strand"}=$fields[6];
+            (scalar @fields>7) and $attribs->{"gff:frame"}=$fields[7];
+            if (scalar @fields>8) {
+                for (my $i=7; ($i+1)<(scalar @fields); $i+=2) {
+                    $attribs->{"gff:".$fields[$i]} = $fields[$i+1];
+                }
+            }
+        }
+        push @{$annotLines{$fields[1]}}, [$line, $attribs];
+    }
+}
+
+foreach my $labels (keys %annotLines) {
+    print "startgroup\t".$labels."\n";
+    foreach my $annot (@{$annotLines{$labels}}) {
+        print "".(join "\t",@{$annot->[0]})."\n";
+    }
+    print "endgroup\t".$labels."\n";
+}