[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.26, Sun Oct 8 05:44:55 2006 UTC revision 1.30, Thu Dec 6 14:58:03 2007 UTC
# Line 6  Line 6 
6  the genomes in each of the genome groups. Genomes that are new to this version  the genomes in each of the genome groups. Genomes that are new to this version
7  of the Sprout will be specially marked. In order for this to work, both the  of the Sprout will be specially marked. In order for this to work, both the
8  current and previous Sprout databases must be available on this machine.  current and previous Sprout databases must be available on this machine.
 This is one positional parameter: the name of a directory in which to place  
 the include files.  
9    
10  The currently-supported command-line options are as follows.  The currently-supported command-line options are as follows.
11    
# Line 95  Line 93 
93  use SFXlate;  use SFXlate;
94  use CGI qw(:standard);  use CGI qw(:standard);
95  use FIG;  use FIG;
 no warnings 'once'; # only when coding  
96    
97  # Get the command-line options and parameters.  # Get the command-line options and parameters.
98  my ($options, @parameters) = StandardSetup([qw(Sprout ERDB) ],  my ($options, @parameters) = StandardSetup([qw(Sprout ERDB) ],
# Line 110  Line 107 
107                                              counterStyle => ['countercell', 'style for cells with counter values'],                                              counterStyle => ['countercell', 'style for cells with counter values'],
108                                              linkCGI => ['../FIG/genome_statistics.cgi',                                              linkCGI => ['../FIG/genome_statistics.cgi',
109                                                          'path to CGI script for detailed statistics'],                                                          'path to CGI script for detailed statistics'],
                                             groupFile => ["$FIG_Config::sproutData/groups.tbl",  
                                                           'location of the NMPDR group description file'],  
110                                              noNewCheck => [0, 'if specified, skips the check for new genomes'],                                              noNewCheck => [0, 'if specified, skips the check for new genomes'],
111                                              targetDir => ["$FIG_Config::nmpdr_base/next/html/includes",                                              targetDir => ["$FIG_Config::nmpdr_base/next/html/includes",
112                                                            'target directory'],                                                            'target directory'],
113                                              },                                              },
114                                             "",                                             "",
115                                             @ARGV);                                             @ARGV);
116    # The return type (error/no error) goes in here.
117    my $rtype;
118    eval {
119        # This table controls the special attribute columns. For each we need to know the attribute name and the
120        # column title. If any genomes in a group have a value for one of the special columns, that column is
121        # displayed along with the attribute values.
122        my %specialCols = (Serotype => 'Serotype_code',
123                           Phenotype => 'Phenotype');
124  # Verify the directory name.  # Verify the directory name.
125  my $targetDir = $options->{targetDir};  my $targetDir = $options->{targetDir};
126  if (! $targetDir) {  if (! $targetDir) {
# Line 130  Line 133 
133      my %newGroupHash = $sprout->GetGroups();      my %newGroupHash = $sprout->GetGroups();
134      # Extract the genome group data from the new Sprout.      # Extract the genome group data from the new Sprout.
135      if (! $options->{strict}) {      if (! $options->{strict}) {
136          %newGroupHash = Sprout::Fix(%newGroupHash);              %newGroupHash = $sprout->Fix(%newGroupHash);
137      }      }
138      # This hash will be used to determine which genomes are new.      # This hash will be used to determine which genomes are new.
139      my %oldGroupHash = ();      my %oldGroupHash = ();
# Line 140  Line 143 
143          %oldGroupHash = map { $_ => $newGroupHash{$_} } keys %newGroupHash;          %oldGroupHash = map { $_ => $newGroupHash{$_} } keys %newGroupHash;
144      } else {      } else {
145          # Get the old Sprout.          # Get the old Sprout.
146          my $oldSprout = SFXlate->new_sprout_only($FIG_Config::oldSproutDB);              my $oldSprout = SFXlate->old_sprout_only();
147          # Extract the genome group data from the old Sprout.          # Extract the genome group data from the old Sprout.
148          %oldGroupHash = $oldSprout->GetGroups();          %oldGroupHash = $oldSprout->GetGroups();
149          if (! $options->{strict}) {          if (! $options->{strict}) {
150              %oldGroupHash = Sprout::Fix(%oldGroupHash);                  %oldGroupHash = $oldSprout->Fix(%oldGroupHash);
151          }          }
152      }      }
153      # Read the group file.          # Get a FIG object for computing attributes.
154      my %groupData = Sprout::ReadGroupFile($options->{groupFile});          my $fig = FIG->new();
155            # Get the super-group list.
156            my @superGroups = sort keys %newGroupHash;
157      # Set up some useful stuff for the four count columns.      # Set up some useful stuff for the four count columns.
158      my %linkParms = ( s0 => "nothypo_sub", n0 => "nothypo_nosub",      my %linkParms = ( s0 => "nothypo_sub", n0 => "nothypo_nosub",
159                        s1 => "hypo_sub", n1 => "hypo_nosub" );                        s1 => "hypo_sub", n1 => "hypo_nosub" );
# Line 160  Line 165 
165      # Prepare a hash for the summary counters. These will be used on the organism summary page.      # Prepare a hash for the summary counters. These will be used on the organism summary page.
166      my %summaries = ();      my %summaries = ();
167      # Loop through the groups.      # Loop through the groups.
168      for my $groupID (keys %newGroupHash) {          for my $groupID (@superGroups) {
169          Trace("Processing group $groupID.") if T(2);          Trace("Processing group $groupID.") if T(2);
170          # Create a hash for summarizing the counters.          # Create a hash for summarizing the counters.
171          my %groupTotals = ( genomes => 0, pegs => 0, RNAs => 0,          my %groupTotals = ( genomes => 0, pegs => 0, RNAs => 0,
# Line 176  Line 181 
181          # Create the output file.          # Create the output file.
182          my $outFileName = "stats-" . lc($groupID) . ".inc";          my $outFileName = "stats-" . lc($groupID) . ".inc";
183          Open(\*GROUPFILE, ">$targetDir/$outFileName");          Open(\*GROUPFILE, ">$targetDir/$outFileName");
184          # Start the table.              # Get the special columns. We'll stuff them in a hash keyed by column name. Each column name will contain
185          print GROUPFILE "<table class=\"$tableStyle\">\n";              # a sub-hash that translates each genome ID to its applicable attribute value (if any).
186          # Create the header row.              my %specialData = ();
187          print GROUPFILE Tr( { class => 'odd' }, th(["Strain annotated in NMPDR",              for my $specialColumn (keys %specialCols) {
188                                                   "Genome size, bp",                  # Get the attribute mapping.
189                    my %specialDataList = map { $_->[0] => $_->[2] } $fig->get_attributes(\@newGenomes, $specialCols{$specialColumn});
190                    # We only proceed if some attributes were found. As a result, the keys in %specialData will only be keys
191                    # for columns that exist in the output.
192                    if (scalar(keys %specialDataList)) {
193                        $specialData{$specialColumn} = \%specialDataList;
194                    }
195                }
196                # Set up the column names.
197                my @columnNames = "Strain annotated in NMPDR";
198                push @columnNames, sort keys %specialData;
199                push @columnNames,  "Genome size, bp",
200                                                   "Protein Encoding Genes (PEGs)",                                                   "Protein Encoding Genes (PEGs)",
201                                                   "Named genes in subsystems",            # s0                                                   "Named genes in subsystems",            # s0
202                                                   "Named genes not in subsystems",        # n0                                                   "Named genes not in subsystems",        # n0
203                                                   "Hypothetical genes in subsystems",     # s1                                                   "Hypothetical genes in subsystems",     # s1
204                                                   "Hypothetical genes not in subsystems", # n1                                                   "Hypothetical genes not in subsystems", # n1
205                                                   "Subsystems",                                                   "Subsystems",
206                                                   "RNAs",                                  "RNAs";
207                                                     ])) . "\n";              # Start the table.
208                print GROUPFILE "<table class=\"$tableStyle\">\n";
209                # Create the header row.
210                print GROUPFILE Tr( { class => 'odd' }, th(\@columnNames)) . "\n";
211          # 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
212          # 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.
213          my %rows = ();          my %rows = ();
# Line 203  Line 222 
222              Trace("Processing ${new}genome $genomeID for $groupID.") if T(3);              Trace("Processing ${new}genome $genomeID for $groupID.") if T(3);
223              # Get the strain name.              # Get the strain name.
224              my $genomeName = $sprout->GenusSpecies($genomeID);              my $genomeName = $sprout->GenusSpecies($genomeID);
225                    # Apply a link.
226                    my $genomeText = CGI::a({ href => "../FIG/genome_statistics.cgi?genome=$genomeID;SPROUT=1" }, $genomeName);
227              # If this is a new strain, build the HTML for the NEW! mark.              # If this is a new strain, build the HTML for the NEW! mark.
228              if ($new) {              if ($new) {
229                  $new = " <span class=\"$markerStyle\">NEW!</span>";                  $new = " <span class=\"$markerStyle\">NEW!</span>";
# Line 265  Line 286 
286                                                 [$genomeID]);                                                 [$genomeID]);
287              my $ssLink = "$options->{linkCGI}?user=\&genome=$genomeID&SPROUT=1&show_subsystems=1";              my $ssLink = "$options->{linkCGI}?user=\&genome=$genomeID&SPROUT=1&show_subsystems=1";
288              my $ssCol = "<a href=\"$ssLink\">$ssCount</a>";              my $ssCol = "<a href=\"$ssLink\">$ssCount</a>";
289              # Create the row text. Note that we use the distributive capability of the TD                  # Start creating the table cells.
290              # function to apply the same style to each one.                  my $rowHtml = td("$genomeText$new");
291              my $rowHtml = join("",                  # Add any special columns.
292                                 td("$genomeName$new"),                  for my $specialCol (keys %specialData) {
293                        # Here we get the attribute value. If there is none, we leave the column blank.
294                        my $attribute = $specialData{$specialCol}->{$genomeID} || "&nbsp;";
295                        $rowHtml .= td($attribute);
296                    }
297                    # Now add the data columns.
298                    $rowHtml .= join("",
299                                 td({ class => $numStyle }, $genomeLen),                                 td({ class => $numStyle }, $genomeLen),
300                                 td({ class => $numStyle }, $pegCount),                                 td({ class => $numStyle }, $pegCount),
301                                 td({ class => $counterStyle }, \@counterValues),                                 td({ class => $counterStyle }, \@counterValues),
# Line 321  Line 348 
348      for my $groupName (sort keys %summaries) {      for my $groupName (sort keys %summaries) {
349          my $group = $summaries{$groupName};          my $group = $summaries{$groupName};
350          # Compute the link for the current group.          # Compute the link for the current group.
351          my $groupLink = a({ href => $groupData{$groupName}->[0] }, $groupName);              my $groupLink = a({ href => $sprout->GroupPageName($groupName) }, $groupName);
352          # Create the table row.          # Create the table row.
353          my $rowHtml = join("",          my $rowHtml = join("",
354                             td($groupLink),                             td($groupLink),
# Line 340  Line 367 
367      # We're all done.      # We're all done.
368      Trace("Processing complete.") if T(2);      Trace("Processing complete.") if T(2);
369  }  }
370    };
371    if ($@) {
372        Trace("Stats failed with error: $@") if T(0);
373        $rtype = "error";
374    } else {
375        Trace("Stats complete.") if T(2);
376        $rtype = "no error";
377    }
378    if ($options->{phone}) {
379        my $msgID = Tracer::SendSMS($options->{phone}, "GenomeStats terminated with $rtype.");
380        if ($msgID) {
381            Trace("Phone message sent with ID $msgID.") if T(2);
382        } else {
383            Trace("Phone message not sent.") if T(2);
384        }
385    }
386    
387  1;  1;

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.30

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3