Back to index

python-biopython  1.60
Public Member Functions | Static Public Attributes | Private Attributes
Bio.AlignIO.PhylipIO.SequentialPhylipIterator Class Reference
Inheritance diagram for Bio.AlignIO.PhylipIO.SequentialPhylipIterator:
Inheritance graph
[legend]
Collaboration diagram for Bio.AlignIO.PhylipIO.SequentialPhylipIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def next

Static Public Attributes

 id_width = _PHYLIP_ID_WIDTH

Private Attributes

 _header

Detailed Description

Sequential Phylip format Iterator

The sequential format carries the same restrictions as the normal
interleaved one, with the difference being that the sequences are listed
sequentially, each sequence written in its entirety before the start of
the next. According to the PHYLIP documentation for input file formatting,
newlines and spaces may optionally be entered at any point in the sequences.

Definition at line 363 of file PhylipIO.py.


Member Function Documentation

Reimplemented from Bio.AlignIO.PhylipIO.PhylipIterator.

Definition at line 373 of file PhylipIO.py.

00373 
00374     def next(self):
00375         handle = self.handle
00376 
00377         try:
00378             #Header we saved from when we were parsing
00379             #the previous alignment.
00380             line = self._header
00381             del self._header
00382         except AttributeError:
00383             line = handle.readline()
00384 
00385         if not line:
00386             raise StopIteration
00387         line = line.strip()
00388         parts = filter(None, line.split())
00389         if len(parts)!=2:
00390             raise ValueError("First line should have two integers")
00391         try:
00392             number_of_seqs = int(parts[0])
00393             length_of_seqs = int(parts[1])
00394         except ValueError:
00395             raise ValueError("First line should have two integers")
00396 
00397         assert self._is_header(line)
00398 
00399         if self.records_per_alignment is not None \
00400         and self.records_per_alignment != number_of_seqs:
00401             raise ValueError("Found %i records in this alignment, told to expect %i" \
00402                              % (number_of_seqs, self.records_per_alignment))
00403 
00404         ids = []
00405         seqs = []
00406 
00407         # By default, expects STRICT truncation / padding to 10 characters.
00408         # Does not require any whitespace between name and seq.
00409         for i in xrange(number_of_seqs):
00410             line = handle.readline().rstrip()
00411             sequence_id, s = self._split_id(line)
00412             ids.append(sequence_id)
00413             while len(s) < length_of_seqs:
00414                 # The sequence may be split into multiple lines
00415                 line = handle.readline().strip()
00416                 if not line:
00417                     break
00418                 if line == "":
00419                     continue
00420                 s = "".join([s, line.strip().replace(" ", "")])
00421                 if len(s) > length_of_seqs:
00422                     raise ValueError("Found a record of length %i, should be %i" \
00423                             % (len(s), length_of_seqs))
00424             if "." in s:
00425                 raise ValueError("PHYLIP format no longer allows dots in sequence")
00426             seqs.append(s)
00427         while True:
00428             # Find other alignments in the file
00429             line = handle.readline()
00430             if not line:
00431                 break
00432             if self._is_header(line):
00433                 self._header = line
00434                 break
00435 
00436         records = (SeqRecord(Seq(s, self.alphabet), \
00437                              id=i, name=i, description=i) \
00438                    for (i,s) in zip(ids, seqs))
00439         return MultipleSeqAlignment(records, self.alphabet)
00440         

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from Bio.AlignIO.PhylipIO.PhylipIterator.

Definition at line 432 of file PhylipIO.py.

Definition at line 164 of file PhylipIO.py.


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