blib/conf/plugins/GeneFinder.pm untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 14 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 149 CC 15 SCAR 47.6
CC
15
Cov
0%
annotate
240.0
name
2.0
description
2.0
CRAP 117.2
1 package Bio::Graphics::Browser2::Plugin::GeneFinder;
2  
3 # $Id: GeneFinder.pm,v 1.3 2005-12-09 22:19:09 mwz444 Exp $
4 # test plugin
5 use strict;
6 use File::Temp 'tempfile';
7 use File::Spec;
8 use Bio::Graphics::Browser2::Plugin;
9 use Bio::SeqFeature::Generic;
10 use CGI qw(:standard *table);
11  
12 use vars '$VERSION','@ISA';
13 $VERSION = '0.2';
14  
15 use constant GENEFINDER => 'gfcode'; # must be in the path somewhere
16 use constant GFTABLES => 'gftables'; # must be in the gbrowse.conf directory
17  
18 @ISA = qw(Bio::Graphics::Browser2::Plugin);
19  
20 sub name { "GeneFinder Features" }
21  
22 sub description {
23 p("This plugin is a front end to Phil Green's GeneFinder program.").
24 p("It is an early work in progress.").
25 p("Please build and install the 'gfcode' program (located in the contrib directory) before using this plugin.");
26 }
27  
28 sub type { 'annotator' }
29  
30 sub init { }
31  
32 sub config_defaults {
33 my $self = shift;
34 return { };
35 }
36  
37 sub reconfigure {
38 my $self = shift;
39 return;
40 }
41  
42  
43  
44 sub configure_form {
45 my $self = shift;
46 return;
47 }
48  
49 sub annotate {
50 my $self = shift;
51 my $segment = shift;
52 my $dna = $segment->seq;
53 my $abs_start = $segment->start;
54  
55 # write DNA out into a tempfile
56 my ($fh,$filename) = tempfile('gfXXXXXXX',
57 SUFFIX => '.fa',
58 UNLINK => 1,
59 DIR => File::Spec->tmpdir,
60 );
61 print $fh ">segment\n";
62 print $fh $dna;
63 close $fh;
64  
65 my $gftables = File::Spec->catfile($self->config_path(),GFTABLES);
66 my $command = join ' ',GENEFINDER,$gftables,$filename;
67  
68 open (F,"$command |") or die "Couldn't open genefinder. Did you install the gfcode program and the gftables config file?: $!";
69 my $atgheight = sub {
70 my $f = shift;
71 return int($f->score/5 * 20);
72 };
73  
74 my $atgtop = sub {
75 return (20-$atgheight->(@_));
76 };
77  
78 my $feature_list = Bio::Graphics::FeatureFile->new;
79 $feature_list->add_type(splice => {glyph => 'splice_site',
80 key => 'GF splice acceptor/donor',
81 bump => 0,
82 direction => sub {
83 my $f = shift;
84 my $method = $f->primary_tag;
85 return 'right' if $method eq 'splice5';
86 return 'left' if $method eq 'splice3';
87 },
88 height => 30,
89 height_fraction => sub {
90 my $f = shift;
91 my $score = abs($f->score);
92 $score = 4 if $score > 4;
93 return $score/4;
94 },
95 fgcolor => sub {
96 my $f = shift;
97 my $method = $f->primary_tag;
98 return 'red' if $method eq 'splice5';
99 return 'blue' if $method eq 'splice3';
100 }
101 }
102 );
103 $feature_list->add_type(startplus => {glyph => 'generic',
104 key => 'GF start site (+)',
105 height => $atgheight,
106 pad_top => $atgtop,
107 bump => 0,
108 bgcolor => 'red',
109 fgcolor => 'red'}
110 );
111 $feature_list->add_type(codingplus => {glyph => 'generic',
112 key => 'GF coding segment (+)',
113 strand_arrow => 1,
114 bgcolor => 'yellow'});
115 $feature_list->add_type(startminus => {glyph => 'generic',
116 key => 'GF start site (-)',
117 bump => 0,
118 height => $atgheight,
119 pad_top => $atgtop,
120 bgcolor => 'blue',
121 fgcolor => 'blue'}
122 );
123 $feature_list->add_type(codingminus => {glyph => 'generic',
124 key => 'GF coding segment (-)',
125 strand_arrow => 1,
126 bgcolor => 'yellow'});
127  
128 while (<F>) {
129 next if /^\#/;
130 my (undef,$source,$method,$start,$end,$score,$strand) = split "\t";
131 next unless defined $method;
132 my $type = $method =~ /splice/ ? 'splice'
133 : $method eq 'atg' && $strand eq '+' ? 'startplus'
134 : $method eq 'atg' && $strand eq '-' ? 'startminus'
135 : $method =~ /coding/ && $strand eq '+' ? 'codingplus'
136 : $method =~ /coding/ && $strand eq '-' ? 'codingminus'
137 : '';
138 next unless $type;
139 my $f = Bio::SeqFeature::Generic->new(-start => $abs_start + $start,
140 -end => $abs_start + $end,
141 -strand => $strand eq '-' ? -1 : +1,
142 -source => $source,
143 -score => $score,
144 -primary=> $method);
145 $feature_list->add_feature($f,$type);
146 }
147 close F;
148  
149 return $feature_list;
150 }
151  
152 1;
153