[Biophp-dev] New question from the Newbie

S Clark biophp-dev@bioinformatics.org
Mon, 22 Mar 2004 11:10:39 -0700


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

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

On Monday 22 March 2004 09:10 am, Nico Stuurman wrote:
> > The local BLAST module is a frontend for running a local copy of the
> > BLAST database search.
[...]=20
> I guess I meant to ask in which file this is.  I can not find anything
> that looks like a local BLAST interface in the cvs (no doubt my
> oversight).
> Is it in biophp/Sean/semi-official?

What the?....

Okay, looks like I have to proclaim myself an idiot.  APPARENTLY I do not
have this file uploaded to CVS (I would have SWORN that I had, but it's not
there...)

Let me run through and make sure my copy is correct and get it uploaded -
sorry about the confusion!

> Shall we move it to biophp/genephp/interfaces?

Actually, that would be fine - the only reason we'd never gotten around
to moving my modules into the 'genephp' section is because it was never
obvious just where they should go into the existing tree.  'interfaces'=20
makes sense to me.

> Do we have a common scheme to build interfaces to external programs (I
> simply made a function with as parameters the path to the application
> and an array containing all variables to be fed to the application as an
> array with key-value pairs, the function also returns an array with
> key-value pairs generated by the app).

Well, we don't YET, but it looks like now will be a good time to
develop one...

(Meanwhile, here's a copy of the frontend_blast.php module - you'll see
there are still some 'debug' options in there - I've been trying to=20
track down why the one Windows user of the module can't seem to get
BLASTALL.EXE to give back any results...)

And, argh, somehow I seem to have ended up with multiple versions of the
CVS tree on my hard drive - I need to reconcile which is which...

P.S. Perhaps it WOULD be worth experimenting with a switch to SubVersion?
Supposedly, it supports access via WebDAV, which ought to be a lot more
intuitive for people to use than CVS on all platforms (if it's true).
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.9.5 (GNU/Linux)

iD8DBQFAXywhJ6yQLhNTzSkRAgXlAKCDn9tpullig/wJzrU6AXj1SligrQCfQlws
l0OZNXNXFQ8Vxx/qoLjXx9M=3D
=3DuJeG
=2D----END PGP SIGNATURE-----

--Boundary-00=_fwyXA5ICEE6H6o5
Content-Type: application/x-php;
  name="frontend_blast.php"
Content-Transfer-Encoding: 7bit
Content-Description: local blast executable frontend
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");
        $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=_fwyXA5ICEE6H6o5--