#!/usr/bin/perl ############################################## ############################################## # SCRIPT NAME: Page_Make_Source_ADMIN.cgi # FUNCTION: Automate basic tasks for the # WebMaster ############################################## # 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 = ""; # "1" to print, "0" to hide print statements ####### # 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 "Administration

"; # end table &table_bottom(); ############ # START FORM ############ &table_top(); print $query->startform(); print "Check the global settings for the $database_name: MINE_Customization_File. "; print "This is the file where the manager sets values for the global variables that are used by all MINE scripts.

"; print "Check the fields used by the submit, edit, and search engine scripts: MINE_Preferences.

"; print "Summarize the best matches in blast reports: Summarize Blast Reports.

"; print "Generate a link for each entry to the 1) raw text 2) html and 3) edit form: "; print "BatchEdit

"; print "See the QUICKMINE.config file: "; print "QUICKMINE.config "; print "that is used with the "; print "QUICKMINE_script "; print "

"; # print some buttons # print the button write source code for all Page_*.cgi files print $query->submit('action','Write source for all current scripts'); # print the list ALL files button print "

Update copies of the web-viewable source code for all scripts. To add security, you may wish to restrict some of the code that gets copied into world-viewable source code made with this command. In this version, all code is viewable.

"; print $query->submit('action','List ALL non-data files'); print "

Produce a list of all the files included in this version of MINE

"; # print the list update fasta files button print $query->submit('action','Update the fasta files (*.db.fasta) from all entries in database and update the " SELF_blast_database" file'); print $var =< This command converts all the .db entries in your database (specified in the MINE_Customization_File) into fasta formatted files (e.g. for use with blast).

Each *.db file will be used to produce a *.db.fasta file. Only use if you have enough disk space to keep multiple copies of your database entries. The main reason to create fasta formatted copies is that these files can be piped into the blast interface.

A file called "SELF_blast_database" is simultaneously made. This file contains all the specified .db files in fasta format. Use formatdb to turn this into a blast-ready database using the code in the script make_BLAST_DATABASES. This script can either be run from the command line, or entered into your crontab file for automation (see crontab in the documentation to see how to do this). TEXT print "


"; print $query->endform(); &table_bottom(); ################# # END FORM ################# ################# # PROCESS FORM ################ # get the values $action = $query->param('action'); &table_top(); # TAKE ACTION IF A BUTTON IS PRESSED! ### IF =~ /Update the fasta files/ # Make fasta files from all entries in database if ($action =~ /Update the fasta files/) { &make_fasta_files(); } ### IF =~ /List ALL/) # list ALL the files in the data if "List ALL files used by the database" button is clicked if ($action =~ /List ALL/) { # keep track of the defined prefixes and extensions # can't pass wildcards to be expanded, the shell interprets them as the character "*" # this array is simply to keep track of a list of file patterns to match, and for # ease of printing to screen - NOTE the html tag (
) in the names! @unique_tags = ( "Page_*.cgi (all cgi scripts; click link to start script)
", "Page_*_source (source code for all cgi scripts)
", "*archive* (database specific files)
", "MINE* (extra stuff)
", "*utility (plain perl scripts that run on command line; click link to see source)
", "*driver (driver code for common bioinformatics modules)
" ); print "The prefixes and extension names currently defined in this database version:

"; print $query->b(@unique_tags); @get_files = ; push(@total_files, @get_files); @get_files = ; push(@total_files, @get_files); @get_files = <*archive*>; push(@total_files, @get_files); @get_files = ; push(@total_files, @get_files); @get_files = <*utility>; push(@total_files, @get_files); @get_files = <*driver>; push(@total_files, @get_files); $count = 0; foreach $file (@total_files) { $count++; print "

$count. $file "; } } # IF "Write source for all current scripts" if ($action eq "Write source for all current scripts") { # get all the scripts; they all begin (by convention) # with "Page_" and end in ".cgi" # get all the files that start with the defined prefix Page_ $ext = "Page_"; opendir THISDIR, "." or die "can't read the files in this directory"; @database = grep /$ext/, readdir THISDIR; closedir THISDIR; @file = @database; # set the count to 0, some files with start with Page, but are _source files # we don't want to copy those to source again! $count = 0; foreach $file (@file) { # some files with start with Page, but are _source files # we don't want to copy those to source again! if ($file !~ /_source/ && $file =~ /\.cgi/) { # increment count for each file matching Page_*.cgi $count++; # take the .cgi extension off the file name $file_source = $file; $file_source =~ s/(\.cgi)//; # append the _source extension instead $file_source = $file_source."_source"; # print out all the files and the source files as they are made # copy the .cgi manually to a new _source file open (IN, $file) || die "Can't open the file $file for reading"; open (IN_B, ">$file_source") || die "Can't open the file $file_source for writing"; # make a system call to make the source file web-readable only (4 = read) # (6 = read + write) system (`chmod 644 $file_source`); # read code file and print it to the source file # will overwrite any existing file! undef($line); while ($line = ) {print IN_B $line;} # make a url link $source = "source"; print "

$count. See the source for the $file script: $source"; } # end if ($file !~ /_source/ && $file =~ /\.cgi/) { } # end foreach $file (@file) { } # end if ($query->('action') eq "Write source for all current scripts") { &table_bottom(); ################# # END PROCESS FORM ################# # 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 $query->end_html; ################# # END WEBPAGE ################# ##################### # FUNCTIONS ##################### ######################### # FUNCTION: make_fasta_files # this function opens all the # .db files in the same directory # and extracts the def line (header) # and sequence (using the function &make_fasta) # and makes a second # file called *.db.fasta for use in # blasting.. ######################### # Usage: &make_fasta_files(); sub make_fasta_files { print "A concatenated list of all fasta files can be found here: $blast_database

"; print "If you intend to use this file as a blast database, you will need to run the formatdb (application) command $formatdb_cmd from the command line or set up a cron job to do it for you.

"; # this will be the database open (INB, ">$blast_database") || die "couldn't open $blast_database"; print "The following file extensions were selected (set in the \"MINE_Custmization_File\" by manager) for inclusion in the $blast_database file:

"; foreach $blast_ext (@blast_extensions) { $ext = $blast_ext; print "$ext
"; &get_files(); @file = @database; push (@totalfiles, @file) } @file = @totalfiles; print "

"; foreach $file (@file) { &make_fasta($file); } } # end function ######################### # FUNCTION: make_fasta # this function opens a file # extracts the def line (header) # and sequence and makes a second # file called *.db.fasta ######################### # Usage: &make_fasta(); sub make_fasta { open(IN, "$file") || die "couldn't open $file"; open (INA, ">$file.fasta") || die "couldn't open $file.fasta"; open (GET, "$file.fasta"); chmod 0777, "$file.fasta"; $search_query = new CGI(IN); # get the id from the file $id = $search_query->param('id'); # get the definition from the file $def = $search_query->param('def'); # get the sequence from the file $seq = $search_query->param('seq'); # wrap the sequence into lines with 70 characters &wrap_output($seq, (length $seq), $wrapped_seq); # write the fasta sequence to file .fasta print INA ">File: $file ID: $id DEF: $def\n$wrapped_seq"; print INB ">File: $file ID: $id DEF: $def\n$wrapped_seq"; # print to screen a link to the file made print "File $file.fasta made
"; }