Committing Lukas changes before site update
[sgn.git] / mason / stock / index.mas
blob54bdc0ff5dfa3b2ad123826d6ad879eb1d5f60b0
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};
82 my $schema = $stockref->{schema};
83 my $dbh = $stockref->{dbh};
85 my $stockprop_cv = $schema->resultset("Cv::Cv")->search( {
86  'me.name' => 'stock_property'} );
89 my ($type_name, $uniquename);
90 my $type = $stock_row ? $stock_row->type : undef;
91 $type_name  = $type->name() if $type;
92 $uniquename = $stock->get_uniquename if $type;
93 #################
94 my $is_owner = $stockref->{is_owner};
96 my $this_page = "/stock/$stock_id/view";
98 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>|;
99 my $image_ids =  $stockref->{image_ids} || [] ;
100 my $stockprops = $stockref->{props};
102 my $metadata = ['variety', 'donor', 'donor institute', 'country', 'state' , 'adaptation' , 'notes'];
104 #my $pedigree= ['pedigree', 'male parent', 'female parent'];
105 # get pedigree of stock
106 #my $stock_pedigree = $stockref->{stock_pedigree};
107 #my $stock_descendants = $stockref->{stock_descendants};
110 my $experiment = ['year', 'location', 'replicate']; # these values should be in nd_experimentprop ?
112 my $resources = [ 'synonym', 'solcap number'];
114 my $allele_div = "stock_alleles";
115 my $new_locus_link = !$person_id ? qq|<a href="/solpeople/login.pl">[log-in to associate new locus]</a> | : '' ;
117 #owner
118 my $owners = $stockref->{owners};
119 my $editor_link;
120 foreach my $o_id (@$owners) {
121   my $person = CXGN::People::Person->new($dbh, $o_id);
122   my $first_name = $person->get_first_name;
123   my $last_name = $person->get_last_name;
124   $editor_link .= qq|<a href="/solpeople/personal-info.pl?sp_person_id=$o_id">$first_name $last_name</a> |;
127 #phenotypes measured directly on this stock
128 my $direct_phenotypes = $stockref->{direct_phenotypes} || undef;
130 # get all phenotypes of subjects
131 my $members_phenotypes = $stockref->{members_phenotypes};
132 my $p_download_link = qq|<a href = "/stock/$stock_id/phenotypes">[Download phenotypes]</a>| if ( (keys %$direct_phenotypes) || ( keys %$members_phenotypes) );
133 my $direct_genotypes = $stockref->{direct_genotypes};
134 my $g_download_link = qq|<a href =  "/stock/$stock_id/genotypes">Download genotypes</a>| if (keys %$direct_genotypes) ;
135 ############################
136 my $map_html = $stockref->{map_html};
137 my $map;
138 if ($stock_id) {
139   $map = CXGN::Cview::Map::SGN::Genotype->new($dbh, $stock_id);
140   if ($map->get_chromosome_count > 1 ) {
141     my $overview = CXGN::Cview::MapOverviews::Generic->new($map,
142                                                            {
143                                                             dbh=> $dbh,
144                                                             basepath => $stockref->{cview_basepath},
145                                                             tempfiles_subdir => $stockref->{cview_tmp_dir } });
146     if ($overview) {
147       $overview->render_map();
148       $map_html .= $overview->get_image_html();
149     }
150   }
152 #########################################
153 my $has_qtl_data = $stockref->{has_qtl_data};
156 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>| ;
158 my $pub_count = scalar( keys %$pubs );
160 ## EUSOL, tgrc (stock_dbxref)
161 my $dbxrefs = $stockref->{dbxrefs};
162 my %source_dbs;
163 foreach my $db_name ( keys %$dbxrefs ) {
164   foreach my $dbxref ( @{ $dbxrefs->{$db_name} } ) {
165     my $url = $dbxref->db->urlprefix . $dbxref->db->url;
166     $url .= $dbxref->accession if $url =~ m/\?$|\=$/ ;
167     $source_dbs{$url} = $db_name . ": " . $dbxref->accession if $url;
168   }
171 my $ontology_subtitle = $curator || $submitter || $sequencer  ?
172   qq|<a href="javascript:Tools.toggleContent('associate_cvterm_form', 'stock_ontology')">[Add ontology annotations]</a> | :
173   qq |<span class = "ghosted"> [Add ontology annotations]</span> |;
175 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> |;
177 my $edit_privs = $curator || $submitter || $sequencer;
178 </%perl>
179 <& /util/import_javascript.mas, classes => ["jquery", "jqueryui", "thickbox", "CXGN.Phenome.Tools", "CXGN.Page.FormattingHelpers", "jquery.cookie"] &>
182 <script language="javascript">
183 function jqueryStuff() { 
184    jQuery(function() {
185      jQuery("#species_name").autocomplete({
186         source: '/organism/autocomplete'
187      });
188   });
190 </script>
191 <& /page/page_title.mas, title=> join( ': ', grep $_, ucfirst($type_name), $uniquename ) || 'Create a new stock' &>
194 <&| /page/info_section.mas, title=>"Stock details" , subtitle => "<a href=/phenome/qtl_form.pl>New QTL population</a> | <a href=/stock/search/>Back to stock search</a>"  &>
196 <table><tr><td width="400">
197   <& /page/form.mas,
198   object_type=>'stock',
199   object_id=>"$stock_id",
200   form_name=> 'stock_form',
201   server_side_script => '/phenome/stock/stock_ajax_form.pl',
202   form_div_name=>'stock_details',
203   js_object_name=> 'stockForm',
204   page_url => "/stock/$stock_id/view/" ,
205   alternate_new_button => '<a href ="/stock/0/new">[New]</a>'
206   &>
207 </td><td>
209 <& /util/barcode.mas, identifier => "$identifier_prefix"."$stock_id", text=> "$identifier_prefix stock $stock_id ($uniquename)", format=>"code128"  &><br /><br />
210 % #<& /util/barcode.mas, identifier => "http://solgenomics.net/stock/$stock_id/view", text=>"SGN stock $stock_id ($uniquename)", format=>"qrcode" &>
213 </td></tr></table>
215 <div><b>Stock editors: </b> <% $editor_link %></div>
216 <br />
217 % foreach my $db_url (keys %source_dbs) {
218 <div><a href=<% $db_url %>><% $source_dbs{$db_url} %></a> </div>
220 <br />
221 % my $div_name = join("_", @$resources);
222 % my $subtitle = $edit_privs ? "[<a href=\"javascript:synonyms_addPropDialog()\">Add...</a>]" : "[Add]";
223    <&| /page/info_section.mas, title => "Synonyms" , is_subsection => 1 , subtitle=>$subtitle &>
224       <& /stock/stockprops.mas, stock_id=> $stock_id, props=> $stockprops , div_name=>'synonyms', subset=>$resources, editable=> [ 'synonym' ], edit_privs => $edit_privs   &>
225 </&>
226 %  $div_name = join("_", @$metadata);
227     <&| /page/info_section.mas, title => "Additional information" , collapsible=> 1, is_subsection => 1 &>
228       <& /stock/stockprops.mas, stock_id=>$stock_id, props=> $stockprops, subset=> $metadata  &>
229 </&>
232 </&>
235 <&| /page/info_section.mas, title => "Associated loci (" . $stockref->{allele_count} . ")" , subtitle => $new_locus_link, collapsible=> 1 , collapsed => 1 &>
237 <& /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 &>
239 </&>
242 <&| /page/info_section.mas, title => "Experimental data" , collapsible=> 1, is_subsection => 0 &>
243       <& /stock/stockprops.mas, stock_id=>$stock_id, props=> $stockprops, subset=> $experiment  &>
244 </&>
246 % if($is_owner) {
247 <&| /page/info_section.mas, title=>"Stock history", collapsible=>1, collapsed=>1 &>
249 </&>
252 % }
254 % my $collapsible = 0; 
255 % if ($has_pedigree==1) {
256 %  $collapsible = 1;
257 % }
258 % my $add_parent_link = "Add parent";
259 % if ($person_id && $submitter) { $add_parent_link = qq | <a id="add_parent_link" >Add parent</a> |; }
261 <&| /page/info_section.mas, title=>"Pedigree" , collapsible=> $collapsible, collapsed=>0, subtitle=>"[$add_parent_link]" &>
262   <& /pedigree/stock_pedigree.mas, stock_id => $stock_id, has_pedigree => $has_pedigree &>
263 </&>
269 % if ($has_descendants==1) {
271 <&| /page/info_section.mas, title=>"Descendants" , collapsible=>1, collapsed=>0 &>
272   <& /pedigree/stock_descendants.mas, stock_id => $stock_id &>
273 </&>
275 % } else {
277 <&| /page/info_section.mas, title=>"Descendants" , collapsible=>1, collapsed=>1 &>
278 </&>
280 % }
283 % if ($type) {
284 <&| /page/info_section.mas, title=>"Related stocks" , collapsible=>1, collapsed=>0 &>
285   <& /stock/related_stocks.mas, stock => $stock_row &>
287 </&>
289 % }
292 <&| /page/info_section.mas, title=>"Images (" .  scalar(@$image_ids)  . ")", subtitle => "$add_image_link", collapsible=>1, collapsed=>1 &>
293   <& /image/print_images.mas , images=>$image_ids , dbh=>$dbh &>
295 </&>
298 <&| /page/info_section.mas, title=>"Literature annotation ($pub_count)" , subtitle=>$new_pub_link, id=>"publications" , collapsible=>1, collapsed=>1 &>
300 % my $pub_count = 0;
301 % foreach my $full_accession ( keys %$pubs  ) {
302 % my $pub = CXGN::Chado::Publication->new($dbh, $pubs->{$full_accession}->pub_id );
303 % my ($pub_db_name, $accession) = split ':' , $full_accession;
304 <& /chado/publication.mas, pub=>$pub, count=>$pub_count++, db=>$pub_db_name, accession=>$accession &>
305   <br >
306 % }
308 </&>
310 <&| /page/info_section.mas,
311   id   => 'stock_ontology',
312   title=>"Ontology annotation (" . $stockref->{ontology_count} . ")",
313   collapsible=>1,
314   collapsed=>1,
315   subtitle=>$ontology_subtitle &>
316   <& /ontology/associate_ontology.mas,
317   trait_db_name => $trait_ontology_db_name,
318   object_id     => $stock_id ,
319   object_name   => "stock",
320   cvterm_add_uri=> $cvterm_add_uri,
321   ontology_url  => "/stock/$stock_id/ontologies/",
322   reference_uri => "/stock/$stock_id/references/",
323   evidence_with_uri => "/stock/$stock_id/evidences/",
324   show_form     => $is_owner  &>
325 </&>
327 <&| /page/info_section.mas, title=>"Phenotype data " ,  subtitle=>$p_download_link ,  collapsible => 1, collapsed => 1 &>
328 % foreach my $project (keys %$direct_phenotypes) {
329 %   my $rs = $direct_phenotypes->{$project} ;
331 <&| /page/info_section.mas,
332     id       => "stock_phenotype",
333     title    =>"Experiment: $project",
334     subtitle => $add_phenotype_link,
335     is_subsection => 1,
336     collapsible => 1
338     <& /stock/add_phenotype.mas,
339       stock_id => $stock_id ,
340       trait_ontology_db_name => $trait_ontology_db_name,
341       project=>$project
342     &>
343   <& /phenotypes/phenotype_data.mas ,
344       phenotypes=> $rs
345     &>
346   </&>
347 % }
349 % foreach my $key (keys %$members_phenotypes) {
350 % my $m_rs = $members_phenotypes->{$key};
351 <&| /page/info_section.mas,
352      title         => "Member phenotypes",
353      subtitle      => $key,
354      is_subsection => 1,
355      collapsible   => 1,
356  &>
357     <& /phenotypes/phenotype_data.mas,
358          phenotypes => $m_rs,
359          object_id  => $stock_id,
360          has_qtl    => $has_qtl_data,
361      &>
362   </&>
363 % }
364 </&>
366 <&| /page/info_section.mas, title=>"Genotype data ", subtitle=> $g_download_link, collapsible => 1 , collapsed => 1 &>
367 % print $map_html;
368 % foreach my $project (keys %$direct_genotypes) {
369 %  my $genotypes = $direct_genotypes->{$project} ;
370 <&| /page/info_section.mas, title=>"Experiment: $project", is_subsection => 1, collapsible => 1 &>
371 % foreach my $genotype (@$genotypes) {
372 %  print $genotype->description . "\n";
373 % }       
374   </&>
375 % }
377 </&>
379 <& /page/comments.mas, object_type=>'stock', object_id=>$stock_id, referer=>$this_page &>