Skip to content

Commit

Permalink
Remove last remnants of Seq.tostring and deprecate it
Browse files Browse the repository at this point in the history
  • Loading branch information
bow authored and peterjc committed Mar 27, 2014
1 parent 70c191e commit cab9b20
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
32 changes: 17 additions & 15 deletions Bio/Seq.py
Expand Up @@ -292,16 +292,14 @@ def __radd__(self, other):
raise TypeError

def tostring(self): # Seq API requirement
"""Returns the full sequence as a python string (semi-obsolete).
Although not formally deprecated, you are now encouraged to use
str(my_seq) instead of my_seq.tostring()."""
#TODO - Fix all places elsewhere in Biopython using this method,
#then start deprecation process?
#import warnings
#warnings.warn("This method is obsolete; please use str(my_seq) "
# "instead of my_seq.tostring().",
# PendingDeprecationWarning)
"""Returns the full sequence as a python string (DEPRECATED).
You are now encouraged to use str(my_seq) instead of
my_seq.tostring()."""
import warnings
warnings.warn("This method is obsolete; please use str(my_seq) "
"instead of my_seq.tostring().",
PendingDeprecationWarning)
return str(self)

def tomutable(self): # Needed? Or use a function?
Expand Down Expand Up @@ -1722,7 +1720,7 @@ def count(self, sub, start=0, end=sys.maxsize):
"""
try:
#TODO - Should we check the alphabet?
search = sub.tostring()
search = str(sub)
except AttributeError:
search = sub

Expand All @@ -1738,7 +1736,7 @@ def count(self, sub, start=0, end=sys.maxsize):
return count
else:
#TODO - Can we do this more efficiently?
return self.tostring().count(search, start, end)
return str(self).count(search, start, end)

def index(self, item):
for i in range(len(self.data)):
Expand Down Expand Up @@ -1801,10 +1799,10 @@ def extend(self, other):
self.data.append(c)

def tostring(self):
"""Returns the full sequence as a python string (semi-obsolete).
"""Returns the full sequence as a python string (DEPRECATED).
Although not formally deprecated, you are now encouraged to use
str(my_seq) instead of my_seq.tostring().
You are now encouraged to use str(my_seq) instead of my_seq.tostring()
as this method is officially deprecated.
Because str(my_seq) will give you the full sequence as a python string,
there is often no need to make an explicit conversion. For example,
Expand All @@ -1815,6 +1813,10 @@ def tostring(self):
print("ID={%s}, sequence={%s}" % (my_name, my_seq.tostring()))
"""
import warnings
warnings.warn("This method is obsolete; please use str(my_seq) "
"instead of my_seq.tostring().",
PendingDeprecationWarning)
return "".join(self.data)

def toseq(self):
Expand Down
12 changes: 8 additions & 4 deletions BioSQL/BioSeq.py
Expand Up @@ -101,10 +101,14 @@ def __getitem__(self, index): # Seq API requirement
return Seq(full[::index.step], self.alphabet)

def tostring(self):
"""Returns the full sequence as a python string.
Although not formally deprecated, you are now encouraged to use
str(my_seq) instead of my_seq.tostring()."""
"""Returns the full sequence as a python string (DEPRECATED).
You are now encouraged to use str(my_seq) instead of
my_seq.tostring()."""
import warnings
warnings.warn("This method is obsolete; please use str(my_seq) "
"instead of my_seq.tostring().",
PendingDeprecationWarning)
return self.adaptor.get_subseq_as_string(self.primary_id,
self.start,
self.start + self._length)
Expand Down
5 changes: 5 additions & 0 deletions DEPRECATED
Expand Up @@ -22,6 +22,11 @@ Python 3.0, 3.1, 3.2
Never officially supported, these trigger a warning in Release 1.62
recommending Python 3.3 or later if you wish to use Python 3.

Bio.Seq.Seq.tostring() and Bio.Seq.MutableSeq.tostring()
========================================================
Deprecated as of Release 1.64. You should now use str(Bio.Seq.Seq) or
str(Bio.Seq.MutableSeq) instead of the tostring() methods.

