lib/Microarray/Explorer.pm untested

filter: Statementstmt 0.0% 0 / 616 Branchbran 0.0% 0 / 110 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 55 Podpod 0.0% 0 / 50 totaltotal 0.0% 0 / 884 CC 56 SCAR 43.2
CC
56
Cov
0%
_markup_cell
380.0
zoom
30.0
search_feature
30.0
CRAP 75.2
1 package Microarray::Explorer;
2  
3 # The explorer class belongs to the package Microarray. It functions as
4 # a web viewer for dataset objects from the same package. Following the
5 # Model/View/Controller concept, the explorer class is the View/Controller,
6 # whereas the dataset class is the Model.
7  
8 # $Author: sherlock $
9 # $Revision: 1.20 $
10 # $Date: 2004/07/15 14:31:20 $
11 # $Locker: jdemeter
12  
13 # License information (the MIT license)
14  
15 # Copyright (c) 2003 Christian Rees, Janos Demeter, John Matese, Gavin
16 # Sherlock; Stanford University
17  
18 # Permission is hereby granted, free of charge, to any person
19 # obtaining a copy of this software and associated documentation files
20 # (the "Software"), to deal in the Software without restriction,
21 # including without limitation the rights to use, copy, modify, merge,
22 # publish, distribute, sublicense, and/or sell copies of the Software,
23 # and to permit persons to whom the Software is furnished to do so,
24 # subject to the following conditions:
25  
26 # The above copyright notice and this permission notice shall be
27 # included in all copies or substantial portions of the Software.
28  
29 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 # SOFTWARE.
37  
38  
39 use strict;
40 use CGI qw/:all/;
41 use GD;
42 use vars qw($VERSION);
43  
44 use Microarray::Config;
45  
46 $VERSION = "2.0";
47 $| = 1;
48  
49 # need this global for switching row color in markup
50 my $flip = 1;
51  
52 ### Preferences for zoom, ... ##################
53 my $kMaxZoomRowHeight = 25; # max zoom image ROW height - an arbitrary max of 25 pixels
54 my $kMinZoomRowHeight = 15; # min zoom image ROW height - an arbitrary min of 15 pixels
55 my $kMaxZoomWidth = 800; # max zoom image width - an arbitrary max of 800 pixels
56 my $kPrefZoomColWidth = 10; # preferred COLUMN width in Zoom window - an arbitrary 10 pixels
57 my $kExpImgHeight = 100; # the minimal height of experiment image in zoom frame
58 my $kZoomWindowHeight = 100; # Number of ROWs displayed in Zoom window.
59  
60 ### for the radar window, ... ##################
61 my $kMaxRadarHeight = 500; # max radar image height an arbitrary max of 500 pixels
62 my $kPrefRadarRowHeight = 1; # max radar image ROW height - an arbitrary max of 1 pixels
63 my $kMaxRadarWidth = 400; # max radar image width - an arbitrary max of 400 pixels
64 my $kPrefRadarColWidth = 1; # preferred COLUMN width in radar window - an arbitrary 1 pixel
65 my $kMaxAnnotFieldLength = 150; # max length for a field in the zoom frame to be displayed
66 my $kRadarMargin = 20; # the margin on the right side of the radar frame - affects the
67 # the size of the bracket size as well
68  
69 ### for the search tool ...... ##################
70 my $kNumberOfMaxHits = 200; # the max number of hits - result of search - to be displayed
71  
72 my $BGIMAGE = "toolbarBackground.gif";
73 my $BRACKET = "dashedLine.gif";
74  
75 #######################################################################
76 # Public class methods
77 #######################################################################
78  
79 #----------------------------------------------------------------------
80 sub New {
81 #----------------------------------------------------------------------
82 # This is the constructor for the Explorer class.
83 #
84 # Usage: $explObj = Microarray::Explorer->New( dataset => $dataset,
85 # config => $config',
86 # displayConfig => $displayConfig};
87 #
88 # Here $dataset should be a Microarray::CdtDataset object, $config is a
89 # Microarray::Config object, while $displayConfig is the name of a text file
90 # that contains info concerning how to mark up various elements of gene
91 # annotations. It is expected that the displayConfig file will be found in the
92 # $config->gxDataPath directory.
93  
94 my $class = shift;
95  
96 my $self = { };
97  
98 bless($self, $class);
99  
100 $self->_init(@_);
101  
102 return $self;
103  
104 }
105  
106 #######################################################################
107 # Public instance methods
108 #######################################################################
109  
110 #----------------------------------------------------------------------
111 sub print_frameset {
112 #----------------------------------------------------------------------
113 # This subroutine will print the whole display window anew.
114 #
115 # usage: $explorer->print_frameset();
116 #
117 #
118 my $self = shift;
119  
120 # The title of the document
121  
122 my $title = "geneXplorer ".$VERSION." : ".ucfirst($self->_name);
123  
124 $title .= " : ".$self->_dataset->width()." Experiments";
125 $title .= " : ".$self->_dataset->height()." Genes";
126  
127 # Construct the url:
128  
129 my $url = $self->{'info'}->{'url'};
130  
131 $url .= $self->{'info'}->{'scriptname'};
132 $url .= "?n=";
133 $url .= $self->_name;
134 $url .= $self->{'info'}->{'url_params'};
135  
136 # The width of the radar frame depends on the number of experiments
137  
138 my $radarFrameWidth = (($self->_dataset->width() * $self->_radar_x) + $kRadarMargin);
139  
140 # the toolbar is 100 pixels high
141  
142 my $toolBarHeight = 100;
143  
144 print title($title);
145  
146 print frameset({-cols => "$radarFrameWidth, *",
147 -marginheight => '0',
148 -marginwidth => '0',
149 -frameborder => '1',
150 -frameborder => 'yes',
151 -resize => 'no',
152 -border => '3'},
153  
154 frame({'-name' => 'r',
155 -src => $url."&a=r",
156 -marginwidth => 0,
157 -marginheight=> 0,
158 -border => 1,
159 -scrolling => "no"}
160 ),
161 "\n",
162  
163 frameset({-rows => "$toolBarHeight, *",
164 -framespacing => '0',
165 -frameborder => '1',
166 -frameborder => 'no',
167 -border => '0'},
168  
169 frame({'-name' => 't',
170 -src => $url."&a=t",
171 -marginwidth => 0,
172 -marginheight => 0,
173 -border => 1}),
174 "\n",
175 frame({'-name' => 'z',
176 -src => $url."&a=z",
177 -marginwidth => 0,
178 -marginheight => 0,
179 -border => 1}),
180 "\n")
181 );
182  
183 }
184  
185 #----------------------------------------------------------------------
186 sub radar {
187 #----------------------------------------------------------------------
188 # This subroutine prints out the content of the radar frame.
189 #
190 # usage: $explorer->radar();
191  
192 my $self = shift;
193
194 # Image attributes:
195  
196 my $width = $self->_radar_x * $self->_dataset->width; # width of radar image in pxl
197 my $height = $self->_radar_y * $self->_dataset->height(); # height of radar image in pxl
198  
199 my $imageSource =
200  
201 $self->_imgURL.$self->_name.'/'.$self->_dataset->fileBaseName.".data_matrix.".$self->_imgType;
202  
203 # The image map for the radar image
204  
205 my $radarImgLink = image_button({-src => $imageSource,
206 -width => $width,
207 -height => $height,
208 -align => 'LEFT',
209 -border => '0',
210 -hspace => '0',
211 -vspace => '0',
212 -vsize => '100%',
213 -name => 'radar'});
214  
215 # This section determines the bracket size in pixels for $kZoomWindowHeight rows
216  
217 my $bracketSize = $self->_radar_y * $kZoomWindowHeight;
218  
219 # if the dataset height is less than $kZoomWindowHeight
220  
221 $bracketSize = ($bracketSize > $height) ? $height : $bracketSize;
222  
223 # and creates the javascript for the bracket
224  
225 my ($js, $style) = $self->_js_bracket($bracketSize, $height);
226  
227 # Print the html document
228  
229 print start_html(-bgcolor => 'white',
230 -script => {-language => 'JavaScript',
231 -code => $js},
232 -style => {-code => $style},
233 -onLoad => 'init();');
234  
235 print start_form(-action => $self->{'info'}->{'self'},
236 -target => 'z'),
237  
238 div({-id => "radar1",
239 -class => "radar"},
240 $radarImgLink), # print the radar image
241  
242 div({-id => "top_bar", # upper half of bracket
243 -class => "bar"},
244 img({-border => "0",
245 -src => $self->_commonImageURL.$BRACKET,
246 -width => ($kRadarMargin * 2),
247 -height => 2})),
248  
249 div({-id => "bottom_bar", # bottom half of bracket
250 -class => "bar"},
251 img({-border => "0",
252 -src => $self->_commonImageURL.$BRACKET,
253 -width => ($kRadarMargin * 2),
254 -height => 2}));
255  
256 print hidden({'-name' => 'a',
257 -value => 'z',
258 -override => 1});
259  
260 print $self->_hide_params();
261  
262 print end_form();
263  
264 print end_html();
265  
266 }
267  
268 #----------------------------------------------------------------------
269 sub toolbar {
270 #----------------------------------------------------------------------
271 # This sub creates the toolbar frame.
272 #
273 # usage: $explorer->toolbar();
274  
275 my $self = shift;
276  
277 # GeneXplorer logo
278  
279 my $geneXplorer = b(" gene".font({-color=>'#FF8800'},"X")."plorer ".$VERSION);
280  
281 $geneXplorer = font({-face => 'verdana,arial,sans-serif',
282 -size => 2,
283 -bgcolor => 'beige'}, $geneXplorer);
284  
285 chomp($geneXplorer);
286  
287 # to diplay the info pointed to:
288  
289 my $js_info = "function info(txt) { window.frame[1].form[0].text[0].value=(txt) };\n";
290  
291 # print the html table containing the various tools
292  
293 print start_html(-background=>$self->_commonImageURL.$BGIMAGE,
294 -script =>$js_info,
295 -bgcolor=>'white');
296 print center(
297 table({-cellpadding => '3',
298 -cellspacing => '0',
299 -vspace => '0',
300 -hspace => '0',
301 -border => '0'},
302  
303 Tr ({-valign => 'middle',
304 -align => 'center',
305 -height => '10'},
306 $geneXplorer),
307
308 Tr({-nowrap => '',
309 -valign => 'middle',
310 -align => 'center',
311 -height => '10'},
312 $self->_infobox), # make the infobox
313
314 Tr({-nowrap => '',
315 -valign => 'middle',
316 -align => 'center',
317 -height => '10'},
318 $self->_searchTool, # make the search tool
319 $self->_changeTool) # make the change scale tool
320
321 )
322 );
323  
324 print end_html();
325  
326 }
327  
328 #----------------------------------------------------------------------
329 sub zoom {
330 #----------------------------------------------------------------------
331 # This subroutine creates the content of the zoom frame when called from
332 # the radar frame.
333 #
334 # usage: $explorer->zoom();
335  
336 my $self = shift;
337  
338 # Need to find out which genes to display
339  
340 my $x = ($self->_radar_x) ? $self->_radar_x : $self->_setZoom_x;
341 my $y = ($self->_radar_y) ? $self->_radar_y : $self->_setZoom_y;
342  
343 my $xClick = int (param('radar.x') / $x);
344 my $yClick = int (param('radar.y') / $y); # The click was on ROW: yClick
345  
346 # if possible, choose a few ROWs above the click
347  
348 my $yStart = (($yClick - 2) > 0) ? ($yClick - 2) : 0;
349  
350 # and if there are enough ROWs, display $kZoomWindowHeight
351  
352 my $yEnd = $yStart + $kZoomWindowHeight;
353 my $height = $self->_dataset->height();
354  
355 $yEnd = ($yEnd < $height) ? $yEnd : $height - 1;
356  
357 # Make a message for the zoom frame
358  
359 my $message = " Zoom ";
360 $message = $self->_message($message);
361  
362 # create the content of the frame
363  
364 $self->_make_zoom_image([$yStart..$yEnd], $message, '');
365  
366 }
367  
368 #----------------------------------------------------------------------
369 sub search_feature {
370 #----------------------------------------------------------------------
371 # This method takes a query string and the names of feature field
372 # to search. This way, one can search for gene symbols, gene names and/or
373 # GenBank accession numbers or any other field in the feature description.
374 #
375 # usage: $explorer->search("myWords", $field);
376 #
377 # "myWords" - can have multiple words separated by space
378 # (they are combined using 'AND')
379 # $field - has to be one value of %kDespcriptions
380  
381 my $self = shift;
382  
383 # check the parameters passed in
384  
385 my $query = _untaint(param('q'));
386 my $field = _untaint(param('f'));
387  
388 # make sure the words are long enough
389  
390 my @query = sort {length($a) <=> length($b)} split(/\s+/, $query);
391  
392 if (length($query[0]) < 2) {
393  
394 print $self->_start_html;
395 print $self->_message("&nbsp;Please use at least two letter long words in your search!");
396 return;
397  
398 }
399  
400 # create message for zoom window
401  
402 my $message = "<B style=\"color:black;background-color:#ffff66\">";
403  
404 $message .= $query;
405 $message .= "</B>";
406  
407 # find the hits
408
409 my $hits = $self->_get_search_hits(\@query, $field);
410 my $numHits = $#$hits + 1;
411  
412 if ($numHits > 0) {
413  
414 my $add_message;
415  
416 if ( $numHits > $kNumberOfMaxHits ) {
417  
418 @$hits = @$hits[0..($kNumberOfMaxHits - 1)];
419 $add_message = " Only the first $kNumberOfMaxHits are shown.";
420 }
421  
422 $message = "&nbsp;Search for $message returned ".$numHits." hits.".$add_message."\n";
423  
424 }else {
425  
426 $message = "&nbsp;The search for $message did not return any hits. Please try again.";
427  
428 }
429  
430 $message = $self->_message($message);
431  
432 if ($numHits <= 0) {
433 print $self->_start_html;
434 print $message;
435 return;
436 }
437  
438 # Create the content for zoom window to display hits
439  
440 $self->_make_zoom_image($hits, $message, '');
441  
442 }
443  
444 #----------------------------------------------------------------------
445 sub neighbors {
446 #----------------------------------------------------------------------
447 # This method generates the html and png image for the display
448 # of the most correlated gene expression vectors versus a seed vector.
449 # When a gene is clicked on in the zoom window, the most highly correlated
450 # are retrived and their expression is displayed in the zoom frame.
451  
452 my $self = shift;
453  
454 # the vector we want to correlate all others against
455  
456 my $seed = param('seed') ? param('seed') : int( param('radar.y') / $self->_radar_y );
457  
458 # the correlated genes indeces are returned in @idx, the correlations in @corrs
459  
460 my (@idx, @corrs);
461  
462 $self->_dataset->correlations($seed, \@idx, \@corrs);
463  
464 # since we want the seed as well, we stuff it in the array (on the 'left' side)
465  
466 unshift (@idx, $seed);
467  
468 # it's correlated perfectly to itself ( = 1)
469  
470 unshift (@corrs, 1);
471  
472 # create message for the zoom window
473  
474 my $message = "<B style=\"color:black;background-color:#ffff66\">";
475  
476 $message = "&nbsp;Neighbors for: ".$message.$self->_dataset->getFeature($idx[0],"NAME")."</B>";
477 $message = $self->_message($message);
478  
479 # call the sub to make the content of the zoom frame
480  
481 $self->_make_zoom_image(\@idx, $message, \@corrs);
482  
483 }
484  
485 #######################################################################
486 # Private methods
487 #######################################################################
488  
489 #----------------------------------------------------------------------
490 sub _init {
491 #----------------------------------------------------------------------
492  
493 my $self = shift;
494  
495 my $init_href = shift;
496  
497 $self->{'dataset'} = $$init_href{'dataset'} || die "You need to provide a valid dataset object to Explorer!";
498 $self->{'config'} = $$init_href{'config'} || die "You need to provide a valid config object to Explorer!";
499 $self->{'displayConfig'} = $$init_href{'displayConfig'} || die "You need to provide a valid displayConfig file to Explorer!";
500  
501 # init the info fields of the explorer object
502  
503 $self->_info;
504  
505 }
506  
507 #----------------------------------------------------------------------
508 sub _info {
509 #----------------------------------------------------------------------
510 # This procedure stores the variables pertinent to the current explorer
511 # object, run under the CGI of a certain webserver.
512
513 my $self = shift;
514  
515 $self->{'info'}->{'self'} = url();
516 $self->{'info'}->{'url'} = _get_path(url());
517 $self->{'info'}->{'path'} = $0; # absolute script path
518 $self->{'info'}->{'scriptname'} = _path_remove($0); # script name
519  
520 $self->_setZoom_x( param('zx') );
521 $self->_setZoom_y( param('zy') );
522 $self->_setRadar_x( param('rx') );
523 $self->_setRadar_y( param('ry') );
524 $self->{'info'}->{'url_params'} = "&zx=".$self->_zoom_x."&zy=".$self->_zoom_y."&rx=".$self->_radar_x."&ry=".$self->_radar_y;
525 $self->_load_displayConfig;
526 }
527  
528 #----------------------------------------------------------------------
529 sub _imgURL {
530 #----------------------------------------------------------------------
531 # This method returns the url to the image directory
532 my $self = shift;
533 return '/'.$self->{'config'}->gxRootWord.'/';
534 }
535  
536 #----------------------------------------------------------------------
537 sub _imgType {
538 #----------------------------------------------------------------------
539 # This method returns the image type based on the GD version (see
540 # Microarray::Config)
541  
542 my $self = shift;
543 return Microarray::Config->ImageType;
544 }
545  
546  
547 #----------------------------------------------------------------------
548 sub _imgPath {
549 #----------------------------------------------------------------------
550 # This method returns the full path to the image directory
551 my $self = shift;
552 return $self->{'config'}->gxHtmlPath;
553 }
554  
555 #----------------------------------------------------------------------
556 sub _tmpPath {
557 #----------------------------------------------------------------------
558 # This method returns the full path to the temp directory
559 my $self = shift;
560 return $self->{'config'}->tmpPath;
561 }
562  
563 #----------------------------------------------------------------------
564 sub _tmpURL {
565 #----------------------------------------------------------------------
566 # This method returns the url for the temp directory
567  
568 my $self = shift;
569 return $self->{'config'}->tmpUrl;
570 }
571  
572 #----------------------------------------------------------------------
573 sub _commonImageDir {
574 #----------------------------------------------------------------------
575 # This method returns the full path for the common images directory
576  
577 my $self = shift;
578 return $self->{'config'}->gxImagesPath;
579 }
580  
581 #----------------------------------------------------------------------
582 sub _commonImageURL {
583 #----------------------------------------------------------------------
584 # This method returns the url for the common images directory
585  
586 my $self = shift;
587 return $self->{'config'}->gxImagesURL;
588 }
589  
590 #----------------------------------------------------------------------
591 sub _displayConfig {
592 #----------------------------------------------------------------------
593 # This subroutine returns the path to the displayConfig file
594  
595 my $self = shift;
596 $self->{'displayConfig'} = $self->{'config'}->gxDataPath.$self->{'displayConfig'};
597 return $self->{'displayConfig'};
598 }
599  
600 #----------------------------------------------------------------------
601 sub _zoom_y {
602 #----------------------------------------------------------------------
603 # The height of a row in the zoom frame in pixels
604  
605 my $self = shift;
606 return $self->{'info'}->{'zy'};
607 }
608  
609 #----------------------------------------------------------------------
610 sub _zoom_x {
611 #----------------------------------------------------------------------
612 # The width of a column in the zoom frame in pixels
613  
614 my $self = shift;
615 return $self->{'info'}->{'zx'};
616 }
617  
618 #----------------------------------------------------------------------
619 sub _radar_y {
620 #----------------------------------------------------------------------
621 # The height of a row in the radar frame in pixels
622  
623 my $self = shift;
624 return $self->{'info'}->{'ry'};
625 }
626  
627 #----------------------------------------------------------------------
628 sub _radar_x {
629 #----------------------------------------------------------------------
630 # The height of a row in the radar frame in pixels
631  
632 my $self = shift;
633 return $self->{'info'}->{'rx'};
634 }
635  
636 #----------------------------------------------------------------------
637 sub _setZoom_y {
638 #----------------------------------------------------------------------
639 # In the zoom frame the height of one image row is set to between
640 # $kMaxZoomHeight and $kMinZoomHeight pixels.
641  
642 my $self = shift;
643 my $zy;
644  
645 # if zoom height is provided - use what is given
646 if ( @_ ) {
647 $zy = shift; # row height in pixels
648 $zy = ($zy > $kMaxZoomRowHeight) ? $kMaxZoomRowHeight : $zy;
649 $zy = ($zy < $kMinZoomRowHeight) ? $kMinZoomRowHeight : $zy;
650 }
651  
652 # if zoom height is unspecified it is set to the default minimum
653 else{
654 $zy = $kMinZoomRowHeight;
655 }
656 $zy = int ($zy);
657 $self->{'info'}->{'zy'} = $zy;
658 }
659  
660 #----------------------------------------------------------------------
661 sub _setZoom_x {
662 #----------------------------------------------------------------------
663 # In the zoom frame the width of one image column is set to between 10
664 # pixels and $kMaxZoomWidth/(number of columns) pixels.
665  
666 my $self = shift;
667  
668 my $zx; # column width in pixels
669 my $ds_width = $self->_dataset->width();
670 my $max_col_width = $kMaxZoomWidth / $ds_width; # a column can be only
671 # this wide
672 if (@_) { # if there is a request ...
673 $zx = shift;
674 # if requested column width is bigger than the limit
675 $zx = ($zx > $max_col_width) ? $max_col_width : $zx;
676 }
677  
678 # if zoom image column width is unspecified it is set to the default
679 else{
680 $zx = ($max_col_width > $kPrefZoomColWidth) ? $kPrefZoomColWidth : $max_col_width;
681 }
682 $zx = int ($zx);
683 $self->{'info'}->{'zx'} = $zx;
684 }
685  
686 #----------------------------------------------------------------------
687 sub _setRadar_x {
688 #----------------------------------------------------------------------
689 # In the radar frame the width of one image column is set to between 2 pixels
690 # and $kMaxRadarWidth/(number of columns in dataset) pixels.
691  
692  
693 my $self = shift;
694 my $rx; # column width on radar in pixels
695 my $ds_width = $self->_dataset->width(); # number of columns
696 my $max_col_width = $kMaxRadarWidth / $ds_width; # max width of a column
697  
698 if (@_) { # if there is a request ...
699 $rx = shift;
700 # if requested column width is bigger than the limit
701 $rx = ($rx > $max_col_width) ? $max_col_width : $rx;
702 }
703 # if undefined it is set to a default of 100/(# of expts), but at least 1
704 else{
705 $rx = ($max_col_width > $kPrefRadarColWidth) ? $kPrefRadarColWidth : $max_col_width;
706 }
707 $rx = sprintf("%2.2f", $rx);
708 $self->{'info'}->{'rx'} = $rx;
709 }
710  
711 #----------------------------------------------------------------------
712 sub _setRadar_y {
713 #----------------------------------------------------------------------
714 # In the radar frame the height of one image row is set
715  
716 my $self = shift;
717 my $ry;
718 my $ds_height = $self->_dataset->height();
719 my $max_row_height = $kMaxRadarHeight / $ds_height;
720  
721 if ( @_ ) { # if there is a request ...
722 $ry = shift;
723 # if requested row height is bigger than the limit
724 $ry = ($ry > $max_row_height) ? $max_row_height : $ry;
725 }
726  
727 # if not specified set to the preferred or to the limit
728 else{
729 $ry = ($max_row_height > $kPrefRadarRowHeight) ? $kPrefRadarRowHeight : $max_row_height;
730 }
731 $ry = sprintf("%2.2f", $ry);
732 $self->{'info'}->{'ry'} = $ry;
733 }
734  
735 #----------------------------------------------------------------------
736 sub _start_html{
737 #----------------------------------------------------------------------
738  
739 my $self = shift;
740 print <<EOM;
741 <HTML>
742 <HEAD>
743 <STYLE TYPE="text/css">
744 .img1 { vertical-align: bottom; }
745 .font1 { font-size: 75%; }
746 </STYLE>
747 <BODY BGCOLOR='white'>
748 EOM
749 return;
750 }
751  
752 #----------------------------------------------------------------------
753 sub _make_zoom_image {
754 #----------------------------------------------------------------------
755 # This subroutine crates the content of the zoom frame. It expects an
756 # - array reference that contains the indeces of data matrix rows to display;
757 # - string that contains an html-formatted message for the frame to display;
758 # - array reference
759  
760 my $self = shift;
761  
762 my ($rows_ra, $message, $corr_ra) = @_;
763  
764 my $js = script({-language => "JavaScript"},
765 "function info(txt) { parent.t.document.infobox.text.value=(txt) };")."\n";
766  
767 # This section creates a table with each row showing data for a gene
768 # get image rows requested
769  
770 my $row_images = $self->_make_row_image ($rows_ra);
771  
772 # mark up the image rows and and create html table using feature info
773  
774 my $html_table = $self->_make_html_table($rows_ra, $row_images, $corr_ra);
775  
776 $self->_makeExptImageMap();
777
778 $self->_start_html;
779  
780 print $js;
781  
782 print $message;
783  
784 print $self->{'exptMap'};
785  
786 print table({-border => 0,
787 -cellspacing => 2,
788 -cellpadding => 0,
789 -align => 'LEFT'},
790 Tr(
791 $self->{'exptImage'}, "\n",
792 td({-colspan => 1,
793 -align => 'left'},
794 $self->_contrast_legend
795 ), "\n"
796 ), "\n",
797 Tr(
798 td({-colspan => 2,
799 -valign => 'top'}, $html_table
800 ), "\n"
801 ), "\n"
802 )."\n";
803  
804 print end_html();
805  
806 }
807  
808 #--------------------------------------------------------------------
809 sub _make_row_image {
810 #--------------------------------------------------------------------
811 # This method takes as input an array reference that should contain an
812 # ordered index of rows requested from the matrix image.
813 # The image (matrix image) is broken up into individual row images and
814 # and the ones pointed to by the array indeces are passed on for saving
815 # and upon saving returned to the calling function
816  
817 my $self = shift;
818 my $index_aref = shift;
819  
820 my $source_image = $self->_dataset->image("matrix");
821 my $width = $self->_dataset->width();
822 my ($height, @row_images);
823  
824 # the height for the ROW images = 1
825 $height = 1;
826 # break up the source image into image rows
827 for (my $i = 0; $i <= $#$index_aref; $i++ ) {
828 my $image_row = new GD::Image($width, $height);
829 $image_row->copy($source_image, 0, 0, 0, $$index_aref[$i], $width, $height);
830 push (@row_images, $image_row);
831 }
832 $self->_save_img_files($index_aref, \@row_images);
833 }
834  
835 #----------------------------------------------------------------------
836 sub _save_img_files{
837 #----------------------------------------------------------------------
838 # This subroutine saves the image files that are passed in in the form of
839 # an array reference. In addition it expects another array reference that
840 # is an index file specifying which rows of the matrix image the array images
841 # came from.
842  
843 my $self = shift;
844 my ($ids_ra, $images_ra) = @_;
845 my (@image_files);
846  
847 my $imgSuffix = $self->_imgType;
848  
849 for (my $i = 0; $i <= $#$ids_ra; $i++) {
850 my $img_file = $self->_name.$$ids_ra[$i].'.'.$imgSuffix; # name of row image
851 $img_file =~ s/\//_/g; # substitute underscores for slashes in dataset name
852 my $path = $self->_tmpPath.$img_file; # path to row image in temp directory
853 my $image = $$images_ra[$i]->$imgSuffix(); # the row image object
854 if ((!(-e $path)) || (-z $path)) { # if image file does not exist
855 open( OUT,">$path" ) || warn "Cannot print temp image: $!\n";
856 binmode OUT;
857 print OUT $image;
858 close(OUT);
859 }
860 push (@image_files, $img_file);
861 }
862 return \@image_files;
863 }
864  
865 #----------------------------------------------------------------------
866 sub _makeExptImageMap {
867 #----------------------------------------------------------------------
868 ##This will create the content of the infobox: when the mouse is over some
869 ## experiment in the zoom frame this will display the name of the
870 ## appropriate experiment.
871  
872 my $self = shift;
873 return if ((defined $self->{'exptImage'}) && (defined $self->{'exptMap'}));
874 my ($x1, $y1, $x2, @map, $area, $map, $onMouseOver, $imgWidth, $exptImage, $expImgHeight, $height);
875 # The next section creates the experiment image map
876 # first, determine the size of the image
877 ($imgWidth, $expImgHeight) = $self->_dataset->image("expt_info")->getBounds();
878 $imgWidth = $self->_dataset->width() * $self->_zoom_x;
879 $height = ($expImgHeight > $kExpImgHeight) ? $expImgHeight : $kExpImgHeight;
880
881 # then make the html for the image
882 $exptImage = img({-src => $self->_imgURL.$self->_name.'/'.$self->_dataset->fileBaseName.".expt_info.".$self->_imgType,
883 -width => $imgWidth,
884 -ismap => '',
885 -usemap => '#EXPT',
886 -border => '0'});
887  
888 $exptImage = td({-colspan => '1',
889 -valign => 'bottom',
890 -align => 'left',
891 -height => $height}, $exptImage
892 )."\n";
893  
894 $self->{'exptImage'} = $exptImage;
895  
896 # and create the image map
897 my $script_name = $self->{'info'}->{'scriptname'};
898 $y1 = 0;
899  
900 for (my $i=0; $i < $self->_dataset->width; $i++){
901 $x1 = int ($i * $self->_zoom_x);
902 $x2 = int ( ($i * $self->_zoom_x) + $self->_zoom_x);
903  
904 my $text = $self->_dataset->experiment($i, "NAME");
905 $text =~ s/\"//g;
906 $onMouseOver = "onMouseOver=\"javascript:info('EXPT: ".$text."')\"";
907 $area = "<AREA SHAPE=\"RECT\" COORDS=\"$x1, $y1, $x2, $expImgHeight\" HREF=\"#\" ";
908 $area .= $onMouseOver.">\n";
909 push @map, $area;
910 }
911 $map = "<MAP NAME=\"EXPT\">@map</MAP>";
912 $self->{'exptMap'} = $map;
913 }
914  
915 #----------------------------------------------------------------------
916 sub _row_image_markup {
917 #----------------------------------------------------------------------
918 ## This subroutine will mark up the row image in the zoom window:
919 ## - for the infobox: when the mouse is over some gene in the zoom frame
920 ## the name of the appropriate gene is shown.
921 ## - for the correlations display when a gene is clicked on
922  
923  
924 my $self = shift;
925 my $i = shift; # which row in the matrix image
926 my $image_ref = shift; # the row image
927 my $width = shift; # the width of the image display
928 my ($onMouseOver, $area);
929  
930 # display the row image
931 $image_ref = img({-src => $self->_tmpURL.$image_ref,
932 -height => $self->_zoom_y,
933 -width => $width,
934 -border => '0'});
935  
936 # the javascript to display the content of the infoBox for the row
937 $onMouseOver = $self->_dataset->getFeature($i, "NAME");
938 $onMouseOver =~ s/\"//g;
939 $onMouseOver = "onMouseOver=\"javascript:info('GENE: ".$onMouseOver."')\"";
940
941 # construct the url for corr in case the row is clicked on
942 $area = "\n<a HREF=\"".$self->{'info'}->{'scriptname'};
943 $area .= "?n=".$self->_name."&a=c&seed=$i".$self->{'info'}->{'url_params'}.'" ';
944 $area .= $onMouseOver.">\n".$image_ref."</a>";
945 }
946  
947 #--------------------------------------------------------------------
948 sub _make_html_table {
949 #--------------------------------------------------------------------
950 # This method takes a list of vector indices and returns a completely
951 # marked up HTML version. The markup is done according to a displayConfig
952 # file that is associated with this explorer object / dataset.
953  
954 my $self = shift;
955 my $index_ref = shift; # the indeces of the rows in data matrix that are requested
956 my $image_ra = shift; # the corresponding row images
957 my $corr_ra = shift; # the corresponding correlation values (may be empty)
958 my ($row, @rows, $row_table, $row_image);
959 my $imgWidth = $self->_dataset->width() * $self->_zoom_x;
960  
961 # for every row, do the markup
962 for (my $i=0; $i <= $#$index_ref; $i++) {
963 # if there is correlation value for this row
964 if ($corr_ra) {
965 $row = $self->_feature_markup( $$index_ref[$i], $$corr_ra[$i] );
966 }
967 # if there is no corralation to display
968 else{
969 $row = $self->_feature_markup( $$index_ref[$i] );
970 }
971 # markup the image row
972 $row_image = $self->_row_image_markup($$index_ref[$i], $$image_ra[$i], $imgWidth);
973 # make a row in an html table
974 push @rows, Tr(
975 td(
976 $row_image
977 ), "\n",
978 td({-height=>$self->_zoom_y},
979 $row
980 ), "\n",
981 )."\n";
982 }
983 # make the table from the marked up row
984 $row_table = table({-border => '0',
985 -cellborder => '0',
986 -cellpadding => '0',
987 -cellspacing => '0'},
988 @rows)."\n";
989 }
990  
991 #--------------------------------------------------------------------
992 sub _searchTool {
993 #--------------------------------------------------------------------
994 # This sub creates the searchtool for the toolbar and returns it as
995 # html, as a table cell.
996  
997 my $self = shift;
998 my (@keys_used, %desc_used, $searchform, $cell1);
999  
1000 @keys_used = $self->_dataset->getFeatureKeys(); # get the keys used here and sort by (future) value
1001 unshift @keys_used, "ALL"; # add ALL to search all
1002 # and sort by (future) value
1003 @keys_used = sort {$self->{'style'}->{$a}->{'display'} cmp $self->{'style'}->{$b}->{'display'}} @keys_used;
1004  
1005 foreach (@keys_used) { # descriptions for used keys
1006 $desc_used{$_} = $self->{'style'}->{$_}->{'display'};
1007 }
1008  
1009 # make the html form
1010 $searchform = start_form(-action => $self->{'info'}->{'self'},
1011 -target => 'z');
1012 $searchform .= "<td>";
1013 $searchform .= b("Search for ");
1014 $searchform .= textfield(-size => '8',
1015 -maxlength => '20',
1016 -name => 'q');
1017 $searchform .= b(" in ");
1018 $searchform .= popup_menu(-values => \@keys_used,
1019 -labels => \%desc_used,
1020 -name => 'f',
1021 -default => 'ALL');
1022 $searchform .= submit(-label => 'go');
1023  
1024 $searchform .= hidden(-name => 'a',
1025 -value => 's',
1026 -override => 1);
1027 $searchform .= $self->_hide_params();
1028 $searchform .= "</td>";
1029 $searchform .= end_form();
1030 $searchform = font({-face => 'verdana,arial,sans-serif',
1031 -size => 2}, $searchform
1032 );
1033 chomp($searchform);
1034 return $searchform;
1035 }
1036  
1037 #----------------------------------------------------------------------
1038 sub _changeTool {
1039 #----------------------------------------------------------------------
1040 # This subroutine will create the change radar scale tool for the toolbar
1041 # and returns it as html, as a table cell.
1042  
1043 my $self = shift;
1044 my (%change_scale, @scale_values, $changeform, %display);
1045 # labels for changing radar frame scale
1046 %change_scale = ( "0.5" => " 50%",
1047 "1" => "100%",
1048 "2" => "200%",
1049 "4" => "400%");
1050  
1051 foreach (sort keys %change_scale){
1052 # display the percentages
1053 $display{sprintf("%2.2f", $_ * $self->_radar_x)} = $change_scale{$_};
1054 # submit the new rx values
1055 push (@scale_values, sprintf("%2.2f", $_ * $self->_radar_x));
1056 }
1057  
1058 # make the html form for this tool - it is formatted as a table cell
1059 $changeform = start_form(-action => $self->{'info'}->{'self'},
1060 -target => '_top');
1061 $changeform .= "<td>";
1062 $changeform .= "Radar ";
1063 $changeform .= popup_menu(-values => \@scale_values,
1064 -labels => \%display,
1065 -name => 'rx',
1066 -default => '1');
1067 $changeform .= " wide ";
1068 $changeform .= submit(-label => 'change');
1069 $changeform .= $self->_hide_params();
1070 $changeform .= "</td>";
1071 $changeform .= end_form();
1072 $changeform = font({-face => 'verdana,arial,sans-serif',
1073 -size => 2}, $changeform
1074 );
1075 chomp($changeform);
1076 return $changeform;
1077 }
1078  
1079 #----------------------------------------------------------------------
1080 sub _infobox {
1081 #----------------------------------------------------------------------
1082 # This sub creates the infobox tool for the toolbar and returns it as
1083 # html, as a table cell.
1084  
1085 my $self = shift;
1086 my $infobox;
1087
1088 # the html form for this tool
1089 $infobox = start_form({-name => 'infobox'},
1090 ""
1091 );
1092 $infobox .= "<td colspan=\"2\">"; # It is a 2 column wide cell
1093 $infobox .= textfield({-size => '100',
1094 -name => 'text',
1095 -value => 'Put your mouse over elements to see more information here'}
1096 );
1097 $infobox .= "</td>";
1098 $infobox .= end_form;
1099 chomp($infobox);
1100 return $infobox;
1101 }
1102  
1103 #--------------------------------------------------------------------
1104 sub _feature_markup {
1105 #--------------------------------------------------------------------
1106 # This subroutine will markup as html the annotations for a row in the
1107 # zoom table
1108  
1109 my $self = shift;
1110 my $feature_num = shift; # the index of the row to markup in the feature table
1111 my $corr = @_ ? shift : undef; # if there is a corr value provided
1112 my ($data, $spacer, $fieldsUsed, $row, $field);
1113  
1114 # flag for flipping the row background color
1115 $flip = $flip ? 0 : 1;
1116 # the fields that are actually used for this dataset
1117 $fieldsUsed = $self->_style_keys;
1118 # first format the spacer that will separate the individual fields
1119 $spacer = $self->_markup_cell("&nbsp;", 'NUM', $flip);
1120 # if there is a correlation value, mark it up
1121 $row .= $self->_markup_cell($corr, 'CORR', $flip) if ($corr);
1122 $row .= $spacer;
1123 # mark up each field
1124 foreach $field (@$fieldsUsed) {
1125 # the piece of the that needs markup
1126 $data = $self->_dataset->getFeature($feature_num, $field);
1127 if (length($data) > $kMaxAnnotFieldLength){ # if the data is too long to display
1128 $data = substr($data, 0, $kMaxAnnotFieldLength);
1129 $data .= "... ";
1130 }
1131 $row .= $self->_markup_cell($data, $field, $flip);
1132 $row .= $spacer;
1133 }
1134 return $row;
1135 }
1136  
1137 #---------------------------------------------------------------------------------------
1138 sub _markup_cell {
1139 #---------------------------------------------------------------------------------------
1140 # This function returns a TABLE DATA marked up piece of HTML.
1141 # usage: markup_cell ( the piece of data to markup, the type of data, flag to format bkground in table )
1142
1143 my $self = shift;
1144 my $data = shift;
1145 my $colname = shift;
1146 my $flip = shift;
1147 my ($color, $bgcolor, $url, $content, $href, $cell, $height, $width, $name, $image,
1148 %anchor_attr, $target, $font_face, $font_size, $font_color, $bold);
1149  
1150 $color = exists($self->{'style'}->{$colname}->{color}) ? $self->{'style'}->{$colname}->{color} : "white";
1151 $bgcolor = exists($self->{'style'}->{$colname}->{bgcolor}) ? $self->{'style'}->{$colname}->{bgcolor} : ($flip ? "white" : "#EEEEEE");
1152 $url = $self->{'style'}->{$colname}->{'url'};
1153 # if data empty or no data was found, return minimal cell content immediately
1154 if (!defined($data) || $data =~ /$colname/i) {
1155 $cell = td({-height => $self->_zoom_y,
1156 -nowrap => '',
1157 -bgcolor => $bgcolor},
1158 ,"");
1159 return $cell;
1160 }
1161 # print $data, br, $colname, br;
1162 $target = exists($self->{'style'}->{$colname}->{target}) ? $self->{'style'}->{$colname}->{target} : undef;
1163 $font_face = exists($self->{'style'}->{$colname}->{font_face}) ? $self->{'style'}->{$colname}->{font_face} : undef;
1164 $font_size = exists($self->{'style'}->{$colname}->{font_size}) ? $self->{'style'}->{$colname}->{font_size} : 1;
1165 $font_color = exists($self->{'style'}->{$colname}->{font_color}) ? $self->{'style'}->{$colname}->{font_color} : "black";
1166 $bold = exists($self->{'style'}->{$colname}->{bold});
1167  
1168 $content = $data;
1169
1170 # if an image was defined for this field, we make an HTML element (the images
1171 # have to be in the common image dir
1172 if ($self->{'style'}->{$colname}->{image}){
1173 if ($colname eq "CORR") { # format the bar for correlations
1174 $height = $self->_zoom_y - 2;
1175 $width = ($data - 0.4) * 40; # only corrs above 0.5 are given, but make sure something is shown
1176 $image = img({-border => 0,
1177 -height => $height,
1178 -width => $width,
1179 -alt => "correlation = ".$data,
1180 -name => $data,
1181 -onmouseover => "javascript:info('CORR: ".$data."')",
1182 -src => $self->_commonImageURL.$self->{'style'}->{$colname}->{image}}
1183 );
1184 }
1185 else {
1186 $image = img({-border => 0,
1187 -src => $self->_commonImageURL.$self->{'style'}->{$colname}->{image}}
1188 );
1189 }
1190 }
1191  
1192 # build a URL when present in the displayConfig file
1193 if ($self->{'style'}->{$colname}->{url_append} || $self->{'style'}->{$colname}->{url_replace}) {
1194 if ($self->{'style'}->{$colname}->{url_append}){
1195 $href = "http://".$url.$data;
1196 }
1197 elsif ($self->{'style'}->{$colname}->{url_replace}){
1198 $url =~ s/XXX/$data/;
1199 $href = "http://".$url;
1200 }
1201 $anchor_attr{'-href'} = $href;
1202 if ($target){
1203 $anchor_attr{'-target'} = $target;
1204 }
1205 # if an image has been defined, replace the text with it
1206 if ($image){
1207 $content = a(\%anchor_attr, "\n".$image);
1208 }
1209 else {
1210 $content = a(\%anchor_attr, $data);
1211 }
1212 }
1213  
1214 # if an image, but no link was requested, make only the image table cell content
1215 # this case more exceptional, we use it for the correlation display bars
1216 if ($image && !$href) {
1217 $content = $image;
1218 }
1219
1220 # if bold was requested, add <b> tags
1221 if ($bold && !$image) {
1222 $content = b($content);
1223 }
1224 if ($font_face || $font_size) {
1225 $content = font(
1226 {-face => $font_face,
1227 -size => $font_size},
1228 $content
1229 );
1230 }
1231 $cell = td(
1232 {-height => $self->_zoom_y,
1233 -bgcolor => $bgcolor,
1234 -nowrap => ''},
1235 "\n", $content
1236 )."\n";
1237 }
1238  
1239 #--------------------------------------------------------------------
1240 sub _style_keys {
1241 #--------------------------------------------------------------------
1242 # This subroutine will return the a list of the column names that are
1243 # actually used in the feature table for annotation of the dataset. They
1244 # are returned as elements of an array in the order they are to be
1245 # displayed (that is determined by the order they are listed in the
1246 # displayConfig file).
1247  
1248 my $self = shift;
1249 my (@keyStyles, @feature_keys, @ordered_style_keys);
1250  
1251 # load displayConfig file if needed
1252 $self->_load_displayConfig() unless (defined($self->{'style'}));
1253 # all potential columns
1254 @keyStyles = keys %{ $self->{'style'} };
1255 # the ones used for annotation
1256 @feature_keys = $self->_dataset->getFeatureKeys();
1257 # put the ones used in an ordered array
1258 foreach (@feature_keys) {
1259 $ordered_style_keys[$self->{'style'}->{$_}->{'order'}] = $_;
1260 }
1261 return (\@ordered_style_keys);
1262 }
1263  
1264 #--------------------------------------------------------------------
1265 sub _load_displayConfig {
1266 #--------------------------------------------------------------------
1267 # This subroutine parses a markup displayConfig file that can be user defined.
1268 # The displayConfig file contains information on the rendering and linking of
1269 # the fields within an HTML table. This information is used in the
1270 # _table_html_markup function.
1271 # The displayConfig file is expected as a test file containing records in the
1272 # following format:
1273 #
1274 # # comment line
1275 # colname = name of the column from feature info file
1276 # display = how the colname should be displayed in the seach box
1277 # bgcolor = background color of table cell
1278 # color = text color
1279 # url = a URL to use for building a link with the column content
1280 # image = an image that replaces the cell content
1281 # url_append = One value that gets appended to the URL (or self, see below)
1282 # url_replace = what value/text should be put into the placeholder
1283 # positions in the URL string. The values have to be '|' delimited.
1284 # The placeholders have to be three uppercase letters,
1285 # starting with Z and descending (ZZZ, YYY, XXX, WWW etc.)
1286 # There can be multiple replacement values for each URL.
1287 # They will be put in in the given order.
1288 # A special replacement value is 'self', which is the column value.
1289 # url_target = target window for the URL to be build.
1290 # font = desired font for display
1291 # //
1292 #
1293 my $self = shift;
1294 my (%tmphash, @sections, $counter, $displayConfig);
1295  
1296 $displayConfig = $self->_displayConfig;
1297 if (!$displayConfig) {
1298 # if no displayConfig file is defined use the keys that are in the feature table
1299 my @feature_keys = $self->_dataset->getFeatureKeys;
1300 foreach (@feature_keys ) {
1301 $self->{'style'}->{ $_ }->{bgcolor} = "white";
1302 # and display them accordingly
1303 $self->{'style'}->{ $_ }->{'display'} = $_;
1304 }
1305 return;
1306 }
1307 # read in the displayConfig file
1308 open (IN, $displayConfig) || die("Could not open displayConfig $displayConfig: ", $!, "!");
1309 $/ = '//'; # temporarily set the line end delimiter to '//'.
1310 # This is the divider between sections in our file
1311 @sections = (<IN>);
1312 close(IN);
1313 $/ = "\n"; # set the line end delimiter back to newline
1314 $counter = 0; # counter, because we need to store the order in which
1315 # the markup is encountered in the displayConfig file
1316  
1317 # get rid of characters, lines not needed, for each key
1318 foreach (@sections) {
1319 my @rows = split(/\n/, $_);
1320 foreach (@rows){
1321 chomp; # no newline
1322 s/#.*//; # no comment
1323 s/\/\///; # no record delimiter
1324 s/^\s+//; # no leading white
1325 s/\s+$//; # no trailing white
1326 # s/ //g;
1327 next unless length; # anything left?
1328 my ($var, $value) = split(/\s*=\s*/, $_, 2);
1329 # print '_var_', $var, '_value_', $value, br;
1330 $tmphash{$var} = $value;
1331 }
1332 my $colname = $tmphash{'colname'};
1333 delete $tmphash{'colname'}; # remove this key/value pair from hash
1334 foreach (keys %tmphash) {
1335 $self->{'style'}->{ $colname }->{$_} = $tmphash{$_};
1336 }
1337 # if display was not specified, use column name
1338 if (!exists $self->{'style'}->{ $colname }->{'display'}){
1339 $self->{'style'}->{ $colname }->{'display'} = $colname;
1340 }
1341 # store the number at which this columname occured in the file
1342 # this will later determine the output order
1343 $self->{'style'}->{ $colname }->{'order'} = $counter++;
1344 undef %tmphash;
1345 }
1346 }
1347  
1348 #--------------------------------------------------------------------
1349 sub _hide_params {
1350 #--------------------------------------------------------------------
1351 # This sub will hide the parameters form the url
1352 my $self = shift;
1353 my $hidden_fields;
1354  
1355 $hidden_fields = hidden({'-name' => 'rx', -value => $self->_radar_x });
1356 $hidden_fields .= hidden({'-name' => 'ry', -value => $self->_radar_y });
1357 $hidden_fields .= hidden({'-name' => 'zx', -value => $self->_zoom_x });
1358 $hidden_fields .= hidden({'-name' => 'zy', -value => $self->_zoom_y });
1359 $hidden_fields .= hidden({'-name' => 'n', -value => $self->_name });
1360  
1361 return $hidden_fields;
1362 }
1363  
1364 #----------------------------------------------------------------------
1365 sub _get_search_hits {
1366 #----------------------------------------------------------------------
1367 # This subroutine retrives the hits based on the search query entered in
1368 # the searchbox.
1369 # \@hits = _get_search_hits (\@query, $field)
1370 #
1371 # where - @query contains the words used for searching, they will
1372 # be combined by logical 'AND'
1373 # - $field selected field for search
1374  
1375 my $self = shift;
1376 my ($query, $field) = @_;
1377  
1378 my (@hit_bitvec, $resultvec, @hits, @query);
1379  
1380 # if the user submitted a multi word query we search each element separately
1381 # here we extract the space separated words from the query parameter field
1382 @query = @$query;
1383  
1384 for (my $i=0; $i <= $#query; $i++){ # for each query word
1385  
1386 # initialize a bitvector (one bit for each gene in dataset) by setting the last bit
1387 vec( $hit_bitvec[$i], $self->_dataset->height + 1, 1) = 1;
1388 # dataset->search() returns an index of features that matched the search term
1389 @hits = $self->_dataset->search($query[$i], $field);
1390  
1391 for(my $j=0; $j <= $#hits; $j++){
1392 # set the nth bit in the vector to store the hit information
1393 vec($hit_bitvec[$i], $hits[$j], 1) = 1;
1394 }
1395 undef (@hits);
1396 }
1397  
1398 # initialize the result bitvector with the bitvector for the first search term
1399 $resultvec = $hit_bitvec[0];
1400 # logically AND all consecutive bitvectors
1401 for (my $k=1; $k <= $#hit_bitvec; $k++) {
1402 $resultvec = $resultvec & $hit_bitvec[$k];
1403 }
1404  
1405 # read the resultvector back out into an array
1406 for (my $l=0; $l <= $self->_dataset->height; $l++) {
1407 if (vec($resultvec,$l,1)) {
1408 push @hits, $l;
1409 }
1410 }
1411 return \@hits;
1412 }
1413  
1414 #--------------------------------------------------------------------
1415 sub _contrast_legend {
1416 #--------------------------------------------------------------------
1417 # This sub will display the appropriate scalebar. Once is created, it
1418 # is reused.
1419 # The scale is made as a table with 2 rows; one row contains the values,
1420 # the other the corresponding images (pixels).
1421  
1422 my $self = shift;
1423  
1424 return if (defined $self->{'scale'});
1425  
1426 my ($scaleImage, $table, $width, $height, @pixelnames, @pixels,
1427 $pixels, $step, $colScheme, @rows, @bla, $contrast);
1428  
1429 # define a few constants and load the scale image
1430 $contrast = $self->_dataset->contrast;
1431 $colScheme = $self->_dataset->colorScheme;
1432 $scaleImage = $self->_load_image($self->_commonImageDir.'scale_'.$colScheme.'.'.$self->_imgType);
1433 ($width, $height) = $scaleImage->getBounds();
1434  
1435 # break up the image into pixels
1436 for (my $i = 0; $i < $width; $i++){
1437 $pixels[$i] = GD::Image->new(1, 1);
1438 $pixels[$i]->copy($scaleImage, 0, 0, $i, 0, 1, 1);
1439 push (@pixelnames, 'pixel'.$colScheme.$i);
1440 }
1441 # save the pixels and get their path in $pixels
1442 $pixels = $self->_save_img_files(\@pixelnames, \@pixels);
1443  
1444 # find out the fold change numbers
1445 $step = $contrast / 4;
1446 $rows[0] = "&nbsp;1:1 "; # this is the center - no change
1447 for (my $i = $step; $i <= $contrast; $i += $step) {
1448 push @rows, "&nbsp;&gt; ".sprintf("%2.1f", 2**$i)." "; # * step increase
1449 unshift @rows, "&nbsp;&lt; 1/".sprintf("%2d", 2**$i)." "; # 1/step decrease
1450 }
1451  
1452 # format the output as a table
1453 for (my $i = 0; $i <= $#rows; $i++) {
1454 push (@bla, td({-cellpadding => '5',
1455 -height => '14',
1456 -width => '50',
1457 -bgcolor => 'white',
1458 -border => 3,
1459 -align => 'center'},
1460 font({-face => 'verdana,arial,sans-serif',
1461 -size => '1'}
1462 ),
1463 $rows[$i]
1464 )."\n"
1465 );
1466 $$pixels[$i] = td({-background => $self->_tmpURL.$$pixels[$i],
1467 -height => '15'}
1468 )."\n";
1469 }
1470 $table = table({-border => '0',
1471 -cellspacing => '0',
1472 -cellpadding => '0'},
1473 Tr(
1474 b(@bla)
1475 ), "\n",
1476 Tr(
1477 @$pixels
1478 ), "\n"
1479 )."\n";
1480 $self->{'scale'} = $table;
1481 }
1482  
1483 #--------------------------------------------------------------------
1484 sub _load_image {
1485 #--------------------------------------------------------------------
1486 # this sub will load an image, file name should contain the full path
1487  
1488 my ($self, $filename) = @_;
1489 open(IN, $filename) || die "cannot open image within explorer: $filename! $!\n";
1490 my $image = ($self->_imgType eq 'gif') ? GD::Image->newFromGif(*IN) : GD::Image->new(*IN);
1491 return $image;
1492 }
1493  
1494 #--------------------------------------------------------------------
1495 sub _dataset {
1496 #--------------------------------------------------------------------
1497
1498 my $self = shift;
1499 return $self->{dataset};
1500 }
1501  
1502 #----------------------------------------------------------------------
1503 sub _name {
1504 #----------------------------------------------------------------------
1505 # Returns the name of the dataset.
1506  
1507 my $self = shift;
1508 return $self->_dataset->name();
1509 }
1510  
1511 #--------------------------------------------------------------------
1512 sub _get_path {
1513 #--------------------------------------------------------------------
1514 # Returns the URL of the script. (Removes everything after the last '/')
1515 my $url = shift;
1516 $url =~ /(.*\/).+$/;
1517 return $1;
1518 }
1519  
1520 #--------------------------------------------------------------------
1521 sub _path_remove {
1522 #--------------------------------------------------------------------
1523 # Removes the path info (everything up to the last '/')
1524 my $file = shift;
1525 my $position = rindex $file, "/";
1526 my $name = substr $file, $position + 1;
1527 return $name;
1528 }
1529  
1530 #--------------------------------------------------------------------
1531 sub _untaint {
1532 #--------------------------------------------------------------------
1533 # Removes shell characters from a string.
1534 my $value = shift;
1535 $value =~ s/[!@\$%\^&\*\(\)?#|~]//g;
1536 return $value;
1537 }
1538  
1539 #----------------------------------------------------------------------
1540 sub _message {
1541 #----------------------------------------------------------------------
1542 # a small sub to return marked up message for display
1543
1544 my $self = shift;
1545 my $message = shift;
1546  
1547 $message = table({-cellpadding => 3},
1548 Tr(
1549 td({-colspan => '2',
1550 -height => '20',
1551 -bgcolor => 'beige'},
1552 font({-face => 'arial,sans-serif',
1553 -size => 3}, b($message)
1554 ), "\n"
1555 ), "\n"
1556 ), "\n"
1557 )."\n";
1558  
1559 return $message;
1560 }
1561  
1562 #--------------------------------------------------------------------
1563 sub _js_bracket {
1564 #--------------------------------------------------------------------
1565 # This sub creates the javascript to display the bracket in the radar
1566 # frame at the position where the image was clicked on. The bracket is
1567 # displayed on the right edge of the window.
1568  
1569 my $self = shift;
1570 my $window_y = shift; # the distance between the bars (bracket in pixels
1571 my $height = shift; # heigth of the image in pixels
1572 my $offset = 3 * $self->_radar_y;
1573 my $js = <<"EOM";
1574 <!--
1575  
1576 var _dom = 0;
1577  
1578 function getObj(name)
1579 {
1580 if (document.getElementById)
1581 {
1582 this.obj = document.getElementById(name);
1583 this.style = document.getElementById(name).style;
1584 }
1585 else if (document.all)
1586 {
1587 this.obj = document.all[name];
1588 this.style = document.all[name].style;
1589 }
1590 else if (document.layers)
1591 {
1592 this.obj = document.layers[name];
1593 this.style = document.layers[name];
1594 }
1595 }
1596  
1597 function mousehandler(e){
1598 if(document.all) e=window.event; // for IE
1599 var window_y = $window_y;
1600 var dataset_height = $height;
1601  
1602 if(_dom == 2){
1603 var y1 = new getObj('top_bar');
1604 var y2 = new getObj('bottom_bar');
1605 var radar2 = new getObj('radar1');
1606 var y3 = e.pageY;
1607 var radar_y = radar2.style.top;
1608  
1609 if ((y3 < radar_y) || (y3 > (dataset_height + radar_y))) {return false;}
1610  
1611 y3 = y3 - radar_y;
1612 y3 = y3 - $offset;
1613 if (y3 < 0) {y3 = 0;}
1614 y1.style.top= y3 + radar_y - 1;
1615
1616 var y3 = e.pageY;
1617 y3 = y3 - radar_y - $offset;
1618 y3 = y3 + window_y;
1619 if (y3 >= dataset_height) {y3 = dataset_height - 1;}
1620 y2.style.top= y3 + radar_y + 1;
1621  
1622 return false;
1623 }
1624 else {
1625 var y1 = new getObj('top_bar');
1626 var y2 = new getObj('bottom_bar');
1627 var radar1 = new getObj('radar1');
1628 var y3 = e.clientY;
1629 var radar_y = radar1.style.top;
1630  
1631 if ((y3 < radar_y) || (y3 > (dataset_height + radar_y))) {return false;}
1632  
1633 y3 = y3 - radar_y;
1634  
1635 y3 = y3 - 5;
1636 if (y3 < 0) {y3 = 0;}
1637  
1638 if (_dom==3) { y3 += 12; }
1639 y1.style.top = (y3 + radar1.style.top - 12) + "px";
1640  
1641 var y3 = e.clientY;
1642 y3 = y3 - radar_y;
1643  
1644 y3 = y3 + window_y;
1645 if (y3 >= dataset_height) {y3 = dataset_height - 1;}
1646  
1647 if (_dom==3) { y3 += 12; }
1648 y2.style.top = (y3 + radar1.style.top - 12) + "px";
1649 }
1650  
1651 e.cancelBubble = true; // for IE5
1652 e.returnValue = true; // for IE5
1653 return true;
1654 }
1655  
1656 function init(){
1657 _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
1658 document.onmousedown = mousehandler;
1659 if(_dom==2){ // for NN4
1660 document.captureEvents(Event.MOUSEDOWN);
1661 var div = document.layers.radar1;
1662 div.document.onmousedown = mousehandler;
1663 var radar1 = new getObj('radar1');
1664 var y1 = new getObj('top_bar');
1665 var y2 = new getObj('bottom_bar');
1666 var radar_y = document.layers.radar1.top;
1667 y1.style.top= radar1.style.top - 1;
1668 y2.style.top= $window_y + radar1.style.top;
1669 } else {
1670 var y1 = new getObj('top_bar');
1671 var y2 = new getObj('bottom_bar');
1672 var radar1 = new getObj('radar1');
1673 var radar_y = radar1.style.top;
1674 y1.style.top = (0 + radar_y - 12) + "px";
1675 if (_dom==3) { radar_y += 13; }
1676 y2.style.top = ($window_y + radar_y - 13) + "px";
1677 }
1678  
1679 }
1680 // -->
1681  
1682 EOM
1683  
1684 my $style = << "EOS"; # postition the various elements in the frame
1685 <!--
1686  
1687 .radar { position: absolute; top: 0px; left : 0px; VISIBILITY: visible; }
1688 .bar { position: absolute; top: 1px; right: 0px; VISIBILITY: visible; }
1689 .bar2 { position: absolute; top: 1px; right: 0px; VISIBILITY: visible; }
1690  
1691 // -->
1692  
1693 EOS
1694 return $js, $style;
1695 }
1696  
1697 1; # return a true value to make perl happy
1698  
1699 __END__