[BioPython] Translation method for Seq object
Martin MOKREJŠ
mmokrejs at ribosome.natur.cuni.cz
Sun Oct 19 14:28:38 EDT 2008
Peter,
you are right in your points. I think the translate() trick
had some speed advantages over other approaches to zap unwanted
characters - I don't remember but if it is gonna break in future
python releases I will have to rewrite this anyway.
I just wanted to say I really do use the string translate
function and that it has use in bioinformatics as well. ;-)
Still, I think the name clash is asking for disaster, but
overloading is a feature of python so it might be expected.
Do whatever you want. ;)
Cheers,
M.
Peter wrote:
> On Sun, Oct 19, 2008 at 4:52 PM, Martin MOKREJŠ
> <mmokrejs at ribosome.natur.cuni.cz> wrote:
>> Hi,
>> I have been away for 2 weeks but although late,
>
> Untill we release a new biopython, its not too late to change the Seq
> object's new methods.
>
>> let me oppose that string.translate() is of use.
>> Here is my current code:
>> ...
>
> Your code seems to be doing two things with the python string
> translate() method:
>
> (1) Using the deletechars argument (with an empty mapping) to look for
> unexpected letters. It took me a while to work out what your code was
> doing - personally I would have used a python set for this, rather
> than the string translate method. Note also unicode strings don't
> support the deletechars argument, and that python 3.0 removes the
> deletechars argument from the string style objects.
>
> (2) Using the translate mapping to switch "U" and "u" into "T" and "t"
> to back transcribe RNA into DNA. For this, Biopython already has a
> Bio.Seq.back_transcribe function (which does work on strings), and in
> CVS the Seq object gets a back_transcribe method too. These do both
> use the string translate method internally.
>
> Neither of these operations convice me that the Seq object should
> support the python string translate method.
>
> Note that if you still need to use the python string translate method,
> it is accessable by first turning the Seq object into a string (e.g.
> str(my_seq).translate(mapping, delete_chars)), or as Michiel suggested
> earlier, you could use the string module translate function on the Seq
> object.
>
> Also note that (as in your example using the string translate to do
> back transcription) the translate method by its nature makes it
> impossible to know if the original Seq object alphabet still applies
> to the result.
More information about the BioPython
mailing list