same brapi germplasm-search for get and post
[sgn.git] / mason / transcript / unigene_build / basic_unigene_build_info.mas
blob05acee4b8f770a09bb025d5b584cda7ce141a6e1
1 <%doc>
3 =head1 NAME 
4  
5  basic_unigene_build_info.mas
6  Mason code to show basic data for  unigene_build web_page.
8 =cut
10 =head1 VERSION 
12 0.1
14 =cut 
16 =head1 SYNOPSIS
18 <& '/transcript/unigene_build/basic_unigene_build_info.mas', schema => $schema, unigene_build => $unigene_build &>
20 where: $bcs, a DBIx::Class::Schema object with the classes of Bio::Chado::Schema
21        $schema, a DBIx::Class::Schema object with the classes of SGN::Schema
22        $unigene_build, an CXGN::Transcript::UnigeneBuild object
23        
24 =cut
26 =head1 DESCRIPTION
28  This mason script coordinate different mason component to create the unigene build page.
30  Its controller is: unigene_build.pl
32 =cut
34 =head 1 AUTHOR
36  Aureliano Bombarely (ab782@cornell.edu)
38 =cut
40 </%doc>
43 <%args>
44 $bcs
45 $schema
46 $unigene_build
47 </%args>
50 <%perl>
52 use strict;
53 use warnings;
55 use CXGN::Transcript::UnigeneBuild;
56 use CXGN::Chado::Dbxref;
57 use CXGN::Page::FormattingHelpers  qw/ info_section_html info_table_html columnar_table_html page_title_html html_break_string /;
59 my $basic_info_content;
60 my $unigene_build_name;
62 ## If there aren't any unigene_build that comes from unigene_build_detail.mas, it will return a error message.
64 if (defined $ARGS{'unigene_build'}->get_unigene_build_id) {
65    
66    ## Get the object
67    my $id =  $unigene_build->get_unigene_build_id();
68   
69    my $build_name = $unigene_build->get_organism_group_name();
70    my $build_nr = $unigene_build->get_build_nr();
71    $unigene_build_name = $build_name." ".$build_nr;
72    my $build_date = $unigene_build->get_build_date();
73    my $status = $unigene_build->get_status();
74    my $status_html;
75    if ($status eq 'C') {
76        $status_html = '<font color="green"><b>CURRENT</b></font>';
77    } elsif ($status eq 'P') {
78        $status_html = '<font color="orange"><i>Previous to current</i></font>';
79    } elsif ($status eq 'D') {
80        $status_html = '<font color="red"><i>Deprecated</i></font>';
81    }
83    my @organism_html_list;
84    my $organism_group_id = $unigene_build->get_organism_group_id();
85    my $group_linkage_rs = $schema->resultset('GroupLinkage')
86                                  ->search({ group_id => $organism_group_id });
87    
88    my @organism_ids = $group_linkage_rs->get_column('member_id')->all();
89    
90    foreach my $organism_id (@organism_ids) {
92        if ($organism_id =~ m/^\d+$/) {
93            my @organism_rows = $bcs->resultset('Organism::Organism')
94                                    ->search({ sgn_organism_id => $organism_id });
96            foreach my $organism_row (@organism_rows) {
98                my $org_id = $organism_row->get_column('organism_id');
99                my $organism_name = $organism_row->get_column('species'); 
100                my $organism_link = '/chado/organism.pl?organism_id='.$organism_id;
101                my $organism_html = "<a href=$organism_link>$organism_name</a>";
102                if (defined $org_id) {
103                    push @organism_html_list, $organism_html;
104                }
105            }
106        }
107    }
108    my $organism_html_list = join('<br>', @organism_html_list);
110    ## Get the number of unigene, contig and singlets using DBIx::Class (this should be replaced by the right object)
112    my $unigene_nr = $schema->resultset('Unigene')
113                            ->search({ unigene_build_id => $id})
114                            ->count();
116    my $contig_nr = $schema->resultset('Unigene')
117                           ->search({ unigene_build_id => $id, nr_members => {'>', 1} })
118                           ->count();
120    my $singlet_nr = $schema->resultset('Unigene')
121                            ->search({ unigene_build_id => $id, nr_members => {'=', 1} })
122                            ->count();
124    my $member_nr = $schema->resultset('Unigene')
125                           ->search({ unigene_build_id => $id }, {join => 'unigene_members'})
126                           ->count();
128    ## Create the HTML table
130    $basic_info_content = <<HTML;
132     <table width="75%">
133            <tr> <td> <b>Unigene Build ID: </b>           </td> <td> $id </td></tr>
134            <tr> <td> <b>Unigene Build Name: </b>         </td> <td> $unigene_build_name </td></tr>
135            <tr> <td> <b>Date: </b>                       </td> <td> $build_date </td></tr>
136            <tr> <td> <b>Status: </b>                     </td> <td> $status_html </td></tr>
137            <tr> <td> <b>Organism: </b>                   </td> <td> $organism_html_list </td></tr>
138            <tr> <td> <b>Number of Unigenes: </b>         </td> <td> $unigene_nr </td></tr>
139            <tr> <td> <b>Number of Contigs: </b>          </td> <td> $contig_nr </td></tr>
140            <tr> <td> <b>Number of Singlets: </b>         </td> <td> $singlet_nr </td></tr>
141            <tr> <td> <b>Members Assembled:</b> </td> <td> $member_nr </td></tr>
142    </table>
143    
144    <br>
146 HTML
149 else {
150    $basic_info_content = "<big>There aren't any unigene build data for the specified parameters.</big>";
151 }   
153 my $basic_info_html;
154 if (defined $unigene_build_name) {
155    $basic_info_html = "<center><big><b>Unigene Build: $unigene_build_name</b></big></center><br>";
157 $basic_info_html .= info_section_html( title => "Unigene Build Basic Information", contents => $basic_info_content );
159 </%perl>
161 <% $basic_info_html %>