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

Brent Pedersen bpederse at gmail.com
Thu Jan 17 12:49:38 PST 2008


On Jan 17, 2008 12: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? ;)
>

since you did declare it a war. cython big guns make it another 2x as
fast as seq[::-1].

cdef extern from "stdio.h":
    cdef Py_ssize_t strlen(char *)

def inplace_rev(char* seq):
    cdef int l = strlen(seq)
    cdef int i
    for i from 0 <= i < l / 2 :
        seq[i] , seq[l - i - 1] =  seq[l - i - 1],  seq[i]

================= build lib with:
cython rev.pyx
gcc -fPIC -O2 -Wstrict-prototypes  -pthread -fno-strict-aliasing -Wall
-I/usr/include/python2.5 -c -o rev.o rev.c
gcc  -pthread -Wl,-O3 -shared rev.o -o rev.so



More information about the biology-in-python mailing list