/mobile Handheld Friendly website

 performance measurements

Each table row shows performance measurements for this Python 3 program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
250,0001.071.1272,612624  0% 0% 2% 96%
2,500,0009.289.3542,560624  1% 0% 1% 99%
25,000,00091.6091.75375,452624  0% 1% 0% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read k-nucleotide benchmark to see what this program should do.

 notes

Python 3.4.0 (default, Mar 17 2014, 08:05:26) [GCC 4.8.1] on linux

Notice that sought sequences (GGT GGTA GGTATT GGTATTTTAATT GGTATTTTAATTTATAGT) newer overlap and create new function find_seq() with built-in function count(). Previous program iterated all data in function sort_seq() - char by char.

Improved gen_func() - removed "if" statement and used defaultdict() function

BUT skips the sequence generation in the sequence finder step. def find_seq(seq, nucleo): count = seq.count(nucleo) return nucleo, count

 k-nucleotide Python 3 #2 program source code

# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org/
#
# submitted by Ian Osgood
# modified by Sokolov Yura
# modified by bearophile
# modified by jacek2v: few changes in algorytm, added multiprocessing, used str.count (nucleo newer overlapping)

from sys import stdin
from collections import defaultdict
from multiprocessing import Process, Pool, cpu_count

def gen_freq(seq, frame):
    frequences = defaultdict(int)
    ns = len(seq) + 1 - frame
    for ii in range(ns):
        frequences[seq[ii:ii + frame]] += 1
    return ns, frequences

def sort_seq(seq, length):
    n, frequences = gen_freq(seq, length)
    #l = sorted(frequences.items(), reverse=True, key=lambda (seq,freq): (freq,seq))
    l = sorted(list(frequences.items()), reverse=True, key=lambda seq_freq: (seq_freq[1],seq_freq[0]))
    return [(st, 100.0*fr/n) for st, fr in l]

def find_seq(seq, nucleo):
    count = seq.count(nucleo)
    return nucleo, count

def load():
    for line in stdin:
        if line[0:3] == ">TH":
            break
    seq = []
    for line in stdin:
        if line[0] in ">;":
            break
        seq.append( line[:-1] )
    return seq

def main():
    nucleos = "GGT GGTA GGTATT GGTATTTTAATT GGTATTTTAATTTATAGT"
    sequence = "".join(load()).upper()
    plres = []
    pl = Pool(processes=cpu_count() + 1)
    
    for nl in 1,2:
        plres.append(pl.apply_async(sort_seq, (sequence, nl, )))
    for se in nucleos.split():
        plres.append(pl.apply_async(find_seq, (sequence, se, )))
    pl.close()
    pl.join()

    for ii in 0,1:
        print('\n'.join("%s %.3f" % (st, fr) for st,fr in plres[ii].get()))
        print('')
    for ii in range(2, len(nucleos.split()) + 2):
        print("%d\t%s" % (plres[ii].get()[1], plres[ii].get()[0]))
main()

 make, command-line, and program output logs

Tue, 18 Mar 2014 09:50:54 GMT

MAKE:
mv knucleotide.python3-2.python3 knucleotide.python3-2.py
/usr/local/src/Python-3.4.0/bin/python3.4 -OO -c "from py_compile import compile; compile('knucleotide.python3-2.py')"
0.06s to complete and log all make actions

COMMAND LINE:
/usr/local/src/Python-3.4.0/bin/python3.4 knucleotide.python3-2.py 0 < knucleotide-input25000000.txt

PROGRAM OUTPUT:
A 30.295
T 30.151
C 19.800
G 19.754

AA 9.177
TA 9.132
AT 9.131
TT 9.091
CA 6.002
AC 6.001
AG 5.987
GA 5.984
CT 5.971
TC 5.971
GT 5.957
TG 5.956
CC 3.917
GC 3.911
CG 3.909
GG 3.902

1471758	GGT
446535	GGTA
47336	GGTATT
893	GGTATTTTAATT
893	GGTATTTTAATTTATAGT

Revised BSD license

  Home   Conclusions   License   Play