From cab9b201b3f4caee176f3903f5109c5c0ef2eeac Mon Sep 17 00:00:00 2001 From: bow Date: Wed, 19 Dec 2012 19:48:58 +0100 Subject: [PATCH] Remove last remnants of Seq.tostring and deprecate it --- Bio/Seq.py | 32 +++++++++++++++++--------------- BioSQL/BioSeq.py | 12 ++++++++---- DEPRECATED | 5 +++++ Doc/Tutorial.tex | 13 +++++-------- Doc/cookbook/motif/motif.tex | 4 ++-- Tests/test_Seq_objs.py | 6 ------ 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/Bio/Seq.py b/Bio/Seq.py index 6198e084469..ac553459798 100644 --- a/Bio/Seq.py +++ b/Bio/Seq.py @@ -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? @@ -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 @@ -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)): @@ -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, @@ -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): diff --git a/BioSQL/BioSeq.py b/BioSQL/BioSeq.py index f2275b1753c..33fc1b497c7 100644 --- a/BioSQL/BioSeq.py +++ b/BioSQL/BioSeq.py @@ -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) diff --git a/DEPRECATED b/DEPRECATED index 11550bbe87a..af59f2e4abc 100644 --- a/DEPRECATED +++ b/DEPRECATED @@ -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 diff --git a/Doc/Tutorial.tex b/Doc/Tutorial.tex index c46b3c250c4..9c237d194f2 100644 --- a/Doc/Tutorial.tex +++ b/Doc/Tutorial.tex @@ -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. @@ -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} @@ -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 @@ -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 diff --git a/Doc/cookbook/motif/motif.tex b/Doc/cookbook/motif/motif.tex index c4d7ee14a98..c8c1b7f7eaf 100644 --- a/Doc/cookbook/motif/motif.tex +++ b/Doc/cookbook/motif/motif.tex @@ -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 @@ -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 diff --git a/Tests/test_Seq_objs.py b/Tests/test_Seq_objs.py index 6795e210f3d..cbd4b6ec117 100644 --- a/Tests/test_Seq_objs.py +++ b/Tests/test_Seq_objs.py @@ -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: