Exemplo n.º 1
0
void gt_string_matching_shift_and(const char *s, unsigned long n,
                               const char *p, unsigned long m,
                               ProcessMatch process_match, void *data)
{
  GtBittab *D, *B[UCHAR_MAX] = { NULL };
  unsigned long i, j;
  gt_assert(s && p);
  if (m > n || !m || !n) /* no match possible */
    return;
  /* preprocessing */
  for (j = 0; j < m; j++) {
    if (!B[(unsigned) p[j]])
      B[(unsigned) p[j]] = gt_bittab_new(m);
    gt_bittab_set_bit(B[(unsigned) p[j]], j);
  }
  /* searching */
  D = gt_bittab_new(m);
  for (i = 0; i < n; i++) {
    gt_bittab_shift_left_equal(D);
    gt_bittab_set_bit(D, 0);
    if (B[(unsigned) s[i]])
      gt_bittab_and_equal(D, B[(unsigned) s[i]]);
    else
      gt_bittab_unset(D);
    if (gt_bittab_bit_is_set(D, m - 1) && process_match) {
      if (process_match(i - m + 1, data))
        break;
    }
  }
  /* free */
  for (i = 0; i < UCHAR_MAX; i++)
    gt_bittab_delete(B[i]);
  gt_bittab_delete(D);
}
Exemplo n.º 2
0
static bool splice_form_is_valid(GtBittab *SA_p, const ConsensusSA *csa)
{
  GtBittab *SA_p_complement; /* SA \ SA_p */
  unsigned long sa, sa_prime;
  bool incompatible_found, valid = true;

  SA_p_complement = gt_bittab_new(csa->number_of_sas);
  gt_bittab_complement(SA_p_complement, SA_p);

  for (sa_prime  = gt_bittab_get_first_bitnum(SA_p_complement);
       sa_prime != gt_bittab_get_last_bitnum(SA_p_complement);
       sa_prime  = gt_bittab_get_next_bitnum(SA_p_complement, sa_prime)) {
    incompatible_found = false;
    for (sa  = gt_bittab_get_first_bitnum(SA_p);
         sa != gt_bittab_get_last_bitnum(SA_p);
         sa  = gt_bittab_get_next_bitnum(SA_p, sa)) {
      if (!compatible(csa, sa, sa_prime)) {
        incompatible_found = true;
        break;
      }
    }
    if (!incompatible_found) { valid = false; break; }
  }
  gt_bittab_delete(SA_p_complement);
  return valid;
}
Exemplo n.º 3
0
/* necessary to call consensus_sa() */
static void process_splice_form_func(GtArray *spliced_alignments_in_form,
                                     GT_UNUSED const void *set_of_sas,
                                     GT_UNUSED GtUword number_of_sas,
                                     GT_UNUSED size_t size_of_sa,
                                     void *userdata)
{
  GthPGL *pgl = (GthPGL*) userdata;
  GthAGS *ags;
  GtBittab *assemblytab;
  GtUword i;

  ags = gth_ags_new(pgl);

  assemblytab = gt_bittab_new(gt_array_size(pgl->saclusters));
  for (i = 0; i < gt_array_size(spliced_alignments_in_form); i++) {
    gt_bittab_set_bit(assemblytab, *(GtUword*)
                                gt_array_get(spliced_alignments_in_form, i));
  }

  gth_build_AGS_from_assembly(ags, assemblytab, pgl->saclusters);

  gt_bittab_delete(assemblytab);

  gt_array_add(pgl->assemblies, ags);
}
void gt_clustered_set_union_find_delete(GtClusteredSet *cs,
                                        GT_UNUSED GtError *err)
{
  if (!cs) return;
  GtClusteredSetUF *cs_uf = (GtClusteredSetUF*) cs;
  gt_free(cs_uf->cluster_elems);
  gt_array_delete(cs_uf->cluster_info);
  gt_bittab_delete(cs_uf->in_cluster);
}
Exemplo n.º 5
0
void gt_canvas_delete(GtCanvas *canvas)
{
  if (!canvas) return;
  gt_assert(canvas->c_class);
  if (canvas->c_class->free)
    canvas->c_class->free(canvas);
  if (canvas->pvt->g)
    gt_graphics_delete(canvas->pvt->g);
  if (canvas->pvt->bt)
    gt_bittab_delete(canvas->pvt->bt);
  gt_free(canvas->pvt);
  gt_free(canvas);
}
Exemplo n.º 6
0
int gt_canvas_cairo_visit_line_post(GtCanvas *canvas, GtLine *line,
                                    GtError *err)
{
  int had_err = 0;
  double lheight,
         bar_vspace = BAR_VSPACE_DEFAULT;
  gt_assert(canvas && line);
  had_err = gt_line_get_height(line, &lheight, canvas->pvt->sty, err);
  if (!had_err) {
    if (gt_style_get_num(canvas->pvt->sty,
                         "format", "bar_vspace",
                         &bar_vspace, NULL, err) == GT_STYLE_QUERY_ERROR) {
      return -1;
    }
    canvas->pvt->y += bar_vspace + lheight/2;
    if (canvas->pvt->bt)
      gt_bittab_delete(canvas->pvt->bt);
    canvas->pvt->bt = NULL;
  }
  return had_err;
}
Exemplo n.º 7
0
static void compute_R(GtBittab **R, GtBittab **C, GtBittab **right,
                      unsigned long number_of_sas)
{
  unsigned long sa_1, sa_2, sa_1_size = 0, sa_2_size;
  long sa;
  GtBittab *tmpset = gt_bittab_new(number_of_sas);

  for (sa = number_of_sas-1; sa >= 0; sa--) {
    sa_1 = GT_UNDEF_ULONG;

    if (!gt_bittab_is_true(right[sa])) {
      /* bittab is empty */
      gt_bittab_equal(R[sa], C[sa]);
    }
    else {
      for (sa_2  = gt_bittab_get_first_bitnum(right[sa]);
           sa_2 != gt_bittab_get_last_bitnum(right[sa]);
           sa_2  = gt_bittab_get_next_bitnum(right[sa], sa_2)) {
        if (sa_1 == GT_UNDEF_ULONG) {
          sa_1 = sa_2;

          gt_bittab_or(tmpset, R[sa_1], C[sa]);
          sa_1_size = gt_bittab_count_set_bits(tmpset);
        }
        else {
          gt_bittab_or(tmpset, R[sa_2], C[sa]);
          sa_2_size = gt_bittab_count_set_bits(tmpset);

          if (sa_2_size > sa_1_size) {
            sa_1      = sa_2;
            sa_1_size = sa_2_size;
          }
        }
      }
      gt_assert(sa_1 != GT_UNDEF_ULONG);
      gt_bittab_or(R[sa], R[sa_1], C[sa]);
    }
  }
  gt_bittab_delete(tmpset);
}
Exemplo n.º 8
0
static void compute_L(GtBittab **L, GtBittab **C, GtBittab **left,
                      unsigned long number_of_sas)
{
  unsigned long sa, sa_1, sa_2, sa_1_size = 0, sa_2_size;
  GtBittab *tmpset = gt_bittab_new(number_of_sas);

  for (sa = 0; sa < number_of_sas; sa++) {
    sa_1 = GT_UNDEF_ULONG;

    if (!gt_bittab_is_true(left[sa])) {
      /* bittab is empty */
      gt_bittab_equal(L[sa], C[sa]);
    }
    else {
      for (sa_2  = gt_bittab_get_first_bitnum(left[sa]);
           sa_2 != gt_bittab_get_last_bitnum(left[sa]);
           sa_2  = gt_bittab_get_next_bitnum(left[sa], sa_2)) {
        if (sa_1 == GT_UNDEF_ULONG) {
          sa_1 = sa_2;

          gt_bittab_or(tmpset, L[sa_1], C[sa]);
          sa_1_size = gt_bittab_count_set_bits(tmpset);
        }
        else {
          gt_bittab_or(tmpset, L[sa_2], C[sa]);
          sa_2_size = gt_bittab_count_set_bits(tmpset);

          if (sa_2_size > sa_1_size) {
            sa_1      = sa_2;
            sa_1_size = sa_2_size;
          }
        }
      }

      gt_assert(sa_1 != GT_UNDEF_ULONG);
      gt_bittab_or(L[sa], L[sa_1], C[sa]);
    }
  }
  gt_bittab_delete(tmpset);
}
Exemplo n.º 9
0
static void compute_csas(ConsensusSA *csa)
{
  unsigned long i, sa_i, sa_i_size = 0, sa_prime, sa_prime_size;
  GtArray *splice_form;
  GtBittab **C, **left, **right, **L, **R, *U_i, *SA_i, *SA_prime;
#ifndef NDEBUG
  unsigned long u_i_size, u_i_minus_1_size;
  gt_assert(csa && csa->set_of_sas);
#endif

  /* init sets */
  C     = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas);
  left  = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas);
  right = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas);
  L     = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas);
  R     = gt_malloc(sizeof (GtBittab*) * csa->number_of_sas);

  for (i = 0; i < csa->number_of_sas; i++) {
    C[i]     = gt_bittab_new(csa->number_of_sas);
    left[i]  = gt_bittab_new(csa->number_of_sas);
    right[i] = gt_bittab_new(csa->number_of_sas);
    L[i]     = gt_bittab_new(csa->number_of_sas);
    R[i]     = gt_bittab_new(csa->number_of_sas);
  }

  U_i      = gt_bittab_new(csa->number_of_sas);
  SA_i     = gt_bittab_new(csa->number_of_sas);
  SA_prime = gt_bittab_new(csa->number_of_sas);

  splice_form = gt_array_new(sizeof (unsigned long));

  /* compute sets */
  compute_C(C, csa);
  compute_left(left, csa);
  compute_right(right, csa);
  compute_L(L, C, left, csa->number_of_sas);
  compute_R(R, C, right, csa->number_of_sas);

  /* U_0 = SA */
  for (i = 0; i < csa->number_of_sas; i++)
    gt_bittab_set_bit(U_i, i);

