blib/conf/plugins/RandomGene.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 90 CC 4 SCAR 14.8
CC
4
Cov
0%
annotate
12.0
reconfigure
6.0
name
2.0
CRAP 4.4
1 package Bio::Graphics::Browser2::Plugin::RandomGene;
2 # $Id: RandomGene.pm,v 1.2 2005-12-09 22:19:09 mwz444 Exp $
3 # test plugin
4 use strict;
5 use Bio::Graphics::Browser2::Plugin;
6 use Bio::Graphics::Feature;
7 use CGI qw(:standard *table);
8  
9 use vars '$VERSION','@ISA';
10 $VERSION = '0.3';
11  
12 @ISA = qw(Bio::Graphics::Browser2::Plugin);
13  
14 sub name { "Simulated Genes" }
15  
16 sub description {
17 p("The simulated gene plugin generates random genes",
18 "on the current view.").
19 p("It was written to illustrate how annotation plugins work.");
20 }
21  
22 sub type { 'annotator' }
23  
24 sub init { }
25  
26 sub config_defaults {
27 my $self = shift;
28 return { gene_size => 5_000,
29 exon_size => 100,
30 intron_size => 500,
31 };
32 }
33  
34 sub reconfigure {
35 my $self = shift;
36 my $current_config = $self->configuration;
37 my $defaults = $self->config_defaults;
38  
39 for my $size ('exon_size','intron_size','gene_size') {
40 my $new_size = $self->config_param($size);
41 if ($new_size > 0 and $new_size < 1_000_000) { # sanity check
42 $current_config->{$size} = $new_size;
43 } else { # doesn't pass check, so go to defaults
44 $current_config->{$size} = $defaults->{$size};
45 }
46 }
47  
48 }
49  
50  
51  
52 sub configure_form {
53 my $self = shift;
54 my $current_config = $self->configuration;
55 return
56 "Average length of simulated gene: ".textfield(-name=>$self->config_name('gene_size'),
57 -default=>$current_config->{gene_size}
58 )
59 .br().
60 "Average length of simulated exon: ".textfield(-name=>$self->config_name('exon_size'),
61 -default=>$current_config->{exon_size}
62 )
63 .br().
64 "Average length of simulated intron: ".textfield(-name=>$self->config_name('intron_size'),
65 -default=>$current_config->{intron_size}
66 );
67 }
68  
69 sub annotate {
70 my $self = shift;
71 my $segment = shift;
72 my $dna = $segment->seq;
73  
74 my $abs_start = $segment->start;
75 my $end = $segment->end;
76 my $length = $segment->length;
77  
78 my $exon_size = $self->configuration->{exon_size};
79 my $gene_size = $self->configuration->{gene_size};
80 my $intron_size = $self->configuration->{intron_size};
81  
82 my $feature_list = Bio::Graphics::FeatureFile->new;
83 $feature_list->add_type('gene' => {glyph => 'transcript2',
84 key => 'simulated gene',
85 bgcolor => 'blue',
86 });
87  
88 for (1..5) {
89 my $gene_start = int(rand($length));
90 my $gene_end = $gene_start+int(rand($gene_size));
91 my $strand = rand > 0.5 ? +1 : -1;
92 my $name = sprintf("GMOD%010d",rand(1E6));
93 my $gene = Bio::Graphics::Feature->new(-start=>$abs_start+$gene_start,
94 -end =>$abs_start+$gene_end,
95 -display_name => $name,
96 -type=>'gene',
97 -strand => $strand,
98 -url => "http://www.google.com/search?q=$name",
99 );
100  
101 my $exon_start = $gene_start;
102 my $exon_end;
103 do {
104 $exon_end = $exon_start + int(rand($exon_size));
105 $exon_end = $gene_end if $exon_end > $gene_end;
106  
107 my $exon_feature = Bio::Graphics::Feature->new(-start=>$abs_start+$exon_start,
108 -end =>$abs_start+$exon_end,
109 -type => 'exon',
110 -strand => $strand,
111 );
112 $gene->add_segment($exon_feature);
113 $exon_start = $exon_end + int(rand($intron_size));
114 } until ($exon_end >= $gene_end);
115  
116 $feature_list->add_feature($gene,'gene');
117 }
118  
119 return $feature_list;
120 }
121  
122 1;
123