debugging
[sgn.git] / cgi-bin / phenome / recent_annotated_loci.pl
blobf9a8b3a94d8cee9df8132584cd2809c55604d642
1 #!usr/bin/perl
2 use warnings;
3 use strict;
5 use CXGN::Page;
6 use CXGN::Login;
7 use CXGN::People;
8 use CXGN::Page::WebForm;
10 use CXGN::Phenome::Locus;
11 use CXGN::Page::FormattingHelpers qw/info_section_html
12 page_title_html
13 columnar_table_html
14 info_table_html
15 html_optional_show
16 html_alternate_show
18 #use base qw /CXGN::Page::WebForm/;
19 my $dbh= CXGN::DB::Connection->new('phenome');
20 my $logged_sp_person_id = CXGN::Login->new($dbh)->verify_session();
22 my $page = CXGN::Page->new("Recently annotated loci","Naama");
23 #$page->jsan_use("Dynarch.Calendar");
24 $page->jsan_use("CXGN.Calendar");
26 $page->header();
27 #$page->jsan_use("CXGN.Calendar", "CXGN.Phenome.Locus");
30 my $form = CXGN::Page::WebForm->new();
32 $form->set_data(date =>'');
33 $form->template(<<HTML);
34 <input type="text" name="date" id="cal_target" />
35 <input type="submit" id="submit_button" value="Submit" />
37 HTML
38 print '<form action="" method="get">',
39 '<h3 align="center">Find recently annotated loci</h3>',
41 $form->to_html,
43 '</form>'; #now print the auto-filled-in form
44 my $cal=get_calendar();
45 print $cal;
47 ######Javascript calendar: this stuff is not working. I guess the Calendar object is not called correctly.#####
48 print <<EOT;
50 <script language="javascript" type="text/javascript" >
51 <!--
53 var c = new Calendar;
54 c.showFlatCalendar('');
55 c.showCalendar('cal_target', '%m/%d/%Y', '24', '1');
56 -->
57 </script>
58 EOT
62 my %params= $page->cgi_params();
63 $form->from_request( \%params );
65 my $date = $params{date};
68 if ($date) { print_results($dbh, $date) } ;
71 $page->footer();
73 sub get_calendar {
74 my $c=qq|
76 <a href="javascript:Calendar.showCalendar('cal_id')">[Calendar]</a><br>
78 <div id='popUpCal' style="display: none">
79 <div id='cal_id'>
80 <input type="hidden"
81 value=""
82 id="">
83 </div>
84 </div>
88 sub print_results {
89 my $dbh =shift;
90 my $date = shift;
92 my %locus_edits = CXGN::Phenome::Locus::get_recent_annotated_loci($dbh, $date);
94 ####################
95 #locus updates and creates section
96 ###################
97 my @locus_updates;
98 my $action;
99 foreach my $locus(@{$locus_edits{loci} }) {
100 my $locus_id = $locus->get_locus_id();
101 my $locus_name=$locus->get_common_name() . " " . $locus->get_locus_name();
102 my $updated_by= $locus->get_updated_by() || ($locus->get_owners())[0];
103 my $person= get_person_info($dbh, $updated_by);
104 my $udate = $locus->get_modification_date();
105 $action='Updated';
106 if (!$udate ) { #&& $locus->get_create_date() > $date) {
107 $action= 'Created';
108 $udate = $locus->get_create_date() ;
110 if ($locus->get_obsolete() eq 't') { $action= 'Obsoleted'; }
111 push @locus_updates, [map {$_} (qq|<a href="locus_display.pl?locus_id=$locus_id">$locus_name</a>|, $person,$udate, $action)];
113 my $updated_loci= columnar_table_html(headings => ['Locus name',
114 'Updated by',
115 "Date",
117 data=>\@locus_updates, __align=>'llc') if @locus_updates;
120 print info_section_html(title => "Updated loci (" . scalar(@locus_updates) . ")",
121 contents =>$updated_loci,
122 collapsible=>1,
123 collapsed=>0,
126 ####################
127 #Locus alias section
128 ####################
130 my @alias_updates;;
131 foreach my $alias(@{$locus_edits{aliases} } ) {
132 my $locus_id=$alias->get_locus_id();
133 my $locus_name=$alias->get_common_name() ." " . $alias->get_locus_name();
134 my $alias_name= $alias->get_locus_alias();
135 my $alias_person_id= $alias->get_sp_person_id();
136 my $udate= $alias->get_modification_date() || $alias->get_create_date();
137 my $alias_obsoleted = $alias->get_obsolete();
138 $action='Created';
139 my $person= get_person_info($dbh, $alias_person_id);
140 if ($alias_obsoleted eq 't' ) { $action= 'Obsoleted'; }
141 push @alias_updates, [map {$_} (qq|<a href="locus_display.pl?locus_id=$locus_id">$locus_name</a>|, $alias_name, $person, $udate, $action)];
144 my $aliases;
145 if (@alias_updates) { $aliases= columnar_table_html(headings => ['Locus name',
146 'Synonym',
147 'Submitted by',
148 'Date',
150 data=>\@alias_updates, __align=>'llc'); }
152 print info_section_html(title => "Locus synonyms (" . scalar(@alias_updates) . ")",
153 contents => $aliases ,
154 collapsible=>1,
157 ####################
158 #alleles section
159 ####################
161 my @allele_updates;
163 foreach my $allele(@{$locus_edits{alleles} } ) {
164 my $allele_id=$allele->get_allele_id();
165 my $locus_name=$allele->get_locus()->get_common_name() ." " . $allele->get_locus_name();
166 my $allele_name= $allele->get_allele_name();
167 my $allele_symbol=$allele->get_allele_symbol();
168 my $allele_owner= $allele->get_sp_person_id();
169 my $udate= $allele->get_modification_date() ;
170 my $allele_obsoleted = $allele->get_obsolete();
171 $action='Updated';
172 if (!$udate) {
173 $udate=$allele->get_create_date();
174 $action='Created';
176 my $person= get_person_info($dbh, $allele_owner);
177 if ($allele_obsoleted eq 't' ) { $action= 'Obsoleted'; }
178 push @allele_updates, [map {$_} ($locus_name, qq|<a href="allele.pl?allele_id=$allele_id">$allele_symbol</a>|, $person, $udate, $action)];
181 my $alleles;
182 if (@allele_updates) {
183 $alleles= columnar_table_html(headings => ['Locus name',
184 'Allele symbol',
185 'Submitted by',
186 'Date',
188 data=>\@allele_updates, __align=>'llc');}
191 print info_section_html(title => "Alleles (" . scalar(@allele_updates) . ")",
192 contents => $alleles ,
193 collapsible=>1,
196 ####################
197 #locus dbxrefs
198 ####################
200 my @ld_updates;
202 foreach my $ld(@{$locus_edits{locus_dbxrefs} } ) {
203 my $locus_id=$ld->get_locus_id();
204 my $locus=CXGN::Phenome::Locus->new($dbh, $locus_id);
205 my $dbxref=CXGN::Chado::Dbxref->new($dbh, $ld->get_dbxref_id());
206 my $annotation= get_annotation($dbxref);
207 my $locus_symbol=$locus->get_common_name() ." " . $locus->get_locus_symbol();
208 my $ld_owner= $ld->get_sp_person_id();
209 my $udate= $ld->get_modification_date() ;
210 my $ld_obsoleted = $ld->get_obsolete();
211 $action='Updated';
212 if (!$udate) {
213 $udate=$ld->get_create_date();
214 $action='Created';
216 my $person= get_person_info($dbh, $ld_owner);
217 if ($ld_obsoleted eq 't' ) { $action= 'Obsoleted'; }
218 push @ld_updates, [map {$_} (qq|<a href="locus_display.pl?locus_id=$locus_id">$locus_symbol</a>|, $annotation, $person, $udate, $action)];
221 my $lds;
222 if (@ld_updates) {
223 $lds= columnar_table_html(headings => ['Locus',
224 'Annotation',
225 'Updated by',
226 'Date',
228 data=>\@ld_updates, __align=>'llc');}
231 print info_section_html(title => "Locus Annotations (" . scalar(@ld_updates) . ")",
232 contents => $lds ,
233 collapsible=>1,
234 collapsed=>1,
238 ####################
239 #locus images
240 ####################
242 my @locus_images;
244 foreach my $list(@{$locus_edits{locus_images} } ) {
245 #[$locus, $image, $person_id, $cdate, $mdate, $obsolete];
246 my $locus=$list->[0];
247 my $image_id=$list->[1];
248 # my $image_id=$image->get_image_id();
249 # my $image_name= $image->get_name() || "image: $image_id";
250 my $locus_id=$locus->get_locus_id();
251 my $locus_symbol=$locus->get_common_name() ." " . $locus->get_locus_symbol();
252 my $owner= $list->[2];
253 my $person= get_person_info($dbh, $owner);
255 my $udate= $list->[4];
256 $action='Updated';
257 if (!$udate) {
258 $udate=$list->[3];
259 $action='Created';
261 my $obsoleted = $list->[5];
262 if ($obsoleted eq 't' ) { $action= 'Obsoleted'; }
263 push @locus_images, [map {$_} (qq|<a href="locus_display.pl?locus_id=$locus_id">$locus_symbol</a>|, qq|<a href="/image/index.pl?image_id=$image_id">image: $image_id</a>|, $person, $udate, $action)];
266 my $lis;
267 if (@locus_images) {
268 $lis= columnar_table_html(headings => ['Locus',
269 'Image',
270 'Updated by',
271 'Date',
273 data=>\@locus_images, __align=>'llc');}
276 print info_section_html(title => "Locus images (" . scalar(@locus_images) . ")",
277 contents => $lis ,
278 collapsible=>1,
279 collapsed=>1,
282 ####################
283 #individuals
284 ####################
286 my @individuals;
288 foreach my $list(@{$locus_edits{individuals} } ) {
289 my $ind=$list->[0];
290 my $allele=$list->[1];
291 my $ind_id=$ind->get_individual_id();
292 my $ind_name= $ind->get_name() ;
293 my $locus_name=$allele->get_locus()->get_common_name() ." " . $allele->get_locus_name();
294 my $locus_id=$allele->get_locus_id();
295 my $owner= $list->[2];
296 my $person= get_person_info($dbh, $owner);
298 my $udate= $list->[4];
299 $action='Updated';
300 if (!$udate) {
301 $udate=$list->[3];
302 $action='Created';
304 my $obsoleted = $list->[5];
305 if ($obsoleted eq 't' ) { $action= 'Obsoleted'; }
306 push @individuals, [map {$_} (qq|<a href="locus_display.pl?locus_id=$locus_id">$locus_name</a>|, qq|<a href="individual.pl?individual_id=$ind_id">$ind_name</a>|, $person, $udate, $action)];
309 my $ias;
310 if (@individuals) {
311 $ias= columnar_table_html(headings => ['Locus',
312 'Accessions',
313 'Updated by',
314 'Date',
316 data=>\@individuals, __align=>'llc');}
319 print info_section_html(title => "Locus accessions (" . scalar(@individuals) . ")",
320 contents => $ias ,
321 collapsible=>1,
322 collapsed=>1,
325 ####################
326 #locus unigenes
327 ####################
329 my @locus_unigenes;
331 foreach my $list(@{$locus_edits{locus_unigenes} } ) {
332 my $unigene=$list->[0];
333 my $locus=$list->[1];
334 my $unigene_id='SGN-U' . $unigene->get_unigene_id();
335 my $locus_name=$locus->get_common_name() ." " . $locus->get_locus_name();
336 my $locus_id=$locus->get_locus_id();
337 my $owner= $list->[2];
338 my $person= get_person_info($dbh, $owner);
340 my $udate= $list->[4];
341 $action='Updated';
342 if (!$udate) {
343 $udate=$list->[3];
344 $action='Created';
346 my $obsoleted = $list->[5];
347 if ($obsoleted eq 't' ) { $action= 'Obsoleted'; }
348 push @locus_unigenes, [map {$_} (qq|<a href="locus_display.pl?locus_id=$locus_id">$locus_name</a>|, qq|<a href="/search/unigene.pl?unigene_id=$unigene_id">$unigene_id</a>|, $person, $udate, $action)];
351 my $uls;
352 if (@locus_unigenes) {
353 $uls= columnar_table_html(headings => ['Locus',
354 'Unigene',
355 'Updated by',
356 'Date',
358 data=>\@locus_unigenes, __align=>'llc');}
361 print info_section_html(title => "Locus-unigenes (" . scalar(@locus_unigenes) . ")",
362 contents => $uls ,
363 collapsible=>1,
364 collapsed=>1,
368 ####################
369 #locus markers
370 ####################
372 my @lm_updates;
374 foreach my $lm(@{$locus_edits{locus_markers} } ) {
375 my $locus_id=$lm->get_locus_id();
376 my $locus=CXGN::Phenome::Locus->new($dbh, $locus_id);
377 my $marker_id= $lm->get_marker_id();
378 my $marker=CXGN::Marker->new($dbh, $lm->get_marker_id());
379 my $marker_name=$marker->name_that_marker();
380 my $locus_symbol=$locus->get_common_name() ." " . $locus->get_locus_symbol();
381 my $lm_owner= $lm->get_sp_person_id();
382 my $udate= $lm->get_modification_date() ;
383 my $lm_obsoleted = $lm->get_obsolete();
384 $action='Updated';
385 if (!$udate) {
386 $udate=$lm->get_create_date();
387 $action='Created';
389 my $person= get_person_info($dbh, $lm_owner);
390 if ($lm_obsoleted eq 't' ) { $action= 'Obsoleted'; }
391 push @lm_updates, [map {$_} (qq|<a href="locus_display.pl?locus_id=$locus_id">$locus_symbol</a>|, qq|<a href="/markers/marker_info.pl?marker_id=$marker_id">$marker_name</a>|, $person, $udate, $action)];
394 my $lms;
395 if (@lm_updates) {
396 $lms= columnar_table_html(headings => ['Locus',
397 'Marker',
398 'Updated by',
399 'Date',
401 data=>\@lm_updates, __align=>'llc');}
404 print info_section_html(title => "Locus markers (" . scalar(@lm_updates) . ")",
405 contents => $lms ,
406 collapsible=>1,
407 collapsed=>1,
414 sub get_person_info {
415 my $dbh=shift;
416 my $sp_person_id=shift;
417 my $user = CXGN::People::Person -> new($dbh, $sp_person_id);
418 my $username=$user->get_first_name()." ".$user->get_last_name();
419 my $person= qq| <a href="../solpeople/personal_info.pl?sp_person_id=$sp_person_id">$username</a> | ;
420 return $person;
423 sub get_annotation {
424 my $dbxref=shift;
425 my $acc=$dbxref->get_full_accession();
426 my $accession= $dbxref->get_accession();
427 my $db=$dbxref->get_db_name();
428 if ($db eq 'SGN_ref') {
429 $accession= $dbxref->get_publication()->get_pub_id();
431 my $url=$dbxref->get_urlprefix() . $dbxref->get_url() . $accession;
432 return qq |<a href="$url">$acc</a>|;