Bio.SeqIO.SeqXmlIO module

Bio.SeqIO support for the “seqxml” file format, SeqXML.

This module is for reading and writing SeqXML format files as SeqRecord objects, and is expected to be used via the Bio.SeqIO API.

SeqXML is a lightweight XML format which is supposed be an alternative for FASTA files. For more Information see and Schmitt et al (2011),

class Bio.SeqIO.SeqXmlIO.ContentHandler

Bases: xml.sax.handler.ContentHandler

Handles XML events generated by the parser (PRIVATE).


Create a handler to handle XML events.


Set XML handlers when an XML declaration is found.

startSeqXMLElement(self, name, qname, attrs)

Handle start of a seqXML element.

endSeqXMLElement(self, name, qname)

Handle end of the seqXML element.

startEntryElement(self, name, qname, attrs)

Set new entry with id and the optional entry source (PRIVATE).

endEntryElement(self, name, qname)

Handle end of an entry element.

startEntryFieldElement(self, name, qname, attrs)

Receive a field of an entry element and forward it.

startSpeciesElement(self, attrs)

Parse the species information.

endSpeciesElement(self, name, qname)

Handle end of a species element.

startDescriptionElement(self, attrs)

Parse the description.

endDescriptionElement(self, name, qname)

Handle the end of a description element.

startSequenceElement(self, attrs)

Parse DNA, RNA, or protein sequence.

endSequenceElement(self, name, qname)

Handle the end of a sequence element.

startDBRefElement(self, attrs)

Parse a database cross reference.

endDBRefElement(self, name, qname)

Handle the end of a DBRef element.

startPropertyElement(self, attrs)

Handle the start of a property element.

endPropertyElement(self, name, qname)

Handle the end of a property element.

characters(self, data)

Handle character data.

class Bio.SeqIO.SeqXmlIO.SeqXmlIterator(stream_or_path, namespace=None)

Bases: Bio.SeqIO.Interfaces.SequenceIterator

Parser for seqXML files.

Parses seqXML files and creates SeqRecords. Assumes valid seqXML please validate beforehand. It is assumed that all information for one record can be found within a record element or above. Two types of methods are called when the start tag of an element is reached. To receive only the attributes of an element before its end tag is reached implement _attr_TAGNAME. To get an element and its children as a DOM tree implement _elem_TAGNAME. Everything that is part of the DOM tree will not trigger any further method calls.

BLOCK = 1024
__init__(self, stream_or_path, namespace=None)

Create the object and initialize the XML parser.

parse(self, handle)

Start parsing the file, and return a SeqRecord generator.

iterate(self, handle)

Iterate over the records in the XML file.

__abstractmethods__ = frozenset({})
class Bio.SeqIO.SeqXmlIO.SeqXmlWriter(target, source=None, source_version=None, species=None, ncbiTaxId=None)

Bases: Bio.SeqIO.Interfaces.SequenceWriter

Writes SeqRecords into seqXML file.

SeqXML requires the SeqRecord annotations to specify the molecule_type; the molecule type is required to contain the term “DNA”, “RNA”, or “protein”.

__init__(self, target, source=None, source_version=None, species=None, ncbiTaxId=None)

Create Object and start the xml generator.

  • target - Output stream opened in binary mode, or a path to a file.

  • source - The source program/database of the file, for example UniProt.

  • source_version - The version or release number of the source program or database from which the data originated.

  • species - The scientific name of the species of origin of all entries in the file.

  • ncbiTaxId - The NCBI taxonomy identifier of the species of origin.


Write root node with document metadata.

write_record(self, record)

Write one record.

Close the root node and finish the XML document.