Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / mason / tools / bulk / display / browse_html.mas
blob0017f6961800531dcfb62201a64f3198678798ee
2 <%args>
3 $data
4 </%args>
6 <& /tools/bulk/display/buttons.mas, 
7    page_size=>$data->{page_size} || 50, 
8    page_number => $data->{page_number},
9    idType => $data->{idType},
10    dumpfile => $data->{dumpfile} &>
12 <%perl>
13 use Data::Dumper;
14 use File::Slurp qw | read_file |;
15 use CXGN::Page::FormattingHelpers qw | html_break_string |;
16 print STDERR "DATA:".Data::Dumper::Dumper($data);
18 $data->{page_size} || ($data->{page_size} = 50);
20 if ( !( exists($data->{page_number}) ||  $data->{page_number} ) ) {
21 $data->{page_number} = 1;
23 if ( !( exists($data->{page_size}) || $data->{page_size} )) { $data->{page_size} = 50; }
24 my $file = $data->{tempdir} . "/" . $data->{dumpfile};
27 my $content = "";
28 my @file_lines = read_file($file);
30 print STDERR "Line Count in the file: ".scalar(@file_lines)."\n";
32 if ( @file_lines < 2 ) {
33               $content .=
34               "No data was retrieved. Please verify your input parameters. Thanks.<br /><br />\n";
35               }
36               else {
37               
38               # read the column definitions
39               #
40               my @output_fields;
41               my $defs = shift @file_lines;
42               if ($defs) { chomp($defs); @output_fields = split /\t/, $defs; }
43               print STDERR  "column definitions: " . ( join " ", @output_fields )."\n";
44               
45               # define the links
46         my %links = (
47             clone_name =>
48 "/search/est.pl?request_type=10&amp;search=Search&amp;request_id=",
49             SGN_U        => "/search/unigene.pl?unigene_id=",
50             converted_id => "/search/unigene.pl?unigene_id=",
51         );
52         $data->{links} = \%links;
54         #
55         # read in the required page
56         #
57         my $line_count = 0;
58         my @data = ();
60         $content .= "<table summary=\"\" border=\"1\">\n";
62         # print table header
63         $content .=
64             "<tr><td>line</td><td>"
65           . ( join "</td><td>", @output_fields )
66           . "</td></tr>";
68         foreach my $fl (@file_lines) {
69             print STDERR "Processing line $fl...\n";
70             chomp($fl);
71             $line_count++;
73             my $show_line = ( $line_count >= ($data->{page_number} - 1 ) * $data->{page_size} + 1 )
74                 && ($line_count <=  ( $data->{page_number} ) * $data->{page_size} );
76             if ($show_line) { 
77                 my @fields = split /\t/, $fl;
78                 my %row;
79                 for ( my $i = 0 ; $i < @fields ; $i++ ) {
80                     $row{ $output_fields[$i] } = $fields[$i];
81                 }
83                 # format the sequence data for output to browser.
84                 # number of letters in sequence or qual to wrap on
85                 my $breakspace_num = 60;
86                 
87                 $row{est_seq} =
88                   html_break_string( $row{est_seq}, $breakspace_num );
90                 $row{est_seq} =
91 "<span class=\"sequence\" style=\"font-size: smaller;\"> $row{est_seq}</span>";
93                 $row{unigene_seq} =
94                   html_break_string( $row{unigene_seq}, $breakspace_num );
95                 $row{unigene_seq} =
96 "<span class=\"sequence\" style=\"font-size: smaller;\"> $row{unigene_seq}</span>";
98                 $row{protein_seq} =
99                   html_break_string( $row{protein_seq}, $breakspace_num );
100                 $row{protein_seq} =
101 "<span class=\"sequence\" style=\"font-size: smaller;\"> $row{protein_seq}</span>";
102                 $row{estscan_seq} =
103                   html_break_string( $row{estscan_seq}, $breakspace_num );
104                 $row{estscan_seq} =
105 "<span class=\"sequence\" style=\"font-size: smaller;\"> $row{estscan_seq}</span>";
106                 $row{longest6frame_seq} =
107                   html_break_string( $row{longest6frame_seq}, $breakspace_num );
108                 $row{longest6frame_seq} =
109 "<span class=\"sequence\" style=\"font-size: smaller;\"> $row{longest6frame_seq}</span>";
110                 $row{preferred_protein_seq} =
111                   html_break_string( $row{preferred_protein_seq},
112                     $breakspace_num );
113                 $row{preferred_protein_seq} =
114 "<span class=\"sequence\" style=\"font-size: smaller;\"> $row{preferred_protein_seq}</span>";
116                 $row{bac_end_sequence} =
117                   html_break_string( $row{bac_end_sequence}, $breakspace_num );
118                 $row{bac_end_sequence} =
119 "<span class=\"sequence\" style=\"font-size: smaller;\"> $row{bac_end_sequence}</span>";
121                 my $qual = $row{qual_value_seq};
122                 my @qual = split /\s+/, $qual;
123                 $row{qual_value_seq} = "";
124                 s/^(\d)$/&nbsp;$1/ foreach (@qual);
125                 while ( my @a = splice( @qual, 0, $breakspace_num ) ) {
126                     $row{qual_value_seq} .= join( "&nbsp;", @a ) . "<br />";
127                 }
128                 $row{qual_value_seq} =
129 "<span class=\"sequence\" style=\"font-size: smaller;\"> $row{qual_value_seq}</span>";
131                 my @output;
133          #
134          # cycle through @output_fields and find the corresponding hash elements
135          #
136                 $content .= "<tr><td>$line_count</td>\n";
137                 foreach my $f (@output_fields) {
139                     #$data-> debug("outputting $row{$f}...");
140                     if ( !exists( $row{$f} ) || $row{$f} eq undef ) {
141                         $row{$f} = "N.A.";
142                     }
145 # add links as required. Links for each output field are stored in the %links hash.
147                     if ( exists( $links{$f} ) && $row{$f} ne "N.A." ) {
148                         $row{$f} =
149                           "<a href=\"$links{$f}$row{$f}\">$row{$f}</a>";
150                     }
151                     if ( $f eq "clone_id" ) {
152                         $content .= "<td>$row{$f}</td>";
153                     }
154                     else {
155                         $content .= "<td>$row{$f}</td>";
156                     }
158                     #push @output, $row{$f};
159                 }
160                 $content .= "</tr>\n";
162      #$content .= "<tr><td>".(join "</td><td>", @output) . "</td></tr>";
163             }
164         }
165         $content .= "</table><!-- dump info -->\n";
166 #$data->buttons();
170 # output to browser
172 print $content;
174 close(F);
177 </%perl>
179 <& /tools/bulk/display/buttons.mas, 
180   line_count => $data->{line_count}, 
181   page_size=>$data->{page_size}, 
182   page_number => $data->{page_number},
183   dumpfile => $data->{dumpfile},
184   idType => $data->{idType}