[bip] mRNA lengths of all Human/Mouse refseqs (tutorial)

Bruce Southey bsouthey at gmail.com
Thu Jan 17 07:08:52 PST 2008


Hi,
In this code you are just reversing a string so just use:

reverse=sequence[::-1]


I don't know of the best reverse complement code but I liked this one
liner from Andrew Dalke:
http://www.dalkescientific.com/writings/NBN/python_intro/functions.html

rcomp=sequence.translate(string.maketrans("ATCG", "TAGC"))[::-1]

BioPython's is the same idea but more general.

Regards
Bruce


On Jan 17, 2008 2:53 AM, Titus Brown <titus at caltech.edu> wrote:
> On Wed, Jan 16, 2008 at 04:32:20PM -0800, Brandon King wrote:
> -> for reverse complementing DNA sequence. And the short answer is I don't
> -> know... He did some benchmarking if I remember correctly on why this was
> -> faster... I've CC'ed Chris as he probably has a better answer. I think
> -> that particular module was written pre-2002 and therefore was
> -> benchmarked against an older version of Python. Chris?
> ->
> -> Let me know if you have any other questions or request for documentation
> -> and I'll see about writing some additional examples/tutorials.
> ->
> -> -Brandon
> ->
> -> P.S. Chris, you might want to check out http://bio.scipy.org/
> ->
> -> Brent Pedersen wrote:
> -> > hi, and thanks for making this available. i have immediate use for the
> -> > fasta indexing.
> -> > what's this in SequenceUtils.py? am i missing something or is
> -> > [seq]*len(seq) uneccessary. what's the advantage over python's
> -> > reversed?
> -> >
> -> >
> -> > def reverse(seq):
> -> >   """reverse a sequence"""
> -> >   return(''.join(map(operator.getitem, [seq]*len(seq),
> -> >                      xrange(len(seq)-1, -1, -1))))
>
> Ooh, goodie, do we get to have a profiling/benchmark war now? ;)
>
> Anyway, I'm never one to pass up a chance to take Chris down a peg... I
> did a quick benchmark of these three functions:
>
> ---
>
> def bh_reverse(seq):
>    return(''.join(map(operator.getitem, [seq]*len(seq),
>                       xrange(len(seq)-1, -1, -1))))
>
> def ctb_reverse(seq):
>    r = array('c', seq)
>    r.reverse()
>    r = string.join(r, '')
>
>    return r
>
> def obvious_reverse(seq):
>    r = list(seq)
>    r.reverse()
>    r = "".join(r)
>
>    return r
>
> ---
>
> (full code is attached).  Here are the numbers for 10x reversing of a
> 1mb string of As:
>
> bh 7.85962796211
> obv 2.24124288559
> ctb 2.69798088074
>
> Obviously, obvious_reverse is the way to go...
>
> The behavior of that map statement is confusing to me; perhaps it will
> be clearer in the morning.
>
> --titus
>
> _______________________________________________
> biology-in-python mailing list - bip at lists.idyll.org.
>
> See http://bio.scipy.org/ for our Wiki.
>



More information about the biology-in-python mailing list