#!/usr/local/bin/perl -w #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Program : CreateBiosapRun.cgi # Author : Michael Johnson # $Id$ # # Description : This CGI program allows users to generate biosap # parameter files in unique directories (under a # directory), based on input they provide through # a web interface. # # SBEAMS is Copyright (C) 2000-2005 Institute for Systems Biology # This program is governed by the terms of the GNU General Public License (GPL) # version 2 as published by the Free Software Foundation. It is provided # WITHOUT ANY WARRANTY. See the full description of GPL terms in the # LICENSE file distributed with this software. # #----------------------------------------------------------------------- ############################################################################### # Set up all needed modules and objects ############################################################################### use strict; use Getopt::Long; use FindBin; use POSIX qw(strftime); use POSIX qw(:sys_wait_h); use lib qw (../../lib/perl); use vars qw ($q $tm $tm_rng $o_conc $s_conc $blast_lib $same_as_lib $mn_len $mx_len $mx_selfcomp $init_offset $step $dist $ftrs $featurama_lib $dirstr $pol_at $pol_gc $win_sz $win_at $win_gc $action $comments $PROG_NAME $dbh $sbeams $sbeamsMOD $current_username $USAGE %OPTIONS $VERBOSE $QUIET $DEBUG); use DBI; #use CGI; use CGI::Carp qw(fatalsToBrowser croak); use SBEAMS::Connection qw($q); use SBEAMS::Connection::Settings; use SBEAMS::Connection::Tables; use SBEAMS::Biosap; use SBEAMS::Biosap::Settings; use SBEAMS::Biosap::Tables; $sbeams = new SBEAMS::Connection; $sbeamsMOD = new SBEAMS::Biosap; $sbeamsMOD->setSBEAMS($sbeams); $sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR); #$q = new CGI; ############################################################################### # Set program name and usage banner for command like use ############################################################################### $PROG_NAME = $FindBin::Script; $USAGE = <Authenticate( #connect_read_only=>1, #allow_anonymous_access=>1, #permitted_work_groups_ref=>['Proteomics_user','Proteomics_admin'], )); #### Read in the default input parameters my %parameters; my $n_params_found = $sbeams->parse_input_parameters( q=>$q,parameters_ref=>\%parameters); #$sbeams->printDebuggingInfo($q); #### Decide what action to take based on information so far $sbeamsMOD->printPageHeader(); if ($parameters{action} eq "Submit to BioSap") { process_request(ref_parameters=>\%parameters, testonly=>0); }elsif ($parameters{action} eq "Test Run Featurama") { process_request(ref_parameters=>\%parameters, testonly=>1); }else { print_javascript(); create_request_form(ref_parameters=>\%parameters); } $sbeamsMOD->printPageFooter(); } # end main ############################################################################### # print_javascript ############################################################################## sub print_javascript { print qq~ ~; return 1; } ############################################################################### # Process Request ############################################################################### sub process_request { my %args = @_; my $SUB_NAME = "process_request"; #### Process the arguments list my $ref_parameters = $args{'ref_parameters'} || die "ERROR[$SUB_NAME]: ref_parameters not passed"; my $testonly = $args{'testonly'}; #### If the parameters are okay, then create the necessary files my ($ok, $ref_parameters) = verify_parameters(ref_parameters=>$ref_parameters); if ($ok == 1) { my $output_dir = make_output_dir (testonly=>$testonly); write_parameters_files(ref_parameters=>$ref_parameters, output_dir=>$output_dir); if ($testonly==1){run_featurama(output_dir=>$output_dir);} else { print qq~ You have successfully subbmitted a job to BIOSAP
Your job will be processed in the order received. You can see the log file of your job by clicking on the link below:

Well, theres no link yet, but paste this into a unix window:

cd $output_dir
if ( -e $output_dir ) tail -f blast.out



~; } } create_request_form(ref_parameters=>$ref_parameters); return; } # end process_request ############################################################################### # run_featurama ############################################################################### sub run_featurama { my %args = @_; my $SUB_NAME = "run_featurama"; #### Process the argument list my $output_dir = $args{'output_dir'} || die "ERROR[$SUB_NAME]: output_dir not passed!\n"; #### Define standard variables my $featurama_location = "/net/db/projects/BioSap/src/biosap/featurama/src"; my $featurama_params = "$output_dir/featurama.params"; my ($start_hour,$start_min,$start_sec) = ((localtime)[2],(localtime)[1],(localtime)[0]); $| = 1; print "
\n";
  system "$featurama_location/featurama $featurama_params 2>&1" 
      || croak "Couldn't run featurama : $!";
  print "
