static int difference_clip_contig(GapIO *io, int contig, int start, int end, int *old_start, int *old_end, int add_tags) { int rnum; int win_len = 31; double disfract = 0.25; char *seq; int win_len2; int start2, end2, length2; int i, i_end, j; char *con; int count, worst_count; int lowest_dis, lowest_pos; int score, highest_score, highest_pos; int new_left, new_right; GReadings r; int nbases = 0; win_len2 = win_len / 2; /* Get consensus sequence */ if (NULL == (con = (char *)xmalloc(io_clength(io, contig)+1))) return -1; calc_consensus(contig, 1, io_clength(io, contig), CON_SUM, con, NULL, NULL, NULL, consensus_cutoff, quality_cutoff, database_info, (void *)io); /* Find start reading */ for (rnum = io_clnbr(io, contig); io_relpos(io, rnum) < start; rnum = io_rnbr(io, rnum)) ; /* Loop through readings up to 'end' position */ for (; rnum && io_relpos(io, rnum) <= end; rnum = io_rnbr(io, rnum)) { /* * Find segment with the lowest difference count, averaged * over 'win_len' bases. */ io_aread_seq(io, rnum, &length2, &start2, &end2, &seq, NULL, NULL, 0); if (length2 < win_len) { if (seq) xfree(seq); continue; } count = 0; worst_count = 0; if (win_len > end2 - start2) { if (seq) xfree(seq); continue; /* too short to compare over win_len */ } for (j = io_relpos(io, rnum) - 1, i = start2; i < start2 + win_len && i < end2 - 1; i++, j++) { if (!same_char(seq[i], con[j])) count++; } i_end = end2 - 2 - win_len2; lowest_dis = count; lowest_pos = start2 + win_len2; for (i = start2 + win_len2, j = io_relpos(io, rnum) - 1 + win_len2; i < i_end; i++, j++) { if (count < lowest_dis) { lowest_dis = count; lowest_pos = i; } if (count > worst_count) worst_count = count; count -= !same_char(seq[i-win_len2], con[j-win_len2]); count += !same_char(seq[i+win_len2+1], con[j+win_len2+1]); } if (worst_count < disfract * win_len) { if (seq) xfree(seq); continue; } gel_read(io, rnum, r); /* * Work outwards from lowest_pos in both directions finding the * location where the alignment score is highest. We used a fixed * score/penalty system. */ score = highest_score = 0; highest_pos = lowest_pos; for (j = io_relpos(io, rnum) - 1 + lowest_pos - start2, i = lowest_pos; i < r.end - 1; i++, j++) { if (same_char(seq[i], con[j])) score += SCORE_MATCH; else score += SCORE_MISMATCH; if (score > highest_score) { highest_score = score; highest_pos = i; } } /* printf("Read %d: Best match at %d, extend R to %d (score %d)\n", rnum, lowest_pos, highest_pos, highest_score); */ new_right = highest_pos + 2; score = highest_score = 0; highest_pos = lowest_pos; for (j = io_relpos(io, rnum) - 1 + lowest_pos - start2, i = lowest_pos; i >= r.start; i--, j--) { if (same_char(seq[i], con[j])) score += SCORE_MATCH; else score += SCORE_MISMATCH; if (score > highest_score) { highest_score = score; highest_pos = i; } } /* printf("Read %d: Best match at %d, extend L to %d (score %d)\n", rnum, lowest_pos, highest_pos, highest_score); */ new_left = highest_pos; if (new_right < new_left + 2) new_right = new_left + 2; /* Tag the change */ if (add_tags && new_left != r.start) { char buf[100]; int tag_st; if (r.sense) { tag_st = r.length - new_left + 1; } else { tag_st = r.start + 1; } sprintf(buf, "Difference clipped from old start at %d\n", r.start); insert_NEW_tag(io, rnum, tag_st, new_left - r.start, "DIFF", buf, 2); } if (add_tags && new_right != r.end) { char buf[100]; int tag_st; if (r.sense) { tag_st = r.length - r.end + 2; } else { tag_st = new_right; } sprintf(buf, "Difference clipped from old end at %d\n", r.end); insert_NEW_tag(io, rnum, tag_st, r.end - new_right, "DIFF", buf, 2); } /* Update reading positions/length */ gel_read(io, rnum, r); r.position += new_left - r.start; old_start[rnum] = r.start; old_end[rnum] = r.end; r.start = new_left; r.end = new_right; nbases += r.sequence_length - (r.end - r.start - 1); r.sequence_length = r.end - r.start - 1; gel_write(io, rnum, r); io_relpos(io, rnum) = r.position; io_length(io, rnum) = r.sense ? -r.sequence_length : r.sequence_length; if (seq) xfree(seq); } xfree(con); return nbases; }
static void seg_test( __segment seg_var, char __far* seg_beg, char __far* elements, unsigned line_no ) { char __based( seg_var ) *pseg; pseg = (unsigned)(elements - seg_beg); same_char( 'a', *(pseg+0), line_no ); same_char( 'b', *(pseg+1), line_no ); same_char( 'c', *(pseg+2), line_no ); same_char( 'd', *(pseg+3), line_no ); same_char( 'e', *(pseg+4), line_no ); }
static void addrs_of() { char *p01 = &char_file_scope; // regular same_char( *p01, 'q', __LINE__ ); char __far16 *p02 = &char_file_scope; // far16 same_char( *p02, 'q', __LINE__ ); char __based( base_ptr ) *p03 = &array_file_scope[2]; same_char( *p03, 't', __LINE__ ); char _far *p04; p04 = p01; same_char( *p04, 'q', __LINE__ ); p04 = p02; same_char( *p04, 'q', __LINE__ ); p04 = p03; same_char( *p04, 't', __LINE__ ); same_char( 'j', char_area, __LINE__ ); same_char( 'c', array_area[2], __LINE__ ); same_char( 'j', char_data, __LINE__ ); same_char( 'c', array_data[2], __LINE__ ); same_char( 'j', char_code, __LINE__ ); same_char( 'c', array_code[2], __LINE__ ); same_char( 'j', char_text, __LINE__ ); same_char( 'c', array_text[2], __LINE__ ); }