[Biophp-dev] Re: front end blast

S Clark biophp-dev@bioinformatics.org
Wed, 24 Dec 2003 09:55:41 -0700


--Boundary-00=_NUc6/x/5/qNkHfs
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sorry about being so slow right now!

I've come up with one more thing to try - we're about to leave
for the holidays, so I haven't had time to test this, but I've
made another test version of the blast frontend.
There are two changes - one is that it will ALWAY use=20
'blast_results.html' as the filename for the results (and
without the temporary directory, so it SHOULD show up in the
same directory as the BLAST data files), and it should also
now get the entire text from the command line output instead of
just the last line.  That assumes that I haven't done this too
quickly and made a stupid mistake somewhere, but give it a try
and see what it does.  If I get a chance during the holiday I=20
will check email and see how it goes.  Good luck!


On Monday 22 December 2003 04:23 am, you wrote:
> hi clark !
> ------
> C:\WINDOWS\Temp\BQF273.TMP
> The resulting output will be stored temporarily in:
> C:\WINDOWS\Temp\BRF274.TMP Opened C:\WINDOWS\Temp\BQF273.TMP to save the
> sequence to it. Successfully wrote 52 characters of data to
> C:\WINDOWS\Temp\BQF273.TMP. Setting -i value to C:\WINDOWS\Temp\BQF273.TMP
> Setting -o value to C:\WINDOWS\Temp\BRF274.TMP
> Preparing to attempt to run C:\blast\blastall.exe -p 'blastn' -d 'seq1.tx=
t'
> -i 'C:\WINDOWS\Temp\BQF273.TMP' -o 'C:\WINDOWS\Temp\BRF274.TMP' -v '25' -b
> '25' -T 'T' (If it doesn't work, try running this exact command from a
> console prompt to see what, if any, the error is.) Like, Dude! Something
> went wrong!
> If there is a line of output from the attempt, you'll see it here:
> -----
> when i go to C:\windows\temp\BQF273.tmp and i open it with wordpad or IE i
> find the sequence i entered, which prove that the file was opened with
> writing, but the file C:\windows\temp\BQR274.tmp contains no output result
> , it seems like the file was not opened or the writing result operation d=
id
> not happen ! I THINK THAT the $resultfname is not open to write in it the
> blast results when the blast runs !! whereas we open $queryfname to write
> in it blastsequence ?,??? do u think it could be that the problem ?
> ANIBA
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Another distracting business trip (what's a mere 700 mile drive?) but
> > while I'm here I'm going to try to get some time to make one last attem=
pt
> > to figure out what's going on. It sounds like we've got it boiled
> > down to something to do with getting blastall.exe on windows to properly
> > generate the output file...
> >
> > Hopefully be able to post a further 'debug' attempt sometime tomorrow.
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.2.3 (GNU/Linux)
> >
> > iD8DBQE/0rFdJ6yQLhNTzSkRAptCAJwL/FRZKT4rpMBE6NmsSdoI9Wq7QgCgvYJ4
> > 2d/e/hmzxNWqN6V3ip/aOC0=3D
> > =3DR+ax
> > -----END PGP SIGNATURE-----
>
> Acc=E9dez au courrier =E9lectronique de La Poste : www.laposte.net ;
> 3615 LAPOSTENET (0,34=80/mn) ; t=E9l : 08 92 68 13 50 (0,34=80/mn)
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/6cURJ6yQLhNTzSkRAsO2AJ9fRU4Px6wvj320mxyG3M4cEpHqjACffjkd
SQ0hdKbdfkq7cYAbyfCtOFw=3D
=3DFtIv
=2D----END PGP SIGNATURE-----

--Boundary-00=_NUc6/x/5/qNkHfs
Content-Type: application/x-php;
  name="frontend_blast.php"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="frontend_blast.php"

<?php
/*
Frontend for 'local' BLAST program(s)
Copyright 2003 by Sean Clark
Consider this released (by default) under the terms of the GPL 2.0
*/

class Frontend_Blast
{
    var $FRONTEND_BLAST_EXEC_DEFAULTS = Array('-p'=>'','-d'=>'nr',
    '-i'=>'STDIN','-e'=>'10.0','-m'=>'0','-o'=>'STDOUT','-F'=>'T','-G'=>'0','-E'=>'0','-X'=>'0',
    '-I'=>'F','-q'=>'-3','-r'=>'1','-v'=>'500','-b'=>'250','-f'=>'0','-g'=>'T','-Q'=>'1',
    '-D'=>'1','-a'=>'1','-J'=>'F','-M'=>'BLOSUM62','-W'=>'0','-z'=>'0','-K'=>'0','-P'=>'0',
    '-Y'=>'0','-S'=>'3','-T'=>'F','-U'=>'F','-y'=>'0.0','-Z'=>'0.0','-n'=>'F','-A'=>'0',
    '-w'=>'0','-t'=>'0','-B'=>'0');//default values in the BLAST executable for non-optional flags

    var $blastExecDefaults = Array('-p'=>'blastn','-d'=>'nr',
    '-i'=>'./blast-query.txt','-e'=>'10.0','-m'=>'7','-o'=>'./blast-results.xml','-F'=>'T','-G'=>'0','-E'=>'0','-X'=>'0',
    '-I'=>'F','-q'=>'-3','-r'=>'1','-v'=>'25','-b'=>'25','-f'=>'0','-g'=>'T','-Q'=>'1',
    '-D'=>'1','-a'=>'1','-J'=>'F','-M'=>'BLOSUM62','-W'=>'0','-z'=>'0','-K'=>'0','-P'=>'0',
    '-Y'=>'0','-S'=>'3','-T'=>'F','-U'=>'F','-y'=>'0.0','-Z'=>'0.0','-n'=>'F','-A'=>'0',
    '-w'=>'0','-t'=>'0','-B'=>'0'); //default values used by this module

    var $blastExecParams=Array(); //currently-used parameters for blastall executable

    var $blastExecPath; //path to local blastall executable

    var $blastSequence; //string containing sequence to BLAST
    
    var $dataDir; //location of BLAST database(s) to be used

    var $results=""; //text of BLAST results
    
    var $errorstr=""; //if blast doesn't execute, error line goes here
    
    var $tempDir="/tmp";
    
//########Class Constructor################
    function Frontend_Blast($blastpath="")
    {//may be passed a path to the blast executable on instantiation
    //or set later with blastExecPath() method
        if ($blastpath!="") {
            $this->blastExecPath($blastpath);
            $this->blastExecParams=$this->blastExecDefaults; //set default parameters
            }
    }
    
//########Interface methods################
    function blastDataDir($datadir="")
    {//if passed a directory containing BLAST db files, sets it.
    //returns false if passed a dir that doesn't contain db files
    //if no errors, returns current data dir
        if ($datadir!="") {
   
                $this->dataDir=$datadir;
            
        }
        return $this->dataDir;
    }
    
    function blastExecPath($blastpath="")
    {//if a full path to blastall executable is passed, set it
    //if a path is passed and the file doesn't exist, return false, otherwise
    //return current blastExecPath
    //example: "/usr/local/bin/blastall" or "C:\Blast\BLASTALL.EXE"
        if ($blastpath!="") {
            if (file_exists($blastpath)) {
                $this->blastExecPath=$blastpath;
            } else {
                return false; //could not set path
            }
        }
        return $this->blastExecPath;
    }    

    function blastParam($param="",$value="")
    {//if nothing is passed, return the entire array of currently-set
    //parameters.
    //if a parameter name is passed without a value, return that parameter's current value
    //if both parameter and value are passed, set the parameter to that value, then return that value.
    //return 'false' if passed a non-existent parameter name
    //These are the same as the command-line parameters, so to set the e-value to 1.0, for example, 
    //blastParam("-e","1.0");
    //TODO - add validation of value for parameters passed and return false if invalid
        if ($param=="") {
            return $this->blastExecParams;
        } else if ($value=="") {
            if (isset($this->blastExecParams[$param])) {
                return $this->blastExecParams[$param];
            } else {
                return false;
            }
        } else {
            if ($param=="-d") { //special handler for database file name
                $this->setDB($value);
            }
            if (isset($this->blastExecParams[$param])) {
            //only allow 'legal' parameters         
                $this->blastExecParams[$param]=$value;
                return $this->blastExecParams[$param];
            } else {
                return false;
            }
        }
    }
    
    function blastSequence($sequence="")
    {//if passed a sequence to BLAST, makes a note of it.
    //either way, returns the currently-set sequence-to-blast
        if ($sequence!="") {
            $this->blastSequence=$sequence;
        }
        return $this->blastSequence;
    }
    
    function error()
    {
        return $this->errorstr;
    }
    
    function results()
    {
        return $this->results;
    }
    
    function setDB($dbname)
    {
        $this->blastExecParams['-d']=$dbname;
    }
//############other stuff###############    
    function doBlast() 
    {//attempts to run the BLAST query
        $returnval=0; //return value of the blast execution - checks for runtime errors
        $execparmstr=""; //will hold 'not blast executable default' parameters
        $lastline="";//last line of BLAST command output (not results)
        
        //create temp files to hold query for blast and text of results
        $queryfname=tempnam($this->tempDir,"BQ");
        //modified for DEBUG
        //$resultfname=tempnam($this->tempDir,"BR");
        $resultfname="blast_results.xml";
        $qhandle=fopen($queryfname,"w");
        fwrite($qhandle,$this->blastSequence."\n");
        fclose($qhandle);
        $this->blastParam("-i",$queryfname);
        //MODIFIED for Debugging purposes
        //$this->blastParam("-o",$resultfname);
        $this->blastParam("-o","blast_results.xml");
        foreach (array_keys($this->blastExecParams) as $param) {
            if ($this->blastExecParams[$param] != $this->FRONTEND_BLAST_EXEC_DEFAULTS[$param]) {
                $execparmstr.=" $param ".escapeshellarg($this->blastExecParams[$param]);
            }
        }
        
        //now actually attempt to execute
        $cwd=getcwd();
        chdir($this->dataDir);
        //
        //$lastline=system($this->blastExecPath.$execparmstr,$returnval);
        $exec="$this->blastExecPath $execparmstr";
        $lastline=`$exec`;
        if (filesize($resultfname) > 0) {//shell programs should return 0 on proper execution
            $this->results=file_get_contents($resultfname);
            chdir($cwd);
            
            return true;
        } else {
            $this->errorstr=$lastline;
            unlink($queryfname);
            unlink($resultfname);
            chdir($cwd);
            return false;
        }
        
    }
}
?>

--Boundary-00=_NUc6/x/5/qNkHfs--