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

Diff of /Sprout/ShowCounts.pl

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

revision 1.5, Fri Jun 23 19:08:58 2006 UTC revision 1.17, Tue Sep 16 18:59:01 2008 UTC
# Line 17  Line 17 
17  and the number of new annotations. This file is included in the  and the number of new annotations. This file is included in the
18  C<index.php> document.  C<index.php> document.
19    
20  =item forms/subsystems.inc  =item forms/all_genomes.inc
21    
22  Displays a form allowing the user to select an organism and see a summary of  Displays a form allowing the user to select an organism and see a summary of
23  its subsystems and reactions. This file is included in the  its subsystems and reactions. This file is included in the
# Line 60  Line 60 
60    
61  Display this command's parameters and options.  Display this command's parameters and options.
62    
 =item age  
   
 Maximum age in days of an annotation for it to be considered new. The default is  
 C<14>.  
   
 =item target  
   
 Target directory for the include files. The default is C<includes> in the  
 C<$FIG_Config::nmpdr_pages> directory.  
   
63  =back  =back
64    
65  =cut  =cut
66    
67  use strict;  use strict;
68  use Tracer;  use Tracer;
 use DocUtils;  
 use TestUtils;  
69  use Cwd;  use Cwd;
70  use File::Copy;  use File::Copy;
71  use File::Path;  use File::Path;
72  use FIG;  use FIG;
73  use CGI qw(:standard);  use CGI qw(:standard);
74    use WikiTools;
75    
76  # Get the command-line options and parameters.  # Get the command-line options and parameters.
77  my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate) ],  my ($options, @parameters) = StandardSetup([qw(Sprout ERDB SFXlate WikiTools) ],
78                                             {                                             {
79                                              age => [14, 'maximum age of a new annotation'],                                              trace => [2, 'tracing level'],
                                             target => ["$FIG_Config::nmpdr_pages/includes",  
                                                           'output directory'],  
80                                             },                                             },
81                                             "<version date>",                                             "<version date>",
82                                             @ARGV);                                             @ARGV);
83    
84  use SFXlate;  use SFXlate;
85    
86    # The return type (error/no error) will be put in here.
87    my $rtype;
88    eval {
89  # Get the target directory.  # Get the target directory.
90  my $targetDir = $options->{target};  my $targetDir = $options->{target};
91  # Verify the parameters.  # Verify the parameters.
92  if (! $parameters[0]) {  if (! $parameters[0]) {
93      Confess("Please specify a version date.");      Confess("Please specify a version date.");
 } elsif (! -d $targetDir) {  
     Confess("Target directory $targetDir does not exist.");  
94  } else {  } else {
95      Trace("Output going to $targetDir.") if T(2);          Trace("Connecting to Sprout.") if T(2);
96      # Get the Sprout object.      # Get the Sprout object.
97      my $sfx = SFXlate->new_sprout_only();      my $sfx = SFXlate->new_sprout_only();
98      # Create the counts file.          # Get the old Sprout.
99      CreateCounts($sfx, $options->{age}, $parameters[0], "$targetDir/version.inc");          my $oldSprout = SFXlate->old_sprout_only();
100      # Create the subsystem summary file.          # Create the counts page.
101      CreateSubForm($sfx, "$targetDir/forms/subsystems.inc");          my $page = CreateCounts($sfx, $oldSprout, $parameters[0]);
102      # Create the database documentation file.          # Put it in the wiki.
103      CreateSproutDoc($sfx, "$targetDir/sproutdb.inc");          my $wiki = WikiTools->new();
104      # Tell the user we're done.          my $rc = $wiki->Save('NmpdrVersion', 'Main', 'WebHome', $page);
105      Trace("File creation complete.") if T(2);          if ($rc) {
106                Trace("Page creation complete.") if T(2);
107            } else {
108                Confess("Page creation failed: " . $wiki->{error});
109            }
110        }
111    };
112    if ($@) {
113        Trace("Counts failed with error: $@") if T(0);
114        $rtype = "error";
115    } else {
116        Trace("Counts complete.") if T(2);
117        $rtype = "no error";
118    }
119    if ($options->{phone}) {
120        my $msgID = Tracer::SendSMS($options->{phone}, "ShowCounts terminated with $rtype.");
121        if ($msgID) {
122            Trace("Phone message sent with ID $msgID.") if T(2);
123        } else {
124            Trace("Phone message not sent.") if T(2);
125        }
126  }  }
127    
128  =head3 CreateCounts  =head3 CreateCounts
129    
130  C<< CreateCounts($fig, $fileName); >>      my $content = CreateCounts($sprout, $oldSprout, $versionDate);
131    
132  Create the count and version display for the front page of the NMPDR.  Create the count and version display for the front page of the NMPDR.
133    
134  =over 4  =over 4
135    
136  =item sfx  =item sprout
137    
138  A Sprout object for accessing the database.  A Sprout object for accessing the database.
139    
140  =item age  =item oldSprout
141    
142  The maximum age for an annotation to be considered new.  A Sprout object for accessing the previous database.
143    
144  =item versionDate  =item versionDate
145    
# Line 141  Line 149 
149    
150  The name of the output file.  The name of the output file.
151    
152    =item RETURN
153    
154    Returns a string that can be published for inclusion in the front page of the wiki.
155    
156  =back  =back
157    
158  =cut  =cut
159    
160  sub CreateCounts {  sub CreateCounts {
161      # Get the parameters.      # Get the parameters.
162      my ($sfx, $age, $versionDate, $fileName) = @_;      my ($sprout, $oldSprout, $versionDate) = @_;
     # Open the output file.  
     my $handle = Open(undef, ">$fileName");  
163      # Start the heading.      # Start the heading.
164      print $handle "<h3 class=\"home\">Version $versionDate\n";      my $retVal = "<h3 class=\"home\">Version of $versionDate\n";
165      # Get the counts.      # Get the counts.
166      my @counts = $sfx->GenomeCounts();      my @counts = $sprout->GenomeCounts();
167      my @names = qw(archaeal bacterial eukaryal viral environmental);      my @names = qw(archaeal bacterial eukaryal viral environmental);
168      # Get a list of named counts for all the categories with nonzero values.      # Get a list of named counts for all the categories with nonzero values.
169      my @namedCounts = ();      my @namedCounts = ();
# Line 172  Line 182 
182      }      }
183      $output .= " genomes.";      $output .= " genomes.";
184      # Output the counts.      # Output the counts.
185      print $handle "<br />$output";      $retVal .= "<br />$output";
186      # Get the number of subsystems.      # Get the number of subsystems.
187      my $subsystems = $sfx->GetCount(['Subsystem'], "", []);      my $subsystems = $sprout->GetCount(['Subsystem'], "", []);
188      print $handle "<br />$subsystems subsystems";      $retVal .= "<br />$subsystems active subsystems";
189      # Get the current time and subtract the number of days indicated by the age.      # Count the number of new annotations, genomes, and features.
190      my $time = time() - $age * 86400;      my %things = ( Annotation => 'annotations',
191      # Count the number of new annotations.                     Feature => 'features',
192      my $newAnnotations = $sfx->GetCount(['Annotation'], "Annotation(time) >= ?",                     Genome => 'organisms'
193                                          [$time]);                   );
194        for my $thing (sort keys %things) {
195            my $newCount = $sprout->GetCount([$thing], "", []);
196            my $oldCount = $oldSprout->GetCount([$thing], "", []);
197            my $delta = $newCount - $oldCount;
198      # Only display them if there's a reasonable number.      # Only display them if there's a reasonable number.
199      if ($newAnnotations > 5) {          if ($delta > 5) {
200          print $handle ", $newAnnotations new annotations";              $retVal .= ", $delta&nbsp;new&nbsp;$things{$thing}";
201      }      }
     # Terminate the heading.  
     print $handle ".</h3>\n";  
     # Close the output file.  
     close $handle;  
202  }  }
203        # Terminate the heading.
204  =head3 CreateSubForm      $retVal .= ".</h3>\n";
205        # Return it.
206  C<< CreateSubForm($sfx, $fileName); >>      return $retVal;
   
 Output the subsystem summary form. The subsystem summary form allows the user  
 to select an organism and view a summary of its subsystems.  
   
 =over 4  
   
 =item sfx  
   
 A Sprout object that can be used to access the NMPDR database.  
   
 =item fileName  
   
 The name of the file to create with the form HTML in it.  
   
 =back  
   
 =cut  
   
 sub CreateSubForm {  
     # Get the parameters.  
     my ($sfx, $fileName) = @_;  
     # Start the form.  
     my @page = ();  
     push @page, start_form({method => "post", action => "../FIG/genome_statistics.cgi",  
                             enctype=> "application/x-www-form-urlencoded"});  
     # Make sure the script knows it's for SPROUT.  
     push @page, input({type => "hidden", name => "SPROUT", value => "1"});  
     # Surround the form parts with a table.  
     push @page, "<table><tr><td>";  
     # Create the gene menu.  
     push @page, $sfx->GeneMenu({ name => 'genome', size => 10 }, "", []);  
     # End the first table cell.  
     push @page, "</td></tr><tr><td>";  
     # Add the buttons.  
     push @page, input({type => "submit", name => "show_subsystems",  
                        value => "Show Subsystems"});  
     push @page, input({type => "submit", name => "show_reactions",  
                        value => "Show Reactions"});  
     # Close the table.  
     push @page, "</td></tr></table>";  
     # Close the form.  
     push @page, end_form();  
     # Put together all the pieces.  
     my $wholePage = join("\n", @page);  
     # Open the output file.  
     my $handle = Open(undef, ">$fileName");  
     # Write out the HTML.  
     print $handle $wholePage;  
     # Close the file.  
     close $handle;  
   
 }  
   
 =head3 CreateSproutDoc  
   
 C<< CreateSproutDoc($sfx, $fileName); >>  
   
 Output the Sprout database documentation.  
   
 =over 4  
   
 =item sfx  
   
 A Sprout object that can be used to access the NMPDR database.  
   
 =item fileName  
   
 The name of the file to create with the documentation in it.  
   
 =back  
   
 =cut  
   
 sub CreateSproutDoc {  
     # Get the parameters.  
     my ($sfx, $fileName) = @_;  
     # Open the output file.  
     my $handle = Open(undef, ">$fileName");  
     # Write the Sprout database document into it.  
     print $handle $sfx->DisplayMetaData();  
     # Close the file.  
     close $handle;  
207  }  }
208    
209    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.17

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3