Skip to content

Commit

Permalink
Speed up PHYLIP output a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed Jan 11, 2013
1 parent dd7342f commit 615a625
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Bio/AlignIO/PhylipIO.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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]
Expand Down

0 comments on commit 615a625

Please sign in to comment.