Skip to content

Commit

Permalink
Fix for first base
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-q committed Nov 18, 2018
1 parent 247a527 commit 344f08f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions faops.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,31 +349,31 @@ int fa_masked(int argc, char *argv[]) {
kseq_t *seq = kseq_init(fp);

while (kseq_read(seq) >= 0) {
int begin = 0, end = 0;
int begin = -1, end = -1;
for (int i = 0; i < seq->seq.l; i++) {
if (flag_g
? is_n(seq->seq.s[i])
: (is_n(seq->seq.s[i]) || islower(seq->seq.s[i]))) {
if (begin == 0) {
if (begin == -1) {
begin = i, end = i;
} else {
end = i;
}
} else if (begin != 0) {
} else if (begin != -1) {
if (begin == end) {
printf("%s:%u\n", seq->name.s, begin + 1);
} else {
printf("%s:%u-%u\n", seq->name.s, begin + 1, end + 1);
}
// reset
begin = 0, end = 0;
begin = -1, end = -1;
}


}

// last region
if (begin != 0) {
if (begin != -1) {
if (begin == end) {
printf("%s:%u\n", seq->name.s, begin + 1);
} else {
Expand Down
6 changes: 6 additions & 0 deletions test/16-masked.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ load test_helper
res=$($BATS_TEST_DIRNAME/../faops masked $BATS_TEST_DIRNAME/ufasta.fa | grep '^read46' | head -n 1)
assert_equal "$exp" "$res"
}

@test "masked" {
exp="read0:1"
res=$($BATS_TEST_DIRNAME/../faops masked $BATS_TEST_DIRNAME/ufasta.fa | grep '^read0' | head -n 1)
assert_equal "$exp" "$res"
}

0 comments on commit 344f08f

Please sign in to comment.