forked from vikas0633/perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
augustus_to_GFF3.pl
78 lines (49 loc) · 1.47 KB
/
augustus_to_GFF3.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib ("$FindBin::Bin/../../PerlLib");
use Gene_obj;
my $model_type = "Augustus";
my $usage = "usage: $0 augustus.gff.output\n\n";
my $input_file = $ARGV[0] or die $usage;
main: {
my %data;
my $scaffold = "";
## parse input file
open (my $fh, $input_file) or die "Error, cannot open file $input_file";
while (<$fh>) {
if (/^\#/) { next; }
chomp;
unless (/\w/) { next; }
my @x = split(/\t/);
if ($x[2] eq 'CDS') {
my $scaffold = $x[0];
my $orient = $x[6];
my $lend = $x[3];
my $rend = $x[4];
my ($end5, $end3) = ($orient eq '+') ? ($lend, $rend) : ($rend, $lend);
my $info = $x[8];
$info =~ /Parent=(\S+)/;
my $model = $1 or die "Error, canno tparse model from $info";
$data{$scaffold}->{$model}->{$end5} = $end3;
}
}
close $fh;
## Generate gff3 output
foreach my $scaffold (keys %data) {
my $models_href = $data{$scaffold};
foreach my $model (keys %$models_href) {
my $coords_href = $models_href->{$model};
my $gene_obj = new Gene_obj();
$gene_obj->populate_gene_object($coords_href, $coords_href);
$gene_obj->{asmbl_id} = $scaffold;
$gene_obj->{TU_feat_name} = "gene.$model";
$gene_obj->{Model_feat_name} = "model.$model";
$gene_obj->{com_name} = "$model_type prediction";
print $gene_obj->to_GFF3_format(source => $model_type) . "\n";
# print $gene_obj->toString() . "\n\n";
}
}
exit(0);
}