#!/usr/bin/perl ############################################## ############################################## # SCRIPT NAME: Page_Statistics.cgi # FUNCTION: Show database statistics ############################################## # MINE: Molecular INformation Explorer # Copyright 2000 Dawn Field. All rights reserved. # The CGI-PERL scripts belonging to MINE # may be used and modified freely, but I do # request that this copyright notice remain attached # to this file/source code. If you make modifications # please do not distribute unless # you fully document the modifications. use CGI; require "CGI-MINE.pl"; ################# # START EACH MINE CGI SCRIPT ################# # this redirects the error messages to the user's screen # and is useful for debugging CGI scripts! open (STDERR, ">&STDOUT"); # print errors to screen $| = 1; # flush the print buffer continuously # make a new query object using CGI.pm module $query = new CGI; # print the required header and start the web page print $query->header; print $query->start_html('MINE'); # Each time a script is invoked for the first time (or $action undef), # log the visit in the custom MINE server log (see CGI-MINE.pl) # (put this after the header incase an error message is printed) # check value of $action $action = $query->param('action'); if ($action eq undef) {&log();} $debug = 0; # set to one to see debugging print info ####### # START THE WEBPAGE ####### # print the MINE menu &menu; # start the basic gray table used for formatting MINE pages &table_top(); # put the main title of your page here print ""; print "Database Statistics

"; ############ # START AUTOMATIC PROCESS OF STATISTICS ############ # put all the files in the database into an array # @files = <*.db>; # use this array to print how many files are in the database print ""; print ""; # go into each set of files and get the length of the sequences # don't presume the "length" field is defined, caluculate it # again here from the sequences in each file foreach $ext (@stat_extensions) { # use Perl's equivalent function called readdir to get the names of all the files opendir THISDIR, "." or die "can't read the files in this directory"; @database = grep /$ext$/, readdir THISDIR; closedir THISDIR; # this puts the files into order, so that you get 0001, 0002, 0003, and not 0001, 0010 or stranger @database = sort @database; @files = @database; # call the function to calculate total characters &total_nuc_in_database(@files); print ""; $total_count += $total_len; undef($total_len); } print "<\/tr><\/table>"; # finish the table formatting &table_bottom(); ################# # END PROCESSING STATISTICS ################# # PRINT BOTTOM OF EACH WEB PAGE # if $show_source is set to 1 show a link # at the bottom of each script to the source # code - pass the name of this script to the # function in CGI-MINE.pl if ($show_source) { $script_name = $query->script_name(); &source ($script_name); } # ATTACH the MINE copywrite &mine_cp; print ""; print $query->end_html; ################# # END WEBPAGE ################# ##################### # FUNCTIONS ##################### ############################# # FUNCTION: TOTAL NUCLEOTIDES # goes through all .db file # and tallies up the total # nucleotide lengths of all # combined seq # basic start to a more # general function for # determine lengths of # sets of seqs ############################# # Usage: &total_nuc_in_database(@files); sub total_nuc_in_database { # get the list of files @files = @_; # declare local variables my $seq_len = undef; my $search_query = undef; my $file = undef; # loop over them to get the sequence out of each # send and list of file names in the array! # @files = ("SBW0002.db", "SBW0003.db"); # by default @files is all .db files in the directory foreach $file (@files) { # open the file to restore the query open (IN, $file) || die "can't open the file $file"; $search_query = new CGI(IN); # get the sequence from the file $seq = $search_query->param('seq'); # get the length $seq_len = length $seq; if ($debug) { print "$seq_len

";} # add it to the total length $total_len += $seq_len; $seq_len = undef; } # end foreach $file (@files) }

File TypeTotal NumberTotal characters
$ext".@files."$total_len