[Bio] / Sprout / GenomeStats.pl Repository:
ViewVC logotype

Diff of /Sprout/GenomeStats.pl

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

revision 1.19, Thu Aug 24 17:29:45 2006 UTC revision 1.23, Wed Sep 13 04:26:44 2006 UTC
# Line 102  Line 102 
102                                              counterStyle => ['countercell', 'style for cells with counter values'],                                              counterStyle => ['countercell', 'style for cells with counter values'],
103                                              linkCGI => ['../FIG/genome_statistics.cgi',                                              linkCGI => ['../FIG/genome_statistics.cgi',
104                                                          'path to CGI script for detailed statistics'],                                                          'path to CGI script for detailed statistics'],
105                                                groupFile => ["$FIG_Config::sproutData/groups.tbl",
106                                                              "location of the NMPDR group description file"],
107                                             },                                             },
108                                             "<targetDir>",                                             "<targetDir>",
109                                             @ARGV);                                             @ARGV);
# Line 117  Line 119 
119      # Extract the genome group data from the old Sprout.      # Extract the genome group data from the old Sprout.
120      my %oldGroupHash = $oldSprout->GetGroups();      my %oldGroupHash = $oldSprout->GetGroups();
121      if (! $options->{strict}) {      if (! $options->{strict}) {
122          %oldGroupHash = Fix(%oldGroupHash);          %oldGroupHash = Sprout::Fix(%oldGroupHash);
123      }      }
124      # Get the new Sprout.      # Get the new Sprout.
125      my $sprout = SFXlate->new_sprout_only();      my $sprout = SFXlate->new_sprout_only();
126      my %newGroupHash = $sprout->GetGroups();      my %newGroupHash = $sprout->GetGroups();
127      if (! $options->{strict}) {      if (! $options->{strict}) {
128          %newGroupHash = Fix(%newGroupHash);          %newGroupHash = Sprout::Fix(%newGroupHash);
129      }      }
130        # Read the group file.
131        my %groupData = Sprout::ReadGroupFile($options->{groupFile});
132        # Set up some useful stuff for the four count columns.
133        my %linkParms = ( s0 => "nothypo_sub", n0 => "nothypo_nosub",
134                          s1 => "hypo_sub", n1 => "hypo_nosub" );
135        my @columnTypes = ('s0', 'n0', 's1', 'n1');
136        # Get the styles.
137        my ($tableStyle, $markerStyle, @rowStyle) = ($options->{tableStyle}, $options->{markerStyle},
138                                                     $options->{evenStyle}, $options->{oddStyle});
139        my ($numStyle, $counterStyle) = ($options->{numStyle}, $options->{counterStyle});
140        # Prepare a hash for the summary counters. These will be used on the organism summary page.
141        my %summaries = ();
142      # Loop through the groups.      # Loop through the groups.
143      for my $groupID (keys %newGroupHash) {      for my $groupID (keys %newGroupHash) {
144          Trace("Processing group $groupID.") if T(2);          Trace("Processing group $groupID.") if T(2);
145            # Create a hash for summarizing the counters.
146            my %groupTotals = ( genomes => 0, pegs => 0, RNAs => 0,
147                               map { $_ => } @columnTypes, features => 0 );
148          # Get the genomes from the new hash.          # Get the genomes from the new hash.
149          my @newGenomes = @{$newGroupHash{$groupID}};          my @newGenomes = @{$newGroupHash{$groupID}};
150          # Create a hash for finding if a genome is in the old group. If the entire group is          # Create a hash for finding if a genome is in the old group. If the entire group is
# Line 139  Line 156 
156          # Create the output file.          # Create the output file.
157          my $outFileName = "stats-" . lc($groupID) . ".inc";          my $outFileName = "stats-" . lc($groupID) . ".inc";
158          Open(\*GROUPFILE, ">$targetDir/$outFileName");          Open(\*GROUPFILE, ">$targetDir/$outFileName");
         # Get the styles.  
         my ($tableStyle, $markerStyle, @rowStyle) = ($options->{tableStyle}, $options->{markerStyle},  
                                                      $options->{evenStyle}, $options->{oddStyle});  
         my ($numStyle, $counterStyle) = ($options->{numStyle}, $options->{counterStyle});  
159          # Start the table.          # Start the table.
160          print GROUPFILE "<table class=\"$tableStyle\">\n";          print GROUPFILE "<table class=\"$tableStyle\">\n";
161          # Create the header row.          # Create the header row.
# Line 153  Line 166 
166                                                   "Named genes not in subsystems",        # n0                                                   "Named genes not in subsystems",        # n0
167                                                   "Hypothetical genes in subsystems",     # s1                                                   "Hypothetical genes in subsystems",     # s1
168                                                   "Hypothetical genes not in subsystems", # n1                                                   "Hypothetical genes not in subsystems", # n1
169                                                   "",                                                   "Subsystems",
170                                                   "RNAs",                                                   "RNAs",
171                                                     ])) . "\n";                                                     ])) . "\n";
         # Set up some useful stuff for the four count columns.  
         my %linkParms = ( s0 => "nothypo_sub", n0 => "nothypo_nosub",  
                           s1 => "hypo_sub", n1 => "hypo_nosub" );  
         my @columnTypes = ('s0', 'n0', 's1', 'n1');  
