Python Program Accepting Fasta And Blast, Outputting In Xml Then Returning Ids Of All Sequences
0
0
Entering edit mode
10.6 years ago
te502 • 0

Ok. The assignment was to write a program which accepts an input argument of a FASTA file and prints the hit_id of all found sequences using three functions: run_blast (accepting the FASTA and optional input for BLAST, then using subprocess executes BLAST with BLAST output in XML format), read_blast (accepts the above BLAST XML file and returns IDs of sequences), and main (contains main processes the script will execute).

After 4 hours, all I can come up with is this:

import subprocess
from Bio.Blast import NCBIXML
def run_blast(fasta_filename,blastoutput):
    f=open(fasta_filename,'r')###opening the file with reading access           
    lines=f.read() ###lines equates to reading                                  
    col=lines.split("\n")###splits first and second lines                       
    sequence=col[1] ###gives this second column a name                          
    return sequence ###returns the answer of the second line of the FASTA       
fasta_filename='RBP1a.fa'###defining file names                                 
blastoutput='RBP1a.xml'
subprocess.call(['blastn','-query',"fasta_filename",'-db','nt','-outfmt','5','-\
out','blastoutput']) ###blast output in xml form                                
from Bio.Blast import NCBIXML
record=NCBIXML.read(open("blastoutput"))

def read_blast(blastoutput):

#####I don't even know what to put in order to extract the sequences from the XML file. Something about the order isn't correct here.

fasta blast python xml homework • 4.7k views
ADD COMMENT
0
Entering edit mode

I suggest you take a look at the cookbook http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc86 There is an example of a similar thing, I can send you a code that does that if you'd like.

ADD REPLY
0
Entering edit mode

I've been trying to go off of the cookbook, but I don't see where it uses subprocess (which is required in our assignment). I'm a Master's student in BIOLOGY. It was quite a mistake to take this class with no prior programming knowledge.

ADD REPLY
0
Entering edit mode

The Biopython application wrappers can do the subprocess bit for you, but but some of the more advanced examples using stdin/stdout elsewhere in the Biopython Tutorial do this explicitly.

ADD REPLY
0
Entering edit mode

but I would absolutely appreciate it if you could it to me! :)

ADD REPLY
1
Entering edit mode

BioStars isn't really intended for helping people to cheat on their coursework - if you want to share an example, post it openly here please.

ADD REPLY

Login before adding your answer.

Traffic: 1333 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6