Esempio n. 1
0
static int encseq_builder_lua_delete(lua_State *L)
{
  GtEncseqBuilder **builder;
  builder = check_encseq_builder(L, 1);
  gt_encseq_builder_delete(*builder);
  return 0;
}
Esempio n. 2
0
int gt_codon_iterator_encseq_unit_test(GtError *err)
{
  int had_err = 0,
      i, j;
  const char *testseq    = "gctgatcgactgaacatagctagcacggccgcgcgatcgtacgatg",
             *testseq_rc = "catcgtacgatcgcgcggccgtgctagctatgttcagtcgatcagc",
             *testseq_rv = "gtagcatgctagcgcgccggcacgatcgatacaagtcagctagtcg",
             *testseq_cm = "cgactagctgacttgtatcgatcgtgccggcgcgctagcatgctac";
  GtEncseq *encseq;
  GtEncseqBuilder *eb;
  GtCodonIterator *ci;
  GtAlphabet *alpha;
  char n1, n2, n3;
  unsigned int frame;
  gt_error_check(err);

  alpha = gt_alphabet_new_dna();
  eb = gt_encseq_builder_new(alpha);
  gt_encseq_builder_add_cstr(eb, testseq, strlen(testseq), "foo");
  encseq = gt_encseq_builder_build(eb, NULL);

  /* forward tests */
  had_err = gt_codon_iterator_encseq_single_test(encseq, testseq, testseq,
                                                 GT_READMODE_FORWARD, err);

  /* complement tests */
  had_err = gt_codon_iterator_encseq_single_test(encseq, testseq, testseq_cm,
                                                 GT_READMODE_COMPL, err);

  /* revcompl tests */
  had_err = gt_codon_iterator_encseq_single_test(encseq, testseq, testseq_rc,
                                                 GT_READMODE_REVCOMPL, err);

  /* reverse tests */
  had_err = gt_codon_iterator_encseq_single_test(encseq, testseq, testseq_rv,
                                                 GT_READMODE_REVERSE, err);

  /* lengths < 3 */
  for (j = 0; !had_err && j < 3; j++) {
    ci = gt_codon_iterator_encseq_new_with_readmode(encseq, 10, j,
                                                    GT_READMODE_REVCOMPL, NULL);
    i = 10;
    while (!(gt_codon_iterator_next(ci, &n1, &n2, &n3, &frame, NULL))) {
      gt_ensure(had_err, false);
    }
    gt_ensure(had_err, i == 10);
    gt_codon_iterator_delete(ci);
  }

  gt_encseq_delete(encseq);
  gt_encseq_builder_delete(eb);
  gt_alphabet_delete(alpha);
  return had_err;
}
Esempio n. 3
0
int gt_sarrquerysubstringmatch(const GtUchar *dbseq,
                               GtUword dblen,
                               const GtUchar *query,
                               GtUword querylen,
                               unsigned int minlength,
                               GtAlphabet *alpha,
                               GtProcessquerymatch processquerymatch,
                               void *processquerymatchinfo,
                               GtLogger *logger,
                               GtError *err)
{
  unsigned int numofchars, recommendedprefixlength;
  bool haserr = false;
  GtEncseq *dbencseq;
  GtEncseqBuilder *eb;

  gt_assert(querylen >= (GtUword) minlength && dblen >= (GtUword) minlength);
  eb = gt_encseq_builder_new(alpha);
  gt_encseq_builder_disable_multiseq_support(eb);
  gt_encseq_builder_disable_description_support(eb);
  gt_encseq_builder_set_logger(eb, logger);
  gt_encseq_builder_add_multiple_encoded(eb,dbseq,dblen);
  dbencseq = gt_encseq_builder_build(eb, err);
  gt_encseq_builder_delete(eb);
  numofchars = gt_alphabet_num_of_chars(alpha);
  recommendedprefixlength
    = gt_recommendedprefixlength(numofchars,dblen,
                                 GT_RECOMMENDED_MULTIPLIER_DEFAULT,
                                 true);
  if (gt_constructsarrandrunmmsearch(dbencseq,
                                     GT_READMODE_FORWARD,
                                     recommendedprefixlength,
                                     1U, /* parts */
                                     0, /* maximumspace */
                                     query,
                                     querylen,
                                     minlength,
                                     processquerymatch,
                                     processquerymatchinfo,
                                     NULL,
                                     false,
                                     logger,
                                     err) != 0)
  {
    haserr = true;
  }
  gt_encseq_delete(dbencseq);
  dbencseq = NULL;
  return haserr ? -1 : 0;
}
Esempio n. 4
0
static int sarrselfsubstringmatch(const GtUchar *dbseq,
                                  GtUword dblen,
                                  const GtUchar *query,
                                  GtUword querylen,
                                  unsigned int minlength,
                                  GtAlphabet *alpha,
                                  Processmaxpairs processmaxpairs,
                                  void *processmaxpairsinfo,
                                  GtLogger *logger,
                                  GtError *err)
{
  Substringmatchinfo ssi;
  unsigned int numofchars, recommendedprefixlength;
  GtEncseqBuilder *eb;
  bool haserr = false;

  eb = gt_encseq_builder_new(alpha);
  gt_encseq_builder_disable_multiseq_support(eb);
  gt_encseq_builder_disable_description_support(eb);
  gt_encseq_builder_set_logger(eb, logger);
  gt_encseq_builder_add_encoded(eb, dbseq, dblen, NULL);
  gt_encseq_builder_add_encoded(eb, query, querylen, NULL);
  ssi.encseq = gt_encseq_builder_build(eb, err);
  gt_encseq_builder_delete(eb);

  ssi.minlength = minlength;
  ssi.processmaxpairs = processmaxpairs;
  ssi.processmaxpairsinfo = processmaxpairsinfo;
  numofchars = gt_alphabet_num_of_chars(alpha);
  recommendedprefixlength
    = gt_recommendedprefixlength(numofchars,
                                 dblen+querylen+1,
                                 GT_RECOMMENDED_MULTIPLIER_DEFAULT,
                                 true);
  if (constructsarrandrunmaxpairs(&ssi,
                                  GT_READMODE_FORWARD,
                                  recommendedprefixlength,
                                  1U, /* parts */
                                  0, /* maximumspace */
                                  NULL,
                                  false,
                                  logger,
                                  err) != 0)
  {
    haserr = true;
  }
  gt_encseq_delete(ssi.encseq);
  ssi.encseq = NULL;
  return haserr ? -1 : 0;
}
Esempio n. 5
0
int gt_encseq_gc_unit_test(GtError *err)
{
  int had_err = 0;
  double *results;
  GtEncseqBuilder *eb;
  GtEncseq *encseq;
  const char testseq1[] = "aaaaaa",
             testseq2[] = "cccccc",
             testseq3[] = "acgtacgt",
             testseq4[] = "acgtn";
          /* testseq5[] = "xxxxn"; */
  GtAlphabet *alpha;
/*GtError *tmp_err;*/

  gt_error_check(err);

  alpha = gt_alphabet_new_dna();

  /* test a-seq */
  eb = gt_encseq_builder_new(alpha);
  gt_encseq_builder_create_ssp_tab(eb);
  gt_encseq_builder_enable_description_support(eb);
  gt_encseq_builder_add_cstr(eb, testseq1, 6UL, "only a");
  encseq = gt_encseq_builder_build(eb, err);
  if ((results = gt_encseq_get_gc(encseq,
                                  false,
                                  true,
                                  err)) != NULL)
  {
    gt_ensure(had_err, gt_double_equals_double(results[0], 0.0));
  }
  else
  {
    had_err = -1;
  }
  gt_free(results);
  gt_encseq_builder_delete(eb);
  gt_encseq_delete(encseq);

  if (!had_err)
  {
    /* test c-seq */
    eb = gt_encseq_builder_new(alpha);
    gt_encseq_builder_create_ssp_tab(eb);
    gt_encseq_builder_enable_description_support(eb);
    gt_encseq_builder_add_cstr(eb, testseq2, 6UL, "only c");
    encseq = gt_encseq_builder_build(eb, err);
    if ((results = gt_encseq_get_gc(encseq,
                                    false,
                                    true,
                                    err)) != NULL)
    {
      gt_ensure(had_err, gt_double_equals_one(results[0]));
    }
    else
    {
      had_err = -1;
    }
    gt_free(results);
    gt_encseq_builder_delete(eb);
    gt_encseq_delete(encseq);
  }

  if (!had_err)
  {
    /* test dna-seq and dna+special-seq*/
    eb = gt_encseq_builder_new(alpha);
    gt_encseq_builder_create_ssp_tab(eb);
    gt_encseq_builder_enable_description_support(eb);
    gt_encseq_builder_add_cstr(eb, testseq3, 8UL, "0.5");
    gt_encseq_builder_add_cstr(eb, testseq4, 5UL, "0.5+special");
    encseq = gt_encseq_builder_build(eb, err);
    if ((results = gt_encseq_get_gc(encseq,
                                    false,
                                    true,
                                    err)) != NULL)
    {
      gt_ensure(had_err, gt_double_equals_double(results[0], 0.5));
      gt_ensure(had_err, gt_double_equals_double(results[1], 0.5));
    }
    else
    {
      had_err = -1;
    }
    gt_free(results);

    if (!had_err)
    {
      /* count special chars */
      if ((results = gt_encseq_get_gc(encseq,
                                      true,
                                      true,
                                      err)) != NULL)
      {
        gt_ensure(had_err, gt_double_equals_double(results[0], 0.5));
        gt_ensure(had_err, gt_double_equals_double(results[1], (2.0/5.0)));
      }
      else
      {
        had_err = -1;
      }
      gt_free(results);
    }

    gt_encseq_builder_delete(eb);
    gt_encseq_delete(encseq);
  }

  if (!had_err)
    {
      /* test dna-seq and dna+special-seq*/
      eb = gt_encseq_builder_new(alpha);
      gt_encseq_builder_create_ssp_tab(eb);
      gt_encseq_builder_enable_description_support(eb);
      gt_encseq_builder_add_cstr(eb, testseq3, 8UL, "0.5");
      gt_encseq_builder_add_cstr(eb, testseq4, 5UL, "0.5+special");
      encseq = gt_encseq_builder_build(eb, err);
      /*add mirrored sequence*/
      had_err = gt_encseq_mirror(encseq, err);
      /* sequence wise */
      if ((results = gt_encseq_get_gc(encseq,
                                      false,
                                      true,
                                      err)) != NULL)
      {
        gt_ensure(had_err, gt_double_equals_double(results[0], 0.5));
        gt_ensure(had_err, gt_double_equals_double(results[1], 0.5));
        gt_ensure(had_err, gt_double_equals_double(results[2], 0.5));
        gt_ensure(had_err, gt_double_equals_double(results[3], 0.5));
      }
      else
      {
        had_err = -1;
      }
      gt_free(results);

      if (!had_err)
      {
        /* count special chars */
        if ((results = gt_encseq_get_gc(encseq,
                                        true,
                                        true,
                                        err)) != NULL)
        {
          gt_ensure(had_err, gt_double_equals_double(results[0], 0.5));
          gt_ensure(had_err, gt_double_equals_double(results[1], (2.0/5.0)));
          gt_ensure(had_err, gt_double_equals_double(results[2], (2.0/5.0)));
          gt_ensure(had_err, gt_double_equals_double(results[3], 0.5));
        }
        else
        {
          had_err = -1;
        }
        gt_free(results);
      }
      gt_encseq_builder_delete(eb);
      gt_encseq_delete(encseq);
    }
    gt_alphabet_delete(alpha);
  return had_err;
}