📄 blast_gapalign.c
字号:
decline_penalty; score_gap_row -= gap_extend; b_size++; } } if (b_size <= N) { score_array[b_size].best = MININT; score_array[b_size].best_gap = MININT; score_array[b_size].best_decline = MININT; b_size++; } } sfree(score_array); return best_score;}/** Low level function to perform gapped extension with out-of-frame * gapping with traceback * @param A The query sequence [in] * @param B The subject sequence [in] * @param M Maximal extension length in query [in] * @param N Maximal extension length in subject [in] * @param S The traceback information from previous extension [in] * @param a_offset Resulting starting offset in query [out] * @param b_offset Resulting starting offset in subject [out] * @param sapp The traceback information [out] * @param gap_align Structure holding various information and allocated * memory for the gapped alignment [in] * @param score_params Parameters related to scoring [in] * @param query_offset The starting offset in query [in] * @param reversed Has the sequence been reversed? Used for psi-blast [in] * @return The best alignment score found. */#define SCRIPT_GAP_IN_A 0#define SCRIPT_AHEAD_ONE_FRAME 1#define SCRIPT_AHEAD_TWO_FRAMES 2#define SCRIPT_NEXT_IN_FRAME 3#define SCRIPT_NEXT_PLUS_ONE_FRAME 4#define SCRIPT_NEXT_PLUS_TWO_FRAMES 5#define SCRIPT_GAP_IN_B 6#define SCRIPT_OOF_OP_MASK 0x07#define SCRIPT_OOF_OPEN_GAP 0x10#define SCRIPT_EXTEND_GAP_IN_A 0x20#define SCRIPT_EXTEND_GAP_IN_B 0x40static Int4 OOF_ALIGN(Uint1* A, Uint1* B, Int4 M, Int4 N, Int4* S, Int4* a_offset, Int4* b_offset, Int4** sapp, BlastGapAlignStruct* gap_align, const BlastScoringParameters* score_params, Int4 query_offset, Boolean reversed){ BlastGapDP* score_array; /* sequence pointers and indices */ Int4 i, increment; Int4 a_index; Int4 b_index, b_size, first_b_index, last_b_index; Int4 gap_open; /* alignment penalty variables */ Int4 gap_extend; Int4 gap_open_extend; Int4 shift_penalty; Int4 x_dropoff; Int4* *matrix; /* pointers to the score matrix */ Int4* matrix_row; Int4 score; /* score tracking variables */ Int4 score_row1; Int4 score_row2; Int4 score_row3; Int4 score_gap_col; Int4 score_col1; Int4 score_col2; Int4 score_col3; Int4 score_other_frame1; Int4 score_other_frame2; Int4 best_score; GapData data; /* traceback variables */ GapStateArrayStruct* state_struct; Uint1** edit_script; Uint1* edit_script_row; Int4 orig_b_index; Int1 script, next_script; Int4 align_len; /* do initialization and sanity-checking */ matrix = gap_align->sbp->matrix; *a_offset = 0; *b_offset = -2; gap_open = score_params->gap_open; gap_extend = score_params->gap_extend; gap_open_extend = gap_open + gap_extend; shift_penalty = score_params->shift_pen; x_dropoff = gap_align->gap_x_dropoff; if (x_dropoff < gap_open_extend) x_dropoff = gap_open_extend; if(N <= 0 || M <= 0) return 0; /* Initialize traceback information. edit_script[] is a 2-D array which is filled in row by row as the dynamic programming takes place */ data.sapp = S; data.last = 0; *sapp = S; GapPurgeState(gap_align->state_struct); edit_script = (Uint1**) malloc(sizeof(Uint1*)*(M+1)); state_struct = GapGetState(&gap_align->state_struct, N + 5); edit_script[0] = state_struct->state_array; edit_script_row = state_struct->state_array; /* Allocate and fill in the auxiliary bookeeping structures (one struct per letter of B) */ score_array = (BlastGapDP*)calloc((N + 4), sizeof(BlastGapDP)); score = -gap_open_extend; score_array[0].best = 0; score_array[0].best_gap = -gap_open_extend; for (i = 3; i <= N + 2; i += 3) { score_array[i].best = score; score_array[i].best_gap = score - gap_open_extend; edit_script_row[i] = SCRIPT_GAP_IN_B; score_array[i-1].best = MININT; score_array[i-1].best_gap = MININT; edit_script_row[i-1] = SCRIPT_GAP_IN_B; score_array[i-2].best = MININT; score_array[i-2].best_gap = MININT; edit_script_row[i-2] = SCRIPT_GAP_IN_B; if (score < -x_dropoff) break; score -= gap_extend; } /* The inner loop below examines letters of B from index 'first_b_index' to 'b_size' */ b_size = i - 2; state_struct->used = b_size + 1; score_array[b_size].best = MININT; score_array[b_size].best_gap = MININT; best_score = 0; first_b_index = 0; if (reversed) { increment = -1; } else { /* Allow for a backwards frame shift */ B -= 2; increment = 1; } for (a_index = 1; a_index <= M; a_index++) { /* Set up the next row of the edit script; this involves allocating memory for the row, then pointing to it */ state_struct = GapGetState(&gap_align->state_struct, N + 5 - first_b_index); edit_script[a_index] = state_struct->state_array + state_struct->used + 1; edit_script_row = edit_script[a_index]; orig_b_index = first_b_index; if (!(gap_align->positionBased)) { matrix_row = matrix[ A[ a_index * increment ] ]; } else { if(reversed) matrix_row = gap_align->sbp->posMatrix[M - a_index]; else matrix_row = gap_align->sbp->posMatrix[a_index + query_offset]; } score = MININT; score_row1 = MININT; score_row2 = MININT; score_row3 = MININT; score_gap_col = MININT; score_col1 = MININT; score_col2 = MININT; score_col3 = MININT; score_other_frame1 = MININT; score_other_frame2 = MININT; last_b_index = first_b_index; b_index = first_b_index; /* The inner loop is identical to that of OOF_SEMI_G_ALIGN, except that traceback operations are sprinkled throughout. */ while (b_index < b_size) { /* FRAME 0 */ score = MAX(score_other_frame1, score_other_frame2) - shift_penalty; score = MAX(score, score_col1); if (score == score_col1) { script = SCRIPT_NEXT_IN_FRAME; } else if (score + shift_penalty == score_other_frame1) { if (score_other_frame1 == score_col2) script = SCRIPT_AHEAD_TWO_FRAMES; else script = SCRIPT_NEXT_PLUS_TWO_FRAMES; } else { if (score_other_frame2 == score_col3) script = SCRIPT_AHEAD_ONE_FRAME; else script = SCRIPT_NEXT_PLUS_ONE_FRAME; } score += matrix_row[ B[ b_index * increment ] ]; score_other_frame1 = MAX(score_col1, score_array[b_index].best); score_col1 = score_array[b_index].best; score_gap_col = score_array[b_index].best_gap; if (score < MAX(score_gap_col, score_row1)) { if (score_gap_col > score_row1) { score = score_gap_col; script = SCRIPT_OOF_OPEN_GAP | SCRIPT_GAP_IN_A; } else { score = score_row1; script = SCRIPT_OOF_OPEN_GAP | SCRIPT_GAP_IN_B; } if (best_score - score > x_dropoff) { if (first_b_index == b_index) first_b_index = b_index + 1; else score_array[b_index].best = MININT; } else { last_b_index = b_index + 1; score_array[b_index].best = score; score_array[b_index].best_gap = score_gap_col - gap_extend; score_row1 -= gap_extend; } } else { if (best_score - score > x_dropoff) { if (first_b_index == b_index) first_b_index = b_index + 1; else score_array[b_index].best = MININT; } else { last_b_index = b_index + 1; score_array[b_index].best = score; if (score > best_score) { best_score = score; *a_offset = a_index; *b_offset = b_index; } score -= gap_open_extend; score_row1 -= gap_extend; if (score > score_row1) score_row1 = score; else script |= SCRIPT_EXTEND_GAP_IN_B; score_gap_col -= gap_extend; if (score < score_gap_col) { score_array[b_index].best_gap = score_gap_col; script |= SCRIPT_EXTEND_GAP_IN_A; } else { score_array[b_index].best_gap = score; } } } edit_script_row[b_index] = script; if (++b_index >= b_size) { score = score_row1; score_row1 = score_row2; score_row2 = score_row3; score_row3 = score; break; } /* FRAME 1 */ score = MAX(score_other_frame1, score_other_frame2) - shift_penalty; score = MAX(score, score_col2); if (score == score_col2) { script = SCRIPT_NEXT_IN_FRAME; } else if (score + shift_penalty == score_other_frame1) { if (score_other_frame1 == score_col1) script = SCRIPT_AHEAD_ONE_FRAME; else script = SCRIPT_NEXT_PLUS_ONE_FRAME; } else { if (score_other_frame2 == score_col3) script = SCRIPT_AHEAD_TWO_FRAMES; else script = SCRIPT_NEXT_PLUS_TWO_FRAMES; } score += matrix_row[ B[ b_index * increment ] ]; score_other_frame2 = MAX(score_col2, score_array[b_index].best); score_col2 = score_array[b_index].best; score_gap_col = score_array[b_index].best_gap; if (score < MAX(score_gap_col, score_row2)) { score = MAX(score_gap_col, score_row2); if (best_score - score > x_dropoff) { if (first_b_index == b_index) first_b_index = b_index + 1; else score_array[b_index].best = MININT; } else { if (score == score_gap_col) script = SCRIPT_OOF_OPEN_GAP | SCRIPT_GAP_IN_A; else script = SCRIPT_OOF_OPEN_GAP | SCRIPT_GAP_IN_B; last_b_index = b_index + 1; score_array[b_index].best = score; score_array[b_index].best_gap = score_gap_col - gap_extend; score_row2 -= gap_extend; } } else { if (best_score - score > x_dropoff) { if (first_b_index == b_index) first_b_index = b_index + 1; else score_array[b_index].best = MININT; } else { last_b_index = b_index + 1; score_array[b_index].best = score; if (score > best_score) { best_score = score; *a_offset = a_index; *b_offset = b_index; } score -= gap_open_extend; score_row2 -= gap_extend; if (score > score_row2) score_row2 = score; else script |= SCRIPT_EXTEND_GAP_IN_B; score_gap_col -= gap_extend; if (score < score_gap_col) { score_array[b_index].best_gap = score_gap_col; script |= SCRIPT_EXTEND_GAP_IN_A; } else { score_array[b_index].best_gap = score; } } } edit_script_row[b_index] = script; ++b_index; if (b_index >= b_size) { score = score_row2; score_row2 = score_row1; score_row1 = score_row3; score_row3 = score; break; } /* FRAME 2 */ score = MAX(score_other_frame1, score_other_frame2) - shift_penalty; score = MAX(score, score_col3); if (score == score_col3) { script = SCRIPT_NEXT_IN_FRAME; } else if (score + shift_penalty == score_other_frame1) { if (score_other_frame1 == score_col1) script = SCRIPT_AHEAD_TWO_FRAMES;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -