/*show sequences, alignment and score*/ static void alignment_show_with_sequences(const GtUchar *useq, GtUword ulen, const GtUchar *vseq, GtUword vlen, const GtAlignment *align, const GtUchar *characters, GtUchar wildcardshow, bool showscore, bool showalign, bool showsequences, bool global, const GtScoreHandler *scorehandler, FILE *fp) { if (fp != NULL) { if (showsequences) { gt_linspace_print_sequence(characters,wildcardshow,useq, ulen, fp); gt_linspace_print_sequence(characters,wildcardshow,vseq, vlen, fp); } fprintf(fp, "######\n"); if (showalign && gt_alignment_get_length(align) > 0) { gt_alignment_show_with_mapped_chars(align, characters, wildcardshow, fp, 80); } else { if (showalign) { fprintf(fp, "empty alignment\n"); } } if (!showalign || showscore) { GtWord score = gt_scorehandler_eval_alignmentscore(scorehandler, align, characters); fprintf(fp, "%s: "GT_WD"\n", global? "distance" : "score", score); } } }
static GtMatchIteratorStatus gt_match_iterator_sw_next(GtMatchIterator *mi, GT_UNUSED GtMatch **match, GT_UNUSED GtError *err) { GtMatchIteratorSW *mis; GtSeq *seq_a, *seq_b; char *a, *b; const char *adesc, *bdesc; GtAlignment *ali = NULL; unsigned long seqlen_a, seqlen_b, seqpos; GtRange arng, brng; gt_assert(mi && match); mis = gt_match_iterator_sw_cast(mi); while (true) { if (!mis->pvt->firstali) mis->pvt->seqno_es2++; if (mis->pvt->seqno_es2 == gt_encseq_num_of_sequences(mis->pvt->es2)) { mis->pvt->seqno_es1++; if (mis->pvt->seqno_es1 == gt_encseq_num_of_sequences(mis->pvt->es1)) return GT_MATCHER_STATUS_END; mis->pvt->seqno_es2 = 0; } seqlen_a = gt_encseq_seqlength(mis->pvt->es1, mis->pvt->seqno_es1); seqlen_b = gt_encseq_seqlength(mis->pvt->es2, mis->pvt->seqno_es2); /* XXX: reuse buffers for performance improvement */ a = gt_malloc(seqlen_a * sizeof (char)); seqpos = gt_encseq_seqstartpos(mis->pvt->es1, mis->pvt->seqno_es1); gt_encseq_extract_decoded(mis->pvt->es1, a, seqpos, seqpos + seqlen_a - 1); b = gt_malloc(seqlen_b * sizeof (char)); seqpos = gt_encseq_seqstartpos(mis->pvt->es2, mis->pvt->seqno_es2); gt_encseq_extract_decoded(mis->pvt->es1, b, seqpos, seqpos + seqlen_b - 1); seq_a = gt_seq_new(a, seqlen_a, gt_encseq_alphabet(mis->pvt->es1)); seq_b = gt_seq_new(b, seqlen_b, gt_encseq_alphabet(mis->pvt->es2)); ali = gt_swalign(seq_a, seq_b, mis->pvt->sf); mis->pvt->firstali = false; if (ali && gt_alignment_get_length(ali) >= mis->pvt->min_len && gt_alignment_eval(ali) <= mis->pvt->max_edist) { break; } gt_alignment_delete(ali); gt_seq_delete(seq_a); gt_seq_delete(seq_b); gt_free(a); gt_free(b); } arng = gt_alignment_get_urange(ali); brng = gt_alignment_get_vrange(ali); adesc = gt_encseq_description(mis->pvt->es1, &seqlen_a, mis->pvt->seqno_es1); bdesc = gt_encseq_description(mis->pvt->es2, &seqlen_b, mis->pvt->seqno_es2); *match = gt_match_sw_new("", "", mis->pvt->seqno_es1, mis->pvt->seqno_es2, gt_alignment_get_length(ali), gt_alignment_eval(ali), arng.start, brng.start, arng.end, brng.end, GT_MATCH_DIRECT); gt_match_set_seqid1_nt(*match, adesc, seqlen_a); gt_match_set_seqid2_nt(*match, bdesc, seqlen_b); gt_alignment_delete(ali); gt_seq_delete(seq_a); gt_seq_delete(seq_b); gt_free(a); gt_free(b); return GT_MATCHER_STATUS_OK; }
static GtWord gt_alignment_eval_generic_with_affine_score( bool mapped, bool downcase, const GtUchar *characters, const GtAlignment *alignment, const GtScoreMatrix *scorematrix, GtWord matchscore, GtWord mismatchscore, GtWord gap_opening, GtWord gap_extension) { GtUword i, j, idx_u = 0, idx_v = 0, meoplen; GtWord sumscore = 0; GtMultieop meop; AlignmentEoptype next_meop_type = Insertion + 1; gt_assert(alignment != NULL && (!mapped || !downcase)); if (gt_alignment_get_length(alignment) == 0) return 0; #ifndef NDEBUG gt_assert(gt_alignment_is_valid(alignment)); #endif meoplen = gt_multieoplist_get_num_entries(alignment->eops); for (i = meoplen; i > 0; i--) { meop = gt_multieoplist_get_entry(alignment->eops, i - 1); switch (meop.type) { case Mismatch: case Match: case Replacement: for (j = 0; j < meop.steps; j++) { GtUchar a = alignment->u[idx_u], b = alignment->v[idx_v]; if (mapped) { if (scorematrix != NULL) { sumscore += gt_score_matrix_get_score(scorematrix, a, b); } else { if (ISSPECIAL(a) || ISSPECIAL(b) || characters[a] != characters[b]) { sumscore += mismatchscore; } else sumscore += matchscore; } } else { if (downcase) { a = tolower((int) a); b = tolower((int) b); } sumscore += (a != b) ? mismatchscore : matchscore; } idx_u++; idx_v++; } break; case Deletion: if (i < meoplen && next_meop_type == Deletion) { sumscore += gap_extension * meop.steps; } else { sumscore += gap_extension * meop.steps + gap_opening; } idx_u += meop.steps; break; case Insertion: if (i < meoplen && next_meop_type == Insertion) { sumscore += gap_extension * meop.steps; } else { sumscore += gap_extension * meop.steps + gap_opening; } idx_v += meop.steps; break; } next_meop_type = meop.type; } return sumscore; }