\n";
  system "/bin/rm -fr $output_dir"
      || croak "Couldn't formatdb: $!";

  my ($finish_hour,$finish_min,$finish_sec) = ((localtime)[2],(localtime)[1],(localtime)[0]);

  print qq ~
    
Featurama Test Run is Done !
Started at $start_hour:$start_min:$start_sec
Completed at $finish_hour:$finish_min:$finish_sec
~; } ############################################################################### # write_parameters_files ############################################################################### sub write_parameters_files { my %args = @_; my $SUB_NAME = "write_parameters_files"; #### Process the arguments list my $ref_parameters = $args{'ref_parameters'} || die "ref_parameters not passed\n"; my %parameters = %{$ref_parameters}; my $output_dir = $args{'output_dir'} || die "output_dir not passed\n"; my ($sql,@rows); #### write Comments file open (COMMENTS, ">$output_dir/comments") || croak "ERROR[$SUB_NAME]: could not create comments file\n"; if ($parameters{'comments'}) { print (COMMENTS $parameters{'comments'}); }else { print (COMMENTS "No comments were submitted\n"); } close (COMMENTS); #### write Featurama parameters file open (FEATURAMA, ">$output_dir/featurama.params") || croak "ERROR[$SUB_NAME]: could not create featurama parameters file\n"; my $user = $sbeams->getCurrent_username(); my $featurama_params = "user_name=$user\n"; my $bs_id = $parameters{'featuramalib'}; $sql = qq~ SELECT set_path FROM $TBBS_BIOSEQUENCE_SET WHERE biosequence_set_id = '$bs_id' AND record_status != 'D' ~; @rows = $sbeams->selectOneColumn($sql); my $biosequence_set = $rows[0]; $featurama_params .= qq~gene_library=$biosequence_set output_directory=$output_dir melting_temp=$parameters{'meltTemp'} melting_temp_range=$parameters{'meltTempRange'} minimum_length=$parameters{'minLen'} maximum_length=$parameters{'maxLen'} maximum_selfcomp=$parameters{'maxSelfComp'} step_size=$parameters{'stepSize'} maximum_3prime_distance=$parameters{'max3PrimeDist'} initial_3prime_offset=$parameters{'initOffset'} maximum_features=$parameters{'maxReporters'} maximum_polyAT_length=$parameters{'maxPolyAT'} maximum_polyGC_length=$parameters{'maxPolyGC'} content_window_size=$parameters{'windowSize'} maximum_windowAT_content=$parameters{'maxATinWindow'} maximum_windowGC_content=$parameters{'maxGCinWindow'} oligo_concentration_mMol=$parameters{'oligoConc'} salt_concentration_mMol=$parameters{'saltConc'}~; # print "
$featurama_params
"; print FEATURAMA $featurama_params; close(FEATURAMA) || print "WARNING[$SUB_NAME]: featurama params file did not close nicely!
"; print "File ".$output_dir."/featurama.params created.
"; #### write BLAST parameters file open (BLAST, ">$output_dir/blast.params") || croak "ERROR[$SUB_NAME]: could not create BLAST parameters file\n"; my $blast_lib = $parameters{'blastlib'}; $sql = qq~ SELECT set_path FROM $TBBS_BIOSEQUENCE_SET WHERE biosequence_set_id = '$blast_lib' AND record_status != 'D' ~; my @blast_lib_id = $sbeams->selectOneColumn($sql); print BLAST qq~blast_library=$blast_lib_id[0] expect_value=1 ~; close (BLAST) || print "WARNING[$SUB_NAME]: blast params file did not close nicely!
"; print "File ".$output_dir."/blast.params created.
"; return; } # end write_parameters_files ############################################################################### # make_output_dir ############################################################################### sub make_output_dir { my %args = @_; my $SUB_NAME = "make_output_dir"; #### Process the arguments list my $testonly = $args{'testonly'}; my $unique_dir = 0; # my $output_dir = "/net/techdev/biosap_ext"; # for MySQL site my $output_dir = "/net/techdev/biosap/"; # for ISB-internal site ($testonly == 1) ? ($output_dir .= "tmp/") : ($output_dir .= "data/"); #### Create an output directory. Make sure it's unique for (my $i=0; $i<10 && $unique_dir==0; $i++) { my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); $output_dir .= strftime("%Y%m%d.%H%M%S",$sec,$min,$hour,$mday,$mon,$year); if (-e $output_dir) { print "WARNING[$SUB_NAME]: ".$output_dir." is not unique. This is attempt ". ($i+1)." of 10
\n"; sleep 5; }else { $unique_dir = 1; mkdir ($output_dir) || croak "ERROR[$SUB_NAME]: directory ". $output_dir."could not be created.\n".$!; chmod (0777, $output_dir) || croak "ERROR[$SUB_NAME]: could not change". "permissions for directory ".$output_dir."\n"; print "Directory ".$output_dir." created successfully
"; } } return $output_dir; } # end process_request ############################################################################### # Create Request Form ############################################################################### sub create_request_form { my %args = @_; my $SUB_NAME = "create_request_form"; #### Process the arguments list my $ref_parameters = $args{'ref_parameters'} || die "ref_parameters not passed"; my %parameters = %{$ref_parameters}; my ($sql, @rows); my $html; my $o_conc=0.00025; #hard-coded default Oligo concentration my $s_conc=50; #hard-coded default salt concentration #--------------- print_form_head ---------------# $html = qq~
~; print $html; #------------ print_search_bs_sets -------------# $html = qq~

