Question: Biopython NCBIcommandline from PHP
0
gravatar for belden
4.1 years ago by
belden0
United States
belden0 wrote:

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

php biopython blast • 1.4k views
ADD COMMENTlink modified 4.0 years ago by Biostar ♦♦ 20 • written 4.1 years ago by belden0

is Blast.py flagged as "executable" ? can you only see/read 

Blast.py from PHP ? 

ADD REPLYlink modified 4.1 years ago • written 4.1 years ago by Pierre Lindenbaum118k

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.

ADD REPLYlink written 4.1 years ago by belden0

Do you get any error message? e.g. via stderr? Are you sure blastn.exe is on the $PATH? If not, you would have to call NcbiblastnCommandline giving the full path to the exe as the first argument.

ADD REPLYlink written 4.0 years ago by Peter5.8k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1174 users visited in the last hour