Exemple #1
0
def plot_cne(name, scores, valid):
    lookahead = len(scores) / 50
    scores = np.array([float(x) for x in scores])
    signal = smooth(scores, window_len=40, window='bartlett')
    maxima = peakdetect(signal, lookahead=lookahead)[0]
    m_x = np.array([m[0] for m in maxima])
    m_y = np.array([m[1] for m in maxima])
    plt.plot(range(len(signal)), signal, 'k', m_x, m_y, 'bo')
    plt.axvspan(valid[0], valid[1], facecolor='r', alpha=0.4)
    plt.xlabel('alignment')
    plt.ylabel('score')
    plt.title(name)
    fig = plt.gcf()
    fig.set_size_inches(8, 5)
    plt.savefig(name + '.png', dpi=140)
Exemple #2
0
def ranked_peaks(cne_dict, extra):
  def dist(cne, i):
    v_avg = (extra[cne]['dr_valid_co']['start'] + extra[cne]['dr_valid_co']['end']) / 2.0
    v_i = v_avg - extra[cne]['dr_co']['start']
    return abs(i - v_i)
  results = defaultdict(dict)
  for cne, scores in cne_dict.iteritems():
    lookahead = int(len(scores) / 50) + 1
    scores = np.array([float(x) for x in scores])
    signal = smooth(scores, window_len=40, window='bartlett')
    maxima = peakdetect(signal, lookahead=lookahead)[0]
    maxima.sort(key=itemgetter(1), reverse=True)
    if not maxima:
      print cne
      continue
    hit_rank = np.argmin(np.array([dist(cne, i) for i, score in maxima]))
    results[cne]['rank'] = hit_rank + 1
    results[cne]['places'] = len(maxima)
  return results