Hi all,<div><br></div><div>New to the list and fairly new to pypy.  First of all, congrats on the new 1.6 release-- the growing support for numpy is very exciting (go, fight, win, take state!).</div><div><br></div><div>So I snagged the 1.6 release to test if it would be faster on the kind of code I often write: Bioinformatics.  In this snippet, the point is to check the mappability of the genome-- if a particular substring appears more than once in the genome, the region is called unmappable.</div>

<div><br></div><div>Machine Specs:</div><div>64bit Ubuntu 11.04</div><div>119048 CPython 2.7.1 pystones/second </div><div>416667 pypy1.6 pystones/second</div><div><div><br></div></div><div>The CPython version of the following code takes a bit more than a minute to run on the 21st chromosome of the human reference genome, but the pypy version has been going for 27+ minutes and hasn&#39;t yet finished the first step of loading the genome as a dict of strings.  </div>

<div><br></div><div>Am I using some construct that&#39;s particularly difficult for pypy?  Am I missing something?</div><div><br></div><div>hg18 chrom 21 is available at <a href="http://hgdownload.cse.ucsc.edu/goldenPath/hg18/chromosomes/chr21.fa.gz">http://hgdownload.cse.ucsc.edu/goldenPath/hg18/chromosomes/chr21.fa.gz</a></div>

<div><br></div><div><br></div><div><div><font face="&#39;courier new&#39;, monospace">import sys</font></div><div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">def slide_dna(dna, windowsize):</font></div>

<div><font face="&#39;courier new&#39;, monospace">    for i in xrange(len(dna) - windowsize):</font></div><div><font face="&#39;courier new&#39;, monospace">        slice = dna[i:i+windowsize]</font></div><div><font face="&#39;courier new&#39;, monospace">        if &#39;N&#39; not in slice:</font></div>

<div><font face="&#39;courier new&#39;, monospace">            yield slice</font></div></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><span style="font-family: &#39;courier new&#39;, monospace; ">fasta_file = sys.argv[1]  # should be *.fa</span></div>

<div><font face="&#39;courier new&#39;, monospace">print &#39;loading dna from&#39;, fasta_file</font></div><div><font face="&#39;courier new&#39;, monospace">chroms = {}</font></div><div><font face="&#39;courier new&#39;, monospace">dna = None</font></div>

<div><font face="&#39;courier new&#39;, monospace">for l in open(fasta_file):</font></div><div><font face="&#39;courier new&#39;, monospace">    if l.startswith(&#39;&gt;&#39;):  # new chromosome</font></div><div><font face="&#39;courier new&#39;, monospace">        if dna is not None:</font></div>

<div><font face="&#39;courier new&#39;, monospace">            chroms[chrom] = dna</font></div><div><font face="&#39;courier new&#39;, monospace">        chrom = l.strip().replace(&#39;&gt;&#39;, &#39;&#39;)</font></div>
<div>
<font face="&#39;courier new&#39;, monospace">        dna = &#39;&#39;</font></div><div><font face="&#39;courier new&#39;, monospace">    else:</font></div><div><font face="&#39;courier new&#39;, monospace">        dna += l.rstrip()</font></div>

<div><font face="&#39;courier new&#39;, monospace">if dna is not None:</font></div><div><font face="&#39;courier new&#39;, monospace">    chroms[chrom] = dna</font></div><div><font face="&#39;courier new&#39;, monospace"><br>

</font></div><div><font face="&#39;courier new&#39;, monospace">for length in [15]:#, 25, 35, 45, 55, 65, 75]:</font></div><div><font face="&#39;courier new&#39;, monospace">    print &#39;now on&#39;, length</font></div>

<div><font face="&#39;courier new&#39;, monospace">    mappable = 0</font></div><div><font face="&#39;courier new&#39;, monospace">    repeat = 0</font></div><div><font face="&#39;courier new&#39;, monospace">    s = {}</font></div>

<div><font face="&#39;courier new&#39;, monospace">    for dna in chroms.itervalues():</font></div><div><font face="&#39;courier new&#39;, monospace">        for slice in slide_dna(dna, length):</font></div><div><font face="&#39;courier new&#39;, monospace">            try:</font></div>

<div><font face="&#39;courier new&#39;, monospace">                s[slice] += 1</font></div><div><font face="&#39;courier new&#39;, monospace">            except KeyError:</font></div><div><font face="&#39;courier new&#39;, monospace">                s[slice] = 1</font></div>

<div><font face="&#39;courier new&#39;, monospace">    print &#39;built, now counting&#39;</font></div><div><font face="&#39;courier new&#39;, monospace">    for dna in chroms.itervalues():</font></div><div><font face="&#39;courier new&#39;, monospace">        for slice in slide_dna(dna, length):</font></div>

<div><font face="&#39;courier new&#39;, monospace">            if s[slice] == 1:</font></div><div><font face="&#39;courier new&#39;, monospace">                mappable += 1</font></div><div><font face="&#39;courier new&#39;, monospace">            else:</font></div>

<div><font face="&#39;courier new&#39;, monospace">                repeat += 1</font></div><div><font face="&#39;courier new&#39;, monospace">    print &#39;for substring length %s, mappable: %s, repeat: %s&#39; % (length, mappable, repeat)</font></div>

<div><font face="&#39;courier new&#39;, monospace"><br></font></div></div><div><br></div><div>--<br>Jake Biesinger<br>Graduate Student<br>Xie Lab, UC Irvine<br><br>
</div>