Entering edit mode
10 months ago
Hey guys, i want make a blast with two fasta sequences in python i am using this code:
import os
blastcommand = 'blastp -query a.fasta -subject b.fasta'
os.system(blastcommand)
the output is always "1"
how can i fix that?
That's just the system exit code indicating an error occurred. To capture the output you need to write it to a file and parse it thereafter. See https://www.w3schools.com/python/ref_os_system.asp
I cover sending BLAST output to parseable files & parsing them with Python & Pandas in a series of Jupyter Notebooks available here. I even bring up alternatives like awk for parsing the output. I have a script that I use there that converts the output to a Pandas dataframe that is useful for sorting through data in a Python context. In the context of Jupyter, you can even skip the file output intermediates for the results. You can work through this without installing anything all by going there and clicking 'launch binder' badge near the top or click here to launch a session directly. Everything is installed and loaded in the temporary Jupyter session served via the MyBInder service to work through the examples in the available notebooks that come up listed when the session starts. I suggest working through the available notebooks in the order they are listed there. You'll probably primarily be interested in the earlier ones in the series for now.