Beispiel #1
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;
}
Beispiel #2
0
static int encseq_builder_lua_add_str(lua_State *L)
{
  GtEncseqBuilder **builder;
  const char *str, *desc;
  builder = check_encseq_builder(L, 1);
  str = luaL_checkstring(L, 2);
  if (lua_isnil(L, 3))
    desc = "";
  else
    desc = luaL_checkstring(L, 3);
  gt_assert(*builder);
  gt_encseq_builder_add_cstr(*builder, str, strlen(str), desc);
  return 0;
}
Beispiel #3
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;
}