Added to perldoc instructions about the use of the environment variables.
[cxgn-corelibs.git] / lib / CXGN / Cview / Map_overviews / Individual.pm
blob907ee2d50d9e1045d9a9232cf0229a093024bfc8
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;
30 #use CXGN::Map::IndividualMap;
32 package CXGN::Cview::Map_overviews::Individual;
34 use CXGN::Cview::Map_overviews;
36 use base qw | CXGN::Cview::Map_overviews |;
38 =head2 function new
40 Synopsis:
41 Arguments:
42 Returns:
43 Side effects:
44 Description:
46 =cut
48 sub new {
49 my $class = shift;
51 my $self = $class->SUPER::new(@_);
52 my $individual_id = shift;
53 $self->set_individual_id($individual_id);
54 $self->render_map();
55 if (!$self->get_cache()->is_valid() && !$self->get_chromosome_count()) {
56 return undef;
58 return $self;
61 =head2 accessors set_individual_id, get_individual_id
63 Property:
64 Setter Args:
65 Getter Args:
66 Getter Ret:
67 Side Effects:
68 Description:
70 =cut
72 sub get_individual_id {
73 my $self=shift;
74 return $self->{individual_id};
77 sub set_individual_id {
78 my $self=shift;
79 $self->{individual_id}=shift;
83 =head2 function render_map
85 Synopsis:
86 Arguments:
87 Returns:
88 Side effects:
89 Description:
90 To Do: move this to the data adapter
92 =cut
94 sub render_map {
95 my $self = shift;
96 my $individual_id = $self->get_individual_id();
98 #$self->get_cache()->set_force(1); # during development
99 $self->get_cache()->set_key("individual overview $individual_id");
100 $self->get_cache()->set_expiration_time(); # should never expire...
101 $self->get_cache()->set_map_name("overview");
103 if ($self->get_cache()->is_valid()) { return; }
105 my $IMAGE_WIDTH = 700;
107 # get chromosome number of the individual in question.
108 my $chr_q = "SELECT count(distinct(linkage_group.lg_name)) FROM phenome.genotype
109 JOIN phenome.genotype_experiment using (genotype_experiment_id)
110 JOIN sgn.map_version ON (genotype_experiment.reference_map_id=sgn.map_version.map_id)
111 JOIN sgn.linkage_group using (map_version_id)
112 WHERE map_version.current_version='t' AND individual_id=?";
113 my $chr_h = $self->prepare($chr_q);
114 $chr_h->execute($individual_id);
115 my ($chr_count) = $chr_h->fetchrow_array();
117 print STDERR "Individual has $chr_count chromosomes.\n";
118 $self->set_chromosome_count($chr_count);
119 if (!$chr_count) { return; }
121 $self->set_horizontal_spacing( int($IMAGE_WIDTH/($chr_count+1)) );
123 my %lengths = ();
125 my $query = "SELECT lg_name, max(position), map_version.map_id FROM sgn.linkage_group
126 JOIN sgn.marker_location using (lg_id)
127 JOIN sgn.map_version on (map_version.map_version_id=linkage_group.map_version_id)
128 JOIN phenome.genotype_experiment on (map_version.map_id=genotype_experiment.reference_map_id)
129 JOIN phenome.genotype using (genotype_experiment_id)
130 WHERE genotype.individual_id=?
131 AND map_version.current_version='t'
132 GROUP BY lg_name, map_version.map_id";
134 print STDERR "QUERY: $query\n";
136 my $sth = $self->prepare($query);
137 $sth ->execute($self->get_individual_id());
138 my $map_id = 0;
139 while (my ($lg_name, $length, $reference_map_id) = $sth->fetchrow_array()) {
140 print STDERR "LENGTHS: $lg_name is $length long.\n";
141 $lengths{$lg_name}=$length;
142 $map_id=$reference_map_id;
147 my @c = ();
148 # my %clen = $self->get_map()->get_linkage_group_lengths();
149 $self->{map_image}=CXGN::Cview::MapImage->new("", 700, 200);
150 foreach my $chr (0..($chr_count-1)) {
151 print STDERR "Generating chromosome $chr...\n";
152 $c[$chr] = CXGN::Cview::Chromosome->new();
153 $c[$chr]->set_vertical_offset(40);
154 $c[$chr]->set_width(12);
155 $c[$chr]->set_height(100);
156 $c[$chr]->set_caption($chr+1);
157 $c[$chr]->set_length($lengths{$chr+1});
158 $c[$chr]->set_horizontal_offset(($chr+1) * $self->get_horizontal_spacing());
159 $c[$chr]->set_hilite_color(100, 100, 200);
161 $self->{map_image}->add_chromosome($c[$chr]);
164 # now get the fragments to be highlighted
166 my $query2 = "SELECT linkage_group.lg_name, position, type, zygocity_code FROM phenome.genotype
167 JOIN phenome.genotype_region USING(genotype_id)
168 JOIN phenome.genotype_experiment USING (genotype_experiment_id)
169 JOIN sgn.map_version ON (genotype_experiment.reference_map_id=sgn.map_version.map_id)
170 JOIN sgn.marker_location using(map_version_id)
171 JOIN sgn.marker_experiment using(location_id)
172 JOIN sgn.linkage_group ON (genotype_region.lg_id=linkage_group.lg_id)
173 WHERE map_version.current_version='t'
174 AND genotype_region.marker_id_ns=sgn.marker_experiment.marker_id
175 AND individual_id =? and genotype_experiment.preferred='t' ORDER BY position";
177 # print STDERR "QUERY2: $query2\n";
180 my $query3 = "SELECT linkage_group.lg_name, position FROM phenome.genotype
181 JOIN phenome.genotype_region USING(genotype_id)
182 JOIN phenome.genotype_experiment USING (genotype_experiment_id)
183 JOIN sgn.map_version ON (genotype_experiment.reference_map_id=sgn.map_version.map_id)
184 JOIN sgn.marker_location using(map_version_id)
185 JOIN sgn.marker_experiment using(location_id)
186 JOIN sgn.linkage_group ON (genotype_region.lg_id=linkage_group.lg_id)
187 WHERE map_version.current_version='t'
188 -- AND phenome.genotype_region.lg_id=sgn.linkage_group.lg_id
189 AND marker_id_sn=sgn.marker_experiment.marker_id
190 AND individual_id =? and genotype_experiment.preferred='t' ORDER BY position";
192 # print STDERR "QUERY3: $query3\n";
194 my $sth2 = $self-> prepare($query2);
195 $sth2->execute($individual_id);
197 my $sth3 = $self-> prepare($query3);
198 $sth3->execute($individual_id);
200 while (my ($chr1, $top_marker, $type, $zygocity_code) = $sth2->fetchrow_array()) {
201 my ($chr2, $bottom_marker) = $sth3->fetchrow_array();
203 if ($type eq "map") {
204 my $m = CXGN::Cview::Marker->new($c[$chr1-1]);
205 $m->get_label()->set_hidden(1);
207 my @color = (200, 200, 200);
208 if ($zygocity_code eq "a") { @color = (255, 0, 0); }
209 if ($zygocity_code eq "b") { @color = (0, 0, 255); }
210 if ($zygocity_code eq "c") { @color = (200, 100, 0); }
211 if ($zygocity_code eq "d") { @color = (0, 100, 200); }
212 if ($zygocity_code eq "h") { @color = (50, 50, 50); }
213 $m->set_color(@color);
214 $m->set_offset($top_marker);
215 $c[$chr1-1]->add_marker($m);
216 $c[$chr1-1]->set_url("/cview/view_chromosome.pl?chr_nr=$chr1&map_id=$map_id&show_ruler=1");
219 elsif ("$chr1" eq "$chr2") {
221 my $m = CXGN::Cview::Marker::RangeMarker->new($c[$chr1-1]);
222 #$m->get_label()->set_stacking_level(1);
223 # $m->set_label_side("right");
224 $m->get_label()->set_name("IL");
226 my $offset = ($top_marker+$bottom_marker)/2;
227 $m->set_offset($offset);
228 $m->set_north_range($offset-$top_marker);
229 $m->set_south_range($bottom_marker-$offset);
231 $c[$chr1-1]->add_marker($m);
232 $m->set_hilite_chr_region(1);
233 #$m->get_label()->set_url("/cview/view_chromosome.pl?map_id=5&cM_start=$top_marker&cM_end=$bottom_marker&show_zoomed=1");
234 $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");
236 #print STDERR "Fragment: $offset, $top_marker, $bottom_marker\n";
238 else { print STDERR "[Individual_overviews] $chr1 should be the same as $chr2...\n"; }
241 $self->get_cache()->set_image_data( $self->{map_image}->render_png_string() );
242 $self->get_cache()->set_image_map_data( $self->{map_image}->get_image_map("overview") );
246 =head2 function get_cache_key
248 Synopsis:
249 Arguments:
250 Returns:
251 Side effects:
252 Description:
254 =cut
256 sub get_cache_key {
257 my $self = shift;
258 return "Individual".$self->get_individual_id();
262 =head2 accessors set_chromosome_count, get_chromosome_count
264 Property:
265 Setter Args:
266 Getter Args:
267 Getter Ret:
268 Side Effects:
269 Description:
271 =cut
273 sub get_chromosome_count {
274 my $self=shift;
275 return $self->{chromosome_count};
278 sub set_chromosome_count {
279 my $self=shift;
280 $self->{chromosome_count}=shift;
284 package CXGN::Cview::Map_overviews::Individual_overview;
286 use base qw | CXGN::Cview::Map_overviews::Individual |;
288 sub new {
289 my $class = shift;
290 my $self = $class->SUPER::new(@_);
291 return $self;
294 return 1;