~ubuntu-branches/ubuntu/natty/python-cogent/natty

« back to all changes in this revision

Viewing changes to cogent/maths/_period.pyx

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2010-12-04 22:30:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204223035-j11kinhcrrdgg2p2
Tags: 1.5-1
* Bumped standard to 3.9.1, no changes required.
* New upstream version.
  - major additions to Cookbook
  - added AlleleFreqs attribute to ensembl Variation objects.
  - added getGeneByStableId method to genome objects.
  - added Introns attribute to Transcript objects and an Intron class.
  - added Mann-Whitney test and a Monte-Carlo version
  - exploratory and confirmatory period estimation techniques (suitable for
    symbolic and continuous data)
  - Information theoretic measures (AIC and BIC) added
  - drawing of trees with collapsed nodes
  - progress display indicator support for terminal and GUI apps
  - added parser for illumina HiSeq2000 and GAiix sequence files as 
    cogent.parse.illumina_sequence.MinimalIlluminaSequenceParser.
  - added parser to FASTQ files, one of the output options for illumina's
    workflow, also added cookbook demo.
  - added functionality for parsing of SFF files without the Roche tools in
    cogent.parse.binary_sff
  - thousand fold performance improvement to nmds
  - >10-fold performance improvements to some Table operations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from numpy import pi, exp, sqrt, cos
 
2
cimport numpy as np
 
3
 
 
4
# TODO intro the version idea of peter's see email from him on Wednesday, 26 May 2010
 
5
 
 
6
def goertzel_inner(np.ndarray[np.float64_t, ndim=1] x, int N, int period):
 
7
    """returns the power from series x for period"""
 
8
    cdef int n
 
9
    cdef np.float64_t coeff, s, s_prev, s_prev2, power
 
10
    
 
11
    coeff = 2.0 * cos(2 * pi / period)
 
12
    s_prev = 0.0
 
13
    s_prev2 = 0.0
 
14
    for n in range(N):
 
15
        s = x[n] + coeff * s_prev - s_prev2
 
16
        s_prev2 = s_prev
 
17
        s_prev = s
 
18
    
 
19
    power = sqrt(s_prev2**2 + s_prev**2 - coeff * s_prev2 * s_prev)
 
20
    return power
 
21
 
 
22
def ipdft_inner(np.ndarray[np.float64_t, ndim=1] x,
 
23
                       np.ndarray[np.complex128_t, ndim=1] X,
 
24
                       np.ndarray[np.complex128_t, ndim=1] W,
 
25
                       int ulim, int N):
 
26
    """use this when repeated calls for window of same length are to be
 
27
    made"""
 
28
    cdef int n, p
 
29
    cdef np.complex128_t w
 
30
    
 
31
    for p in range(ulim):
 
32
        w = 1.0
 
33
        for n in range(N):
 
34
            if n != 0:
 
35
                w = w * W[p]
 
36
            X[p] = X[p] + x[n]*w
 
37
    return X
 
38
 
 
39
def autocorr_inner(np.ndarray[np.float64_t, ndim=1] x, np.ndarray[np.float64_t, ndim=1] xc, int N):
 
40
    cdef int m, n
 
41
    
 
42
    for m in range(-N+1, N):
 
43
        for n in range(N):
 
44
            if 0 <= n-m < N:
 
45
                xc[m+N-1] += (x[n]*x[n-m])
 
46
 
 
47
def seq_to_symbols(char* seq, list motifs, int motif_length,
 
48
    np.ndarray[np.uint8_t, ndim=1] result):
 
49
    cdef int i, j, N, num_motifs
 
50
    cdef bytes got
 
51
    
 
52
    N = len(seq)
 
53
    num_motifs = len(motifs)
 
54
    motif_length = len(motifs[0])
 
55
    for i in range(N - motif_length + 1):
 
56
        got = seq[i: i+motif_length]
 
57
        for j in range(num_motifs):
 
58
            if got == motifs[j]:
 
59
                result[i] = 1
 
60
    return result
 
61
    
 
 
b'\\ No newline at end of file'