Back to index

python-biopython  1.60
Public Member Functions
Bio.AlignIO.PhylipIO.SequentialPhylipWriter Class Reference
Inheritance diagram for Bio.AlignIO.PhylipIO.SequentialPhylipWriter:
Inheritance graph
[legend]
Collaboration diagram for Bio.AlignIO.PhylipIO.SequentialPhylipWriter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def write_alignment

Detailed Description

Sequential Phylip format Writer

Definition at line 311 of file PhylipIO.py.


Member Function Documentation

def Bio.AlignIO.PhylipIO.SequentialPhylipWriter.write_alignment (   self,
  alignment,
  id_width = _PHYLIP_ID_WIDTH 
)

Definition at line 315 of file PhylipIO.py.

00315 
00316     def write_alignment(self, alignment, id_width=_PHYLIP_ID_WIDTH):
00317         handle = self.handle
00318 
00319         if len(alignment)==0:
00320             raise ValueError("Must have at least one sequence")
00321         length_of_seqs = alignment.get_alignment_length()
00322         for record in alignment:
00323             if length_of_seqs != len(record.seq):
00324                 raise ValueError("Sequences must all be the same length")
00325         if length_of_seqs <= 0:
00326             raise ValueError("Non-empty sequences are required")
00327 
00328         # Check for repeated identifiers...
00329         # Apply this test *after* cleaning the identifiers
00330         names = []
00331         for record in alignment:
00332             name = record.id.strip()
00333             #Either remove the banned characters, or map them to something
00334             #else like an underscore "_" or pipe "|" character...
00335             for char in "[](),":
00336                 name = name.replace(char,"")
00337             for char in ":;":
00338                 name = name.replace(char,"|")
00339             name = name[:id_width]
00340             if name in names:
00341                 raise ValueError("Repeated name %r (originally %r), "
00342                                  "possibly due to truncation" \
00343                                  % (name, record.id))
00344             names.append(name)
00345 
00346         # From experimentation, the use of tabs is not understood by the
00347         # EMBOSS suite.  The nature of the expected white space is not
00348         # defined in the PHYLIP documentation, simply "These are in free
00349         # format, separated by blanks".  We'll use spaces to keep EMBOSS
00350         # happy.
00351         handle.write(" %i %s\n" % (len(alignment), length_of_seqs))
00352         for name, record in zip(names, alignment):
00353             sequence = str(record.seq)
00354             if "." in sequence:
00355                 raise ValueError("PHYLIP format no longer allows dots in "
00356                                  "sequence")
00357             handle.write(name[:id_width].ljust(id_width))
00358             # Write the entire sequence to one line (see sequential format
00359             # notes in the SequentialPhylipIterator docstring
00360             handle.write(sequence)
00361             handle.write("\n")
00362         


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