Back to index

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

List of all members.

Public Member Functions

def __init__
def __iter__
def get_raw
def get

Private Attributes

 _marker
 _marker_re

Detailed Description

Definition at line 637 of file _index.py.


Constructor & Destructor Documentation

def Bio.SeqIO._index.SequentialSeqFileRandomAccess.__init__ (   self,
  filename,
  format,
  alphabet 
)

Reimplemented from Bio.SeqIO._index.SeqFileRandomAccess.

Definition at line 638 of file _index.py.

00638 
00639     def __init__(self, filename, format, alphabet):
00640         SeqFileRandomAccess.__init__(self, filename, format, alphabet)
00641         marker = {"ace" : "CO ",
00642                   "embl" : "ID ",
00643                   "fasta" : ">",
00644                   "genbank" : "LOCUS ",
00645                   "gb": "LOCUS ",
00646                   "imgt" : "ID ",
00647                   "phd" : "BEGIN_SEQUENCE",
00648                   "pir" : ">..;",
00649                   "qual": ">",
00650                   "qual": ">",
00651                   "swiss" : "ID ",
00652                   "uniprot-xml" : "<entry ",
00653                    }[format]
00654         self._marker = marker
00655         self._marker_re = re.compile(_as_bytes("^%s" % marker))
        

Member Function Documentation

Returns (id,offset) tuples.

Reimplemented from Bio.SeqIO._index.SeqFileRandomAccess.

Reimplemented in Bio.SeqIO._index.UniprotRandomAccess, Bio.SeqIO._index.SwissRandomAccess, Bio.SeqIO._index.EmblRandomAccess, and Bio.SeqIO._index.GenBankRandomAccess.

Definition at line 656 of file _index.py.

00656 
00657     def __iter__(self):
00658         """Returns (id,offset) tuples."""
00659         marker_offset = len(self._marker)
00660         marker_re = self._marker_re
00661         handle = self._handle
00662         handle.seek(0)
00663         #Skip and header before first record
00664         while True:
00665             start_offset = handle.tell()
00666             line = handle.readline()
00667             if marker_re.match(line) or not line:
00668                 break
00669         #Should now be at the start of a record, or end of the file
00670         while marker_re.match(line):
00671             #Here we can assume the record.id is the first word after the
00672             #marker. This is generally fine... but not for GenBank, EMBL, Swiss
00673             id = line[marker_offset:].strip().split(None, 1)[0]
00674             length = len(line)
00675             while True:
00676                 end_offset = handle.tell()
00677                 line = handle.readline()
00678                 if marker_re.match(line) or not line:
00679                     yield _bytes_to_string(id), start_offset, length
00680                     start_offset = end_offset
00681                     break
00682                 else:
00683                     #Track this explicitly as can't do file offset difference on BGZF
00684                     length += len(line)
00685         assert not line, repr(line)

def Bio.SeqIO._index.SeqFileRandomAccess.get (   self,
  offset 
) [inherited]
Returns SeqRecord.

Reimplemented in Bio.SeqIO._index.UniprotRandomAccess, Bio.SeqIO._index.SffTrimedRandomAccess, and Bio.SeqIO._index.SffRandomAccess.

Definition at line 540 of file _index.py.

00540 
00541     def get(self, offset):
00542         """Returns SeqRecord."""
00543         #Should be overriden for binary file formats etc:
00544         return self._parse(StringIO(_bytes_to_string(self.get_raw(offset))))

Here is the call graph for this function:

Similar to the get method, but returns the record as a raw string.

Reimplemented from Bio.SeqIO._index.SeqFileRandomAccess.

Reimplemented in Bio.SeqIO._index.UniprotRandomAccess.

Definition at line 686 of file _index.py.

00686 
00687     def get_raw(self, offset):
00688         """Similar to the get method, but returns the record as a raw string."""
00689         #For non-trivial file formats this must be over-ridden in the subclass
00690         handle = self._handle
00691         marker_re = self._marker_re
00692         handle.seek(offset)
00693         lines = [handle.readline()]
00694         while True:
00695             line = handle.readline()
00696             if marker_re.match(line) or not line:
00697                 #End of file, or start of next record => end of this record
00698                 break
00699             lines.append(line)
00700         return _as_bytes("").join(lines)
00701 

Here is the call graph for this function:


Member Data Documentation

Definition at line 653 of file _index.py.

Definition at line 654 of file _index.py.


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