172          # The data rows will be built next. We'll be putting them into a hash keyed by          # The data rows will be built next. We'll be putting them into a hash keyed by
173          # organism name. The hash enables us to spit them out sorted by name.          # organism name. The hash enables us to spit them out sorted by name.
174          my %rows = ();          my %rows = ();
175            # This variable is used to hold the counts.
176            my $num;
177          # Loop through the genomes in the new group.          # Loop through the genomes in the new group.
178          for my $genomeID (@newGenomes) {          for my $genomeID (@newGenomes) {
179                # Count this genome.
180                $groupTotals{genomes}++;
181              # Check to see if this genome is new.              # Check to see if this genome is new.
182              my $new = (! exists $oldGenomes{$genomeID} ? "new " : "");              my $new = (! exists $oldGenomes{$genomeID} ? "new " : "");
183              Trace("Processing ${new}genome $genomeID for $groupID.") if T(3);              Trace("Processing ${new}genome $genomeID for $groupID.") if T(3);
# Line 175  Line 188 
188                  $new = " <span class=\"$markerStyle\">NEW!</span>";                  $new = " <span class=\"$markerStyle\">NEW!</span>";
189              }              }
190              # Get the genome length.              # Get the genome length.
191              my $genomeLen = Tracer::CommaFormat($sprout->GenomeLength($genomeID));              $num = $sprout->GenomeLength($genomeID);
192                my $genomeLen = Tracer::CommaFormat($num);
193              # Get the number of PEGs.              # Get the number of PEGs.
194              my $pegCount = Tracer::CommaFormat($sprout->FeatureCount($genomeID, 'peg'));              $num = $sprout->FeatureCount($genomeID, 'peg');
195                my $pegCount = Tracer::CommaFormat($num);
196                $groupTotals{pegs} += $num;
197              # Get the number of RNAs.              # Get the number of RNAs.
198              my $rnaCount = Tracer::CommaFormat($sprout->FeatureCount($genomeID, 'rna'));              $num = $sprout->FeatureCount($genomeID, 'rna');
199                my $rnaCount = Tracer::CommaFormat($num);
200                $groupTotals{RNAs} += $num;
201              # If there are no RNAs, we say we don't know the number, since we know there              # If there are no RNAs, we say we don't know the number, since we know there
202              # must be RNAs somewhere.              # must be RNAs somewhere.
203              if (! $rnaCount) {              if (! $rnaCount) {
# Line 208  Line 226 
226                  $totalFeatures++;                  $totalFeatures++;
227              }              }
228              Trace("$totalFeatures total features found for $genomeID.") if T(3);              Trace("$totalFeatures total features found for $genomeID.") if T(3);
229                for my $counterKey (@columnTypes) {
230                    $groupTotals{$counterKey} += $counters{$counterKey};
231                }
232                $groupTotals{features} += $totalFeatures;
233              # We have all our data. Next we need to compute the percentages and the links.              # We have all our data. Next we need to compute the percentages and the links.
234              # First, the link stuff.              # First, the link stuff.
235              my $linkPrefix = "$options->{linkCGI}?user=\&genome=$genomeID&SPROUT=1&request=";              my $linkPrefix = "$options->{linkCGI}?user=\&genome=$genomeID&SPROUT=1&request=";
# Line 219  Line 241 
241              }              }
242              my @counterValues = map { $counters{$_} } @columnTypes;              my @counterValues = map { $counters{$_} } @columnTypes;
243              # The last link is a button to look at the subsystem summaries.              # The last link is a button to look at the subsystem summaries.
244                my $ssCount = $sprout->GetCount(['ParticipatesIn'], 'ParticipatesIn(from-link) = ?',
245                                                   [$genomeID]);
246              my $ssLink = "$options->{linkCGI}?user=\&genome=$genomeID&SPROUT=1&show_subsystems=1";              my $ssLink = "$options->{linkCGI}?user=\&genome=$genomeID&SPROUT=1&show_subsystems=1";
247              my $ssCol = "<a href=\"$ssLink\"><img src=\"../images/button-ss.gif\"></a>";              my $ssCol = "<a href=\"$ssLink\">$ssCount</a>";
248              # Create the row text. Note that we use the distributive capability of the TD              # Create the row text. Note that we use the distributive capability of the TD
249              # function to apply the same style to each one.              # function to apply the same style to each one.
250              my $rowHtml = join("",              my $rowHtml = join("",
# Line 228  Line 252 
252                                 td({ class => $numStyle }, $genomeLen),                                 td({ class => $numStyle }, $genomeLen),
253                                 td({ class => $numStyle }, $pegCount),                                 td({ class => $numStyle }, $pegCount),
254                                 td({ class => $counterStyle }, \@counterValues),                                 td({ class => $counterStyle }, \@counterValues),
255                                 td($ssCol),                                 td({ class => $numStyle }, $ssCol),
256                                 td({ class => $numStyle }, $rnaCount),                                 td({ class => $numStyle }, $rnaCount),
257                                );                                );
258              # Put it in the row hash.              # Put it in the row hash.
# Line 253  Line 277 
277          print GROUPFILE "</table>\n";          print GROUPFILE "</table>\n";
278          close GROUPFILE;          close GROUPFILE;
279          Trace("$rowCount genomes processed.") if T(2);          Trace("$rowCount genomes processed.") if T(2);
280            # Now save the group totals.
281            $summaries{$groupID} = \%groupTotals;
282      }      }
283        # Now produce the summary table.
284        my $sumFileName = "stats-groups.inc";
285        Open(\*SUMFILE, ">$targetDir/$sumFileName");
286        # Start the table.
287        print SUMFILE "<table class=\"$tableStyle\">\n";
288        # Create the header row.
289        print SUMFILE Tr( { class => 'odd' }, th(["Group name",
290                                                 "Genomes",
291                                                 "Protein Encoding Genes (PEGs)",
292                                                 "Named genes in subsystems",            # s0
293                                                 "Named genes not in subsystems",        # n0
294                                                 "Hypothetical genes in subsystems",     # s1
295                                                 "Hypothetical genes not in subsystems", # n1
296                                                 "RNAs",
297                                                   ])) . "\n";
298        # Set up a flag for the odd-even styling.
299        my $rowFlag = 0;
300        # Put in the data rows.
301        for my $groupName (sort keys %summaries) {
302            my $group = $summaries{$groupName};
303            # Compute the link for the current group.
304            my $groupLink = a({ href => $groupData{$groupName}->[0] }, $groupName);
305            # Create the table row.
306            my $rowHtml = join("",
307                               td($groupLink),
308                               td({ class => $numStyle }, Tracer::CommaFormat($group->{genomes})),
309                               td({ class => $numStyle }, Tracer::CommaFormat($group->{pegs})),
310                               td({ class => $counterStyle }, [ map { Tracer::CommaFormat($group->{$_}) } @columnTypes ]),
311                               td({ class => $numStyle }, Tracer::CommaFormat($group->{RNAs})),
312                              );
313            print SUMFILE Tr( { class => $rowStyle[$rowFlag] }, $rowHtml ) . "\n";
314            # Flip the row style.
315            $rowFlag = 1 - $rowFlag;
316        }
317        # Terminate the table and close the file.
318        print SUMFILE "</table>\n";
319        close SUMFILE;
320      # We're all done.      # We're all done.
321      Trace("Processing complete.") if T(2);      Trace("Processing complete.") if T(2);
322  }  }
323    
 =head3 Fix  
   
 C<< my %fixedHash = Fix(%groupHash); >>  
   
 Prepare a genome group hash for processing. Groups with the same primary name will be combined.  
 The primary name is the first capitalized word in the group name.  
   
 =over 4  
   
 =item groupHash  
   
 Hash to be fixed up.  
   
 =item RETURN  
   
 Returns a fixed-up version of the hash.  
   
 =back  
   
 =cut  
   
 sub Fix {  
     # Get the parameters.  
     my (%groupHash) = @_;  
     # Create the result hash.  
     my %retVal = ();  
     # Copy over the genomes.  
     for my $groupID (keys %groupHash) {  
         # Make a safety copy of the group ID.  
         my $realGroupID = $groupID;  
         # Yank the primary name.  
         if ($groupID =~ /([A-Z]\w+)/) {  
             $realGroupID = $1;  
         }  
         # Append this group's genomes into the result hash.  
         Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});  
     }  
     # Return the result hash.  
     return %retVal;  
 }  
   
   
324  1;  1;

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.23

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3