2 package CXGN
::Cview
::ViewMaps
;
4 use CXGN
::Page
::FormattingHelpers qw
| page_title_html
|;
5 use CXGN
::Cview
::MapFactory
;
6 use CXGN
::Cview
::Chromosome_viewer
;
7 use CXGN
::Cview
::ChrLink
;
8 use CXGN
::Cview
::Utils qw
| set_marker_color
|;
9 use CXGN
::Cview
::MapImage
;
10 use CXGN
::Tools
::WebImageCache
;
14 use base qw
| CXGN
::DB
::Object
|;
21 Arguments: a database handle [ DBI object or CXGN::DB::Connection object]
22 the base dir [ file path ]
23 the temp_dir [ relative path ]
24 Returns: a handle to a view_maps object
26 Description: constructor
36 my $self = bless {}, $class;
38 # set some defaults...
40 $self->{unzoomedheight
} = 20; # how many cM are seen at zoom level 1
42 # create an set the cache file in the constructor,
43 # such that we can define the temp dirs before
44 # we generate the image using generate_image()
46 my $cache = CXGN
::Tools
::WebImageCache
->new();
47 $self->set_cache($cache);
48 $cache->set_basedir($basepath);
49 $cache->set_temp_dir($temp_dir);
54 sub adjust_parameters
{
57 # adjust input arguments
63 =head2 accessors set_maps(), get_maps()
76 return @
{$self->{maps
}};
84 =head2 accessors set_cache(), get_cache()
86 Property: the CXGN::Tools::WebImageCache object
88 Side Effects: this is the object used to generate the
96 return $self->{cache
};
101 $self->{cache
}=shift;
107 =head2 function generate_page()
111 Side effects: generates the CXGN::Cview::MapImage and stores it
112 to the cache if necessary, or reads just reads
113 the image cache if it is still valid.
120 # define a key for the cache. lets just use the name of the
121 # script and the map_version_ids of the maps being displayed
123 $self->get_cache()->set_key("view_maps".(join "-", map { $_->get_id() } ($self->get_maps())));
125 $self->get_cache()->set_expiration_time(86400);
128 if (! $self->get_cache()->is_valid()) {
129 my $map_width = $self->{map_width
} = 720;
130 my $x_distance = $map_width/4; # the number of pixels the different elements are spaced
132 my $row_height = 120; # the height of a row (vertical space for each chromosome image)
133 my $y_distance = $row_height * (1/3);
134 my $chr_height = $row_height * (2/3);
137 # determine the maximum chromosome count among all maps
138 # so that we can accommodate it
141 foreach my $m ($self->get_maps()) {
144 $chr_count = $m->get_chromosome_count();
146 if ($chr_count > $max_chr) { $max_chr=$chr_count; }
149 $map_height = $row_height * $max_chr+2*$y_distance;
150 # show the ruler if requested
152 # if ($self->{show_ruler}) {
153 # my $r = ruler->new($x_distance-20, $row_height * $row_count + $y_distance, $chr_height, 0, $self->{c}{$track}[$i]->get_chromosome_length());
154 # $self->{map}->add_ruler($r);
158 $self->{map} = CXGN
::Cview
::MapImage
-> new
("", $map_width, $map_height);
160 # get all the chromosomes and add them to the map
163 foreach my $map ($self->get_maps()) {
164 my @chr_names = $map->get_chromosome_names();
165 for (my $i=0; $i<$map->get_chromosome_count(); $i++) {
167 $self->{c
}{$track}[$i] = ($self->get_maps())[$track]->get_chromosome($i+1);
168 $self->{c
}{$track}[$i] -> set_vertical_offset
($row_height*$i+$y_distance);
169 $self->{c
}{$track}[$i] -> set_horizontal_offset
($x_distance + $x_distance * ($track));
170 $self->{c
}{$track}[$i] -> set_height
($chr_height);
171 $self->{c
}{$track}[$i] -> set_caption
( $chr_names[$i] );
172 $self->{c
}{$track}[$i] -> set_width
(16);
173 $self->{c
}{$track}[$i] -> set_url
("/cview/view_chromosome.pl?map_version_id=".($self->get_maps())[$track]->get_id()."&chr_nr=$chr_names[$i]");
175 $self->{c
}{$track}[$i] -> set_labels_none
();
176 $self->{map}->add_chromosome($self->{c
}{$track}[$i]);
182 # get the connections between the chromosomes
186 for (my $track=0; $track<($self->get_maps()); $track++) {
187 for (my $i =0; $i< ($self->get_maps())[$track]->get_chromosome_count(); $i++) {
188 foreach my $m ($self->{c
}{$track}[$i]->get_markers()) {
190 # make entry into the find hash and store corrsponding chromosomes and offset
191 # (for drawing connections)
192 # if the map is the reference map ($compare_to_map is false).
194 $find{$m->get_id()}->{$track}->{chr}=$i;
195 $find{$m->get_id()}->{$track}->{offset
}=$m->get_offset();
197 # set the marker colors
199 set_marker_color
($m, "marker_types");
204 foreach my $f (keys(%find)) {
205 foreach my $t (keys %{$find{$f}}) {
206 my $chr = $find{$f}->{$t}->{chr};
207 my $offset = $find{$f}->{$t}->{offset
};
209 if (exists($find{$f}->{$t-1}) || defined($find{$f}->{$t-1})) {
210 my $comp_chr = $find{$f}->{$t-1}->{chr};
211 my $comp_offset = $find{$f}->{$t-1}->{offset
};
212 #print STDERR "Found on track $t: Chr=$chr offset=$offset, links to track ".($t-1)." Chr=$comp_chr offset $comp_offset\n";
214 my $link1 = CXGN
::Cview
::ChrLink
->new($self->{c
}{$t}[$chr], $offset, $self->{c
}{$t-1}[$comp_chr], $comp_offset);
215 $self->{map}->add_chr_link($link1);
218 if (exists($find{$f}->{$t+1})) {
219 my $comp_chr = $find{$f}->{$t+1}->{chr};
220 my $comp_offset = $find{$f}->{$t+1}->{offset
};
221 my $link2 = CXGN
::Cview
::ChrLink
->new($self->{c
}{$t}[$chr], $offset, $self->{c
}{$t+1}[$comp_chr], $comp_offset);
222 $self->{map}->add_chr_link($link2);
229 $self->get_cache()->set_map_name("viewmap");
230 $self->get_cache()->set_image_data($self->{map}->render_png_string());
231 $self->get_cache()->set_image_map_data($self->{map}->get_image_map("viewmap"));
233 # # show the ruler if requested
235 # if ($self->{show_ruler}) {
236 # my $r = ruler->new($x_distance-20, $row_height * $row_count + $y_distance, $chr_height, 0, $self->{c}{$track}[$i]->get_chromosome_length());
237 # $self->{map}->add_ruler($r);
242 # my $filename = "cview".(rand())."_".$$.".png";
244 # $self->{image_path} = $vhost_conf->get_conf('basepath').$vhost_conf->get_conf('tempfiles_subdir')."/cview/$filename";
245 # $self->{image_url} = $vhost_conf->get_conf('tempfiles_subdir')."/cview/$filename";
247 # $self->{map} -> render_png_file($self->{image_path});
249 # $self->{imagemap} = $self->{map}->get_image_map("imagemap");
255 sub get_select_toolbar
{
258 # $left_map = $self->get_left_map() || 0;
259 # $center_map = $self->get_center_map() || 0;
260 # $right_map = $self->get_right_map || 0;
261 my @names = ("left_map_version_id", "center_map_version_id", "right_map_version_id");
263 for (my $i=0; $i< 3; $i++) {
264 if ( defined(($self->get_maps())[$i])) {
265 push @selects, CXGN
::Cview
::Utils
::get_maps_select
($self->get_dbh(), ($self->get_maps())[$i]->get_id(), $names[$i], 1);
268 push @selects, CXGN
::Cview
::Utils
::get_maps_select
($self->get_dbh(), undef, $names[$i], 1);
271 # my $center_select = CXGN::Cview::Utils::get_maps_select($self, !$center_map || $center_map->get_id(), "center_map_version_id", 1);
272 # my $right_select = CXGN::Cview::Utils::get_maps_select($self, !$right_map || $right_map->get_id(), "right_map_version_id", 1);
278 <table summary
=""><tr
><td
>$selects[0]</td><td>$selects[1]</td
><td
>$selects[2]</td></tr
></table
>
279 <input type
="submit" value
="set" />
285 # =head2 function display()
291 # Description: composes the page and displays it.
299 # $self->{page}->header("SGN comparative mapviewer");
300 # my $width = int($self->{map_width}/3);
302 # my $select = $self->get_select_toolbar();
306 # if (!$self->get_maps()) {
307 # print "<br /><br /><center>Note: No maps are selected. Please select maps from the pull down menus above.</center>\n";
310 # print $self->get_cache()->get_image_html();
312 # # print "<img src=\"$self->{image_url}\" usemap=\"#chr_comp_map\" border=\"0\" alt=\"\" />\n";
314 # # print $self->{map}->get_image_map("chr_comp_map");
316 # $self->{page}->footer();
322 =head2 function error_message_page()
332 sub error_message_page
{
335 my $title = page_title_html
("Error: No center map defined");
341 A center map needs to be defined for this page to work. Please supply
342 a center_map_version_id as a parameter. If this was the result of a link,
343 please inform SGN about the error.
346 Contact SGN at <a href="mailto:sgn-feedback\@sgn.cornell.edu">sgn-feedback\@sgn.cornell.edu</a>