Permalink
Browse files

Bio/AlignIO: PEP8 whitespace cleanup.

  • Loading branch information...
1 parent e54c5da commit f90bbbdc367df2ea6c2abcc0c38715e1e902c565 @cbrueffer cbrueffer committed with peterjc Dec 26, 2012
Showing with 139 additions and 139 deletions.
  1. +8 −8 Bio/AlignIO/ClustalIO.py
  2. +10 −10 Bio/AlignIO/EmbossIO.py
  3. +21 −21 Bio/AlignIO/FastaIO.py
  4. +1 −1 Bio/AlignIO/NexusIO.py
  5. +44 −44 Bio/AlignIO/PhylipIO.py
  6. +39 −39 Bio/AlignIO/StockholmIO.py
  7. +16 −16 Bio/AlignIO/__init__.py
View
@@ -63,7 +63,7 @@ def write_alignment(self, alignment):
#Make sure we don't get any spaces in the record
#identifier when output in the file by replacing
#them with underscores:
- line = record.id[0:30].replace(" ","_").ljust(36)
+ line = record.id[0:30].replace(" ", "_").ljust(36)
line += str(record.seq[cur_char:(cur_char + show_num)])
output += line + "\n"
@@ -105,7 +105,7 @@ def next(self):
# find the clustal version in the header line
version = None
for word in line.split():
- if word[0]=='(' and word[-1]==')':
+ if word[0] == '(' and word[-1] == ')':
word = word[1:-1]
if word[0] in '0123456789':
version = word
@@ -152,7 +152,7 @@ def next(self):
letters = int(fields[2])
except ValueError:
raise ValueError("Could not parse line, bad sequence number:\n%s" % line)
- if len(fields[1].replace("-","")) != letters:
+ if len(fields[1].replace("-", "")) != letters:
raise ValueError("Could not parse line, invalid sequence number:\n%s" % line)
elif line[0] == " ":
#Sequence consensus line...
@@ -195,7 +195,7 @@ def next(self):
if not line:
break # end of file
- if line.split(None,1)[0] in known_headers:
+ if line.split(None, 1)[0] in known_headers:
#Found concatenated alignment.
done = True
self._header = line
@@ -231,7 +231,7 @@ def next(self):
letters = int(fields[2])
except ValueError:
raise ValueError("Could not parse line, bad sequence number:\n%s" % line)
- if len(seqs[i].replace("-","")) != letters:
+ if len(seqs[i].replace("-", "")) != letters:
raise ValueError("Could not parse line, invalid sequence number:\n%s" % line)
#Read in the next line
@@ -257,7 +257,7 @@ def next(self):
% (len(ids), self.records_per_alignment))
records = (SeqRecord(Seq(s, self.alphabet), id=i, description=i)
- for (i,s) in zip(ids, seqs))
+ for (i, s) in zip(ids, seqs))
alignment = MultipleSeqAlignment(records, self.alphabet)
#TODO - Handle alignment annotation better, for now
#mimic the old parser in Bio.Clustalw
@@ -384,7 +384,7 @@ def next(self):
handle = StringIO()
ClustalWriter(handle).write_file(alignments)
handle.seek(0)
- for i,a in enumerate(ClustalIterator(handle)):
+ for i, a in enumerate(ClustalIterator(handle)):
assert a.get_alignment_length() == alignments[i].get_alignment_length()
handle.seek(0)
@@ -393,7 +393,7 @@ def next(self):
handle = StringIO()
ClustalWriter(handle).write_file([alignment])
handle.seek(0)
- for i,a in enumerate(ClustalIterator(handle)):
+ for i, a in enumerate(ClustalIterator(handle)):
assert a.get_alignment_length() == alignment.get_alignment_length()
assert len(a) == 1
View
@@ -94,15 +94,15 @@ def next(self):
#Read in the rest of this alignment header,
#try and discover the number of records expected
#and their length
- parts = line[1:].split(":",1)
+ parts = line[1:].split(":", 1)
key = parts[0].lower().strip()
if key == "aligned_sequences":
number_of_seqs = int(parts[1].strip())
assert len(ids) == 0
# Should now expect the record identifiers...
for i in range(number_of_seqs):
line = handle.readline()
- parts = line[1:].strip().split(":",1)
+ parts = line[1:].strip().split(":", 1)
assert i+1 == int(parts[0].strip())
ids.append(parts[1].strip())
assert len(ids) == number_of_seqs
@@ -136,33 +136,33 @@ def next(self):
#(an aligned seq is broken up into multiple lines)
id, start = id_start
seq, end = seq_end
- if start==end:
+ if start == end:
#Special case, either a single letter is present,
#or no letters at all.
- if seq.replace("-","") == "":
+ if seq.replace("-", "") == "":
start = int(start)
end = int(end)
else:
start = int(start) - 1
end = int(end)
else:
- assert seq.replace("-","") != ""
+ assert seq.replace("-", "") != ""
start = int(start) - 1 # python counting
end = int(end)
#The identifier is truncated...
assert 0 <= index and index < number_of_seqs, \
"Expected index %i in range [0,%i)" \
% (index, number_of_seqs)
- assert id==ids[index] or id == ids[index][:len(id)]
+ assert id == ids[index] or id == ids[index][:len(id)]
if len(seq_starts) == index:
#Record the start
seq_starts.append(start)
#Check the start...
if start == end:
- assert seq.replace("-","") == "", line
+ assert seq.replace("-", "") == "", line
else:
assert start - seq_starts[index] == len(seqs[index].replace("-","")), \
"Found %i chars so far for sequence %i (%s, %s), line says start %i:\n%s" \
@@ -172,9 +172,9 @@ def next(self):
seqs[index] += seq
#Check the end ...
- assert end == seq_starts[index] + len(seqs[index].replace("-","")), \
+ assert end == seq_starts[index] + len(seqs[index].replace("-", "")), \
"Found %i chars so far for sequence %i (%s, %s, start=%i), file says end %i:\n%s" \
- % (len(seqs[index].replace("-","")), index, id, repr(seqs[index]),
+ % (len(seqs[index].replace("-", "")), index, id, repr(seqs[index]),
seq_starts[index], end, line)
index += 1
@@ -614,6 +614,6 @@ def next(self):
assert len(alignments) == 1
assert len(alignments[0]) == 2
assert [r.id for r in alignments[0]] \
- == ["asis","asis"]
+ == ["asis", "asis"]
print "Done"
View
@@ -60,7 +60,7 @@ def _extract_alignment_region(alignment_seq_with_flanking, annotation):
return align_stripped[start:end]
-def FastaM10Iterator(handle, alphabet = single_letter_alphabet):
+def FastaM10Iterator(handle, alphabet=single_letter_alphabet):
"""Alignment iterator for the FASTA tool's pairwise alignment output.
This is for reading the pairwise alignments output by Bill Pearson's
@@ -149,10 +149,10 @@ def build_hsp():
#Query
#=====
record = SeqRecord(Seq(q, alphabet),
- id = query_id,
- name = "query",
- description = query_descr,
- annotations = {"original_length" : int(query_tags["sq_len"])})
+ id=query_id,
+ name="query",
+ description=query_descr,
+ annotations={"original_length": int(query_tags["sq_len"])})
#TODO - handle start/end coordinates properly. Short term hack for now:
record._al_start = int(query_tags["al_start"])
record._al_stop = int(query_tags["al_stop"])
@@ -167,16 +167,16 @@ def build_hsp():
elif query_tags["sq_type"] == "p":
record.seq.alphabet = generic_protein
if "-" in q:
- if not hasattr(record.seq.alphabet,"gap_char"):
+ if not hasattr(record.seq.alphabet, "gap_char"):
record.seq.alphabet = Gapped(record.seq.alphabet, "-")
#Match
#=====
record = SeqRecord(Seq(m, alphabet),
- id = match_id,
- name = "match",
- description = match_descr,
- annotations = {"original_length" : int(match_tags["sq_len"])})
+ id=match_id,
+ name="match",
+ description=match_descr,
+ annotations={"original_length": int(match_tags["sq_len"])})
#TODO - handle start/end coordinates properly. Short term hack for now:
record._al_start = int(match_tags["al_start"])
record._al_stop = int(match_tags["al_stop"])
@@ -189,7 +189,7 @@ def build_hsp():
elif match_tags["sq_type"] == "p":
record.seq.alphabet = generic_protein
if "-" in m:
- if not hasattr(record.seq.alphabet,"gap_char"):
+ if not hasattr(record.seq.alphabet, "gap_char"):
record.seq.alphabet = Gapped(record.seq.alphabet, "-")
return alignment
@@ -215,7 +215,7 @@ def build_hsp():
yield build_hsp()
state = state_NONE
query_descr = line[line.find(">>>")+3:].strip()
- query_id = query_descr.split(None,1)[0]
+ query_id = query_descr.split(None, 1)[0]
match_id = None
header_tags = {}
align_tags = {}
@@ -256,7 +256,7 @@ def build_hsp():
elif line.startswith(">>>"):
#Should be start of a match!
assert query_id is not None
- assert line[3:].split(", ",1)[0] == query_id, line
+ assert line[3:].split(", ", 1)[0] == query_id, line
assert match_id is None
assert not header_tags
assert not align_tags
@@ -277,7 +277,7 @@ def build_hsp():
match_seq = ""
cons_seq = ""
match_descr = line[2:].strip()
- match_id = match_descr.split(None,1)[0]
+ match_id = match_descr.split(None, 1)[0]
state = state_ALIGN_HEADER
elif line.startswith(">--"):
#End of one HSP
@@ -297,13 +297,13 @@ def build_hsp():
#Should be start of query alignment seq...
assert query_id is not None, line
assert match_id is not None, line
- assert query_id.startswith(line[1:].split(None,1)[0]), line
+ assert query_id.startswith(line[1:].split(None, 1)[0]), line
state = state_ALIGN_QUERY
elif state == state_ALIGN_QUERY:
#Should be start of match alignment seq
assert query_id is not None, line
assert match_id is not None, line
- assert match_id.startswith(line[1:].split(None,1)[0]), line
+ assert match_id.startswith(line[1:].split(None, 1)[0]), line
state = state_ALIGN_MATCH
elif state == state_NONE:
#Can get > as the last line of a histogram
@@ -316,14 +316,14 @@ def build_hsp():
#Next line(s) should be consensus seq...
elif line.startswith("; "):
if ": " in line:
- key, value = [s.strip() for s in line[2:].split(": ",1)]
+ key, value = [s.strip() for s in line[2:].split(": ", 1)]
else:
import warnings
#Seen in lalign36, specifically version 36.3.4 Apr, 2011
#Fixed in version 36.3.5b Oct, 2011(preload8)
warnings.warn("Missing colon in line: %r" % line)
try:
- key, value = [s.strip() for s in line[2:].split(" ",1)]
+ key, value = [s.strip() for s in line[2:].split(" ", 1)]
except ValueError:
raise ValueError("Bad line: %r" % line)
if state == state_QUERY_HEADER:
@@ -613,9 +613,9 @@ def build_hsp():
if os.path.splitext(filename)[-1] == ".m10":
print
print filename
- print "="*len(filename)
- for i,a in enumerate(FastaM10Iterator(open(os.path.join(path,filename)))):
- print "#%i, %s" % (i+1,a)
+ print "=" * len(filename)
+ for i, a in enumerate(FastaM10Iterator(open(os.path.join(path, filename)))):
+ print "#%i, %s" % (i+1, a)
for r in a:
if "-" in r.seq:
assert r.seq.alphabet.gap_char == "-"
View
@@ -199,7 +199,7 @@ def _classify_alphabet_for_nexus(self, alphabet):
handle = StringIO()
try:
- NexusWriter(handle).write_file([a,a])
+ NexusWriter(handle).write_file([a, a])
assert False, "Should have rejected more than one alignment!"
except ValueError:
pass
Oops, something went wrong.

0 comments on commit f90bbbd

Please sign in to comment.