Skip to content

Commit

Permalink
Refactored twobit_bases function
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Sep 19, 2024
1 parent 73d88d8 commit 27a5053
Showing 1 changed file with 11 additions and 38 deletions.
49 changes: 11 additions & 38 deletions ext/bio/twobit/twobit.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ twobit_bases(VALUE self, VALUE chrom, VALUE start, VALUE end, VALUE fraction)
TwoBit *tb;
void *o = NULL;
VALUE val, hash;
const char *bases[4] = {"A", "C", "T", "G"};

tb = getTwoBit(self);
if (!tb)
Expand All @@ -317,48 +318,20 @@ twobit_bases(VALUE self, VALUE chrom, VALUE start, VALUE end, VALUE fraction)

hash = rb_hash_new();

if (fr)
for (int i = 0; i < 4; i++)
{
val = DBL2NUM(((double *)o)[0]);
}
else
{
val = UINT32_2NUM(((uint32_t *)o)[0]);
}
rb_hash_aset(hash, rb_str_new2("A"), val);

if (fr)
{
val = DBL2NUM(((double *)o)[1]);
}
else
{
val = UINT32_2NUM(((uint32_t *)o)[1]);
}
rb_hash_aset(hash, rb_str_new2("C"), val);

if (fr)
{
val = DBL2NUM(((double *)o)[2]);
}
else
{
val = UINT32_2NUM(((uint32_t *)o)[2]);
}
rb_hash_aset(hash, rb_str_new2("T"), val);

if (fr)
{
val = DBL2NUM(((double *)o)[3]);
}
else
{
val = UINT32_2NUM(((uint32_t *)o)[3]);
if (fr)
{
val = DBL2NUM(((double *)o)[i]);
}
else
{
val = UINT32_2NUM(((uint32_t *)o)[i]);
}
rb_hash_aset(hash, rb_str_new2(bases[i]), val);
}
rb_hash_aset(hash, rb_str_new2("G"), val);

free(o);

return hash;
}

Expand Down

0 comments on commit 27a5053

Please sign in to comment.