Skip to content

Commit

Permalink
Updates all unchanged Bio.Seq.tostring() to str(Bio.Seq)
Browse files Browse the repository at this point in the history
  • Loading branch information
bow authored and peterjc committed Sep 4, 2012
1 parent 97b6aea commit 79842f4
Show file tree
Hide file tree
Showing 39 changed files with 620 additions and 619 deletions.
2 changes: 1 addition & 1 deletion Bio/Align/AlignInfo.py
Expand Up @@ -697,7 +697,7 @@ def print_info_content(summary_info,fout=None,rep_record=0):

alignment = AlignIO.read(open(filename), format)
for record in alignment:
print record.seq.tostring()
print str(record.seq)
print "="*alignment.get_alignment_length()

summary = SummaryInfo(alignment)
Expand Down
6 changes: 3 additions & 3 deletions Bio/AlignIO/ClustalIO.py
Expand Up @@ -63,7 +63,7 @@ def write_alignment(self, alignment):
#identifier when output in the file by replacing
#them with underscores:
line = record.id[0:30].replace(" ","_").ljust(36)
line += record.seq[cur_char:(cur_char + show_num)].tostring()
line += str(record.seq[cur_char:(cur_char + show_num)])
output += line + "\n"

# now we need to print out the star info, if we've got it
Expand Down Expand Up @@ -349,7 +349,7 @@ def next(self):
assert 2 == len(alignment)
assert alignment[0].id == "gi|4959044|gb|AAD34209.1|AF069"
assert alignment[1].id == "gi|671626|emb|CAA85685.1|"
assert alignment[0].seq.tostring() == \
assert str(alignment[0].seq) == \
"MENSDSNDKGSDQSAAQRRSQMDRLDREEAFYQFVNNLSEEDYRLMRDNN" + \
"LLGTPGESTEEELLRRLQQIKEGPPPQSPDENRAGESSDDVTNSDSIIDW" + \
"LNSVRQTGNTTRSRQRGNQSWRAVSRTNPNSGDFRFSLEINVNRNNGSQT" + \
Expand All @@ -362,7 +362,7 @@ def next(self):
alignment = alignments[0]
assert 9 == len(alignment)
assert alignment[-1].id == "HISJ_E_COLI"
assert alignment[-1].seq.tostring() == \
assert str(alignment[-1].seq) == \
"MKKLVLSLSLVLAFSSATAAF-------------------AAIPQNIRIG" + \
"TDPTYAPFESKNS-QGELVGFDIDLAKELCKRINTQCTFVENPLDALIPS" + \
"LKAKKIDAIMSSLSITEKRQQEIAFTDKLYAADSRLV"
Expand Down
2 changes: 1 addition & 1 deletion Bio/AlignIO/NexusIO.py
Expand Up @@ -106,7 +106,7 @@ def write_alignment(self, alignment):
n = Nexus.Nexus(minimal_record)
n.alphabet = alignment._alphabet
for record in alignment:
n.add_sequence(record.id, record.seq.tostring())
n.add_sequence(record.id, str(record.seq))
n.write_nexus_data(self.handle)

def _classify_alphabet_for_nexus(self, alphabet):
Expand Down
8 changes: 4 additions & 4 deletions Bio/AlignIO/PhylipIO.py
Expand Up @@ -504,15 +504,15 @@ def next(self):
for record in alignment:
count=count+1
print record.id
#print record.seq.tostring()
#print str(record.seq)
assert count == 8

expected="""mkklvlslsl vlafssataa faaipqniri gtdptyapfe sknsqgelvg
fdidlakelc krintqctfv enpldalips lkakkidaim sslsitekrq qeiaftdkly
aadsrlvvak nsdiqptves lkgkrvgvlq gttqetfgne hwapkgieiv syqgqdniys
dltagridaafqdevaaseg flkqpvgkdy kfggpsvkde klfgvgtgmg lrkednelre
alnkafaemradgtyeklak kyfdfdvygg""".replace(" ","").replace("\n","").upper()
assert record.seq.tostring().replace("-","") == expected
assert str(record.seq).replace("-","") == expected

#From here:
#http://atgc.lirmm.fr/phyml/usersguide.html
Expand Down Expand Up @@ -550,7 +550,7 @@ def next(self):

