Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Speed up PHYLIP output a bit

  • Loading branch information...
commit 615a625cb579b9e8f3f98a9c312ab9b1b35ddeaf 1 parent dd7342f
@peterjc peterjc authored
Showing with 8 additions and 5 deletions.
  1. +8 −5 Bio/AlignIO/PhylipIO.py
View
13 Bio/AlignIO/PhylipIO.py
@@ -72,6 +72,7 @@ def write_alignment(self, alignment, id_width=_PHYLIP_ID_WIDTH):
# Check for repeated identifiers...
# Apply this test *after* cleaning the identifiers
names = []
+ seqs = []
for record in alignment:
"""
Quoting the PHYLIP version 3.6 documentation:
@@ -102,6 +103,12 @@ def write_alignment(self, alignment, id_width=_PHYLIP_ID_WIDTH):
"possibly due to truncation"
% (name, record.id))
names.append(name)
+ sequence = str(record.seq)
+ if "." in sequence:
+ # Do this check here (once per record, not once per block)
+ raise ValueError("PHYLIP format no longer allows dots in "
+ "sequence")
+ seqs.append(sequence)
# From experimentation, the use of tabs is not understood by the
# EMBOSS suite. The nature of the expected white space is not
@@ -111,7 +118,7 @@ def write_alignment(self, alignment, id_width=_PHYLIP_ID_WIDTH):
handle.write(" %i %s\n" % (len(alignment), length_of_seqs))
block = 0
while True:
- for name, record in zip(names, alignment):
+ for name, sequence in zip(names, seqs):
if block == 0:
#Write name (truncated/padded to id_width characters)
#Now truncate and right pad to expected length.
@@ -120,10 +127,6 @@ def write_alignment(self, alignment, id_width=_PHYLIP_ID_WIDTH):
#write indent
handle.write(" " * id_width)
#Write five chunks of ten letters per line...
- sequence = str(record.seq)
- if "." in sequence:
- raise ValueError("PHYLIP format no longer allows dots in "
- "sequence")
for chunk in range(0, 5):
i = block*50 + chunk*10
seq_segment = sequence[i:i+10]
Please sign in to comment.
Something went wrong with that request. Please try again.