void init_dp(data *d) {
  const int width = d->m.width;
  int i;
  d->dp_seqlen = 0;
  d->dp_mat = xmalloc2(width+1, 1 * sizeof(double));
  d->forbidden = xmalloc2(width+1, 1);
  /* boundary conditions for short-in-long alignment: */
  d->dp_mat[0][0] = 0;
  for (i = 0; i < width; ++i)
    d->dp_mat[i+1][0] = d->delete_scores[i] + d->dp_mat[i][0];
}
unsigned int *
headint32(struct rpmhead *h, int tag, int *cnt)
{
    unsigned int i, o, *r;
    unsigned char *d, taga[4];

    d = h->data;
    taga[0] = tag >> 24;
    taga[1] = tag >> 16;
    taga[2] = tag >> 8;
    taga[3] = tag;
    for (i = 0; i < h->cnt; i++, d += 16)
        if (d[3] == taga[3] && d[2] == taga[2] && d[1] == taga[1] && d[0] == taga[0])
            break;
    if (i >= h->cnt)
        return 0;
    if (d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 4)
        return 0;
    o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
    i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
    if (o + 4 * i > h->dcnt)
        return 0;
    d = h->dp + o;
    r = xmalloc2(i ? i : 1, sizeof(unsigned int));
    if (cnt)
        *cnt = i;
    for (o = 0; o < i; o++, d += 4)
        r[o] = d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
    return r;
}
Exemple #3
0
extern "C" void *
xcalloc(size_t n, size_t size)
{
    void* ptr = xmalloc2(n, size);

    memset(ptr, 0, n * size);

    return ptr;
}
Exemple #4
0
static VALUE
rb_buffer_read(VALUE self, SEL sel, VALUE queue)
{
  int i;
  cl_int err;
  cl_command_queue q = (cl_command_queue) rb_ivar_get(queue, rb_intern("queue"));
  float* d = xmalloc2(ROpenCLBuffer(self)->size, sizeof(float));

  err = clEnqueueReadBuffer(q, ROpenCLBuffer(self)->buffer, CL_TRUE, 0, sizeof(float)*ROpenCLBuffer(self)->size, d, 0, NULL, NULL);
  if(err != CL_SUCCESS)
    rb_raise(rb_eArgError, "Failed with error `%d'", err);

  VALUE res = rb_ary_new2(ROpenCLBuffer(self)->size);
  for(i=0; i<ROpenCLBuffer(self)->size; i++) {
    rb_ary_push(res, rb_float_new(d[i]));
  }
  return res;
}
Exemple #5
0
static VALUE
rb_buffer_write(VALUE self, SEL sel, VALUE queue, VALUE data)
{
  int i;
  cl_int err;
  cl_command_queue q = (cl_command_queue) rb_ivar_get(queue, rb_intern("queue"));
  float* d = xmalloc2(ROpenCLBuffer(self)->size, sizeof(float));

  for(i=0; i<ROpenCLBuffer(self)->size; i++) {
    d[i] = NUM2DBL(rb_ary_entry(data, i));
  }

  err = clEnqueueWriteBuffer(q, ROpenCLBuffer(self)->buffer, CL_TRUE, 0, sizeof(double)*ROpenCLBuffer(self)->size, d, 0, NULL, NULL);

  if(err != CL_SUCCESS)
    rb_raise(rb_eArgError, "Failed with error `%d'", err);

  return Qnil;
}
void init_scores(data *d) {
  const int alph_size = d->m.alph_size;
  const int width = d->m.width;
  const double *bg = d->alph.prob;
  glam2_scorer *s = &d->scorer;
  int i, j;

  d->match_scores = xmalloc2(width, (alph_size+1) * sizeof(double));
  XMALLOC(d->delete_scores, width);
  XMALLOC(d->insert_scores, width);

  for (i = 0; i < width; ++i) {
    const int *residue_counts = d->m.residue_counts[i];
    const int match_count = sum_int(residue_counts, alph_size);
    const int delete_count = d->m.delete_counts[i];
    const int insert_count = d->m.insert_counts[i];
    const int aligned_seq = match_count + delete_count;

    const double ds = beta_ratio_a(&s->d_prior, delete_count, match_count);
    const double ms = beta_ratio_b(&s->d_prior, delete_count, match_count);
    const double is = beta_ratio_a(&s->i_prior, insert_count, aligned_seq);
    const double js = beta_ratio_b(&s->i_prior, insert_count, aligned_seq);

    dmix_ratios(&s->e_prior, d->match_scores[i], residue_counts);

    if (i+1 < width) {
      for (j = 0; j < alph_size; ++j)
        d->match_scores[i][j] = xlog(js * ms * d->match_scores[i][j] / bg[j]);
      d->delete_scores[i] = xlog(ds * js);
      d->insert_scores[i] = xlog(is);
    } else {  /* no insertions after last column: special case */
      for (j = 0; j < alph_size; ++j)
        d->match_scores[i][j] = xlog(ms * d->match_scores[i][j] / bg[j]);
      d->delete_scores[i] = xlog(ds);
      d->insert_scores[i] = -DBL_MAX;  /* overflow risk? */
    }

    /* overflow risk? */
    d->match_scores[i][alph_size] = -DBL_MAX;  /* mask character forbidden */
  }
}