Hi, this is my first post. I am writing a web program in PHP and I want it to perform a python script that performs a local blast (of a fasta file) on my laboratory's server and then return information using json_decode for further processing. The local blast (using Biopython NCBIblastnCommandline) works fine and writes the expected xml file when run in Idle and my PHP program can retrieve the results when run separately. But for some reason it will not execute NcbiblastnCommandline and return the results. I'm developing it on a Windows 7 machine using WAMP but will eventually move it to a server with Ubuntu.
The PHP code is.
<?php $command= "C:/Python27/python C:/path_to_file/Blast.py"; $result = json_decode(exec($command), true); ?>
The Python script is below and I have tried many permutation on it using stdout, sterr, below is my last attempt (probably should have sought help sooner).
#!/usr/bin/python import sys import os from Bio import SeqIO from Bio.Blast.Applications import NcbiblastnCommandline from Bio.Blast import NCBIStandalone data_base = "C:/path_to_file/db" input_handle=open("C:/path_to_file/DNA.fa", "rU") blastn_cline = NcbiblastnCommandline(query="C:/path_to_file/DNA.fa", db=data_base, out="C:/path_to_file/out_file.xml", outfmt=5, task="blastn-short") #save_stdout=sys.stdout #sys.stdout, sys.stderr=blastn_cline() os.system(str(blastn_cline)) input_handle.close # The program then counts the number of alignments and passes the information with json.dumps but left out the code because it runs fine. D={"alignments":i} print json.dumps(D)
If anyone can help I'd really appreciate it.
Thanks,
Bill
is Blast.py flagged as "executable" ? can you only see/read
Blast.py from PHP ?
It can read and execute other python scripts when set up the exact same way. It just won't execute the NCBIBlastnCommandline. The stdout, stderr are commented out because that was causing a problem.
Do you get any error message? e.g. via
stderr
? Are you sureblastn.exe
is on the$PATH
? If not, you would have to callNcbiblastnCommandline
giving the full path to the exe as the first argument.