for i in range(0,5):
list2[0][i].id == list3[0][i].id
list2[0][i].seq.tostring() == list3[0][i].seq.tostring()
str(list2[0][i].seq) == str(list3[0][i].seq)

#From here:
#http://evolution.genetics.washington.edu/phylip/doc/sequence.html
Expand Down Expand Up @@ -630,5 +630,5 @@ def next(self):
assert len(a1) == len(a2)
for r1, r2 in zip(a1, a2):
assert r1.id == r2.id
assert r1.seq.tostring() == r2.seq.tostring()
assert str(r1.seq) == str(r2.seq)
print "Done"
2 changes: 1 addition & 1 deletion Bio/AlignIO/StockholmIO.py
Expand Up @@ -205,7 +205,7 @@ def _write_record(self, record):
if seq_name in self._ids_written:
raise ValueError("Duplicate record identifier: %s" % seq_name)
self._ids_written.append(seq_name)
self.handle.write("%s %s\n" % (seq_name, record.seq.tostring()))
self.handle.write("%s %s\n" % (seq_name, str(record.seq)))

#The recommended placement for GS lines (per sequence annotation)
#is above the alignment (as a header block) or just below the
Expand Down
2 changes: 1 addition & 1 deletion Bio/GA/Organism.py
Expand Up @@ -123,7 +123,7 @@ def __init__(self, genome, fitness_calculator, start_fitness = None):
def __str__(self):
"""Provide a string output for debugging.
"""
return "Genome: %s; Fitness %s" % (self.genome.tostring(), self.fitness)
return "Genome: %s; Fitness %s" % (str(self.genome), self.fitness)

def __eq__(self, other):
"""Compare organisms by their genomes (as strings of letters).
Expand Down
2 changes: 1 addition & 1 deletion Bio/GA/Repair/Stabilizing.py
Expand Up @@ -44,7 +44,7 @@ def repair(self, organism):
while 1:
# first find all of the ambigous items
seq_genome = new_org.genome.toseq()
all_ambiguous = self._ambig_finder.find_ambiguous(seq_genome.tostring())
all_ambiguous = self._ambig_finder.find_ambiguous(str(seq_genome))

# if we have less then the number of ambiguous allowed, stop
if len(all_ambiguous) <= self._num_ambiguous:
Expand Down
4 changes: 2 additions & 2 deletions Bio/NeuralNetwork/Gene/Motif.py
Expand Up @@ -71,7 +71,7 @@ def _get_motif_dict(self, seq_records, motif_size):

# now start finding motifs in the sequence
for start in range(len(seq_record.seq) - (motif_size - 1)):
motif = seq_record.seq[start:start + motif_size].tostring()
motif = str(seq_record.seq[start:start + motif_size])

# if we are being alphabet strict, make sure the motif
# falls within the specified alphabet
Expand Down Expand Up @@ -187,7 +187,7 @@ def representation(self, sequence):

# count all of the motifs we are looking for in the sequence
for start in range(len(sequence) - (self._motif_size - 1)):
motif = sequence[start:start + self._motif_size].tostring()
motif = str(sequence[start:start + self._motif_size])

if motif in seq_motifs:
seq_motifs[motif] += 1
Expand Down
4 changes: 2 additions & 2 deletions Bio/NeuralNetwork/Gene/Pattern.py
Expand Up @@ -63,9 +63,9 @@ def write_seq(self, seq_pattern_list, output_handle):
for seq_pattern in seq_pattern_list:
if isinstance(seq_pattern, MutableSeq):
seq = seq_pattern.toseq()
all_patterns.append(seq.tostring())
all_patterns.append(str(seq))
elif isinstance(seq_pattern, Seq):
all_patterns.append(seq_pattern.tostring())
all_patterns.append(str(seq_pattern))
else:
raise ValueError("Unexpected pattern type %r" % seq_pattern)

Expand Down
14 changes: 7 additions & 7 deletions Bio/NeuralNetwork/Gene/Schema.py
Expand Up @@ -248,7 +248,7 @@ def find_schemas(self, fitness, num_schemas):
# convert the Genome from a MutableSeq to a Seq so that
# the schemas are just strings (and not array("c")s)
seq_genome = org.genome.toseq()
schema_info[seq_genome.tostring()] = org.fitness
schema_info[str(seq_genome)] = org.fitness

return PatternRepository(schema_info)

Expand Down Expand Up @@ -289,20 +289,20 @@ def calculate_fitness(self, genome):
"""
# convert the genome into a string
seq_motif = genome.toseq()
motif = seq_motif.tostring()
motif = str(seq_motif)

