4 CXGN::Cview::MapOverviews::Generic - a class to display generic genetic map overviews.
8 see L<CXGN::Cview::MapOverviews> for a definition of the interface.
12 This class implements an overview of a genetic map that is stored in the database.
16 Lukas Mueller (lam87@cornell.edu)
24 This class implements the following functions:
30 package CXGN
::Cview
::MapOverviews
::Generic
;
32 use CXGN
::Cview
::Map
::Tools
;
33 use CXGN
::Marker
::Tools qw
| clean_marker_name
|;
35 use base qw
| CXGN
::Cview
::MapOverviews CXGN
::DB
::Object
|;
39 Synopsis: my $overview = CXGN::Cview::MapOverviews::generic_map_overview->new(CXGN::Cview::Map::SGN::Genetic->new(9));
40 Arguments: The a CXGN::Cview::Map object for the map to be displayed.
41 Returns: an overview object (constructor)
42 Side effects: sets up the overview object.
52 my $self = $class -> SUPER
::new
($map, $args);
54 # if (!$map) { exit(); }
56 $self->set_dbh($args->{dbh
});
64 my $map_width=$self->get_image_width();
65 my $image_height = $self->get_image_height();
67 $self->{map_image
}= CXGN
::Cview
::MapImage
->new("", $map_width, $image_height);
70 # my $unit_eq = 0.4; # 1 cM corresponds to 0.4 pixels.
72 # determine the longest chromosome for proper scaling...
74 my @c_len = $self->get_map()->get_chromosome_lengths();
75 #print STDERR "chromosome lengths: ".(join " ", @c_len)."\n";
76 my $longest_length = 0; # zero based
77 my $longest_chr = undef;
78 if (!$self->get_map()->get_chromosome_count()) {
79 die "This map does not seem to have any chromosomes...";
81 for (my $i=0; $i<$self->get_map()->get_chromosome_count(); $i++) {
82 if ($c_len[$i] >= $longest_length) {
84 $longest_length = $c_len[$i];
89 # Prevent division by zero, but does it make sense?
90 my $unit_eq = $longest_length ?
($image_height-2*$top_margin) / $longest_length : 0;
91 #print STDERR "unit_eq = $unit_eq\n";
93 my @clean_markers = ();
94 foreach my $hm ($self->get_hilite_markers()) {
95 my($clean, $suffix) = clean_marker_name
($hm);
96 push @clean_markers, $clean;
99 my @map_item_names = map { (split /\s+/, $_)[2] } $self->get_map()->get_map_items();
101 my $hilite_markers = join (" ", @clean_markers, @map_item_names);
102 my $hilite_markers_link = $hilite_markers;
103 $hilite_markers_link =~ s/ /\+/g;
104 # my $max_chr_len_units = 0;
105 # my $max_chr_len_pixels = 0;
106 my $chr_count = $self->get_map()->get_chromosome_count();
107 my @chr_names = $self->get_map()->get_chromosome_names();
109 #print STDERR "chromosome names: ".(join " ", @chr_names)."\n";
110 $self->set_horizontal_spacing(int(($map_width-40)/($chr_count)));
112 #print STDERR "chromosome count is $chr_count\n";
113 my %marker_found = ();
115 for (my $i=$chr_count-1; $i>=0; $i--) {
117 #print STDERR "Instantiating chr $chr_names[$i]... in index $i\n";
119 $c[$i] = $self->get_map()->get_overview_chromosome($chr_names[$i]);
121 $c[$i]->set_horizontal_offset($self->get_horizontal_spacing()*($i)+35);
122 $c[$i]->set_vertical_offset($top_margin);
124 $c[$i]->set_caption($chr_names[$i]);
126 my @markers = $c[$i]->get_markers();
130 foreach my $m (@markers) {
132 #$m -> set_color(200, 100, 100);
133 if ($m->get_offset() > $chr_len) { $chr_len = $m->get_offset(); }
134 #print STDERR "Read: ".$m->get_name." offset: ".$m->get_offset()."\n";
135 my $marker_name_suffix = $m->get_marker_name();
136 my $marker_name = $m->get_name();
137 my $marker_id = $m->get_id();
138 foreach my $label ($marker_name, $marker_name_suffix, $m->get_synonyms()) {
139 #if (($hilite_markers =~ /\b($marker_name)\b|\b($marker_name_suffix)\b/i)) {
140 if ($hilite_markers =~ /\b($label)\b/) {
142 #print STDERR "MATCH:$match\n";
143 $marker_found{$match}=1;
144 $m->set_label_spacer(15);
145 #$m->set_url("/search/markers/markerinfo.pl?marker_id=$marker_id");
147 $m->get_label()->set_label_text($label);
153 #print STDERR "$i, $c_len[$i], $unit_eq\n";
154 #print STDERR "(".join(", ", @c_len).")\n";
155 $c[$i]->set_height($c_len[$i]*$unit_eq);
156 $c[$i]->set_length($c_len[$i]);
158 if ($self->get_map()->can_zoom()) {
159 my $lg_name = $chr_names[$i];
160 $c[$i]->rasterize(5);
161 $c[$i]->set_rasterize_link("/cview/view_chromosome.pl?map_version_id=".$self->get_map()->get_id()."&chr_nr=$lg_name&show_offsets=1&show_zoomed=1&show_ruler=1&hilite=$hilite_markers_link&clicked=1&cM=");
165 $c[$i]->set_url("/cview/view_chromosome.pl?map_version_id=".($self->get_map()->get_id())."&chr_nr=$chr_names[$i]");
167 if ($c[$i]->get_scaling_factor() == 0) {
168 print STDERR
join (", ", map { $_->get_offset } $c[$i]->get_markers())."\n";
169 print STDERR
"LENGTH = ".$c[$i]->get_length()."\n";
170 print STDERR
"HEIGHT = ".$c[$i]->get_height()."\n";
171 die "Scaling factor is 0 for chromosome $i. How did this happen?";
173 $self->{map_image
}->add_chromosome($c[$i]);
175 # if (!$self->is_fish_map()) {
176 # my $ruler = CXGN::Cview::Ruler->new(20, $top_margin, $longest_length * $unit_eq, 0, $longest_length, $self->get_map()->get_units());
177 # $ruler ->set_units( $self->get_map()->get_units() );
178 # $self->{map_image}->add_ruler($ruler);
181 # get the ruler and add it to the image
183 #print STDERR "Setting up the ruler... longest chr is $longest_chr\n";
184 my $ruler = $c[$longest_chr]->get_ruler();
185 $ruler->set_vertical_offset($top_margin);
186 $ruler->set_horizontal_offset(20);
187 $ruler->set_units($self->get_map()->get_units());
188 $ruler->set_start_value(0);
189 $ruler->set_end_value( $c[$longest_chr]->get_length() );
190 $ruler->set_height( $c[$longest_chr]->get_height() );
193 $self->{map_image
}->add_ruler($ruler);
195 #print STDERR "done.\n";
197 # hilite markers that were requested...
199 foreach my $hm (@clean_markers) {
201 if (!exists($marker_found{$hm})) {
202 #print STDERR "Adding $hm to the list...\n";
203 $self->add_marker_not_found($hm);
207 # add a legend if the map is F2-2000.
209 if (CXGN
::Cview
::Map
::Tools
::find_map_id_with_version
($self->get_dbh(), $self->get_map()->get_id()) == CXGN
::Cview
::Map
::Tools
::current_tomato_map_id
()) {
211 # $image->string($font,$x,$y,$string,$color)
212 my $legend = CXGN
::Cview
::Label
->new();
213 $legend->set_name('Note: Positions of fully sequenced BACs are shown in yellow');
214 $legend->set_vertical_offset($image_height-12);
215 $legend->set_horizontal_offset(30);
216 $legend->set_reference_point(30, $image_height-15);
218 $self->{map_image
}->add_image_object($legend);
220 $self->set_chromosomes(\
@c);
229 $self->get_cache()->set_key($self->get_map()->get_id()."-".($self->get_image_height())."-".join (".", $self->get_map()->get_map_items())."-".(join "-", ($self->get_hilite_markers())).__PACKAGE__
);
230 $self->get_cache()->set_map_name("mapmap");
232 if ($self->get_cache()->is_valid()) {
236 #print STDERR "Regenerating the map ".$self->get_map()->get_id()."\n";
239 $self->get_cache()->set_image_data( $self->{map_image
}->render_png_string());
240 $self->get_cache()->set_image_map_data( $self->{map_image
}->get_image_map("mapmap") );
247 if ($self->get_map()->get_type() =~/fish/i) { return 1; }