Get rid of some warnings in CXGN::Cview::Chromosome::Vector
[cview.git] / lib / CXGN / Cview / Map_overviews / Individual.pm
blob6260981047fa6fccf0c25e8850913e1d993b727d
3 =head1 NAME
5 CXGN::Cview::Map_overviews::Individual - a class to display genetic map overviews associated with individual that contain chromosome fragments from other accessions (such as ILs) or carry genes mapped between 2 flanking markers.
7 =head1 SYNOPSYS
10 =head1 DESCRIPTION
13 =head1 AUTHOR(S)
15 Lukas Mueller (lam87@cornell.edu)
17 =head1 VERSION
20 =head1 LICENSE
23 =head1 FUNCTIONS
25 This class implements the following functions:
27 =cut
29 use strict;
31 package CXGN::Cview::Map_overviews::Individual;
33 use CXGN::Cview::Map_overviews;
35 use base qw | CXGN::Cview::Map_overviews |;
37 =head2 function new
39 Synopsis:
40 Arguments:
41 Returns:
42 Side effects:
43 Description:
45 =cut
47 sub new {
48 my $class = shift;
50 my $self = $class->SUPER::new(@_);
51 my $individual_id = shift;
52 $self->set_individual_id($individual_id);
53 $self->render_map();
54 if (!$self->get_cache()->is_valid() && !$self->get_chromosome_count()) {
55 return undef;
57 return $self;
60 =head2 accessors set_individual_id, get_individual_id
62 Property:
63 Setter Args:
64 Getter Args:
65 Getter Ret:
66 Side Effects:
67 Description:
69 =cut
71 sub get_individual_id {
72 my $self=shift;
73 return $self->{individual_id};
76 sub set_individual_id {
77 my $self=shift;
78 $self->{individual_id}=shift;
82 =head2 function render_map
84 Synopsis:
85 Arguments:
86 Returns:
87 Side effects:
88 Description:
89 To Do: move this to the data adapter
91 =cut
93 sub render_map {
94 my $self = shift;
95 my $individual_id = $self->get_individual_id();
97 #$self->get_cache()->set_force(1); # during development
98 $self->get_cache()->set_key("individual overview $individual_id");
99 $self->get_cache()->set_expiration_time(); # should never expire...
100 $self->get_cache()->set_map_name("overview");
102 if ($self->get_cache()->is_valid()) { return; }
104 my $IMAGE_WIDTH = 700;
106 # get chromosome number of the individual in question.
107 my $chr_q = "SELECT count(distinct(linkage_group.lg_name)) FROM phenome.genotype
108 JOIN phenome.genotype_experiment using (genotype_experiment_id)
109 JOIN sgn.map_version ON (genotype_experiment.reference_map_id=sgn.map_version.map_id)
110 JOIN sgn.linkage_group using (map_version_id)
111 WHERE map_version.current_version='t' AND individual_id=?";
112 my $chr_h = $self->prepare($chr_q);
113 $chr_h->execute($individual_id);
114 my ($chr_count) = $chr_h->fetchrow_array();
116 #print STDERR "Individual has $chr_count chromosomes.\n";
117 $self->set_chromosome_count($chr_count);
118 if (!$chr_count) { return; }
120 $self->set_horizontal_spacing( int($IMAGE_WIDTH/($chr_count+1)) );
122 my %lengths = ();
124 my $query = "SELECT lg_name, max(position), map_version.map_id FROM sgn.linkage_group
125 JOIN sgn.marker_location using (lg_id)
126 JOIN sgn.map_version on (map_version.map_version_id=linkage_group.map_version_id)
127 JOIN phenome.genotype_experiment on (map_version.map_id=genotype_experiment.reference_map_id)
128 JOIN phenome.genotype using (genotype_experiment_id)
129 WHERE genotype.individual_id=?
130 AND map_version.current_version='t'
131 GROUP BY lg_name, map_version.map_id";
133 #print STDERR "QUERY: $query\n";
135 my $sth = $self->prepare($query);
136 $sth ->execute($self->get_individual_id());
137 my $map_id = 0;
138 while (my ($lg_name, $length, $reference_map_id) = $sth->fetchrow_array()) {
139 #print STDERR "LENGTHS: $lg_name is $length long.\n";
140 $lengths{$lg_name}=$length;
141 $map_id=$reference_map_id;
146 my @c = ();
147 # my %clen = $self->get_map()->get_linkage_group_lengths();
148 $self->{map_image}=CXGN::Cview::MapImage->new("", 700, 200);
149 foreach my $chr (0..($chr_count-1)) {
150 #print STDERR "Generating chromosome $chr...\n";
151 $c[$chr] = CXGN::Cview::Chromosome->new();
152 $c[$chr]->set_vertical_offset(40);
153 $c[$chr]->set_width(12);
154 $c[$chr]->set_height(100);
155 $c[$chr]->set_caption($chr+1);
156 $c[$chr]->set_length($lengths{$chr+1});
157 $c[$chr]->set_horizontal_offset(($chr+1) * $self->get_horizontal_spacing());
158 $c[$chr]->set_hilite_color(100, 100, 200);
160 $self->{map_image}->add_chromosome($c[$chr]);
163 # now get the fragments to be highlighted
165 my $query2 = "SELECT linkage_group.lg_name, position, type, zygocity_code FROM phenome.genotype
166 JOIN phenome.genotype_region USING(genotype_id)
167 JOIN phenome.genotype_experiment USING (genotype_experiment_id)
168 JOIN sgn.map_version ON (genotype_experiment.reference_map_id=sgn.map_version.map_id)
169 JOIN sgn.marker_location using(map_version_id)
170 JOIN sgn.marker_experiment using(location_id)
171 JOIN sgn.linkage_group ON (genotype_region.lg_id=linkage_group.lg_id)
172 WHERE map_version.current_version='t'
173 AND genotype_region.marker_id_ns=sgn.marker_experiment.marker_id
174 AND individual_id =? and genotype_experiment.preferred='t' ORDER BY position";
176 # print STDERR "QUERY2: $query2\n";
179 my $query3 = "SELECT linkage_group.lg_name, position FROM phenome.genotype
180 JOIN phenome.genotype_region USING(genotype_id)
181 JOIN phenome.genotype_experiment USING (genotype_experiment_id)
182 JOIN sgn.map_version ON (genotype_experiment.reference_map_id=sgn.map_version.map_id)
183 JOIN sgn.marker_location using(map_version_id)
184 JOIN sgn.marker_experiment using(location_id)
185 JOIN sgn.linkage_group ON (genotype_region.lg_id=linkage_group.lg_id)
186 WHERE map_version.current_version='t'
187 -- AND phenome.genotype_region.lg_id=sgn.linkage_group.lg_id
188 AND marker_id_sn=sgn.marker_experiment.marker_id
189 AND individual_id =? and genotype_experiment.preferred='t' ORDER BY position";
191 # print STDERR "QUERY3: $query3\n";
193 my $sth2 = $self-> prepare($query2);
194 $sth2->execute($individual_id);
196 my $sth3 = $self-> prepare($query3);
197 $sth3->execute($individual_id);
199 while (my ($chr1, $top_marker, $type, $zygocity_code) = $sth2->fetchrow_array()) {
200 my ($chr2, $bottom_marker) = $sth3->fetchrow_array();
202 if ($type eq "map") {
203 my $m = CXGN::Cview::Marker->new($c[$chr1-1]);
204 $m->get_label()->set_hidden(1);
206 my @color = (200, 200, 200);
207 if ($zygocity_code eq "a") { @color = (255, 0, 0); }
208 if ($zygocity_code eq "b") { @color = (0, 0, 255); }
209 if ($zygocity_code eq "c") { @color = (200, 100, 0); }
210 if ($zygocity_code eq "d") { @color = (0, 100, 200); }
211 if ($zygocity_code eq "h") { @color = (50, 50, 50); }
212 $m->set_color(@color);
213 $m->set_offset($top_marker);
214 $c[$chr1-1]->add_marker($m);
215 $c[$chr1-1]->set_url("/cview/view_chromosome.pl?chr_nr=$chr1&map_id=$map_id&show_ruler=1");
218 elsif ("$chr1" eq "$chr2") {
220 my $m = CXGN::Cview::Marker::RangeMarker->new($c[$chr1-1]);
221 #$m->get_label()->set_stacking_level(1);
222 # $m->set_label_side("right");
223 $m->get_label()->set_name("IL");
225 my $offset = ($top_marker+$bottom_marker)/2;
226 $m->set_offset($offset);
227 $m->set_north_range($offset-$top_marker);
228 $m->set_south_range($bottom_marker-$offset);
230 $c[$chr1-1]->add_marker($m);
231 $m->set_hilite_chr_region(1);
232 #$m->get_label()->set_url("/cview/view_chromosome.pl?map_id=5&cM_start=$top_marker&cM_end=$bottom_marker&show_zoomed=1");
233 $c[$chr1-1]->set_url("/cview/view_chromosome.pl?chr_nr=$chr1&map_id=$map_id&cM_start=".($top_marker-1)."&cM_end=".($bottom_marker+1)."&show_zoomed=1&show_ruler=1");
235 #print STDERR "Fragment: $offset, $top_marker, $bottom_marker\n";
237 else { warn "[Individual_overviews] $chr1 should be the same as $chr2...\n"; }
240 $self->get_cache()->set_image_data( $self->{map_image}->render_png_string() );
241 $self->get_cache()->set_image_map_data( $self->{map_image}->get_image_map("overview") );
245 =head2 function get_cache_key
247 Synopsis:
248 Arguments:
249 Returns:
250 Side effects:
251 Description:
253 =cut
255 sub get_cache_key {
256 my $self = shift;
257 return "Individual".$self->get_individual_id();
261 =head2 accessors set_chromosome_count, get_chromosome_count
263 Property:
264 Setter Args:
265 Getter Args:
266 Getter Ret:
267 Side Effects:
268 Description:
270 =cut
272 sub get_chromosome_count {
273 my $self=shift;
274 return $self->{chromosome_count};
277 sub set_chromosome_count {
278 my $self=shift;
279 $self->{chromosome_count}=shift;
283 package CXGN::Cview::Map_overviews::Individual_overview;
285 use base qw | CXGN::Cview::Map_overviews::Individual |;
287 sub new {
288 my $class = shift;
289 my $self = $class->SUPER::new(@_);
290 return $self;
293 return 1;