File: peakdetect.py

package info (click to toggle)
python-seqcluster 1.2.9%2Bds-3
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 113,624 kB
  • sloc: python: 5,308; makefile: 184; sh: 122; javascript: 55
file content (28 lines) | stat: -rw-r--r-- 621 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import numpy as np


def _summarize_peaks(peaks):
    """
    merge peaks position if closer than 10
    """
    previous = peaks[0]
    new_peaks = [previous]
    for pos in peaks:
        if pos > previous + 10:
            new_peaks.add(pos)
        previous = pos
    return new_peaks


def find_mature(x, y, win=10):
    """
    Window apprach to find hills in the expression profile
    """
    previous = min(y)
    peaks = []
    intervals = range(x, y, win)
    for pos in intervals:
        if y[pos] > previous * 10:
            previous = y[pos]
            peaks.add(pos)
    peaks = _summarize_peaks(peaks)