# get the counts in the positive examples
num_pos = 0
for seq_record in self._pos_seqs:
cur_counts = self._schema_eval.num_matches(motif,
seq_record.seq.tostring())
str(seq_record.seq))
num_pos += cur_counts

# get the counts in the negative examples
num_neg = 0
for seq_record in self._neg_seqs:
cur_counts = self._schema_eval.num_matches(motif,
seq_record.seq.tostring())
str(seq_record.seq))

num_neg += cur_counts

Expand Down Expand Up @@ -349,13 +349,13 @@ def calculate_fitness(self, genome):
"""
# convert the genome into a string
seq_motif = genome.toseq()
motif = seq_motif.tostring()
motif = str(seq_motif)

# find the number of times the genome matches
num_times = 0
for seq_record in self._records:
cur_counts = self._evaluator.num_matches(motif,
seq_record.seq.tostring())
str(seq_record.seq))
num_times += cur_counts

return num_times
Expand Down Expand Up @@ -510,7 +510,7 @@ def representation(self, sequence):
schema_counts = []

for schema in self._schemas:
num_counts = self._converter.num_matches(schema, sequence.tostring())
num_counts = self._converter.num_matches(schema, str(sequence))
schema_counts.append(num_counts)

# normalize the counts to go between zero and one
Expand Down
8 changes: 4 additions & 4 deletions Bio/NeuralNetwork/Gene/Signature.py
Expand Up @@ -75,11 +75,11 @@ def _get_signature_dict(self, seq_records, sig_size, max_gap):
largest_sig_size = sig_size * 2 + max_gap
for start in range(len(seq_record.seq) - (largest_sig_size - 1)):
# find the first part of the signature
first_sig = seq_record.seq[start:start + sig_size].tostring()
first_sig = str(seq_record.seq[start:start + sig_size])

# now find all of the second parts of the signature
for second in range(start + 1, (start + 1) + max_gap):
second_sig = seq_record.seq[second: second + sig_size].tostring()
second_sig = str(seq_record.seq[second: second + sig_size])

# if we are being alphabet strict, make sure both parts
# of the sig fall within the specified alphabet
Expand Down Expand Up @@ -188,11 +188,11 @@ def representation(self, sequence):
for start in range(len(sequence) - (smallest_sig_size - 1)):
# if the first part matches any of the signatures we are looking
# for, then expand out to look for the second part
first_sig = sequence[start:start + sig_size].tostring()
first_sig = str(sequence[start:start + sig_size])
if first_sig in all_first_sigs:
for second in range(start + sig_size,
(start + sig_size + 1) + self._max_gap):
second_sig = sequence[second:second + sig_size].tostring()
second_sig = str(sequence[second:second + sig_size])

# if we find the motif, increase the counts for it
if (first_sig, second_sig) in sequence_sigs:
Expand Down
31 changes: 16 additions & 15 deletions Bio/Nexus/Nexus.py
Expand Up @@ -262,7 +262,7 @@ def _unique_label(previous_labels,label):

def _seqmatrix2strmatrix(matrix):
"""Converts a Seq-object matrix to a plain sequence-string matrix."""
return dict([(t,matrix[t].tostring()) for t in matrix])
return dict([(t, str(matrix[t])) for t in matrix])

def _compact4nexus(orig_list):
"""Transform [1 2 3 5 6 7 8 12 15 18 20] (baseindex 0, used in the Nexus class)
Expand Down Expand Up @@ -335,13 +335,13 @@ def combine(matrices):
m_only=[t for t in m.taxlabels if t not in both]
for t in both:
# concatenate sequences and unify gap and missing character symbols
combined.matrix[t]+=Seq(m.matrix[t].tostring().replace(m.gap,combined.gap).replace(m.missing,combined.missing),combined.alphabet)
combined.matrix[t]+=Seq(str(m.matrix[t]).replace(m.gap,combined.gap).replace(m.missing,combined.missing),combined.alphabet)
# replace date of missing taxa with symbol for missing data
for t in combined_only:
combined.matrix[t]+=Seq(combined.missing*m.nchar,combined.alphabet)
for t in m_only:
combined.matrix[t]=Seq(combined.missing*combined.nchar,combined.alphabet)+\
Seq(m.matrix[t].tostring().replace(m.gap,combined.gap).replace(m.missing,combined.missing),combined.alphabet)
Seq(str(m.matrix[t]).replace(m.gap,combined.gap).replace(m.missing,combined.missing),combined.alphabet)
combined.taxlabels.extend(m_only) # new taxon list
for cn,cs in m.charsets.iteritems(): # adjust character sets for new matrix
combined.charsets['%s.%s' % (n,cn)]=[x+combined.nchar for x in cs]
Expand Down Expand Up @@ -854,12 +854,12 @@ def _matrix(self,options):
else:
if self.matchchar:
while 1:
p=iupac_seq.tostring().find(self.matchchar)
p=str(iupac_seq).find(self.matchchar)
if p==-1:
break
iupac_seq=Seq(iupac_seq.tostring()[:p]+refseq[p]+iupac_seq.tostring()[p+1:],self.alphabet)
iupac_seq=Seq(str(iupac_seq)[:p]+refseq[p]+str(iupac_seq)[p+1:],self.alphabet)
#check for invalid characters
for i,c in enumerate(iupac_seq.tostring()):
for i,c in enumerate(str(iupac_seq)):
if c not in self.valid_characters and c!=self.gap and c!=self.missing:
raise NexusError( \
('Taxon %s: Illegal character %s in sequence %s ' + \
Expand Down Expand Up @@ -1425,8 +1425,8 @@ def export_fasta(self, filename=None, width=70):
fh=open(filename,'w')
for taxon in self.taxlabels:
fh.write('>'+safename(taxon)+'\n')
for i in range(0, len(self.matrix[taxon].tostring()), width):
fh.write(self.matrix[taxon].tostring()[i:i+width] + '\n')
for i in range(0, len(str(self.matrix[taxon])), width):
fh.write(str(self.matrix[taxon])[i:i+width] + '\n')
fh.close()
return filename

Expand All @@ -1443,7 +1443,7 @@ def export_phylip(self, filename=None):
fh=open(filename,'w')
fh.write('%d %d\n' % (self.ntax,self.nchar))
for taxon in self.taxlabels:
fh.write('%s %s\n' % (safename(taxon),self.matrix[taxon].tostring()))
fh.write('%s %s\n' % (safename(taxon), str(self.matrix[taxon])))
fh.close()
return filename

Expand All @@ -1458,7 +1458,8 @@ def constant(self,matrix=None,delete=[],exclude=[]):
return [x for x in range(len(matrix[undelete[0]])) if x not in exclude]
# get the first sequence and expand all ambiguous values
constant=[(x,self.ambiguous_values.get(n.upper(),n.upper())) for
x,n in enumerate(matrix[undelete[0]].tostring()) if x not in exclude]
x,n in enumerate(str(matrix[undelete[0]])) if x not in exclude]

for taxon in undelete[1:]:
newconstant=[]
for site in constant:
Expand Down Expand Up @@ -1533,7 +1534,7 @@ def crop_matrix(self,matrix=None, delete=[], exclude=[]):
undelete=[t for t in self.taxlabels if t in matrix and t not in delete]
if not undelete:
return {}
m=[matrix[k].tostring() for k in undelete]
m=[str(matrix[k]) for k in undelete]
zipped_m=zip(*m)
sitesm=[s for i,s in enumerate(zipped_m) if i not in exclude]
if sitesm==[]:
Expand All @@ -1557,7 +1558,7 @@ def bootstrap(self,matrix=None,delete=[],exclude=[]):
return cm
undelete=[t for t in self.taxlabels if t in cm]
if seqobjects:
sitesm=zip(*[cm[t].tostring() for t in undelete])
sitesm=zip(*[str(cm[t]) for t in undelete])
alphabet=matrix[matrix.keys()[0]].alphabet
else:
sitesm=zip(*[cm[t] for t in undelete])
Expand Down Expand Up @@ -1624,7 +1625,7 @@ def _adjust(set,x,d,leftgreedy=False):
return
if self.taxlabels:
#python 2.3 does not support zip(*[])
sitesm=zip(*[self.matrix[t].tostring() for t in self.taxlabels])
sitesm=zip(*[str(self.matrix[t]) for t in self.taxlabels])
else:
sitesm=[]
sitesm[pos:pos]=[['-']*len(self.taxlabels)]*n
Expand Down Expand Up @@ -1683,7 +1684,7 @@ def gaponly(self,include_missing=False):
gap=set(self.gap)
if include_missing:
gap.add(self.missing)
sitesm=zip(*[self.matrix[t].tostring() for t in self.taxlabels])
sitesm=zip(*[str(self.matrix[t]) for t in self.taxlabels])
gaponly=[i for i,site in enumerate(sitesm) if set(site).issubset(gap)]
return gaponly

Expand All @@ -1698,7 +1699,7 @@ def terminal_gap_to_missing(self,missing=None,skip_n=True):
if not skip_n:
replace.extend(['n','N'])
for taxon in self.taxlabels:
sequence=self.matrix[taxon].tostring()
sequence=str(self.matrix[taxon])
length=len(sequence)
start,end=get_start_end(sequence,skiplist=replace)
if start==-1 and end==-1:
Expand Down
4 changes: 2 additions & 2 deletions Bio/Restriction/PrintFormat.py
Expand Up @@ -320,8 +320,8 @@ def _make_map_only(self, ls, title, nc = [], s1 = ''):
break
cutloc[x] = l
cutloc[x] = mapping
sequence = self.sequence.tostring()
revsequence = self.sequence.complement().tostring()
sequence = str(self.sequence)
revsequence = str(self.sequence.complement())
a = '|'
base, counter = 0, 0
emptyline = ' ' * 60
Expand Down
2 changes: 1 addition & 1 deletion Bio/Restriction/Restriction.py
Expand Up @@ -144,7 +144,7 @@ def __init__(self, seq, linear = True):
if seq is a FormattedSeq, linear will have no effect on the
shape of the sequence."""
if isinstance(seq, Seq) or isinstance(seq, MutableSeq):
stringy = seq.tostring()
stringy = str(seq)
self.lower = stringy.islower()
#Note this adds a leading space to the sequence (!)
self.data = _check_bases(stringy)
Expand Down
6 changes: 3 additions & 3 deletions Bio/Restriction/_Update/RestrictionCompiler.py
Expand Up @@ -119,7 +119,7 @@ def Antiparallel(sequence):
returns a string which represents the reverse complementary strand of
a DNA sequence."""
return antiparallel(sequence.tostring())
return antiparallel(str(sequence))

def is_palindrom(sequence):
"""is_palindrom(sequence) -> bool.
Expand Down Expand Up @@ -949,10 +949,10 @@ def information_mixer(self, file1, file2, file3):
print name, 'has two different sites.\n'
other = line[0].replace("-","_")
dna = DNA(line[1])
sense1 = regex(dna.tostring())
sense1 = regex(str(dna))
antisense1 = regex(Antiparallel(dna))
dna = DNA(enzymedict[other][0])
sense2 = regex(dna.tostring())
sense2 = regex(str(dna))
antisense2 = regex(Antiparallel(dna))
sense = '(?P<'+other+'>'+sense1+'|'+sense2+')'
antisense = '(?P<'+other+'_as>'+antisense1+'|'+antisense2 + ')'
Expand Down
2 changes: 1 addition & 1 deletion Bio/SeqIO/SeqXmlIO.py
Expand Up @@ -334,7 +334,7 @@ def _write_seq(self,record):
if isinstance(record.seq,UnknownSeq):
raise TypeError("Sequence type is UnknownSeq but SeqXML requires sequence")

seq = record.seq.tostring()
seq = str(record.seq)

if not len(seq) > 0:
raise ValueError("The sequence length should be greater than 0")
Expand Down
2 changes: 1 addition & 1 deletion Bio/SeqIO/SwissIO.py
Expand Up @@ -153,7 +153,7 @@ def SwissIterator(handle):
print record.id
print record.annotations['keywords']
print repr(record.annotations['organism'])
print record.seq.tostring()[:20] + "..."
print str(record.seq)[:20] + "..."
for f in record.features: print f
handle.close()

0 comments on commit 79842f4

Please sign in to comment.