BioSequence Files:

Featurama Library:  (used in Featurama search)
BLAST Library:  (used in BLAST search)

Sanity Check:
Are the sequences for which you want features the same as the BLAST Library you\'ve select? 
~; print $html; #----------- print_search_parameters -----------# $html = qq~

Search Parameters:

Oligo Concentration (mMol): Salt Conc. (mMol):
Tm (0-100): +/- (0-50): Step Size (0-100,000):
Min. Reporter Length (2-100): Max. Reporter Length (Min. Length-100):
Max. 3\' Distance (2-150,000): Max. Reporters per Gene (1-10000):
Initial 3\' Offset (0-100,000): Max. Self-Comp Score (0-Min. Length):
~; print $html; #----------- print_searh_heuristics -----------# $html = qq~

Content Heuristics:

Max. Poly A/T Length (2-Max. Length): Max. Poly G/C Length (2-Max. Length):
Heuristic Window Size (2-Min. Length):
Max. A/T in Window (1-WindowSize): Max. G/C in Window (1-WindowSize):
~; print $html; #------------ print_search_comments -----------# $html = qq~

Comments:




~; print $html; #-------------- print_form_foot ---------------# $html = qq~
~; print $html; return; } # end create_request_form ############################################################################### # verify_parameters ############################################################################### sub verify_parameters { my %args = @_; my $SUB_NAME = "verify_parameters"; #### Process teh arguments list my $ref_parameters = $args{'ref_parameters'} || die "ERROR[$SUB_NAME]:ref_parameters not passed!\n"; my %parameters = %{$ref_parameters}; my $ok = 1; my $same_as_lib = $parameters{'same_as_lib'}; # Featurama Lib and BLAST Lib are the same AND not suppose to be if (($parameters{'featuramalib'} eq $parameters{'blastlib'}) && ($parameters{'same_as_lib'} eq "No")){ print "ERROR: Library files are the same.
\n"; $ok=0; } # Featurama Lib and BLAST Lib are not the same and supposed to be if (($parameters{'featuramalib'} ne $parameters{'blastlib'}) && ($parameters{'same_as_lib'} eq "Yes")) { print "ERROR: Library files are not the same.
\n"; $ok=0; } # Tm my $tm = $parameters{'meltTemp'}; if ($tm > 100 || $tm < 0 || (length($tm)==0 && !($tm=~/^[+-]?0*[.?0|0.?]0*[[eE]+[+-]?\d*[.?\d|\d.?]\d*]*/))) { print "ERROR: Tm is not valid
\n"; $parameters{'meltTemp'} = ""; $ok=0; } # Tm range my $tm_range = $parameters{'meltTempRange'}; if ($tm_range > 50 || $tm_range < 0 || ($tm_range==0 && !($tm =~/^[+-]?0*[.?0|0.?]0*[[eE]+[+-]?\d*[.?\d|\d.?]\d*]*/))) { print "ERROR: Tm range is not valid
\n"; $parameters{'meltTempRange'} = ""; $ok=0; } # Oligo Concentration if ($parameters{'oligoConc'} <= 0) { print "ERROR: Oligo. Conc. is not valid
\n"; $parameters{'oligoConc'} = ""; $ok=0; } # Salt Concentration if ($parameters{'saltConc'} <= 0) { print "ERROR: Salt Conc. is not valid
\n"; $parameters{'saltConc'} = ""; $ok=0; } # Minimum Length my $min_len = $parameters{'minLen'}; if ($min_len > 100 || $min_len < 1 || !($min_len =~ /^[+-]?\d+$/)) { print "ERROR: Min Length is not valid
\n"; $parameters{'minLen'} = ""; $ok=0; } # Maximum Length my $max_len = $parameters{'maxLen'}; if ($max_len > 100 || $max_len < $min_len || $max_len == 0 || !($max_len =~ /^[+-]?\d+$/)) { print "ERROR: Max Length is not valid
"; $parameters{'maxLen'} = ""; $ok=0; } # Self Complementarity my $self_comp = $parameters{'maxSelfComp'}; if ($self_comp>$min_len || $self_comp < 0 || !($max_len =~ /^[+-]?\d+$/)) { print "ERROR: Max Self-Comp is not valid
\n"; $parameters{'maxSelfComp'}=""; $ok=0; } # Step Size my $step = $parameters{'stepSize'}; if ($step > 100000 || $step < 0 || !($step =~ /^[+-]?\d+$/)) { print "ERROR: Step size is not valid
\n"; $parameters{'stepSize'}=""; $ok=0; } # Max 3' Distance my $dist = $parameters{'max3PrimeDist'}; if ($dist > 150000 || $dist < 2 || !($dist =~ /^[+-]?\d+$/)) { print "ERROR: Max 3' distance is not valid
\n"; $parameters{'max3PrimeDist'} = ""; $ok=0; } # Initial 3' Offest my $offset = $parameters{'initOffset'}; if ($offset > 100000 || $offset < 0 || !($offset =~ /^[+-]?\d+$/)) { print "ERROR: Initial 3' offest is not valid
\n"; $parameters{'initOffest'} = ""; $ok=0; } # Maximum Features my $features = $parameters{'maxReporters'}; if ($features > 10000 || $features < 1 || !($features =~ /^[+-]?\d+$/)) { print "ERROR: Maximum features is not valid
\n"; $parameters{'maxReporters'} = ""; $ok=0; } # Maximum Poly AT my $p_AT = $parameters{'maxPolyAT'}; if ($p_AT > $max_len || $p_AT < 2 || !($p_AT =~ /^[+-]?\d+$/)) { print "ERROR:Maximum Poly-AT is not valid
\n"; $parameters{'maxPolyAt'} = ""; $ok=0; } # Maximum Poly GC my $p_GC = $parameters{'maxPolyGC'}; if ($p_GC > $max_len || $p_GC < 2 || !($p_GC =~ /^[+-]?\d+$/)) { print "ERROR:Maximu Poly-GC is not valid
\n" ; $parameters{'maxPolyGC'} = ""; $ok=0; } # Window Size my $win = $parameters{'windowSize'}; if ($win > $min_len || $win < 2 || !($win =~ /^[+-]?\d+$/)) { print "ERROR: Window size is not valid
"; $parameters{'windowSize'}=""; $ok=0; } # Max AT in Window my $win_at = $parameters{'maxATinWindow'}; if ($win_at > $win || $win_at < 1 || !($win_at =~ /^[+-]?\d+$/)) { print "ERROR: Max AT content in window is not valid
"; $parameters{'maxATinWindow'}=""; $ok=0; } # Max GC in Window my $win_gc = $parameters{'maxGCinWindow'}; if ($win_gc > $win || $win_gc < 1 || !($win_gc =~ /^[+-]?\d+$/)) { print "ERROR: Max GC content in window is not valid
"; $parameters{'maxGCinWindow'}=""; $ok=0; } # Comments my $comments = $parameters{'comments'}; if ($comments) { $comments =~ s/<(.*?)/$1/g; } return $ok, \%parameters; }