-
Notifications
You must be signed in to change notification settings - Fork 5
/
SNAP_to_GFF3.pl
74 lines (48 loc) · 1.35 KB
/
SNAP_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
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib ("$FindBin::Bin/../../PerlLib");
use Gene_obj;
my $model_type = "SNAP";
my $usage = "usage: $0 SNAP.output\n\n";
my $input_file = $ARGV[0] or die $usage;
main: {
my %data;
## parse input file
open (my $fh, $input_file) or die "Error, cannot open file $input_file";
while (<$fh>) {
chomp;
if (/^\#/) {
next;
}
my @x = split(/\s+/);
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[7];
$info =~ /Name=(\S+)/;
my $model = $1 or die "Error, cannot parse 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";
}
}
exit(0);
}