Skip to content

Commit

Permalink
fix potential bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hasindu2008 committed Mar 5, 2024
1 parent a2ec103 commit 6e83b04
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/genread.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,34 @@ static inline int get_rlen(core_t *core, int tid){
}

static void methylate_dna(core_t *core, int32_t ref_len, int32_t ref_pos, int32_t rlen, char c, char *seq, int seq_i, int tid){
for(int i=0; i<rlen; i++){
int rpos = ref_pos+i;
if(rpos+1 < ref_len && i+1<rlen){
if(core->ref->ref_seq[seq_i][ref_pos+i] == 'C' &&
core->ref->ref_seq[seq_i][ref_pos+i+1] == 'G'){
int methr = rng(&core->rand_meth[tid]) * 254;
if( methr <= core->ref->ref_meth[seq_i][ref_pos+i]){

int p = i;
if(c == '-'){
//fprintf(stderr,"here\n");
p = rlen - i - 2;
}
if(!(p>=0 && p<rlen)){
fprintf(stderr,"p: %d, i: %d, rlen: %d, c: %c, ref_pos: %d, ref_len: %d\n",p,i,rlen,c,ref_pos,ref_len);
if(core->ref->ref_meth[seq_i]){
for(int i=0; i<rlen; i++){
int rpos = ref_pos+i;
if(rpos+1 < ref_len && i+1<rlen){
if(core->ref->ref_seq[seq_i][ref_pos+i] == 'C' &&
core->ref->ref_seq[seq_i][ref_pos+i+1] == 'G'){
int methr = rng(&core->rand_meth[tid]) * 254;
if( methr <= core->ref->ref_meth[seq_i][ref_pos+i]){

int p = i;
if(c == '-'){
//fprintf(stderr,"here\n");
p = rlen - i - 2;
}
if(!(p>=0 && p<rlen)){
fprintf(stderr,"p: %d, i: %d, rlen: %d, c: %c, ref_pos: %d, ref_len: %d\n",p,i,rlen,c,ref_pos,ref_len);

assert(0);
}
assert(seq[p] == 'C' || seq[p] == 'c');
if(!(seq[p+1] == 'G' || seq[p+1] == 'g')){
fprintf(stderr,"p: %d, i: %d, rlen: %d, c: %c, ref_pos: %d, ref_len: %d\n",p,i,rlen,c,ref_pos,ref_len);
fprintf(stderr,"seq: %c%c%c%c%c%c%c%c%c%c\n",seq[p],seq[p+1],seq[p+2],seq[p+3],seq[p+4],seq[p+5],seq[p+6],seq[p+7],seq[p+8],seq[p+9]);
assert(0);
}
seq[p] = 'M';

assert(0);
}
assert(seq[p] == 'C' || seq[p] == 'c');
if(!(seq[p+1] == 'G' || seq[p+1] == 'g')){
fprintf(stderr,"p: %d, i: %d, rlen: %d, c: %c, ref_pos: %d, ref_len: %d\n",p,i,rlen,c,ref_pos,ref_len);
fprintf(stderr,"seq: %c%c%c%c%c%c%c%c%c%c\n",seq[p],seq[p+1],seq[p+2],seq[p+3],seq[p+4],seq[p+5],seq[p+6],seq[p+7],seq[p+8],seq[p+9]);
assert(0);
}
seq[p] = 'M';

}
}
}
Expand Down

0 comments on commit 6e83b04

Please sign in to comment.