Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.Blast.NCBIStandalone.Iterator Class Reference

List of all members.

Public Member Functions

def __init__
def next
def __iter__

Private Attributes

 _uhandle
 _parser
 _header

Detailed Description

Iterates over a file of multiple BLAST results.

Methods:
next   Return the next record from the stream, or None.

Definition at line 1591 of file NCBIStandalone.py.


Constructor & Destructor Documentation

def Bio.Blast.NCBIStandalone.Iterator.__init__ (   self,
  handle,
  parser = None 
)
__init__(self, handle, parser=None)

Create a new iterator.  handle is a file-like object.  parser
is an optional Parser object to change the results into another form.
If set to None, then the raw contents of the file will be returned.

Definition at line 1598 of file NCBIStandalone.py.

01598 
01599     def __init__(self, handle, parser=None):
01600         """__init__(self, handle, parser=None)
01601 
01602         Create a new iterator.  handle is a file-like object.  parser
01603         is an optional Parser object to change the results into another form.
01604         If set to None, then the raw contents of the file will be returned.
01605 
01606         """
01607         try:
01608             handle.readline
01609         except AttributeError:
01610             raise ValueError(
01611                 "I expected a file handle or file-like object, got %s"
01612                 % type(handle))
01613         self._uhandle = File.UndoHandle(handle)
01614         self._parser = parser
01615         self._header = []

Here is the caller graph for this function:


Member Function Documentation

Definition at line 1664 of file NCBIStandalone.py.

01664 
01665     def __iter__(self):
01666         return iter(self.next, None)

Here is the call graph for this function:

Here is the caller graph for this function:

next(self) -> object

Return the next Blast record from the file.  If no more records,
return None.

Definition at line 1616 of file NCBIStandalone.py.

01616 
01617     def next(self):
01618         """next(self) -> object
01619 
01620         Return the next Blast record from the file.  If no more records,
01621         return None.
01622 
01623         """
01624         lines = []
01625         query = False
01626         while 1:
01627             line = self._uhandle.readline()
01628             if not line:
01629                 break
01630             # If I've reached the next one, then put the line back and stop.
01631             if lines and (line.startswith('BLAST')
01632                           or line.startswith('BLAST', 1)
01633                           or line.startswith('<?xml ')):
01634                 self._uhandle.saveline(line)
01635                 break
01636             # New style files ommit the BLAST line to mark a new query:
01637             if line.startswith("Query="):
01638                 if not query:
01639                     if not self._header:
01640                         self._header = lines[:]
01641                     query = True
01642                 else:
01643                     #Start of another record
01644                     self._uhandle.saveline(line)
01645                     break
01646             lines.append(line)
01647 
01648         if query and "BLAST" not in lines[0]:
01649             #Cheat and re-insert the header
01650             #print "-"*50
01651             #print "".join(self._header)
01652             #print "-"*50
01653             #print "".join(lines)
01654             #print "-"*50
01655             lines = self._header + lines
01656             
01657         if not lines:
01658             return None
01659             
01660         data = ''.join(lines)
01661         if self._parser is not None:
01662             return self._parser.parse(StringIO.StringIO(data))
01663         return data

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1614 of file NCBIStandalone.py.

Definition at line 1613 of file NCBIStandalone.py.

Definition at line 1612 of file NCBIStandalone.py.


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