Added to perldoc instructions about the use of the environment variables.
[cxgn-corelibs.git] / lib / CXGN / Cview / Marker / Physical.pm
blob3e6c0b9ec0794fd414dd9615907c0be67080d5b6
2 =head1 NAME
4 CXGN::Cview::Marker::Physical - a class to draw markers representing physical associations to maps, such as BACs or contigs.
6 =head1 DESCRIPTION
8 CXGN::Cview::Marker::Physical inherits from L<CXGN::Cview::Marker>.
10 my $m = CXGN::Cview::Marker::Physical->new();
11 $m->set_offset(30);
13 =head1 AUTHOR
15 Lukas Mueller (lam87@cornell.edu)
17 =head1 FUNCTIONS
19 This class implements the following functions:
21 =cut
23 use strict;
24 use CXGN::Cview::Marker;
25 use CXGN::Cview::Label::Physical;
27 package CXGN::Cview::Marker::Physical;
29 use base qw / CXGN::Cview::Marker::RangeMarker /;
31 =head2 function new()
33 Constructor.
34 Arguments: A CXGN::Cview::Chromosome object (or subclassed object)
35 to which this marker belongs.
37 =cut
39 sub new {
40 my $class = shift;
41 my $chromosome = shift;
42 my $self = $class -> SUPER::new($chromosome);
44 my $bac_label = CXGN::Cview::Label::Physical->new();
45 $self->show_label();
46 $self->set_label($bac_label);
47 $self->set_label_side("right");
48 $self->set_hilite_chr_region(0);
49 $self->set_region_hilite_color(100, 100, 150);
50 $self->set_north_range(1);
51 $self->set_south_range(1);
52 return $self;
55 sub render {
56 my $self = shift;
57 my $image = shift;
59 # calculate the pos in pixels of the northern range limit
61 my $north_pixels = $self->get_chromosome()->mapunits2pixels($self->get_offset()) + $self->get_chromosome()->get_vertical_offset() - $self->get_chromosome()->mapunits2pixels($self->get_north_range());
63 # determine the pixels of the southern limit
65 my $south_pixels = $self->get_chromosome()->mapunits2pixels($self->get_offset()) + $self->get_chromosome()->get_vertical_offset() + $self->get_chromosome()->mapunits2pixels($self->get_south_range());
66 # print STDERR "cM = ".$self->get_north_range().", pixels= $north_pixels\n";
67 # print STDERR "cM = ".$self->get_south_range().", pixels= $south_pixels\n";
69 $self->get_label()->set_north_position($north_pixels);
70 $self->get_label()->set_south_position($south_pixels);
72 #if ($self->get_url()) { $self->get_label()->set_url($self->get_url()); }
74 my $stacking = $self->get_label()->get_stacking_height() * $self->get_label()->get_stacking_level();
77 if ($self->is_visible()) {
78 if ($self->get_label_side() eq "right") {
79 my $x = $self->get_chromosome()->get_horizontal_offset()
80 +int($self->get_chromosome()->get_width()/2)
81 +$stacking;
83 my $label_horizontal_position = $x + 50;
84 if ($stacking > 200) {
85 $label_horizontal_position=$x-100;
86 $self->get_label()->align_right();
88 $self->get_label()->set_horizontal_offset($label_horizontal_position);
89 $self->get_label()->set_reference_point($x, int($north_pixels+$south_pixels)/2);
92 elsif ($self->get_label_side() eq "left") {
93 my $x = $self->get_chromosome()->get_horizontal_offset()-int($self->get_chromosome()->get_width()/2) - $self->get_label()->get_stacking_height()*($self->get_label()->get_stacking_level());
95 $self->get_label()->set_horizontal_offset($x-50);
96 $self->get_label()->set_reference_point($x, int($north_pixels+$south_pixels)/2);
99 else {
100 die "[RangeMarker.pm] label_side can either be right or left. Sorry.";
102 if ($self->is_label_visible()) {
103 $self->get_label()->render($image);
106 if ($self->get_hilite_chr_region()) {
107 $self->hilite_chr_region($image);
109 $self->draw_tick($image);
115 =head2 accessors set_region_hilite_color(), get_region_hilite_color()
117 Property:
118 Setter Args:
119 Getter Args:
120 Getter Ret:
121 Side Effects:
122 Description:
124 =cut
126 sub get_region_hilite_color {
127 my $self=shift;
128 return @{$self->{region_hilite_color}};
131 sub set_region_hilite_color {
132 my $self=shift;
133 @{$self->{region_hilite_color}}= (shift, shift, shift);
136 =head2 accessors set_hilite_chr_region(), get_hilite_chr_region()
138 Property:
139 Setter Args:
140 Getter Args:
141 Getter Ret:
142 Side Effects:
143 Description:
145 =cut
147 sub get_hilite_chr_region {
148 my $self=shift;
149 return $self->{hilite_chr_region};
152 sub set_hilite_chr_region {
153 my $self=shift;
154 $self->{hilite_chr_region}=shift;
157 sub draw_tick {
158 my $self = shift;
159 my $image = shift;
160 my $color = $image -> colorResolve($self->get_color());
162 my ($x, $north_y, $y, $south_y) = $self->get_enclosing_rect();
164 if ($self->get_show_tick()) {
165 $image -> rectangle($x, $north_y, $y, $south_y, $color);
169 sub get_image_map {
170 my $self = shift;
171 my $coords = join ",", ($self->get_enclosing_rect());
174 my $s= '<area shape="rect" coords="'.$coords.'" href="'.$self->get_url().'" alt="'.$self->get_marker_name().'" title="'.$self->get_tooltip().'" />';
175 #print STDERR "Imagemap = $s\n";
176 return $s;
180 sub get_enclosing_rect {
181 my $self = shift;
182 my $halfwidth = int($self->get_chromosome->get_width/2);
183 my $north_y = $self->get_chromosome()->get_vertical_offset() + $self->get_chromosome()->mapunits2pixels($self->get_offset()-$self->get_north_range());
185 my $south_y = $self->get_chromosome()->get_vertical_offset() + $self->get_chromosome()->mapunits2pixels($self->get_offset()+$self->get_south_range());
187 my $x = $self->get_chromosome()->get_horizontal_offset()+$halfwidth+$self->get_label()->get_stacking_height()*$self->get_label()->get_stacking_level();
188 return ($x-1, $north_y, $x+1, $south_y);
191 return 1;