#ifndef NDEBUG
  /* preparation for assertion below */
  u_i_minus_1_size = gt_bittab_count_set_bits(U_i);
#endif
  while (gt_bittab_is_true(U_i)) {
    sa_i = GT_UNDEF_ULONG;
    for (sa_prime  = gt_bittab_get_first_bitnum(U_i);
         sa_prime != gt_bittab_get_last_bitnum(U_i);
         sa_prime  = gt_bittab_get_next_bitnum(U_i, sa_prime)) {
      if (sa_i == GT_UNDEF_ULONG) {
        sa_i = sa_prime;
        gt_bittab_or(SA_i, L[sa_i], R[sa_i]);
        sa_i_size = gt_bittab_count_set_bits(SA_i);
      }
      else {
        gt_bittab_or(SA_prime, L[sa_prime], R[sa_prime]);
        sa_prime_size = gt_bittab_count_set_bits(SA_prime);
        if (sa_prime_size > sa_i_size) {
          sa_i = sa_prime;
          sa_i_size = sa_prime_size;
          gt_bittab_equal(SA_i, SA_prime);
        }
      }
    }

    /* make sure the computed splice form is maximal w.r.t. to compatibility */
    gt_assert(splice_form_is_valid(SA_i, csa));

    /* process splice form */
    if (csa->process_splice_form) {
      gt_array_reset(splice_form);
      gt_bittab_get_all_bitnums(SA_i, splice_form);
      csa->process_splice_form(splice_form, csa->set_of_sas, csa->number_of_sas,
                               csa->size_of_sa, csa->userdata);
    }

    /* U_i = U_i-1 \ SA_i */
    gt_bittab_nand(U_i, U_i, SA_i);

#ifndef NDEBUG
    /* ensure that |U_i| < |U_i-1| */
    u_i_size = gt_bittab_count_set_bits(U_i);
    gt_assert(u_i_size < u_i_minus_1_size);
    u_i_minus_1_size = u_i_size;
#endif
  }

  /* free sets */
  for (i = 0; i < csa->number_of_sas; i++) {
    gt_bittab_delete(C[i]);
    gt_bittab_delete(left[i]);
    gt_bittab_delete(right[i]);
    gt_bittab_delete(L[i]);
    gt_bittab_delete(R[i]);
  }
  gt_free(C);
  gt_free(left);
  gt_free(right);
  gt_free(L);
  gt_free(R);
  gt_bittab_delete(U_i);
  gt_bittab_delete(SA_i);
  gt_bittab_delete(SA_prime);
  gt_array_delete(splice_form);
}