[Bio] / FigWebServices / SimBlockDisplay.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/SimBlockDisplay.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Wed May 4 03:17:43 2005 UTC revision 1.4, Wed Jan 11 19:37:28 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    #
3    # Copyright (c) 2003-2006 University of Chicago and Fellowship
4    # for Interpretations of Genomes. All Rights Reserved.
5    #
6    # This file is part of the SEED Toolkit.
7    #
8    # The SEED Toolkit is free software. You can redistribute
9    # it and/or modify it under the terms of the SEED Toolkit
10    # Public License.
11    #
12    # You should have received a copy of the SEED Toolkit Public License
13    # along with this program; if not write to the University of Chicago
14    # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15    # Genomes at veronika@thefig.info or download a copy from
16    # http://www.theseed.org/LICENSE.TXT.
17    #
18    
19    
20  BEGIN {  BEGIN {
21      # Print the HTML header.      # Print the HTML header.
# Line 13  Line 30 
30  one of the columns and click the appropriate button to generate an alignment  one of the columns and click the appropriate button to generate an alignment
31  display in the embedded frame below the block lists.  display in the embedded frame below the block lists.
32    
33  For debugging purposes, you can specify the B<Trace> parameter to  Common blocks will be displayed in red if they have snip differences. A I<snip
34  set the tracing level. You can also set the B<ShowMode> parameter to  difference> is a column in which the contents for set 0 are different from the
35  C<1> to display a table of the parameters passed by the form. So,  contents for set 1. So, for example, if column 6 is always A or G for set 0 and
36  for example,  always T for set 1, there is a snip difference. The snip difference is therefore
37    a much stronger condition than merely having different values in a column. If
38  C<< http://myseedurl/CGI/SimBlockDisplay.cgi?ShowMode=1 >>  column 6 contained A and G in set 0 and only A in set 1, it would not be a snip
39    difference, because A occurs in both sets.
40    
41    When a block is selected for display in the lower part of the form, the snip
42    differences are shown in a table. Therefore, that table will be empty unless
43    the block name is displayed in red.
44    
45    At the bottom of the page, an alignment of the snips in the common blocks
46    is displayed. If this alignment is sufficiently large, it will not show up
47    properly in Firefox.
48    
49  will set the form action to display the form contents without processing  For debugging purposes, you can specify the B<Trace> parameter to
50  them, while  set the tracing level. So, for example,
51    
52  C<< http://myseedurl/CGI/SimBlockDisplay.cgi?Trace=3 >>  C<< http://myseedurl/CGI/SimBlockDisplay.cgi?Trace=3 >>
53    
# Line 43  Line 69 
69  use SimBlocks;  use SimBlocks;
70    
71  # Get the CGI parameters.  # Get the CGI parameters.
72  my $query = new CGI;  my ($query, $varHash) = ScriptSetup();
73  my $traceLevel = $query->param("Trace");  # Do this next part safely.
74  if (!defined $traceLevel || length $traceLevel == 0) {  eval {
     $traceLevel = 0;  
 }  
 TSetup("$traceLevel Tracer", "QUEUE");  
 # Choose the output script based on the ShowMode parameter.  
 my $script = ($query->param('ShowMode') ? 'FormDisplay' : 'SimBlockPattern');  
 # Decide whether or not we need debugging fields.  
 my $traceFields = (Tracer::DebugMode() ? Tracer::GetFile("Html/DebugFragment.html") : "");  
 # Create the variable hash used to generate the web page. We start with the debug-related  
 # fields we've already computed.  
 my %varHash = ( script => $script, DebugData => $traceFields );  
75  # Next we get the list of genomes in each set. These come from the radio  # Next we get the list of genomes in each set. These come from the radio
76  # buttons on the incoming form. Basically, we look for any option whose value  # buttons on the incoming form. Basically, we look for any option whose value
77  # is "set1" or "set2", and put it in the appropriate list. To make this process      # is "set0" or "set1", and put it in the appropriate list. To make this process
78  # simpler, we set up a hash to contain the results.  # simpler, we set up a hash to contain the results.
79  my %sets = ( set1 => [], set2 => [] );      my %sets = ( set0 => [], set1 => [] );
80  my @params = $query->param;  my @params = $query->param;
81  for my $param (@params) {  for my $param (@params) {
82      my $parmValue = $query->param($param);      my $parmValue = $query->param($param);
# Line 68  Line 84 
84          push @{$sets{$parmValue}}, "$param";          push @{$sets{$parmValue}}, "$param";
85      }      }
86  }  }
87        # Set up the attribute for the blocks with snip differences.
88        my $snipAttribute = { class => 'snippy' };
89  # The genome IDs are converted to list options in the upper list boxes.  # The genome IDs are converted to list options in the upper list boxes.
90  for my $setID (keys %sets) {  for my $setID (keys %sets) {
91      # Get the list of values for this set.      # Get the list of values for this set.
# Line 79  Line 97 
97      if ($valueCount < 2) {      if ($valueCount < 2) {
98          $valueCount = 2;          $valueCount = 2;
99      }      }
100      # Build a multi-selection scrolling list big enough to show all the genome IDs.          # Build a multi-selection scrolling list big enough to show all the genome IDs. Note
101      $varHash{"${setID}GenomeIDs"} = $query->scrolling_list("${setID}Genomes", $valueList,          # that we pre-select every element.
102                                                             undef, $valueCount, 1);          $varHash->{"${setID}GenomeIDs"} = $query->scrolling_list("${setID}Genomes", $valueList,
103                                                                   $valueList, $valueCount, 1);
104  }  }
105  # Now we create the similarity block object.  # Now we create the similarity block object.
106  my $simBlocks = SimBlocks->new();  my $simBlocks = SimBlocks->new();
107        Trace("Comparing genome sets.") if T(1);
108  # Get a comparison of the genome sets.  # Get a comparison of the genome sets.
109  my %blocks;  my %blocks;
110  ($blocks{set1}, $blocks{set2}, $blocks{both}) = $simBlocks->CompareGenomes($sets{set1},      ($blocks{set0}, $blocks{set1}, $blocks{both}) = $simBlocks->CompareGenomes($sets{set0},
111                                                                             $sets{set2});                                                                                 $sets{set1});
112        Trace("Formatting lists.") if T(1);
113  # Use the results to generate the scrolling lists for the similarity blocks. Our approach  # Use the results to generate the scrolling lists for the similarity blocks. Our approach
114  # here is very much like what we did earlier for the genome IDs, but we put a maximum of  # here is very much like what we did earlier for the genome IDs, but we put a maximum of
115  # 50 on the display size of each list.  # 50 on the display size of each list.
# Line 96  Line 117 
117      # Get the list of blocks for this set.      # Get the list of blocks for this set.
118      my $valueHash = $blocks{$setID};      my $valueHash = $blocks{$setID};
119      my @valueList = sort keys %{$valueHash};      my @valueList = sort keys %{$valueHash};
120      # Compute the desired list height.          # Compute the number of blocks.
121      my $valueCount = @valueList;      my $valueCount = @valueList;
122            $varHash->{"${setID}Count"} = $valueCount;
123            # Constrain it to compute the list height.
124      if ($valueCount > 50) {      if ($valueCount > 50) {
125          $valueCount = 50;          $valueCount = 50;
126      } elsif ($valueCount < 2) {      } elsif ($valueCount < 2) {
127          $valueCount = 2;          $valueCount = 2;
128      }      }
129            # Create a hash to map block IDs to their descriptive names.
130            my %labelMap = ();
131            # Create a hash for the list box attributes. This hash will be empty for
132            # everything but the both-list.
133            my %attributes = ();
134            # Loop through the blocks, counting snip differences and associating labels.
135            my $snipCount = 0;
136            for my $blockID (@valueList) {
137                # If this is the both-list, we need to count the snip differences.
138                if ($setID eq "both") {
139                    # Get the snip differences.
140                    my %snipHash = $simBlocks->SnipScan($blockID, $sets{set0}, $sets{set1});
141                    my $snipDelta = (keys %snipHash);
142                    # If snip differences were found, we need to record the fact.
143                    if ($snipDelta > 0) {
144                        # Count the new snips.
145                        $snipCount += $snipDelta;
146                        # Highlight the block.
147                        $attributes{$blockID} = $snipAttribute;
148                    }
149                }
150                # Regardless of which list it is, we need to store the label.
151                ($labelMap{$blockID}) = $valueHash->{$blockID}->Value('GroupBlock(description)');
152            }
153            # If this is the both-list, save the snip count.
154            if ($setID eq "both") {
155                $varHash->{snipCount} = $snipCount;
156            }
157      # Build a single-selection scrolling list for this set of blocks.      # Build a single-selection scrolling list for this set of blocks.
158      $varHash{"${setID}BlockIDs"} = $query->scrolling_list("${setID}Blocks",          $varHash->{"${setID}BlockIDs"} =
159                                                            \@valueList, undef,              $query->scrolling_list(-name => "${setID}Blocks",
160                                                            $valueCount);                                     -values => \@valueList,
161  }                                     -size => $valueCount,
162  # Flush the trace messages.                                     -labels => \%labelMap,
163  $varHash{TraceMessages} = QTrace('html');                                     -attributes => \%attributes);
164  # Generate the web page.      }
165  my $page = PageBuilder::Build("<Html/SimBlockDisplay.html", \%varHash, "Html");      # Now we need to build the alignment. First, we read the alignment table row fragment.
166  print $page;      Trace("Building alignment.") if T(1);
167        my $alignmentRow = Tracer::GetFile("Html/AlignmentRow.html");
168        # Next, we need to create an alignment hash from the similarities.
169        my @genomes = sort @{$sets{set1}}, @{$sets{set0}};
170        my @blocks = (keys %{$blocks{both}});
171        my %alignment = $simBlocks->GetAlignment(\@blocks, \@genomes);
172        # Loop through the alignment, building the rows.
173        my $alignmentHTML = "";
174        for my $genome (@genomes) {
175            # Get this genome's set number.
176            my $setNumber = SimBlocks::SetNumber($genome, $sets{set0}, $sets{set1});
177            # Produce the alignment row.
178            $alignmentHTML .= PageBuilder::Build($alignmentRow, { genomeID => $genome,
179                                                                  setNumber => $setNumber,
180                                                                  dna => $alignment{$genome} },
181                                                 "Html");
182        }
183        # Put the alignment in the variable hash.
184        $varHash->{alignment} = $alignmentHTML;
185        # Now we need to create the distance matrix.
186        Trace("Computing distances.") if T(1);
187        my %distanceMatrix = SimBlocks::DistanceMatrix(\%alignment);
188        # Get the maximum distance.
189        my $max = 0;
190        for my $dist (values %distanceMatrix) {
191            if ($dist > $max) {
192                $max = $dist;
193            }
194        }
195        # Clean up the formatting of the distances.
196        for my $distanceKey (keys %distanceMatrix) {
197            my $distance = $distanceMatrix{$distanceKey};
198            # Compute the color of the distance.
199            my $intensity = int(($max - $distance) * 200 / $max) + 55;
200            my $color = sprintf("%02X", $intensity);
201            $color = "#$color$color" . "FF";
202            my $distanceString;
203            if ($distance == 0) {
204                $distanceString = "0.00000";
205            } elsif ($distance == 1) {
206                $distanceString = "1.00000";
207            } elsif ($distance >= 0.00001) {
208                $distanceString = sprintf("%.5f", $distance);
209                $distanceString .= "0" x (7 - length $distanceString);
210            } else {
211                $distanceString = sprintf("%E", $distance);
212            }
213            $distanceMatrix{$distanceKey} =
214                "<td align=\"right\" bgcolor=\"$color\">$distanceString</td>";;
215        }
216        # Format it into a table.
217        my $thString = "<th align=\"center\" scope=\"col\">";
218        my $tdString = "<td align=\"right\">";
219        my $distanceHTML = "<tr><td>&nbsp;</td>$thString" .
220            join("</th><th align=\"center\">", @genomes) . "</th></tr>\n";
221        for my $genome1 (@genomes) {
222            my $row = "<tr><th scope=\"row\">$genome1</th>";
223            $row .= join("", map { $distanceMatrix{"$genome1/$_"} } @genomes);
224            $row .= "</tr>\n";
225            $distanceHTML .= $row;
226        }
227        # Add it to the variable hash.
228        $varHash->{distanceMatrix} = $distanceHTML;
229    };
230    # Check for an error from the EVAL.
231    if ($@) {
232        Trace("Script error: $@") if T(0);
233    }
234    # Display the web page.
235    ScriptFinish("Html/SimBlockDisplay.html", $varHash);
236    
237  1;  1;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3