void gt_linearalign_check_local(GT_UNUSED bool forward, const GtUchar *useq, GtUword ulen, const GtUchar *vseq, GtUword vlen) { GtAlignment *align; GtWord score1, score2, score3, score4, matchscore = 2, mismatchscore = -2, gapscore = -1; GtLinspaceManagement *spacemanager; GtScoreHandler *scorehandler; if (memchr(useq, LINEAR_EDIST_GAP,ulen) != NULL) { fprintf(stderr,"%s: sequence u contains gap symbol\n",__func__); exit(GT_EXIT_PROGRAMMING_ERROR); } if (memchr(vseq, LINEAR_EDIST_GAP,vlen) != NULL) { fprintf(stderr,"%s: sequence v contains gap symbol\n",__func__); exit(GT_EXIT_PROGRAMMING_ERROR); } scorehandler = gt_scorehandler_new(matchscore, mismatchscore, 0, gapscore); gt_scorehandler_plain(scorehandler); spacemanager = gt_linspace_management_new(); align = gt_alignment_new(); score1 = gt_linearalign_compute_local_generic(spacemanager, scorehandler, align, useq, 0, ulen, vseq, 0, vlen); score2 = gt_alignment_eval_with_score(align, true, matchscore, mismatchscore, gapscore); gt_linspace_management_delete(spacemanager); gt_scorehandler_delete(scorehandler); if (score1 != score2) { fprintf(stderr,"gt_linearalign_compute_local_generic = "GT_WD" != "GT_WD " = gt_alignment_eval_generic_with_score\n", score1, score2); exit(GT_EXIT_PROGRAMMING_ERROR); } gt_alignment_reset(align); score3 = gt_squarealign_calculate_local(NULL, align, useq, 0, ulen, vseq, 0, vlen, matchscore, mismatchscore, gapscore); if (score1 != score3) { fprintf(stderr,"gt_linearalign_compute_local_generic = "GT_WD" != "GT_WD " = gt_squarealign_calculate_local\n", score1, score3); exit(GT_EXIT_PROGRAMMING_ERROR); } score4 = gt_alignment_eval_with_score(align, true, matchscore, mismatchscore, gapscore); if (score3 != score4) { fprintf(stderr,"gt_squarealign_calculate_local = "GT_WD" != "GT_WD " = gt_alignment_eval_generic_with_score\n", score3, score4); exit(GT_EXIT_PROGRAMMING_ERROR); } gt_alignment_delete(align); }
static int gt_linspace_align_runner(GT_UNUSED int argc, GT_UNUSED const char **argv, GT_UNUSED int parsed_args, void *tool_arguments, GtError *err) { GtLinspaceArguments *arguments = tool_arguments; int had_err = 0; GtAlignment *align; GtWord left_dist = 0, right_dist = 0; GtSequenceTable *sequence_table1, *sequence_table2; GtLinspaceManagement *spacemanager; GtScoreHandler *scorehandler = NULL; GtTimer *linspacetimer = NULL; GtAlphabet *alphabet = NULL; gt_error_check(err); gt_assert(arguments); sequence_table1 = gt_sequence_table_new(); sequence_table2 = gt_sequence_table_new(); align = gt_alignment_new(); spacemanager = gt_linspace_management_new(); gt_linspace_management_set_TSfactor(spacemanager,arguments->timesquarefactor); /* get sequences */ if (gt_str_array_size(arguments->strings) > 0) { get_onesequence(sequence_table1, arguments->strings, 0); sequence_table1->size++; get_onesequence(sequence_table2, arguments->strings, 1); sequence_table2->size++; } else if (gt_str_array_size(arguments->files) > 0) { had_err = get_fastasequences(sequence_table1, gt_str_array_get_str(arguments->files,0),err); if (!had_err) { had_err = get_fastasequences(sequence_table2, gt_str_array_get_str(arguments->files,1),err); } } if (arguments->dna) { alphabet = gt_alphabet_new_dna(); } else { gt_assert(arguments->protein); alphabet = gt_alphabet_new_protein(); } gt_encode_sequence_table(alphabet,sequence_table1); gt_encode_sequence_table(alphabet,sequence_table2); if (!had_err) { scorehandler = gt_arguments2scorehandler(arguments,err); if (scorehandler == NULL) { had_err = -1; } else { if (arguments->global && arguments->protein && !arguments->has_costmatrix) { GtScoreHandler *costhandler = gt_scorehandler2costhandler(scorehandler); gt_scorehandler_delete(scorehandler); scorehandler = costhandler; } } } /* get diagonal band */ if (!had_err && arguments->diagonal) { if (gt_str_array_size(arguments->diagonalbonds) > 0) { had_err = gt_parse_score_value(__LINE__,&left_dist, gt_str_array_get(arguments->diagonalbonds,0), false, err); if (!had_err) { had_err = gt_parse_score_value(__LINE__,&right_dist, gt_str_array_get(arguments->diagonalbonds,1), false, err); } } } if (!had_err && arguments->spacetime) { linspacetimer = gt_timer_new(); } /* alignment functions with linear gap costs */ if (!had_err) { bool affine; if (gt_str_array_size(arguments->linearcosts) > 0) { affine = false; } else { gt_assert(gt_str_array_size(arguments->affinecosts) > 0); affine = true; } had_err = gt_all_against_all_alignment_check ( affine, align, arguments, spacemanager, scorehandler, gt_alphabet_characters(alphabet), gt_alphabet_wildcard_show(alphabet), sequence_table1, sequence_table2, left_dist, right_dist, linspacetimer,err); } /*spacetime option*/ if (!had_err && arguments->spacetime) { printf("# combined space peak in kilobytes: %f\n", GT_KILOBYTES(gt_linspace_management_get_spacepeak(spacemanager))); gt_timer_show_formatted(linspacetimer,"# TIME overall " GT_WD ".%02ld\n", stdout); } gt_timer_delete(linspacetimer); gt_linspace_management_delete(spacemanager); gt_sequence_table_delete(sequence_table1); gt_sequence_table_delete(sequence_table2); gt_alignment_delete(align); gt_alphabet_delete(alphabet); gt_scorehandler_delete(scorehandler); return had_err; }
void gt_linearalign_check(GT_UNUSED bool forward, const GtUchar *useq, GtUword ulen, const GtUchar *vseq, GtUword vlen) { GtAlignment *align; GtUword edist1, edist2, edist3, edist4, matchcost = 0, mismatchcost = 1, gapcost = 1; GtLinspaceManagement *spacemanager; GtScoreHandler *scorehandler; const bool downcase = true; if (memchr(useq, LINEAR_EDIST_GAP,ulen) != NULL) { fprintf(stderr,"%s: sequence u contains gap symbol\n",__func__); exit(GT_EXIT_PROGRAMMING_ERROR); } if (memchr(vseq, LINEAR_EDIST_GAP,vlen) != NULL) { fprintf(stderr,"%s: sequence v contains gap symbol\n",__func__); exit(GT_EXIT_PROGRAMMING_ERROR); } scorehandler = gt_scorehandler_new(matchcost, mismatchcost, 0, gapcost); gt_scorehandler_plain(scorehandler); gt_scorehandler_downcase(scorehandler); spacemanager = gt_linspace_management_new(); align = gt_alignment_new_with_seqs(useq, ulen, vseq, vlen); edist1 = gt_calc_linearalign(spacemanager, scorehandler, align, useq, 0, ulen, vseq, 0, vlen); edist2 = gt_squarealign_global_distance_only(useq, 0, ulen, vseq, 0, vlen, scorehandler); if (edist1 != edist2) { fprintf(stderr,"gt_calc_linearalign = "GT_WU" != "GT_WU " = gt_squarealign_global_distance_only\n", edist1,edist2); exit(GT_EXIT_PROGRAMMING_ERROR); } edist3 = gt_alignment_eval_with_score(align, true, matchcost, mismatchcost, gapcost); if (edist2 != edist3) { fprintf(stderr,"gt_squarealign_global_distance_only = "GT_WU" != "GT_WU " = gt_alignment_eval_with_score\n", edist2,edist3); exit(GT_EXIT_PROGRAMMING_ERROR); } edist4 = gt_calc_linearedist(downcase,useq, ulen, vseq, vlen); if (edist3 != edist4) { fprintf(stderr,"gt_alignment_eval_with_score = "GT_WU" != "GT_WU " = gt_calc_linearedist\n", edist3, edist4); exit(GT_EXIT_PROGRAMMING_ERROR); } gt_linspace_management_delete(spacemanager); gt_scorehandler_delete(scorehandler); gt_alignment_delete(align); }