Back to index

python-biopython  1.60
Public Member Functions | Private Member Functions | Private Attributes
Bio.SeqIO.SeqXmlIO.XMLRecordIterator Class Reference
Inheritance diagram for Bio.SeqIO.SeqXmlIO.XMLRecordIterator:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def __iter__

Private Member Functions

def _attributes

Private Attributes

 _recordTag
 _namespace
 _events

Detailed Description

Base class for building iterators for record style XML formats. 

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.

Definition at line 27 of file SeqXmlIO.py.


Constructor & Destructor Documentation

def Bio.SeqIO.SeqXmlIO.XMLRecordIterator.__init__ (   self,
  handle,
  recordTag,
  namespace = None 
)
Creating the object and initializing the XML parser.

Definition at line 39 of file SeqXmlIO.py.

00039 
00040     def __init__(self,handle,recordTag,namespace=None):
00041         """Creating the object and initializing the XML parser."""
00042         
00043         self._recordTag=recordTag
00044         self._namespace=namespace
00045         self._events=pulldom.parse(handle)
00046         
        

Member Function Documentation

Iterate over the records in the XML file. 
Returns the last parsed record.

Definition at line 47 of file SeqXmlIO.py.

00047 
00048     def __iter__(self):
00049         """Iterate over the records in the XML file. 
00050         Returns the last parsed record.""" 
00051         
00052         record = None
00053         try:
00054             for event,node in self._events:
00055                 
00056                 if event == "START_ELEMENT" and node.namespaceURI == self._namespace:
00057                     
00058                     if node.localName == self._recordTag:
00059                         #create an empty SeqRecord
00060                         record = SeqRecord('', id='')
00061 
00062                     #call matching methods with attributes only                    
00063                     if hasattr(self,"_attr_" + node.localName):
00064                         getattr(self,"_attr_" + node.localName)(self._attributes(node),record)
00065     
00066                     #call matching methods with DOM tree 
00067                     if hasattr(self,"_elem_" + node.localName):
00068                         #read the element and all nested elements into a DOM tree
00069                         self._events.expandNode(node)
00070                         node.normalize()
00071                         
00072                         getattr(self,"_elem_" + node.localName)(node,record)
00073                     
00074                 elif event == "END_ELEMENT" and node.namespaceURI == self._namespace and node.localName == self._recordTag:
00075                     yield record
00076                     
00077         except SAXParseException, e:
00078             
00079             if e.getLineNumber() == 1 and e.getColumnNumber() == 0:
00080                 #empty file
00081                 pass
00082             else:
00083                 import os
00084                 if e.getLineNumber() == 1 and e.getColumnNumber() == 1 \
00085                 and os.name == "java":
00086                     #empty file, see http://bugs.jython.org/issue1774
00087                     pass
00088                 else:
00089                     raise
00090 
    

Here is the call graph for this function:

def Bio.SeqIO.SeqXmlIO.XMLRecordIterator._attributes (   self,
  node 
) [private]
Return the attributes of a DOM node as dictionary.

Definition at line 91 of file SeqXmlIO.py.

00091 
00092     def _attributes(self,node):
00093         """Return the attributes of a DOM node as dictionary."""
00094         
00095         return dict( (node.attributes.item(i).name,node.attributes.item(i).value) for i in xrange(node.attributes.length) )
00096     
00097     

Here is the caller graph for this function:


Member Data Documentation

Definition at line 44 of file SeqXmlIO.py.

Definition at line 43 of file SeqXmlIO.py.

Definition at line 42 of file SeqXmlIO.py.


The documentation for this class was generated from the following file: