phenotype download will print 0 values, while leaving empty values empty
[sgn.git] / mason / stock / index.mas
blobee330e7c4651042218a0cbf7aa59a4010f156a9a
1 <%doc>
3 =head1 NAME
5 /stock/index.mas - a page for displaying stock details (e.g. accession, population, etc.) 
7 =head1 DESCRIPTION
9 parameters:
11 =over 1
13 =item $stockref
15 a hashref with all the parameters needed for printing the stock page! 
17  $stockref->{stock_id}
18  $stockref->{stock}
19  $stockref->{schema}
20  $stockref->{uniquename}
21  $stockref->{curator}  (boolean)
22  $stockref->{submitter} (boolean)
23  $stockref->{is_owner} (boolean)
24  $stockref->{props} (hash of arrayrefs of stockprops. Keys = prop name, value = prop value)
25  $stockref->{has_pedigree} (boolean)
26  $stockref->{has_descendants} (boolean)
27  locus_add_uri
28  locus_autocomplete_uri => '/ajax/locus/autocomplete/'
29  cvterm_add_uri
30  cvterm_autocomplete_uri => '/ajax/cvterm/autocomplete/'
31  barcode_tempdir
32  barcode_tempuri 
33  organism_autocomplete_uri => '/ajax/organism/autocomplete/'
35 =back
37 =head1 AUTHOR
39 Naama Menda <nm249@cornell.edu>
41 =cut
43 </%doc>
45 <%args>
46 $stock_row
47 $stockref => undef
48 $locus_add_uri => ''
49 $locus_autocomplete_uri => undef
50 $cvterm_add_uri => ''
51 $cvterm_autocomplete_uri => undef
52 $barcode_tempdir => undef
53 $barcode_tempuri => undef
54 $identifier_prefix => 'SGN'
55 $organism_autocomplete_uri => '/ajax/organism/autocomplete/'
57 </%args>
60 <%perl>
62 use Bio::Chado::Schema;
63 use CXGN::Chado::Stock;
64 use CXGN::Page::FormattingHelpers qw / html_optional_show info_table_html /;
65 use CXGN::People::Person;
66 use CXGN::Chado::Publication;
67 use CXGN::Cview::Map::SGN::Genotype;
68 use CXGN::Cview::MapOverviews;
70 my $stock = $stockref->{stock};
71 my $stock_id = $stockref->{stock_id};
72 my $action = $stockref->{action} || 'view';
73 my $person_id = $stockref->{person_id};
74 my $curator = $stockref->{curator};
75 my $submitter = $stockref->{submitter};
76 my $sequencer = $stockref->{sequencer};
77 my $pubs = $stockref->{pubs};
78 my $has_pedigree = $stockref->{has_pedigree};
79 my $has_descendants = $stockref->{has_descendants};
80 my $trait_ontology_db_name = $stockref->{trait_ontology_db_name};
81 my $editable_stock_props_string = $stockref->{editable_stock_props};
82 my $schema = $stockref->{schema};
83 my $dbh = $stockref->{dbh};
85 my @editable_stock_props = split "," , $editable_stock_props_string;
87 my $stockprop_cv = $schema->resultset("Cv::Cv")->search( {
88  'me.name' => 'stock_property'} );
91 my ($type_name, $uniquename);
92 my $type = $stock_row ? $stock_row->type : undef;
93 $type_name  = $type->name() if $type;
94 $uniquename = $stock->get_uniquename if $type;
95 #################
96 my $is_owner = $stockref->{is_owner};
98 my $this_page = "/stock/$stock_id/view";
100 my $add_image_link = qq|<a href="/image/add?type_id=$stock_id&action=new&type=stock&refering_page=$this_page">[Add new image]</a>|;
101 my $image_ids =  $stockref->{image_ids} || [] ;
102 my $stockprops = $stockref->{props};
104 ###this is replaced by $editable_stock_props. Needs to be provided in the conf file
105 my $metadata = ['variety', 'donor', 'donor institute', 'country', 'state' , 'adaptation' , 'notes', 'GSOR', 'NPGS', 'Gpno', 'IRGSP', 'NSFTV', 'CIor', 'PI', 'subpopulation'];
106 ####
109 #my $pedigree= ['pedigree', 'male parent', 'female parent'];
110 # get pedigree of stock
111 #my $stock_pedigree = $stockref->{stock_pedigree};
112 #my $stock_descendants = $stockref->{stock_descendants};
115 my $experiment = ['year', 'location', 'replicate']; # these values should be in nd_experimentprop ?
117 my $resources = [ 'stock_synonym', 'solcap number'];
119 my $allele_div = "stock_alleles";
120 my $new_locus_link = !$person_id ? qq|<a href="/solpeople/login.pl">[log-in to associate new locus]</a> | : '' ;
122 #owner
123 my $owners = $stockref->{owners};
124 my $editor_link;
125 foreach my $o_id (@$owners) {
126   my $person = CXGN::People::Person->new($dbh, $o_id);
127   my $first_name = $person->get_first_name;
128   my $last_name = $person->get_last_name;
129   $editor_link .= qq|<a href="/solpeople/personal-info.pl?sp_person_id=$o_id">$first_name $last_name</a> |;
132 #phenotypes measured directly on this stock
133 my $direct_phenotypes = $stockref->{direct_phenotypes} || undef;
135 # get all phenotypes of subjects
136 my $members_phenotypes = $stockref->{members_phenotypes};
137 my $p_download_link = qq|<a href = "/stock/$stock_id/phenotypes">[Download phenotypes]</a>| if ( (keys %$direct_phenotypes) || ( keys %$members_phenotypes) );
138 my $direct_genotypes = $stockref->{direct_genotypes};
139 my $g_download_link = qq|<a href =  "/stock/$stock_id/genotypes">Download genotypes</a>| if (keys %$direct_genotypes) ;
140 ############################
141 my $map_html = $stockref->{map_html};
142 my $map;
143 if ($stock_id) {
144   $map = CXGN::Cview::Map::SGN::Genotype->new($dbh, $stock_id);
145   if ($map->get_chromosome_count > 1 ) {
146     my $overview = CXGN::Cview::MapOverviews::Generic->new($map,
147                                                            {
148                                                             dbh=> $dbh,
149                                                             basepath => $stockref->{cview_basepath},
150                                                             tempfiles_subdir => $stockref->{cview_tmp_dir } });
151     if ($overview) {
152       $overview->render_map();
153       $map_html .= $overview->get_image_html();
154     }
155   }
157 #########################################
158 my $has_qtl_data = $stockref->{has_qtl_data};
161 my $new_pub_link = $curator || $submitter || $sequencer  ?   qq|<a href="/chado/add_publication.pl?type=stock&amp;type_id=$stock_id&amp;refering_page=$this_page&amp;action=new"> [Associate publication] </a>| : qq|<span class=\"ghosted\">[Associate publication]</span>| ;
163 my $pub_count = scalar( keys %$pubs );
165 ## EUSOL, tgrc (stock_dbxref)
166 my $dbxrefs = $stockref->{dbxrefs};
167 my %source_dbs;
168 foreach my $db_name ( keys %$dbxrefs ) {
169   foreach my $dbxref ( @{ $dbxrefs->{$db_name} } ) {
170     my $url = $dbxref->db->urlprefix . $dbxref->db->url;
171     $url .= $dbxref->accession if $url =~ m/\?$|\=$/ ;
172     $source_dbs{$url} = $db_name . ": " . $dbxref->accession if $url;
173   }
176 my $ontology_subtitle = $curator || $submitter || $sequencer  ?
177   qq|<a href="javascript:Tools.toggleContent('associate_cvterm_form', 'stock_ontology')">[Add ontology annotations]</a> | :
178   qq |<span class = "ghosted"> [Add ontology annotations]</span> |;
180 my $add_phenotype_link =  $curator || $submitter || $sequencer  ? qq| <a href="javascript:Tools.toggleContent('add_phenotype_form', 'stock_phenotype')" >[Add phenotype]</a> | :   qq |<span class = "ghosted"> [Add phenotype]</span> |;
182 my $edit_privs = $curator || $submitter || $sequencer;
184 my $project_name = lc($c->config->{project_name});
185 my $test_url = "/jbrowse_$project_name/current/data/json/accessions/" . $stock_id . "/trackList.json";
186 my $jbrowse_url = "/jbrowse/?data=data%2Fjson%2Faccessions%2F" . $stock_id . "&tracks=DNA%2CGene%20exons%2C" . $uniquename . "_2015_V6_imputed&highlight=";
188 </%perl>
189 <& /util/import_javascript.mas, classes => ["jquery", "jqueryui", "thickbox", "CXGN.Page.FormattingHelpers", "jquery.cookie", "CXGN.Stock"] &>
192 <script language="javascript">
193 function jqueryStuff() { 
194    jQuery(function() {
195      jQuery("#species_name").autocomplete({
196         source: '/organism/autocomplete'
197      });
198   });
200 </script>
201 <& /page/page_title.mas, title=> join( ': ', grep $_, ucfirst($type_name), $uniquename ) || 'Create a new stock' &>
204 <&| /page/info_section.mas, title=>"Stock details" , subtitle => "<a href=/phenome/qtl_form.pl>New QTL population</a> | <a href=/search/stocks/>Back to stock search</a>"  &>
206 <div class="row">
207   <div class="col-sm-6">
209   <& /page/form.mas,
210   object_type=>'stock',
211   object_id=>"$stock_id",
212   form_name=> 'stock_form',
213   server_side_script => '/phenome/stock/stock_ajax_form.pl',
214   form_div_name=>'stock_details',
215   js_object_name=> 'stockForm',
216   page_url => "/stock/$stock_id/view/" ,
217   alternate_new_button => '<a href ="/stock/0/new">[New]</a>'
218   &>
220   </div>
221   <div class="col-sm-6">
222 <& /util/barcode.mas, identifier => "$identifier_prefix"."$stock_id", text=> "$identifier_prefix stock $stock_id ($uniquename)", format=>"code128"  &><br /><br />
223 % #<& /util/barcode.mas, identifier => "http://solgenomics.net/stock/$stock_id/view", text=>"SGN stock $stock_id ($uniquename)", format=>"qrcode" &>
225   </div>
226 </div>
228 <div><b>Stock editors: </b> <% $editor_link %></div>
229 <br />
230 % foreach my $db_url (keys %source_dbs) {
231 <div><a href=<% $db_url %>><% $source_dbs{$db_url} %></a> </div>
233 <br />
234 % my $div_name = join("_", @$resources);
235 % my $subtitle = $edit_privs ? "[<a id=\"stock_add_synonym\" href=\"javascript:synonyms_addPropDialog()\">Add...</a>]" : "[Add]";
236    <&| /page/info_section.mas, title => "Synonyms" , is_subsection => 1 , subtitle=>$subtitle &>
237       <& /stock/stockprops.mas,
238        stock_id    => $stock_id,
239         props      => $stockprops ,
240         div_name   =>'synonyms',
241         subset     =>$resources,
242         editable   => [ 'stock_synonym' ],
243         edit_privs => $edit_privs   &>
244 </&>
245 %  $div_name = join("_", @editable_stock_props);
246 % my $props_subtitle = $edit_privs ? "[<a id=\"stock_add_props\" href=\"javascript:stockprops_addPropDialog()\">Add...</a>]" : "[Add]";
248     <&| /page/info_section.mas, title => "Additional information" , collapsible=> 1, is_subsection => 1, subtitle=>$props_subtitle &>
249       <& /stock/stockprops.mas,
250          stock_id  =>$stock_id,
251         props      => $stockprops,
252         div_name   => 'stockprops',
253         edit_privs => $edit_privs,
254         subset     => \@editable_stock_props,
255         editable   => \@editable_stock_props  &>
256 </&>
259 </&>
262 <&| /page/info_section.mas, title => "Associated loci (" . $stockref->{allele_count} . ")" , subtitle => $new_locus_link, collapsible=> 1 , collapsed => 1 &>
264 <& /phenome/associate_locus.mas, object_id => $stock_id , object_name => "stock", locus_add_uri=> $locus_add_uri,   allele_div => $allele_div , show_form => $is_owner &>
266 </&>
269 <&| /page/info_section.mas, title => "Experimental data" , collapsible=> 1, is_subsection => 0 &>
270       <& /stock/stockprops.mas, stock_id=>$stock_id, props=> $stockprops, subset=> $experiment  &>
271 </&>
273 % if($is_owner) {
274 <&| /page/info_section.mas, title=>"Stock history", collapsible=>1, collapsed=>1 &>
276 </&>
279 % }
281 <%perl>
282  my $collapsible = 0; 
283  if ($has_pedigree==1) {
284   $collapsible = 1;
286  my $add_parent_link = "Add parent";
287  if ($person_id && ($submitter || $curator || $sequencer)) { $add_parent_link = qq | <a id="add_parent_link" >Add parent</a> |; }
289 my $remove_parent_link = "Remove parent";
290 if ($person_id && ($submitter || $curator || $sequencer)) { $remove_parent_link = qq | <a id="remove_parent_link">Remove parent</a> |; }
292 </%perl>
294 <div id="remove_parent_dialog">
295 Remove a parent (this will only remove the link to the parent, not the parent accession itself).<br /><br />
296   <div id="remove_parent_list">[loading parent list...]</div>
297 </div>
300 <&| /page/info_section.mas, title=>"Pedigree" , collapsible=> $collapsible, collapsed=>0, subtitle=>"[$add_parent_link] [$remove_parent_link]" &>
301   <& /pedigree/stock_pedigree.mas, stock_id => $stock_id, has_pedigree => $has_pedigree &>
302 </&>
304 % if ($has_descendants==1) {
306 <&| /page/info_section.mas, title=>"Descendants" , collapsible=>1, collapsed=>0 &>
307   <& /pedigree/stock_descendants.mas, stock_id => $stock_id &>
308 </&>
310 % } else {
312 <&| /page/info_section.mas, title=>"Descendants" , collapsible=>1, collapsed=>1 &>
313 </&>
315 % }
317 <& /pedigree/stock_pedigree_string.mas, stock_id => $stock_id &>
320 % if ($type) {
321 <&| /page/info_section.mas, title=>"Related stocks" , collapsible=>1, collapsed=>0 &>
322   <& /stock/related_stocks.mas, stock => $stock_row &>
324 </&>
326 % }
329 <&| /page/info_section.mas, title=>"Images (" .  scalar(@$image_ids)  . ")", subtitle => "$add_image_link", collapsible=>1, collapsed=>1 &>
330   <& /image/print_images.mas , images=>$image_ids , dbh=>$dbh &>
332 </&>
335 <&| /page/info_section.mas, title=>"Literature annotation ($pub_count)" , subtitle=>$new_pub_link, id=>"publications" , collapsible=>1, collapsed=>1 &>
337 % my $pub_count = 0;
338 % foreach my $full_accession ( keys %$pubs  ) {
339 % my $pub = CXGN::Chado::Publication->new($dbh, $pubs->{$full_accession}->pub_id );
340 % my ($pub_db_name, $accession) = split ':' , $full_accession;
341 <& /chado/publication.mas, pub=>$pub, count=>$pub_count++, db=>$pub_db_name, accession=>$accession &>
342   <br >
343 % }
345 </&>
347 <&| /page/info_section.mas,
348   id   => 'stock_ontology',
349   title=>"Ontology annotation (" . $stockref->{ontology_count} . ")",
350   collapsible=>1,
351   collapsed=>1,
352   subtitle=>$ontology_subtitle &>
353   <& /ontology/associate_ontology.mas,
354   trait_db_name => $trait_ontology_db_name,
355   object_id     => $stock_id ,
356   object_name   => "stock",
357   cvterm_add_uri=> $cvterm_add_uri,
358   ontology_url  => "/stock/$stock_id/ontologies/",
359   reference_uri => "/stock/$stock_id/references/",
360   evidence_with_uri => "/stock/$stock_id/evidences/",
361   show_form     => $is_owner  &>
362 </&>
364 <&| /page/info_section.mas, title=>"Phenotype data " ,  subtitle=>$p_download_link ,  collapsible => 1, collapsed => 1 &>
365 % foreach my $project (keys %$direct_phenotypes) {
366 %   my $rs = $direct_phenotypes->{$project} ;
368 <&| /page/info_section.mas,
369     id       => "stock_phenotype",
370     title    =>"Experiment: $project",
371     subtitle => $add_phenotype_link,
372     is_subsection => 1,
373     collapsible => 1
375     <& /stock/add_phenotype.mas,
376       stock_id => $stock_id ,
377       trait_ontology_db_name => $trait_ontology_db_name,
378       project=>$project
379     &>
380   <& /phenotypes/phenotype_data.mas ,
381       phenotypes=> $rs
382     &>
383   </&>
384 % }
386 % foreach my $key (keys %$members_phenotypes) {
387 % my $m_rs = $members_phenotypes->{$key};
388 <&| /page/info_section.mas,
389      title         => "Member phenotypes",
390      subtitle      => $key,
391      is_subsection => 1,
392      collapsible   => 1,
393  &>
394     <& /phenotypes/phenotype_data.mas,
395          phenotypes => $m_rs,
396          object_id  => $stock_id,
397          has_qtl    => $has_qtl_data,
398      &>
399   </&>
400 % }
401 </&>
403 <div id="stock_trials_info_popup">
404   <table id="stock_trials_info_table" >
405     <thead>
406     <tr><th>Trait</th><th>Average</th><th>Std dev</th></tr>
407     </thead>
408   </table>
409 </div>
411 <link rel="stylesheet" type="text/css" href="/documents/inc/datatables/jquery.dataTables.css">
414 <&| /page/info_section.mas, title => "Trials" &>
416   <& /stock/trials.mas, stock_id => $stock_id &>
418 </&>
420 <&| /page/info_section.mas, title => "Traits assayed" &>
422   <& /stock/traits.mas, stock_id => $stock_id &>
424 </&>
426 %#<&| /page/info_section.mas, title => "Phenotypic data" &>
427   
428 %#  <& /stock/phenotypes.mas, stock_id => $stock_id &>
430 %#</&>
432 <&| /page/info_section.mas, title=>"Genotype data ", subtitle=> $g_download_link, collapsible => 1 , collapsed => 1 &>
433 % print $map_html;
434 % foreach my $project (keys %$direct_genotypes) {
435 %  my $genotypes = $direct_genotypes->{$project} ;
436 <&| /page/info_section.mas, title=>"Experiment: $project", is_subsection => 1, collapsible => 1 &>
437 % foreach my $genotype (@$genotypes) {
438 %  print $genotype->description . "\n";
439 % }       
440   </&>
441 % }
442 </&>
445 <&| /page/info_section.mas, title=>"Accession JBrowse", collapsible => 1 , collapsed => 0 &>
446 <p id="jbrowse_check">[loading...]</p>
447 </&>
450 <& /page/comments.mas, object_type=>'stock', object_id=>$stock_id, referer=>$this_page &>
453 <script>
454   jQuery(document).ready(function() { 
455     stock_detail_page_init_dialogs();
456     prepareJbrowse();
458     jQuery('#remove_parent_link').click( function() { 
459       jQuery('#remove_parent_dialog').dialog("open");
460       get_remove_parents_list(<% $stock_id %>);
461     });
463     function prepareJbrowse () { //ajax function to test for existence of given jbrowse trial url
464     jQuery.ajax({
465     type: 'GET',
466     url: "<% $test_url %>",
467     statusCode: {
468         200: function () {  // if page is found, create and display link
469                 jQuery('#jbrowse_check').replaceWith('<a id="jbrowse_link" href="<% $jbrowse_url %>">View vcf tracks for <% $uniquename %> in JBrowse</a>');
470         },
471         404: function () { // if page not found, display message that jbrowse instance wasn't found
472                 jQuery('#jbrowse_check').html(" <i>No Jbrowse instance found for this accession</i>.");
473                 }
474         }
475   });
476   }
479 </script>