#!/usr/bin/perl
use CGI qw(:standard);
use Net::SMTP;
use vars qw();
my $smtp_host = "stat.wharton.upenn.edu";
my $sender_address = "stjensen\@wharton.upenn.edu";
$action="BioOptimizer.web.cgi";
#####################Main Program#####################
BOinputform();
$seqfile = param('seqs');
$biopfile = param('biop');
$nummotif = param('nummotif');
$numblock = param('numblock');
$w1 = param('w1');
$w2 = param('w2');
$mingap = param('mingap');
$maxgap = param('maxgap');
$revcomp = param('revcomp');
$rc = 0;
if ($revcomp eq "Both Strands"){
$rc = 1;
}
$email = param('email');
$jobname = param('jobname');
unless(open (OUT,">programfiles/$jobname.par")){
print "Unable to open file $jobname.par: $!";
exit();
}
print OUT "nummotif=$nummotif\nnumblock=$numblock\n";
print OUT "w1=$w1\nw2=$w2\nmingap=$mingap\nmaxgap=$maxgap\nrevcomp=$revcomp\trc = $rc\n";
print OUT "email=$email\njobname=$jobname\n";
close(OUT);
unless(open(OUT,">programfiles/$jobname.seq")){
print "Unable to open file $jobname.seq: $!";
exit();
}
print OUT "$seqfile";
close(OUT);
unless(open(OUT,">programfiles/$jobname.biop")){
print "Unable to open file $jobname.biop: $!";
exit();
}
print OUT "$biopfile";
close(OUT);
if(!defined(my $kidpid = fork())){ # if the fork fails (OS doesn't support it, not enough memory) warn the user
print "Cannot fork: $! -- Your job has not been executed.
\n";
}
elsif ($kidpid == 0){ # this only runs in the child process generated by the fork
my $content = "";
if ($numblock eq "One-Block"){
$content .= `./BioOptimizer.biop.web programfiles/$jobname.seq programfiles/$jobname.biop $nummotif $rc $w1` ;
}
if ($numblock eq "Two-Block"){
$content .= `./BioOptimizer.twoblock.web programfiles/$jobname.seq programfiles/$jobname.biop $nummotif $rc $w1 $w2 $mingap $maxgap`;
}
# mail the job info
mail_results( $email , $jobname , $content );
# send the child away
exit();
}
else { # this only runs in the parent process of the fork
# nothing to do here in your case, the code continues on afterwards
}
####################Subroutines#############################
sub BOinputform {
print header;
print start_html ("BioOptimizer Web Server"), start_multipart_form(-action=>"$action",-method=>'post');
print "
Click here to download a tar file with stand-alone perl scripts of BioOptimizer.
";
print "Jensen, S.T. and Liu, J.S. (2004).
BioOptimizer: a
Bayesian scoring function approach to motif discovery.
Bioinformatics 20:1557-1564.
";
print "Jensen, S.T., Liu, X.S., Zhou, Q. and Liu,
J.S. (2004).
Computational discovery of gene regulatory binding
motifs: a Bayesian perspective.
Statistical Science 19:188-204.
"; print "Please reference the first of these papers when using results from BioOptimizer.
"; print "
"; print "For both BioProspector and BioOptimizer, your sequences must be in FASTA format e.g.,
";
print "\>genename1
acgtacgatcgatcatgactacgatcgactgcat
\>genename2
agctagctagctgactagctagctacgtacgatc
"; print "
"; print "
"; print "
"; print "
"; print "
"; print "
"; print "
"; print "
"; print "
"; print "
"; print "Email Address:
"; print "Job Name: (no spaces please!)
";
print "";
print "
Note that the program may take some time (5-10 minutes) to run. Please to do not refresh the browser or hit submit more than once!";
print "
1: The \"Final BioOptimizer Score\" can be used to compare motifs from the same dataset. The motif with the highest (least negative) BioOptimizer score is the best motif.
"; print "2: In some cases, BioOptimizer will produce a motif with no sites, even when the input motif has sites. This means that the input motif has a lower score than a motif with no sites, which is an indication that the input motif is quite weak.
"; end_form, end_html; } sub mail_results { my $recipient = shift ; # shift just pulls the first my $jobname = shift ; # item from the argument list my $content = shift ; my $subject = "BioOptimizer Output: $jobname"; my $smtp = Net::SMTP->new($smtp_host); # smtp host $smtp->mail($sender_address); # mail from $smtp->to($recipient); # mail to $smtp->data(); # begin building the message $smtp->datasend("From: ${sender_address}\n"); $smtp->datasend("To: ${recipient}\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); $smtp->datasend($content); $smtp->dataend(); $smtp->quit; # send and terminate }