Repository navigation
Description
Hi, I'm now learning how to use BioPython for parsing BLAST XML output files. I have got a problem with parsing. Below is my code and the output error - "AttributeError: 'BlastParser' object has no attribute '_blast'". I have no idea how to fix it. Could anyone help me? Thanks a lot in advance.
Sorry if issue formatting is not OK. It's my first issue raised.
XML example file is attached.
python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609]
CPythonLinux-4.4.0-127-generic-x86_64-with-Ubuntu-16.04-xenial
BioPython 1.72
XML-example.zip
My code
`from Bio.Blast import NCBIXML
try:
handle=open(input('Please select XML file: '))
except IOError:
print('Selected file does not exist')
blast_records=NCBIXML.parse(handle)
print(type(blast_records))
for record in blast_records:
for alignment in blast_record.alignments:
for hsp in alignment.hsps:
if hsp.expect <0.01:
print('****Alignment****')
print('sequence:', alignment.title)
print('length:', alignment.length)
print('score:', hsps.score)
print('gaps:', hsps.gaps)
print('e value:', hsp.expect)
print(hsp.query[0:90] + '...')
print(hsp.match[0:90] + '...')
print(hsp.sbjct[0:90] + '...')`
Output
<class 'generator'>
Traceback (most recent call last):
File "./XML_open.py", line 15, in
for record in blast_records:
File "/home/andrey/.local/lib/python3.5/site-packages/Bio/Blast/NCBIXML.py", line 631, in parse
expat_parser.Parse(text, False)
File "../Modules/pyexpat.c", line 414, in StartElement
File "/home/andrey/.local/lib/python3.5/site-packages/Bio/Blast/NCBIXML.py", line 67, in startElement
getattr(self, method)()
File "/home/andrey/.local/lib/python3.5/site-packages/Bio/Blast/NCBIXML.py", line 373, in _start_Hit
self._blast.alignments.append(Record.Alignment())
AttributeError: 'BlastParser' object has no attribute '_blast'
Activity
peterjc commentedon Oct 31, 2018
[-]AttributeError while parsing BLAST XML output[/-][+]Add support for NCBI BLAST XML v2[/+]abkomissarov commentedon Nov 1, 2018
Thanks a lot for clarification. On original XML output it works fine.
peterjc commentedon Nov 1, 2018
@bow Would it make sense to add
blastxml2toBio.SearchIOdirectly (only), or do you think putting it underBio.Blastwould be just as straightforward?bow commentedon Nov 2, 2018
Hmm..my hunch says it's more straightforward to add it directly to SearchIO. And although it's hard for me not to be biased here, I think it's also best if there is one interface for parsing these files (at least for newly supported files).
peterjc commentedon Nov 3, 2018
If it looked easy/clean to extend
NCBIXML.py, then I'd focus on that - but if the new format needs a complete new parser then I'm OK with putting in under SearchIO. Its up to you.peterjc commentedon Apr 23, 2019
Fixed in #1997, thank you.
#2031 logged for extending SearchIO as well.