blib/conf/plugins/CMapDumper.pm untested

filter: Statementstmt 0.0% 0 / 105 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 152 CC 11 SCAR 31.3
CC
11
Cov
0%
dump
56.0
mime_type
20.0
print_feature_row
6.0
CRAP 22.8
1 package Bio::Graphics::Browser2::Plugin::CMapDumper;
2  
3 # $Id: CMapDumper.pm,v 1.2 2005-12-09 22:19:09 mwz444 Exp $
4 use strict;
5 use Bio::Graphics::Browser2::Plugin;
6 use CGI qw(:standard *sup);
7  
8 use vars '$VERSION', '@ISA';
9 $VERSION = '0.80';
10  
11 @ISA = qw/ Bio::Graphics::Browser2::Plugin /;
12  
13 sub name { "CMap File" }
14  
15 sub description {
16 p("Dumps a CMap readable file.");
17 }
18  
19 sub config_defaults {
20 my $self = shift;
21 return {
22 version => 2,
23 mode => 'selected',
24 disposition => 'view',
25 coords => 'absolute',
26 };
27 }
28  
29 sub reconfigure {
30 my $self = shift;
31 my $current_config = $self->configuration;
32 delete $current_config->{embed};
33 foreach my $p ( $self->config_param() ) {
34 $current_config->{$p} = $self->config_param($p);
35 }
36 }
37  
38 sub configure_form {
39 my $self = shift;
40 my $current_config = $self->configuration;
41 my $html;
42 $html .= p(
43 'Coordinates',
44 radio_group(
45 -name => $self->config_name('coords'),
46 -values => [ 'absolute', 'relative' ],
47 -labels => {
48 absolute => 'relative to chromosome/contig/clone',
49 relative => 'relative to dumped segment (start at 1)'
50 },
51 -default => $current_config->{coords},
52 -override => 1
53 )
54 );
55 autoEscape(0);
56 $html .= p(
57 radio_group(
58 -name => $self->config_name('disposition'),
59 -values => [ 'view', 'save', 'edit' ],
60 -labels => {
61 view => 'View',
62 save => 'Save to File',
63 edit => 'Edit' . sup('**'),
64 }
65 )
66 );
67 $html .= p(
68 'Where should the feature type be taken from (suggested: Method)?',
69 radio_group(
70 -name => $self->config_name('feature_type_source'),
71 -values => [ 'method', 'source' ],
72 -labels => {
73 method => 'Method',
74 source => 'Source',
75 }
76 )
77 );
78 autoEscape(1);
79  
80 $html .= p(
81 sup('*'),
82 "To edit, install a helper application for MIME type",
83 cite('application/x-cmap'),
84 );
85 $html;
86 }
87  
88 sub mime_type {
89 my $self = shift;
90 my $config = $self->configuration;
91 my $ps = $self->page_settings;
92 my $base = join '_', @{$ps}{qw(ref start stop)};
93 return $config->{disposition} eq 'view' ? 'text/plain'
94 : $config->{disposition} eq 'save'
95 ? ( 'application/octet-stream', "$base" )
96 : $config->{disposition} eq 'edit' ? "application/x-cmap"
97 : 'text/plain';
98 }
99  
100 sub dump {
101 my $self = shift;
102 my ( $segment, @more_feature_sets ) = @_;
103 my $page_settings = $self->page_settings;
104 my $conf = $self->browser_config;
105 my $config = $self->configuration;
106 my $version = $config->{version} || 2;
107 my $mode = $config->{mode} || 'selected';
108 my $db = $self->database;
109 my $whole_segment = $db->segment( Accession => $segment->ref )
110 || $db->segment( $segment->ref );
111 my $ft_source = $config->{feature_type_source};
112 my $coords = $config->{coords};
113 my $embed = $config->{embed};
114  
115 $segment->refseq($segment) if $coords eq 'relative';
116  
117 print join( "\t",
118 'map_name', 'map_start',
119 'map_stop', 'feature_name',
120 'feature_start', 'feature_stop',
121 'feature_direction', 'feature_type_accession' )
122 . "\n";
123  
124 my @args;
125 if ( $mode eq 'selected' ) {
126 my @feature_types = $self->selected_features;
127 @args = ( -types => \@feature_types );
128 }
129  
130 my @feats = ();
131  
132 my $ref_name = $segment->{'sourceseq'};
133 my $ref_start = $segment->start;
134 my $ref_stop = $segment->stop;
135 my $offset = $segment->start - $segment->abs_start;
136 my (
137 $feature_name, $feature_start, $feature_stop,
138 $strand_str, $feature_type
139 );
140 my $iterator = $segment->get_seq_stream(@args);
141  
142 while ( my $f = $iterator->next_seq ) {
143 $feature_name = $f->{'group'}->name;
144 $feature_start = $f->{'start'} + $offset;
145 $feature_stop = $f->{'stop'} + $offset;
146 $strand_str = $f->{'fstrand'};
147 if ( $ft_source eq 'source' ) {
148 $feature_type = $f->{'type'}->source();
149 }
150 else {
151 $feature_type = $f->{'type'}->method();
152 }
153  
154 $self->print_feature_row(
155 map_name => $ref_name,
156 map_start => $ref_start,
157 map_stop => $ref_stop,
158 feature_name => $feature_name,
159 feature_stop => $feature_stop,
160 feature_start => $feature_start,
161 strand_value => $strand_str,
162 feature_type_aid => $feature_type,
163 );
164  
165 for my $set (@more_feature_sets) {
166 if ( $set->can('get_seq_stream') ) {
167 my @feats = ();
168 my $iterator = $set->get_seq_stream;
169 while ( my $f = $iterator->next_seq ) {
170 $feature_name = $f->{'group'}->name;
171 $feature_start = $f->{'start'} + $offset;
172 $feature_stop = $f->{'stop'} + $offset;
173 $strand_str = $f->{'fstrand'};
174 $feature_type = $f->{'type'}->method();
175  
176 $self->print_feature_row(
177 map_name => $ref_name,
178 map_start => $ref_start,
179 map_stop => $ref_stop,
180 feature_name => $feature_name,
181 feature_stop => $feature_stop,
182 feature_start => $feature_start,
183 strand_value => $strand_str,
184 feature_type_aid => $feature_type,
185 );
186 }
187 }
188 }
189 }
190  
191 if ($embed) {
192 my $dna = $segment->dna;
193 $dna =~ s/(\S{60})/$1\n/g;
194 print ">$segment\n$dna\n" if $dna;
195 }
196  
197 }
198  
199 sub print_feature_row {
200  
201 my $self = shift;
202 my %args = @_;
203 my $map_name = $args{'map_name'};
204 my $map_start = $args{'map_start'};
205 my $map_stop = $args{'map_stop'};
206 my $feature_name = $args{'feature_name'};
207 my $feature_stop = $args{'feature_stop'};
208 my $feature_start = $args{'feature_start'};
209 my $strand_value = $args{'strand_value'};
210 my $feature_type_aid = $args{'feature_type_aid'};
211  
212 my $feature_direction = ( $strand_value eq '-' ) ? -1 : 1;
213  
214 print join( "\t",
215 $map_name, $map_start, $map_stop, $feature_name, $feature_start,
216 $feature_stop, $feature_direction, $feature_type_aid )
217 . "\n";
218  
219 }
220  
221 1;