| 1 | package Bio::Graphics::Browser2::Render::TrackConfig; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use CGI qw(:standard); | ||
| 5 | use Bio::Graphics::Browser2::Shellwords 'shellwords'; | ||
| 6 | use constant MIN=>0; | ||
| 7 | use constant MAX=>999999999; | ||
| 8 | |||
| 9 | sub new { | ||
| 10 | my $class = shift; | ||
| 11 | my $render = shift; | ||
| 12 | return bless {render=>$render},ref $class || $class; | ||
| 13 | } | ||
| 14 | |||
| 15 | sub render { shift->{render} } | ||
| 16 | |||
| 17 | sub config_dialog { | ||
| 18 | my $self = shift; | ||
| 19 | my ($label,$revert_to_defaults) = @_; | ||
| 20 | my $render = $self->render; | ||
| 21 | |||
| 22 | my $state = $render->state(); | ||
| 23 | my $data_source = $render->data_source(); | ||
| 24 | my $length = $render->segment_length($label); | ||
| 25 | |||
| 26 | eval 'require Bio::Graphics::Browser2::OptionPick; 1' | ||
| 27 | unless Bio::Graphics::Browser2::OptionPick->can('new'); | ||
| 28 | |||
| 29 | my $picker = Bio::Graphics::Browser2::OptionPick->new($render); | ||
| 30 | |||
| 31 | # summary options | ||
| 32 | my $can_summarize = $data_source->can_summarize($label); | ||
| 33 | my $summary_mode = $data_source->show_summary($label,$length,$state); | ||
| 34 | my $summary_length= $self->setting( $label => 'show summary' , $length, $summary_mode) || 0; | ||
| 35 | my @thresh = sort {$a<=>$b} ($data_source->semantic_thresholds($label),$summary_length); | ||
| 36 | my $semantic_min = (grep {$length >= $_} @thresh)[-1] || MIN; | ||
| 37 | my $semantic_max = (grep {$length < $_} @thresh)[0] || MAX; | ||
| 38 | |||
| 39 | my $slabel = $summary_mode ? $label : $data_source->semantic_label($label,$length); | ||
| 40 | |||
| 41 | if ($revert_to_defaults) { | ||
| 42 | $state->{features}{$label}{summary_override} = {} if $summary_mode; | ||
| 43 | $state->{features}{$label}{semantic_override} = {} unless $summary_mode; | ||
| 44 | delete $state->{features}{$label}{summary_mode_len}; | ||
| 45 | } | ||
| 46 | |||
| 47 | my $semantic_override = $render->find_override_region($state->{features}{$label}{semantic_override},$length); | ||
| 48 | $semantic_override ||= 0; | ||
| 49 | |||
| 50 | # my ($semantic_level) = $slabel =~ /(\d+)$/; | ||
| 51 | # $semantic_level ||= 0; | ||
| 52 | # my @level = map { | ||
| 53 | # scalar $render->data_source->unit_label($_) | ||
| 54 | # } split ':',($semantic_override || $semantic_level); | ||
| 55 | # my $level = join '..',@level; | ||
| 56 | my ($low,$hi) = $render->find_override_bounds($state->{features}{$label}{semantic_override},$length); | ||
| 57 | $semantic_min = $low if defined $low; | ||
| 58 | $semantic_max = $hi if defined $hi; | ||
| 59 | my $level = join '..',map {scalar $render->data_source->unit_label($_)} $semantic_min,$semantic_max; | ||
| 60 | |||
| 61 | my $key = $render->label2key($label); | ||
| 62 | $key .= $summary_mode ? " (".$render->translate('FEATURE_SUMMARY').')' | ||
| 63 | :$level eq '0 bp' ? '' | ||
| 64 | :$level =~ /\.\./ ? " ($level)" | ||
| 65 | :$level ? " (>=$level)" | ||
| 66 | :''; | ||
| 67 | |||
| 68 | my $override = $summary_mode | ||
| 69 | ? $state->{features}{$label}{summary_override} ||= {} | ||
| 70 | : $state->{features}{$label}{semantic_override}{$semantic_override} ||= {}; | ||
| 71 | |||
| 72 | my $return_html = start_html(); | ||
| 73 | |||
| 74 | my $showing = $render->data_source->unit_label($length); | ||
| 75 | my $title = div({-class=>'config-title'},$key,br(),div({-style=>'font-size:9pt'},$render->translate('Currently_Showing',$showing))); | ||
| 76 | my $dynamic = $render->translate('DYNAMIC_VALUE'); | ||
| 77 | |||
| 78 | my $height = $self->setting( $label => 'height' , $length, $summary_mode) || 10; | ||
| 79 | my $width = $self->setting( $label => 'linewidth', $length, $summary_mode ) || 1; | ||
| 80 | my $glyph = $self->setting( $label => 'glyph', $length, $summary_mode ) || 'box'; | ||
| 81 | my $stranded = $self->setting( $label => 'stranded', $length, $summary_mode); | ||
| 82 | $stranded++ if $glyph eq 'gene'; # workaround a inconsistency in gene glyph behavior | ||
| 83 | my $variance_band = $self->setting( $label => 'variance_band', $length, $summary_mode); | ||
| 84 | my $color_series = $self->setting( $label => 'color_series', $length, $summary_mode); | ||
| 85 | my $limit = $self->setting( $label => 'feature_limit' , $length, $summary_mode) || 0; | ||
| 86 | my $opacity = $override->{'opacity'} || $self->setting($label => 'opacity',$length,$summary_mode) || 0.3; | ||
| 87 | |||
| 88 | # options for wiggle & xy plots | ||
| 89 | my $min_score= $self->setting( $label => 'min_score' , $length, $summary_mode); | ||
| 90 | my $max_score= $self->setting( $label => 'max_score' , $length, $summary_mode); | ||
| 91 | $min_score = -1 unless defined $min_score; | ||
| 92 | $max_score = +1 unless defined $max_score; | ||
| 93 | my $autoscale = $self->setting( $label => 'autoscale' , $length, $summary_mode); | ||
| 94 | $autoscale ||= 'local'; | ||
| 95 | |||
| 96 | my $sd_fold = $self->setting( $label => 'z_score_bound' , $length, $summary_mode); | ||
| 97 | $sd_fold ||= 8; | ||
| 98 | |||
| 99 | my $bicolor_pivot = $self->setting( $label => 'bicolor_pivot' , $length, $summary_mode); | ||
| 100 | my $graph_type = $self->setting( $label => 'graph_type' , $length, $summary_mode); | ||
| 101 | my $glyph_subtype = $self->setting( $label => 'glyph_subtype' , $length, $summary_mode); | ||
| 102 | |||
| 103 | # options for wiggle_whiskers | ||
| 104 | my $max_color = $self->setting( $label => 'max_color' , $length, $summary_mode); | ||
| 105 | my $mean_color = $self->setting( $label => 'mean_color' , $length, $summary_mode); | ||
| 106 | my $stdev_color = $self->setting( $label => 'stdev_color' , $length, $summary_mode); | ||
| 107 | |||
| 108 | # packing images | ||
| 109 | my $buttons = $data_source->globals->button_url; | ||
| 110 | my $red_peaks = "$buttons/red_peaks.png"; | ||
| 111 | my $blue_peaks = "$buttons/blue_peaks.png"; | ||
| 112 | my $opacity_thumb = "$buttons/opacity_thumb.png"; | ||
| 113 | |||
| 114 | my @glyph_select = shellwords( | ||
| 115 | $self->setting( $label => 'glyph select', $length, $summary_mode ) | ||
| 116 | ); | ||
| 117 | unshift @glyph_select,$dynamic if ref $data_source->fallback_setting($label=>'glyph') eq 'CODE'; | ||
| 118 | |||
| 119 | my $db = $data_source->open_database($label,$length); | ||
| 120 | my $quantitative = $glyph =~ /wiggle|vista|xy|density|hybrid/ || ref($db) =~ /bigwig/i; | ||
| 121 | my $can_whisker = $quantitative && ref($db) =~ /bigwig/i; | ||
| 122 | my $vista = $glyph =~ /vista/; | ||
| 123 | |||
| 124 | unless (@glyph_select) { # reasonable defaults | ||
| 125 | @glyph_select = $can_whisker ? qw(wiggle_xyplot wiggle_density wiggle_whiskers) | ||
| 126 | :$vista ? 'vista_plot' | ||
| 127 | :$quantitative ? qw(wiggle_xyplot wiggle_density) | ||
| 128 | : qw(arrow anchored_arrow box crossbox dashed_line diamond | ||
| 129 | dna dot dumbbell ellipse gene line primers saw_teeth segments | ||
| 130 | span site transcript triangle | ||
| 131 | two_bolts wave); | ||
| 132 | } | ||
| 133 | |||
| 134 | my $auto_packing_label = $quantitative ? $render->translate('Expand_Label') : $render->translate('Auto'); | ||
| 135 | my %glyphs = map { $_ => 1 } ( $glyph, @glyph_select ); | ||
| 136 | my @all_glyphs = sort keys %glyphs; | ||
| 137 | my $g = $override->{'glyph'} || $glyph; | ||
| 138 | |||
| 139 | my $url = url( -absolute => 1, -path => 1 ); | ||
| 140 | my $mode = $summary_mode ? 'summary' : 'normal'; | ||
| 141 | my $reset_js = <<END; | ||
| 142 | new Ajax.Request('$url', | ||
| 143 | { method: 'get', | ||
| 144 | asynchronous: false, | ||
| 145 | parameters: 'action=configure_track&track=$label&track_defaults=1;mode=$mode', | ||
| 146 | onSuccess: function(t) { document.getElementById('contents').innerHTML=t.responseText; | ||
| 147 | t.responseText.evalScripts(); | ||
| 148 | }, | ||
| 149 | onFailure: function(t) { alert('AJAX Failure! '+t.statusText)} | ||
| 150 | } | ||
| 151 | ); | ||
| 152 | END | ||
| 153 | |||
| 154 | my $self_url = url( -absolute => 1, -path => 1 ); | ||
| 155 | my $form_name = 'track_config_form'; | ||
| 156 | my $form = start_form( | ||
| 157 | -name => $form_name, | ||
| 158 | -id => $form_name, | ||
| 159 | ); | ||
| 160 | |||
| 161 | # NOTE: the -class option determines which form elements are shown for | ||
| 162 | # which track types. See htdocs/js/track_config.js | ||
| 163 | my @rows; | ||
| 164 | push @rows, TR({-class=>'general'}, | ||
| 165 | td( {-colspan => 2}, $title)); | ||
| 166 | |||
| 167 | push @rows,TR( {-class => 'general', | ||
| 168 | -id => 'packing'}, | ||
| 169 | th( { -align => 'right' }, $render->translate('Packing') ), | ||
| 170 | td( popup_menu( | ||
| 171 | -name => 'format_option', | ||
| 172 | -id => 'format_option', | ||
| 173 | -values => ($quantitative ? [0,4] : [ 0..4 ]), | ||
| 174 | -override => 1, | ||
| 175 | -default => $state->{features}{$label}{options}, | ||
| 176 | -labels => { | ||
| 177 | 0 => $auto_packing_label, | ||
| 178 | 1 => $render->translate('Compact'), | ||
| 179 | 2 => $render->translate('Expand'), | ||
| 180 | 3 => $render->translate('Expand_Label'), | ||
| 181 | 4 => $render->translate('Overlap'), | ||
| 182 | } | ||
| 183 | ) | ||
| 184 | ) | ||
| 185 | ); | ||
| 186 | |||
| 187 | push @rows,TR( {-class => 'general', | ||
| 188 | -id => 'opacity'}, | ||
| 189 | th( {-align => 'right' }, 'Opacity'), | ||
| 190 | td( input({-type => 'text', | ||
| 191 | -name => 'conf_opacity', | ||
| 192 | -id => 'opacity_value', | ||
| 193 | -style => "display:inline-block;position:relative;top:-4", | ||
| 194 | -value => '0.00', | ||
| 195 | -size => 2, | ||
| 196 | -maxlength => 4}), | ||
| 197 | div({-id=>'opacity_box', | ||
| 198 | -style => 'display:inline-block;position:relative;background:beige;width:100px;height:16px;border:inset 1px', | ||
| 199 | }, | ||
| 200 | img({-id=>'opacity_thumb', | ||
| 201 | -style=>'position:absolute;left:0', | ||
| 202 | -src => $opacity_thumb})), | ||
| 203 | div({-style=>'display:inline-block;position:relative;width:20px;height:20px'}, | ||
| 204 | img({-class=>'opacity', | ||
| 205 | -src => $red_peaks, | ||
| 206 | -style => 'position:absolute;left:2px;top:0px'}), | ||
| 207 | img({-class=>'opacity', | ||
| 208 | -src => $blue_peaks, | ||
| 209 | -style => 'position:absolute;left:0px;top:5px'}), | ||
| 210 | ))); | ||
| 211 | |||
| 212 | push @rows,TR( {-class=>'general'}, | ||
| 213 | th( { -align => 'right' }, $render->translate('GLYPH') ), | ||
| 214 | td($picker->popup_menu( | ||
| 215 | -name => 'conf_glyph', | ||
| 216 | -values => \@all_glyphs, | ||
| 217 | -default => ref $glyph eq 'CODE' ? $dynamic : $glyph, | ||
| 218 | -current => $override->{'glyph'}, | ||
| 219 | -scripts => {-id=>'glyph_picker_id',-onChange => 'track_configure.glyph_select($(\'config_table\'),this)'} | ||
| 220 | ) | ||
| 221 | ) | ||
| 222 | ); | ||
| 223 | |||
| 224 | for my $glyph (@all_glyphs) { | ||
| 225 | my $class = "Bio\:\:Graphics\:\:Glyph\:\:$glyph"; | ||
| 226 | eval "require $class" unless $class->can('new'); | ||
| 227 | if (my $subtypes = eval{$class->options->{glyph_subtype}}) { | ||
| 228 | my $options = $subtypes->[0]; | ||
| 229 | next unless ref $options eq 'ARRAY'; | ||
| 230 | push @rows,(TR {-class => $glyph, | ||
| 231 | -id => "conf_${glyph}_subtype"}, | ||
| 232 | th({-align => 'right'}, $glyph,$render->tr('Subtype')), | ||
| 233 | td($picker->popup_menu( | ||
| 234 | -values => $options, | ||
| 235 | -name => "conf_${glyph}_subtype", | ||
| 236 | -override => 1, | ||
| 237 | -default => ref $glyph_subtype eq 'CODE' ? $dynamic : $glyph_subtype, | ||
| 238 | -scripts => { -id => "conf_${glyph}_subtype_id", | ||
| 239 | -onChange => 'track_configure.glyph_select($(\'config_table\'),$(\'glyph_picker_id\'))'}, | ||
| 240 | -current => $override->{'glyph_subtype'}))); | ||
| 241 | } | ||
| 242 | if (my $subgraphs = eval{$class->options->{graph_type}}) { | ||
| 243 | my $options = $subgraphs->[0]; | ||
| 244 | $graph_type ||= $subgraphs->[1]; | ||
| 245 | next unless ref $options eq 'ARRAY'; | ||
| 246 | push @rows,(TR {-class => "$glyph graphtype", | ||
| 247 | -id => "conf_${glyph}_graphtype"}, | ||
| 248 | th({-align => 'right'}, $render->tr('XYplot_type')), | ||
| 249 | td($picker->popup_menu( | ||
| 250 | -name => "conf_${glyph}_graphtype", | ||
| 251 | -values => $options, | ||
| 252 | -override => 1, | ||
| 253 | -default => ref $graph_type eq 'CODE' ? $dynamic : $graph_type, | ||
| 254 | -scripts => { -id => "conf_${glyph}_graphtype_id", | ||
| 255 | -onChange => 'track_configure.glyph_select($(\'config_table\'),$(\'glyph_picker_id\'))'}, | ||
| 256 | -current => $override->{'graph_type'}))); | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | ####################### | ||
| 261 | # cycling colors | ||
| 262 | ####################### | ||
| 263 | push @rows,TR({ | ||
| 264 | -id => 'color_series', | ||
| 265 | -class=> 'general' | ||
| 266 | }, | ||
| 267 | th ( { -align=>'right' }, $render->tr('AUTO_COLORS') ), | ||
| 268 | td(hidden(-name => 'conf_color_series',-value=>0), | ||
| 269 | checkbox(-name => 'conf_color_series', | ||
| 270 | -id => 'conf_color_series', | ||
| 271 | -override=> 1, | ||
| 272 | -value => 1, | ||
| 273 | -checked => defined $override->{'color_series'} | ||
| 274 | ? $override->{'color_series'} | ||
| 275 | : $color_series, | ||
| 276 | -label => ''))); | ||
| 277 | |||
| 278 | ####################### | ||
| 279 | # bicolor pivot stuff | ||
| 280 | ####################### | ||
| 281 | my $p = $override->{bicolor_pivot} || $bicolor_pivot || 'none'; | ||
| 282 | my $has_pivot = $g =~ /wiggle_xyplot|wiggle_density|xyplot|hybrid/; | ||
| 283 | |||
| 284 | push @rows,TR( {-class=>'xyplot density color_picker', | ||
| 285 | -id =>'bicolor_pivot_id'}, | ||
| 286 | th( { -align => 'right'}, $render->translate('BICOLOR_PIVOT')), | ||
| 287 | td( $picker->popup_menu( | ||
| 288 | -class => 'color_picker', | ||
| 289 | -name => 'conf_bicolor_pivot', | ||
| 290 | -values => [qw(none zero mean 1SD 2SD 3SD value)], | ||
| 291 | -labels => {value => 'value entered below', | ||
| 292 | '1SD' => 'mean + 1 standard deviation', | ||
| 293 | '2SD' => 'mean + 2 standard deviations', | ||
| 294 | '3SD' => 'mean + 3 standard deviations', | ||
| 295 | }, | ||
| 296 | -default => $bicolor_pivot, | ||
| 297 | -current => $p =~ /^-?[\d.eE]+(?:SD)?$/i ? 'value' : $p, | ||
| 298 | -scripts => {-onChange => 'track_configure.pivot_select(this)', | ||
| 299 | -id => 'conf_bicolor_pivot'} | ||
| 300 | ) | ||
| 301 | ) | ||
| 302 | ); | ||
| 303 | |||
| 304 | my $pv = $p =~ /^[\d.-eE]+$/ ? $p : 0.0; | ||
| 305 | push @rows,TR({-class =>'xyplot density color_picker', | ||
| 306 | -id=>'switch_point_other'}, | ||
| 307 | th( {-align => 'right' },$render->translate('BICOLOR_PIVOT_VALUE')), | ||
| 308 | td( textfield(-name => 'bicolor_pivot_value', | ||
| 309 | -value => $pv))); | ||
| 310 | |||
| 311 | |||
| 312 | push @rows,TR({-class=>'switch_point_color xyplot density color_picker'}, | ||
| 313 | th( { -align => 'right' }, $render->translate('BICOLOR_PIVOT_POS_COLOR')), | ||
| 314 | td( $picker->color_pick( | ||
| 315 | 'conf_pos_color', | ||
| 316 | $self->setting( $label => 'pos_color', $length, $summary_mode ), | ||
| 317 | $override->{'pos_color'} | ||
| 318 | ) | ||
| 319 | ) | ||
| 320 | ); | ||
| 321 | |||
| 322 | push @rows,TR( {-class=>'switch_point_color xyplot density color color_picker'}, | ||
| 323 | th( { -align => 'right' }, $render->translate('BICOLOR_PIVOT_NEG_COLOR') ), | ||
| 324 | td( $picker->color_pick( | ||
| 325 | 'conf_neg_color', | ||
| 326 | $self->setting( $label => 'neg_color', $length, $summary_mode ), | ||
| 327 | $override->{'neg_color'} | ||
| 328 | ) | ||
| 329 | ) | ||
| 330 | ); | ||
| 331 | |||
| 332 | push @rows,TR( { -id => 'bgcolor_picker', | ||
| 333 | -class => 'xyplot density features peaks color_picker', | ||
| 334 | }, | ||
| 335 | th( { -align => 'right' }, $render->translate('BACKGROUND_COLOR') ), | ||
| 336 | td( $picker->color_pick( | ||
| 337 | 'conf_bgcolor', | ||
| 338 | $self->setting( $label => 'bgcolor', $length, $summary_mode ), | ||
| 339 | $override->{'bgcolor'}, | ||
| 340 | ) | ||
| 341 | ) | ||
| 342 | ); | ||
| 343 | push @rows,TR( { -id => 'startcolor_picker', | ||
| 344 | -class => 'peaks color_picker', | ||
| 345 | }, | ||
| 346 | th( { -align => 'right' }, 'Peak gradient start'), | ||
| 347 | td( $picker->color_pick( | ||
| 348 | 'conf_start_color', | ||
| 349 | $self->setting( $label => 'start_color', $length, $summary_mode ), | ||
| 350 | $override->{'start_color'} | ||
| 351 | ) | ||
| 352 | ) | ||
| 353 | ); | ||
| 354 | push @rows,TR( { -id => 'endcolor_picker', | ||
| 355 | -class => 'peaks color_picker', | ||
| 356 | }, | ||
| 357 | th( { -align => 'right' }, 'Peak gradient end'), | ||
| 358 | td( $picker->color_pick( | ||
| 359 | 'conf_end_color', | ||
| 360 | $self->setting( $label => 'end_color', $length, $summary_mode ), | ||
| 361 | $override->{'end_color'} | ||
| 362 | ) | ||
| 363 | ) | ||
| 364 | ); | ||
| 365 | push @rows,TR( {-class=>'xyplot features peaks color_picker'}, | ||
| 366 | th( { -align => 'right' }, $render->translate('FG_COLOR') ), | ||
| 367 | td( $picker->color_pick( | ||
| 368 | 'conf_fgcolor', | ||
| 369 | $self->setting( $label => 'fgcolor', $length, $summary_mode ), | ||
| 370 | $override->{'fgcolor'} | ||
| 371 | ) | ||
| 372 | ) | ||
| 373 | ); | ||
| 374 | |||
| 375 | |||
| 376 | ####################### | ||
| 377 | # wiggle colors | ||
| 378 | ####################### | ||
| 379 | push @rows,TR( {-class=>'whiskers color_picker'}, | ||
| 380 | th( { -align => 'right' }, $render->translate('WHISKER_MEAN_COLOR')), | ||
| 381 | td( $picker->color_pick( | ||
| 382 | 'conf_mean_color', | ||
| 383 | $mean_color || 'black', | ||
| 384 | $override->{'mean_color'} | ||
| 385 | ) | ||
| 386 | ) | ||
| 387 | ); | ||
| 388 | |||
| 389 | push @rows,TR( {-class=>'whiskers color_picker'}, | ||
| 390 | th( { -align => 'right' }, $render->translate('WHISKER_STDEV_COLOR') ), | ||
| 391 | td( $picker->color_pick( | ||
| 392 | 'conf_stdev_color', | ||
| 393 | $stdev_color || 'grey', | ||
| 394 | $override->{'stdev_color'} | ||
| 395 | ) | ||
| 396 | ) | ||
| 397 | ); | ||
| 398 | |||
| 399 | push @rows,TR( {-class=>'whiskers color_picker'}, | ||
| 400 | th( { -align => 'right' }, $render->translate('WHISKER_MAX_COLOR') ), | ||
| 401 | td( $picker->color_pick( | ||
| 402 | 'conf_max_color', | ||
| 403 | $max_color || 'lightgrey', | ||
| 404 | $override->{'max_color'} | ||
| 405 | ) | ||
| 406 | ) | ||
| 407 | ); | ||
| 408 | |||
| 409 | push @rows,TR({-class=>'xyplot autoscale', | ||
| 410 | -id => "xyplot_autoscale" | ||
| 411 | }, | ||
| 412 | th( { -align => 'right' },$render->tr('AUTOSCALING')), | ||
| 413 | td( $picker->popup_menu( | ||
| 414 | -name => "conf_xyplot_autoscale", | ||
| 415 | -values => [qw(none local)], | ||
| 416 | -labels => {none=>'fixed',local=>'scale to view'}, | ||
| 417 | -default => $autoscale, | ||
| 418 | -current => $override->{autoscale}, | ||
| 419 | -scripts => {-onChange => 'track_configure.autoscale_select(this,$(\'glyph_picker_id\'))', | ||
| 420 | -id => "conf_xyplot_autoscale" | ||
| 421 | } | ||
| 422 | ))); | ||
| 423 | |||
| 424 | push @rows,TR({-class=>'wiggle vista_plot autoscale', | ||
| 425 | -id => 'wiggle_autoscale'}, | ||
| 426 | th( { -align => 'right' },$render->translate('AUTOSCALING')), | ||
| 427 | td( $picker->popup_menu( | ||
| 428 | -name => "conf_wiggle_autoscale", | ||
| 429 | -values => $summary_mode ? [qw(none local)] : [qw(none z_score local chromosome global clipped_global)], | ||
| 430 | -labels => {none =>'fixed', | ||
| 431 | z_score =>'scale to SD multiples', | ||
| 432 | local =>'scale to local min/max', | ||
| 433 | chromosome=>'scale to chromosome min/max', | ||
| 434 | global =>'scale to genome min/max', | ||
| 435 | clipped_global =>'clip to +/- SDs shown below' | ||
| 436 | }, | ||
| 437 | -default => $autoscale, | ||
| 438 | -current => $override->{autoscale}, | ||
| 439 | -scripts => {-onChange => 'track_configure.autoscale_select(this,$(\'glyph_picker_id\'))', | ||
| 440 | -id => "conf_wiggle_autoscale" | ||
| 441 | } | ||
| 442 | ))); | ||
| 443 | |||
| 444 | push @rows,TR({-class=>'wiggle vista_plot autoscale', | ||
| 445 | -id => 'wiggle_z_fold'}, | ||
| 446 | th( { -align => 'right' },$render->translate('SD_MULTIPLES')), | ||
| 447 | td( $picker->popup_menu( | ||
| 448 | -name => "conf_z_score_bound", | ||
| 449 | -values => [qw(1 2 3 4 5 6 8 10 20)], | ||
| 450 | -labels => {1 =>'1 SD', | ||
| 451 | 2 =>'2 SD', | ||
| 452 | 3 =>'3 SD', | ||
| 453 | 4 =>'4 SD', | ||
| 454 | 5 =>'5 SD', | ||
| 455 | 6 =>'6 SD', | ||
| 456 | 8 =>'8 SD', | ||
| 457 | 10 =>'10 SD', | ||
| 458 | 20 =>'20 SD', | ||
| 459 | }, | ||
| 460 | -default => $sd_fold, | ||
| 461 | -current => $override->{z_score_bound} | ||
| 462 | ))); | ||
| 463 | |||
| 464 | push @rows,TR( {-class=> 'xyplot density whiskers vista_plot autoscale', | ||
| 465 | -id => 'fixed_minmax' | ||
| 466 | }, | ||
| 467 | th( { -align => 'right' },$render->translate('SCALING')), | ||
| 468 | td( textfield(-name => 'conf_min_score', | ||
| 469 | -class => 'score_bounds', | ||
| 470 | -size => 5, | ||
| 471 | -value => defined $override->{min_score} ? $override->{min_score} | ||
| 472 | : $summary_mode ? 0 : $min_score), | ||
| 473 | '-', | ||
| 474 | textfield(-name => 'conf_max_score', | ||
| 475 | -class => 'score_bounds', | ||
| 476 | -size => 5, | ||
| 477 | -value => defined $override->{max_score} ? $override->{max_score} | ||
| 478 | : $summary_mode ? 10 : $max_score))) | ||
| 479 | if $quantitative; | ||
| 480 | |||
| 481 | push @rows,TR({-class=>'xyplot'}, | ||
| 482 | th( { -align => 'right' }, $render->translate('SHOW_VARIANCE')), | ||
| 483 | td( | ||
| 484 | hidden(-name=>'conf_variance_band',-value=>0), | ||
| 485 | checkbox( | ||
| 486 | -name => 'conf_variance_band', | ||
| 487 | -override=> 1, | ||
| 488 | -value => 1, | ||
| 489 | -checked => defined $override->{'variance_band'} | ||
| 490 | ? $override->{'variance_band'} | ||
| 491 | : $variance_band, | ||
| 492 | -label => '', | ||
| 493 | ) | ||
| 494 | ) | ||
| 495 | ); | ||
| 496 | |||
| 497 | push @rows,TR( {-class=>'features'}, | ||
| 498 | th( { -align => 'right' }, $render->translate('LINEWIDTH') ), | ||
| 499 | td( $picker->popup_menu( | ||
| 500 | -name => 'conf_linewidth', | ||
| 501 | -current => $override->{'linewidth'}, | ||
| 502 | -default => $width || 1, | ||
| 503 | -values => [ sort { $a <=> $b } ( $width, 1 .. 5 ) ] | ||
| 504 | ) | ||
| 505 | ) | ||
| 506 | ); | ||
| 507 | |||
| 508 | push @rows,TR( {-class=>'general'}, | ||
| 509 | th( | ||
| 510 | { -align => 'right' }, $render->translate('HEIGHT') ), | ||
| 511 | td( $picker->popup_menu( | ||
| 512 | -name => 'conf_height', | ||
| 513 | -id => 'conf_height', | ||
| 514 | -current => $override->{'height'}, | ||
| 515 | -default => $height, | ||
| 516 | -values => [ | ||
| 517 | sort { $a <=> $b } | ||
| 518 | ( $height, map { $_ * 5 } ( 1 .. 20 ) ) | ||
| 519 | ], | ||
| 520 | ) | ||
| 521 | ) | ||
| 522 | ); | ||
| 523 | |||
| 524 | push @rows,TR({-class=>'features'}, | ||
| 525 | th( { -align => 'right' }, $render->translate('Limit') ), | ||
| 526 | td( $picker->popup_menu( | ||
| 527 | -name => 'conf_feature_limit', | ||
| 528 | -values => [ 0, 5, 10, 25, 50, 100, 200, 500, 1000 ], | ||
| 529 | -labels => { 0 => $render->translate('NO_LIMIT') }, | ||
| 530 | -current => $override->{feature_limit}, | ||
| 531 | -override => 1, | ||
| 532 | -default => $limit, | ||
| 533 | ) | ||
| 534 | ) | ||
| 535 | ); | ||
| 536 | |||
| 537 | push @rows,TR({-class=>'features'}, | ||
| 538 | th( { -align => 'right' }, $render->translate('STRANDED') ), | ||
| 539 | td( hidden(-name=>'conf_stranded',-value=>0), | ||
| 540 | checkbox( | ||
| 541 | -name => 'conf_stranded', | ||
| 542 | -override=> 1, | ||
| 543 | -value => 1, | ||
| 544 | -checked => defined $override->{'stranded'} | ||
| 545 | ? $override->{'stranded'} | ||
| 546 | : $stranded, | ||
| 547 | -label => '', | ||
| 548 | ) | ||
| 549 | ) | ||
| 550 | ); | ||
| 551 | |||
| 552 | push @rows,TR({-class=>'general'}, | ||
| 553 | th( {-align => 'right' }, | ||
| 554 | $render->translate('APPLY_CONFIG') | ||
| 555 | ), | ||
| 556 | td( | ||
| 557 | $self->region_size_menu('apply_semantic_low',$length,[$semantic_min,MIN],$semantic_min), | ||
| 558 | '-', | ||
| 559 | $self->region_size_menu('apply_semantic_hi',$length,[$semantic_max,MAX],$semantic_max), | ||
| 560 | ) | ||
| 561 | ) unless $summary_mode; | ||
| 562 | |||
| 563 | my $summ = defined $state->{features}{$label}{summary_mode_len} | ||
| 564 | ?$state->{features}{$label}{summary_mode_len} | ||
| 565 | :$summary_length; | ||
| 566 | push @rows,TR({-class=>'general'}, | ||
| 567 | th( { -align => 'right' }, $render->translate('SHOW_SUMMARY')), | ||
| 568 | td( | ||
| 569 | $self->region_size_menu('summary_mode',$summ) | ||
| 570 | ) | ||
| 571 | ) if $can_summarize && $summary_length; | ||
| 572 | |||
| 573 | my $submit_script = <<END; | ||
| 574 | Element.extend(this); | ||
| 575 | var ancestors = this.ancestors(); | ||
| 576 | var form_element = ancestors.find(function(el) {return el.nodeName=='FORM'; }); | ||
| 577 | Controller.reconfigure_track('$label',form_element,'$mode') | ||
| 578 | END | ||
| 579 | |||
| 580 | push @rows,TR({-class=>'general'}, | ||
| 581 | td({-colspan=>2}, | ||
| 582 | button( | ||
| 583 | -style => 'background:pink', | ||
| 584 | -name => $render->translate('Revert'), | ||
| 585 | -onClick => $reset_js | ||
| 586 | ), br, | ||
| 587 | button( | ||
| 588 | -name => $render->translate('Cancel'), | ||
| 589 | -onClick => 'Balloon.prototype.hideTooltip(1)' | ||
| 590 | ), | ||
| 591 | button( | ||
| 592 | -name => $render->translate('Change'), | ||
| 593 | -onClick => $submit_script | ||
| 594 | ), | ||
| 595 | hidden(-name=>'segment_length',-value=>$length), | ||
| 596 | ) | ||
| 597 | ); | ||
| 598 | |||
| 599 | $form .= table({-id=>'config_table',-border => 0 },@rows); | ||
| 600 | $form .= end_form(); | ||
| 601 | $return_html | ||
| 602 | .= table( TR( td( { -valign => 'top' }, [ $form ] ) ) ); | ||
| 603 | |||
| 604 | $return_html .= script({-type=>'text/javascript'},"track_configure.init($opacity)"); | ||
| 605 | $return_html .= end_html(); | ||
| 606 | return $return_html; | ||
| 607 | } | ||
| 608 | |||
| 609 | sub setting { | ||
| 610 | my $self = shift; | ||
| 611 | my ($label,$option,$length,$is_summary) = @_; | ||
| 612 | my $data_source = $self->render->data_source(); | ||
| 613 | |||
| 614 | # bad hack | ||
| 615 | if ($is_summary) { | ||
| 616 | if ($data_source->Bio::Graphics::FeatureFile::setting("$label:summary")) { | ||
| 617 | return $data_source->semantic_fallback_setting("$label:summary",$option,$length); | ||
| 618 | } else { | ||
| 619 | return 'wiggle_density' if $option eq 'glyph'; | ||
| 620 | return 15 if $option eq 'height'; | ||
| 621 | return 0 if $option eq 'min_score'; | ||
| 622 | return 'local' if $option eq 'autoscale'; | ||
| 623 | } | ||
| 624 | } | ||
| 625 | |||
| 626 | return $data_source->semantic_fallback_setting($label,$option,$length); | ||
| 627 | } | ||
| 628 | |||
| 629 | sub region_size_menu { | ||
| 630 | my $self = shift; | ||
| 631 | my ($name,$length,$extra_vals,$default) = @_; | ||
| 632 | $extra_vals ||= []; | ||
| 633 | |||
| 634 | my $source = $self->render->data_source; | ||
| 635 | my %seen; | ||
| 636 | my @r = sort {$a<=>$b} ($source->get_ranges(),$length,@$extra_vals); | ||
| 637 | my @ranges = grep {!$seen{$source->unit_label($_)}++} @r; | ||
| 638 | my %labels = map {$_=> scalar $source->unit_label($_)} @ranges; | ||
| 639 | |||
| 640 | $labels{MIN()} = $self->render->translate('MIN'); | ||
| 641 | $labels{MAX()} = $self->render->translate('MAX'); | ||
| 642 | @ranges = sort {$b||0<=>$a||0} @ranges; | ||
| 643 | $default = $length unless defined $default; | ||
| 644 | |||
| 645 | return popup_menu(-name => $name, | ||
| 646 | -values => \@ranges, | ||
| 647 | -labels => \%labels, | ||
| 648 | -default => $default, | ||
| 649 | -force => 1, | ||
| 650 | ); | ||
| 651 | } | ||
| 652 | |||
| 653 | 1; |