Iterator .next() methods
========================
The .next() method defined for any Biopython iterator is deprecated as of
Expand Down
13 changes: 5 additions & 8 deletions Doc/Tutorial.tex
Expand Up @@ -298,7 +298,7 @@ \section{Frequently Asked Questions (FAQ)}
You need Biopython 1.54 or later, or just wrap the item with \verb|[...]| to create a list of one element.

\item \emph{Why doesn't} \verb|str(...)| \emph{give me the full sequence of a} \verb|Seq| \emph{object?} \\
You need Biopython 1.45 or later. Alternatively, rather than \verb|str(my_seq)|, use \verb|my_seq.tostring()| (which will also work on recent versions of Biopython).
You need Biopython 1.45 or later.

\item \emph{Why doesn't} \verb|Bio.Blast| \emph{work with the latest plain text NCBI blast output?} \\
The NCBI keep tweaking the plain text output from the BLAST tools, and keeping our parser up to date is/was an ongoing struggle.
Expand Down Expand Up @@ -744,13 +744,9 @@ \section{Turning Seq objects into strings}
string from a \verb|SeqRecord| object, while the more general topic of reading and
writing FASTA format sequence files is covered in Chapter~\ref{chapter:Bio.SeqIO}.

\emph{NOTE:} If you are using Biopython 1.44 or older, using \verb|str(my_seq)|
will give just a truncated representation. Instead use \verb|my_seq.tostring()|
(which is still available in the current Biopython releases for backwards compatibility):

%cont-doctest
\begin{verbatim}
>>> my_seq.tostring()
>>> str(my_seq)
'GATCGATGGGCCTATATAGGATCGAAAATCGC'
\end{verbatim}

Expand Down Expand Up @@ -13246,8 +13242,9 @@ \subsection{Searching for instances}
The simplest way to find instances, is to look for exact matches of
the true instances of the motif:
\begin{verbatim}
<<<<<<< HEAD
>>> for pos, seq in m.search_instances(test_seq):
... print(pos, seq.tostring())
... print("%i %s" % (pos, seq))
...
10 TATAA
15 TATAA
Expand All @@ -13256,7 +13253,7 @@ \subsection{Searching for instances}
We can do the same with the reverse complement (to find instances on the complementary strand):
\begin{verbatim}
>>> for pos, seq in m.reverse_complement().search_instances(test_seq):
... print(pos, seq.tostring())
... print("%i %s" % (pos, seq))
...
12 TAATA
20 TTATA
Expand Down
4 changes: 2 additions & 2 deletions Doc/cookbook/motif/motif.tex
Expand Up @@ -276,7 +276,7 @@ \subsection{Searching for instances}
the true instances of the motif:
\begin{verbatim}
>>> for pos,seq in m.search_instances(test_seq):
... print pos,seq.tostring()
... print pos, str(seq)
...
10 TATAA
15 TATAA
Expand All @@ -285,7 +285,7 @@ \subsection{Searching for instances}
We can do the same with the reverse complement (to find instances on the complementary strand):
\begin{verbatim}
>>> for pos,seq in m.reverse_complement().search_instances(test_seq):
... print pos,seq.tostring()
... print pos, str(seq)
...
12 TAATA
20 TTATA
Expand Down
6 changes: 0 additions & 6 deletions Tests/test_Seq_objs.py
Expand Up @@ -304,12 +304,6 @@ def test_str_getitem(self):
self.assertEqual(str(example1[i:j:step]),
str1[i:j:step])

def test_tostring(self):
"""Check str(obj) and obj.tostring() match."""
for example1 in self._examples:
str1 = str(example1)
self.assertEqual(example1.tostring(), str1)

def test_tomutable(self):
"""Check obj.tomutable() method."""
for example1 in self._examples:
Expand Down

0 comments on commit cab9b20

Please sign in to comment.