Attribute Error Using Biopython Bio.SearchIO.convert
-
26-12-2019 - |
Question
I am writing a script in Python using Biopython modules that will convert Blast XML output to Tabular form. I get an attribute error as follows:
Traceback (most recent call last):
File "C:\Python33\myscripts\Working\Convert_Blast_XML_to_Tabular.py", line 4, in
<module>
from Bio import SearchIO
File "C:\Python33\lib\site-packages\Bio\SearchIO\__init__.py", line 213, in <module>
BiopythonExperimentalWarning)
File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning
file.write(warnings.formatwarning(message, category, filename, lineno, line=line))
AttributeError: 'NoneType' object has no attribute 'write'
Not sure where the problem arises, but I don't think it's my code:
from Bio import SearchIO
import os
blast_out= "some_path"
parsed_out="some_path"
os.chdir(blast_out)
all_files = os.listdir(blast_out)
for single_file in all_files:
print ("Current file is: " + single_file)
#define handles
in_file = single_file
in_fmt = 'blast-xml'
out_file = parsed_out + single_file + '.tab'
out_fmt = 'blast-tab'
out_kwarg = {'comments': True}
SearchIO.convert(in_file, in_fmt, out_file, out_fmt, out_kwargs=out_kwarg)
print ("\nFinished Parsing File.\n")
Solution
This error seems to be triggered by the warning in Bio.SearchIO. I don't know why this is the case, however, you can try disabling the warning before running your script, e.g.
python -W ignore Convert_Blast_XML_to_Tabular.py
If that still doesn't work, try suppressing the warning in the code itself when importing SearchIO:
import warnings
with warnings.catch_warnings():
warnings.simplefilter('ignore')
from Bio import SearchIO
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow