Skip to content

Add support for NCBI BLAST XML v2 #1839

Closed

Description

@abkomissarov

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

  1. changed the title [-]AttributeError while parsing BLAST XML output[/-] [+]Add support for NCBI BLAST XML v2[/+] on Oct 31, 2018
  2. abkomissarov commented on Nov 1, 2018

    @abkomissarov
    Author

    You do not have the original BLAST XML output, you have BLAST XML v2 which we do not yet support:

    Thanks a lot for clarification. On original XML output it works fine.

  3. peterjc commented on Nov 1, 2018

    @peterjc
    Member

    @bow Would it make sense to add blastxml2 to Bio.SearchIO directly (only), or do you think putting it under Bio.Blast would be just as straightforward?

  4. bow commented on Nov 2, 2018

    @bow
    Member

    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).

  5. peterjc commented on Nov 3, 2018

    @peterjc
    Member

    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.

  6. peterjc commented on Apr 23, 2019

    @peterjc
    Member

    Fixed in #1997, thank you.

    #2031 logged for extending SearchIO as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions