added a comment section..
[sgn.git] / cgi-bin / phenome / population.pl
blob9108e290931b571c14f204d8c1a0bbddadb20a4e
1 use strict;
3 my $population_detail_page = CXGN::Phenome::PopulationDetailPage->new();
5 package CXGN::Phenome::PopulationDetailPage;
8 use CXGN::Page;
9 use CXGN::Page::FormattingHelpers qw /info_section_html
10 page_title_html
11 columnar_table_html
12 html_optional_show
13 info_table_html
14 tooltipped_text
15 html_alternate_show
18 use CXGN::Phenome::Population;
19 use CXGN::Phenome::PopulationDbxref;
20 use CXGN::People::PageComment;
21 use CXGN::People::Person;
22 use CXGN::Chado::Publication;
23 use CXGN::Chado::Pubauthor;
25 use CXGN::Contact;
26 use CXGN::Map;
29 use base qw / CXGN::Page::Form::SimpleFormPage CXGN::Phenome::Main/;
31 sub new {
32 my $class = shift;
33 my $self = $class->SUPER::new(@_);
34 $self->set_script_name("population.pl");
37 return $self;
40 sub define_object {
41 my $self = shift;
43 # call set_object_id, set_object and set_primary_key here
44 # with the appropriate parameters.
46 $self->set_dbh(CXGN::DB::Connection->new('phenome'));
47 my %args = $self->get_args();
48 my $population_id= $args{population_id};
49 unless (!$population_id || $population_id =~m /^\d+$/) { $self->get_page->message_page("No population exists for identifier $population_id"); }
50 $self->set_object_id($population_id);
51 $self->set_object(CXGN::Phenome::Population->new($self->get_dbh(),$self->get_object_id()));
52 $self->set_primary_key("population_id");
53 $self->set_owners($self->get_object()->get_owners());
59 sub generate_form {
60 my $self = shift;
62 $self->init_form();
64 my %args = $self->get_args();
66 my $population = $self->get_object();
67 my $population_id = $self->get_object_id();
68 my $type_id = $args{type_id};
69 my $type=$args{type};
71 my ($submitter, $submitter_link) = $self->submitter();
73 my $login_user= $self->get_user();
74 my $login_user_id= $login_user->get_sp_person_id();
75 my $form = undef;
77 if ($self->get_action()=~/edit|store/ && ($login_user_id = $submitter || $self->get_user()->get_user_type() eq 'curator') ) {
78 print STDERR "Generating EditableForm..\n";
79 $form = CXGN::Page::Form::Editable->new();
81 else {
82 print STDERR "Generating static Form...\n";
83 $form = CXGN::Page::Form::Static->new();
86 $form->add_field(
87 display_name=>"Name:",
88 field_name=>"name",
89 length=>15,
90 object=>$population,
91 getter=>"get_name",
92 setter=>"set_name",
93 validate => 'string',
95 $form->add_textarea(
96 display_name=>"Description: ",
97 field_name=>"description",
98 object=>$population,
99 getter=>"get_description", setter=>"set_description",
100 columns => 40,
101 rows =>4,
105 $form->add_label( display_name=>"Uploaded by: ",
106 field_name=>"submitter",
107 contents=>$submitter_link,
109 $form->add_hidden( field_name=>"population_id", contents=>$args{population_id});
111 $form->add_hidden (
112 field_name => "sp_person_id",
113 contents =>$self->get_user()->get_sp_person_id(),
114 object => $population,
115 setter =>"set_sp_person_id",
118 $form->add_hidden( field_name=>"action", contents=>"store" );
124 $self->set_form($form);
126 if ($self->get_action=~ /view|edit/) {
127 $self->get_form->from_database();
130 }elsif ($self->get_action=~ /store/) {
131 $self->get_form->from_request($self->get_args());
139 sub display_page {
140 my $self = shift;
142 $self->get_page->add_style( text => <<EOS);
144 a.abstract_optional_show {
145 color: blue;
146 cursor: pointer;
147 white-space: nowrap;
149 div.abstract_optional_show {
150 background: #f0f0ff;
151 border: 1px solid #9F9FC7;
152 margin: 0.2em 1em 0.2em 1em;
153 padding: 0.2em 0.5em 0.2em 1em;
159 my %args = $self->get_args();
161 my $population = $self->get_object();
162 my $population_id = $self->get_object_id();
163 my $population_name = $population->get_name();
165 my $action = $args{action};
166 if (!$population_id && $action ne 'new' && $action ne 'store')
167 { $self->get_page->message_page("No population exists for this identifier"); }
169 #used to show certain elements to only the proper users
170 my $login_user= $self->get_user();
171 my $login_user_id= $login_user->get_sp_person_id();
172 my $login_user_type= $login_user->get_user_type();
173 my $page="../phenome/population.pl?population_id=$population_id";
175 $self->get_page()->header("SGN Population name: $population_name");
177 print page_title_html("Population: $population_name \n");
179 my $page="../phenome/population.pl?population_id=$population_id";
180 $args{calling_page} = $page;
182 my $population_html = $self->get_edit_link_html(). "\t[<a href=/phenome/qtl_form.pl>New QTL Population</a>] <br />";
184 #print all editable form fields
185 $population_html .= $self->get_form()->as_table_string();
188 my $phenotype = "";
189 my @phenotype;
190 my $graph_icon = qq |<img src="../documents/img/pop_graph.png"/> |;
192 if ($population->get_web_uploaded()) {
193 my @traits = $population->get_cvterms();
195 foreach my $trait (@traits) {
196 my $trait_id = $trait->get_user_trait_id();
197 my $trait_name = $trait->get_name();
198 my $definition = $trait->get_definition();
199 my ($min, $max, $avg, $std, $count)= $population->get_pop_data_summary($trait_id);
201 my $cvterm_obj = CXGN::Chado::Cvterm::get_cvterm_by_name( $self->get_dbh(), $trait_name);
202 my $trait_link;
203 my $cvterm_id = $cvterm_obj->get_cvterm_id();
204 if ($cvterm_id)
207 print STDERR "cvterm_id: $cvterm_id\n";
208 $trait_link = qq |<a href="/chado/cvterm.pl?cvterm_id=$cvterm_id">$trait_name</a>|;
210 } else
212 print STDERR "trait_id: $trait_id\n";
213 $trait_link = qq |<a href="/phenome/trait.pl?trait_id=$trait_id">$trait_name</a>|;
217 if ($definition) {
218 push @phenotype, [map {$_} ( (tooltipped_text($trait_link, $definition)),
219 $min, $max, $avg,
220 qq | <a href="/phenome/population_indls.pl?population_id=$population_id&amp;cvterm_id=$trait_id">
221 $count</a>
223 qq | <a href="/phenome/population_indls.pl?population_id=$population_id&amp;cvterm_id=$trait_id">
224 $graph_icon</a>
225 | )];
226 } else { push @phenotype, [map {$_} ($trait_name, $min, $max, $avg,
227 qq | <a href="/phenome/population_indls.pl?population_id=$population_id&amp;cvterm_id=$trait_id">
228 $count</a>
230 qq | <a href="/phenome/population_indls.pl?population_id=$population_id&amp;cvterm_id=$trait_id">
231 $graph_icon</a>
232 | )];
236 else {
237 my @cvterms = $population->get_cvterms();
238 foreach my $cvterm(@cvterms) {
239 my ($min, $max, $avg, $std, $count)= $population->get_pop_data_summary($cvterm->get_cvterm_id());
240 my $cvterm_id = $cvterm->get_cvterm_id();
241 my $cvterm_name = $cvterm->get_cvterm_name();
242 if ($cvterm->get_definition()) {
243 push @phenotype, [map {$_} ( (tooltipped_text( qq|<a href="/chado/cvterm.pl?cvterm_id=$cvterm_id">
244 $cvterm_name</a>
246 $cvterm->get_definition())), $min, $max, $avg,
247 qq | <a href="/phenome/population_indls.pl?population_id=$population_id&amp;cvterm_id=$cvterm_id">
248 $count</a>
250 qq | <a href="/phenome/population_indls.pl?population_id=$population_id&amp;cvterm_id=$cvterm_id">
251 $graph_icon</a>
252 | ) ];
253 } else { push @phenotype, [map {$_} (qq | <a href="/chado/cvterm.pl?cvterm_id=$cvterm_id">$cvterm_name</a>|,
254 $min, $max, $avg,
255 qq | <a href="/phenome/population_indls.pl?population_id=$population_id&amp;cvterm_id=$cvterm_id">
256 $count</a>
258 qq | <a href="/phenome/population_indls.pl?population_id=$population_id&amp;cvterm_id=$cvterm_id">
259 $graph_icon</a>
260 | ) ];
265 my $accessions_link = qq |<a href="../search/phenotype_search.pl?wee9_population_id=$population_id">
266 See all accessions ...</a>
269 my ($phenotype_data, $data_view, $data_download);
271 if (@phenotype) {
272 $phenotype_data = columnar_table_html(headings => [
273 'Trait',
274 'Minimum',
275 'Maximum',
276 'Average',
277 'No. of lines',
278 'QTL(s)...',
280 data =>\@phenotype,
281 __alt_freq =>2,
282 __alt_width =>1,
283 __alt_offset =>3,
284 __align =>'l',
287 # $data_view = html_optional_show("phenotype",
288 # 'View/hide phenotype data summary',
289 # qq|$phenotype_data</b>|,
290 # 1, #< show data by default
291 # );
293 $data_download .= qq { <span><br/><br/>Download:<a href="pop_download.pl?population_id=$population_id"><b>\
294 [Phenotype raw data]</b></a><a href="genotype_download.pl?population_id=$population_id">\
295 <b>[Genotype raw data\]</b></a></span>
300 my $pub_subtitle;
301 if ($population_name && ($login_user_type eq 'curator' || $login_user_type eq 'submitter')) {
302 $pub_subtitle .= qq|<a href="../chado/add_publication.pl?type=population&amp;type_id=$population_id&amp;refering_page=$page&amp;action=new">[Associate publication]</a>|;
306 else { $pub_subtitle= qq|<span class=\"ghosted\">[Associate publication]</span>|;
311 my $pubmed;
312 my $url_pubmed = qq | http://www.ncbi.nlm.nih.gov/pubmed/|;
314 my @publications = $population->get_population_publications();
315 my $abstract_view;
316 my $abstract_count = 0;
320 foreach my $pub (@publications) {
321 my ($title, $abstract, $authors, $journal, $pyear,
322 $volume, $issue, $pages, $obsolete, $pub_id, $accession
324 $abstract_count++;
326 my @dbxref_objs = $pub->get_dbxrefs();
327 my $dbxref_obj = shift(@dbxref_objs);
329 $obsolete = $population->get_population_dbxref($dbxref_obj)->get_obsolete();
331 if ($obsolete eq 'f') {
332 $pub_id = $pub->get_pub_id();
333 $title = $pub->get_title();
334 $abstract = $pub->get_abstract();
335 $pyear = $pub->get_pyear();
336 $volume = $pub->get_volume();
337 $journal = $pub->get_series_name();
338 $pages = $pub->get_pages();
339 $issue = $pub->get_issue();
341 $accession = $dbxref_obj->get_accession();
342 my $pub_info = qq|<a href="/chado/publication.pl?pub_id=$pub_id" >PMID:$accession</a>|;
344 my @authors;
345 my $authors;
346 if ($pub_id) {
348 my @pubauthors_ids = $pub->get_pubauthors_ids($pub_id);
350 foreach my $pubauthor_id (@pubauthors_ids) {
351 my $pubauthor_obj = CXGN::Chado::Pubauthor->new($self->get_dbh, $pubauthor_id);
352 my $last_name = $pubauthor_obj->get_surname();
353 my $first_names = $pubauthor_obj->get_givennames();
354 my @first_names = split (/,/, $first_names);
355 $first_names = shift (@first_names);
356 push @authors, ("$first_names" ." ". "$last_name");
357 $authors = join (", ", @authors);
364 $abstract_view = html_optional_show("abstracts$abstract_count",
365 'Show/hide abstract',
366 qq|$abstract <b> <i>$authors.</i> $journal. $pyear. $volume($issue). $pages.</b>|,
367 0, #< do not show by default
368 'abstract_optional_show', #< don't use the default button-like style
372 $pubmed .= qq| <div><a href="$url_pubmed$accession" target="blank">$pub_info</a> $title $abstract_view</div> |;
376 my $is_public = $population->get_privacy_status();
377 my ($submitter_obj, $submitter_link) = $self->submitter();
378 my $map_link = $self->genetic_map();
379 print info_section_html(title => 'Population Details',
380 contents => $population_html,
383 if ($is_public ||
384 $login_user_type eq 'curator' ||
385 $login_user_id ==
386 $population->get_sp_person_id()
387 ) {
388 if ($phenotype_data) {
389 print info_section_html(title => 'Phenotype Data and QTLs',
390 contents => $phenotype_data ." ".$data_download
392 } else {
393 print info_section_html(title => 'Phenotype Data',
394 contents => $accessions_link
398 unless (!$map_link) {
399 print info_section_html( title => 'Genetic Map',
400 contents => $map_link
404 } else {
405 my $message = "The QTL data for this population is not public yet.
406 If you would like to know more about this data,
407 please contact the owner of the data: <b>$submitter_link</b>
408 or email to SGN:
409 <a href=mailto:sgn-feedback\@sgn.cornell.edu>
410 sgn-feedback\@sgn.cornell.edu</a>.\n";
412 print info_section_html(title => 'Phenotype Data and QTLs',
413 contents =>$message,
417 print info_section_html(title => 'Literature Annotation',
418 #subtitle => $pub_subtitle,
419 contents => $pubmed,
422 if ($population_name) {
423 # change sgn_people.forum_topic.page_type and the CHECK constraint!!
424 my $page_comment_obj = CXGN::People::PageComment->new($self->get_dbh(), "population", $population_id);
425 print $page_comment_obj->get_html();
428 $self->get_page()->footer();
431 exit();
439 # override store to check if a locus with the submitted symbol/name already exists in the database
441 sub store {
442 my $self = shift;
443 my $population = $self->get_object();
444 my $population_id = $self->get_object_id();
445 my %args = $self->get_args();
447 $self->SUPER::store(0);
449 exit();
453 sub submitter {
454 my $self = shift;
455 my $population = $self->get_object();
456 my $sp_person_id= $population->get_sp_person_id();
457 my $submitter = CXGN::People::Person->new($self->get_dbh(), $population->get_sp_person_id());
458 my $submitter_name = $submitter->get_first_name()." ".$submitter->get_last_name();
459 my $submitter_link = qq |<a href="/solpeople/personal-info.pl?sp_person_id=$sp_person_id">$submitter_name</a> |;
461 return $submitter, $submitter_link;
465 sub genetic_map {
466 my $self = shift;
467 my $mapv_id = $self->get_object()->mapversion_id();
469 if ($mapv_id) {
470 my $map = CXGN::Map->new( $self->get_dbh(), { map_version_id => $mapv_id } );
471 my $map_name = $map->get_long_name();
472 my $genetic_map =
473 qq | <a href=/cview/map.pl?map_version_id=$mapv_id>$map_name</a>|;
475 return $genetic_map;
477 else {
478 return;