#include "config.h" #include #include #if defined(_MSC_VER) #include "wingetopt/src/getopt.h" #else #include #endif #include "parasail.h" #include "parasail/io.h" #include "ssw.h" /* This table is used to transform amino acid letters into numbers. */ int8_t aa_table[128] = { 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0, 20, 4, 3, 6, 13, 7, 8, 9, 23, 11, 10, 12, 2, 23, 14, 5, 1, 15, 16, 23, 19, 17, 22, 18, 21, 23, 23, 23, 23, 23, 23, 0, 20, 4, 3, 6, 13, 7, 8, 9, 23, 11, 10, 12, 2, 23, 14, 5, 1, 15, 16, 23, 19, 17, 22, 18, 21, 23, 23, 23, 23, 23 }; /* This table is used to transform nucleotide letters into numbers. */ int8_t nt_table[128] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 1, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 1, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; static void print_help(const char *progname, int status) { fprintf(stderr, "\nusage: %s " "[-e gap_extend] " "[-o gap_open] " "[-m matrix] " "[-d] " "[-M match] " "[-X mismatch] " "-f file " "\n\n", progname); fprintf(stderr, "Defaults:\n" " gap_extend: 1, must be >= 0\n" " gap_open: 10, must be >= 0\n" " matrix: blosum62\n" " -d: if present, assume DNA alphabet\n" " match: 1, must be >= 0\n" " mismatch: 0, must be >= 0\n" " file: no default, must be in FASTA format\n" ); exit(status); } static void print_cigar(const uint32_t *cigar, int32_t cigarLen) { int32_t i; for (i=0; isize*matrix->size; ++i) { ssw_matrix[i] = matrix->matrix[i]; } if (fname == NULL) { fprintf(stderr, "missing input file\n"); print_help(progname, EXIT_FAILURE); } /* print the parameters for reference */ fprintf(stdout, "%20s: %d\n" "%20s: %d\n" "%20s: %s\n" "%20s: %s\n", "gap_extend", gap_extend, "gap_open", gap_open, "matrix", matrixname, "file", fname); sequences = parasail_sequences_from_file(fname); if (do_time) { /* ssw timing */ start = parasail_time(); for (j=0; jl; ++j) { size_t k = 0; char *readSeq = NULL; int32_t readLen = 0; int32_t maskLen = 0; s_profile *p = NULL; int8_t *num = NULL; int32_t m = 0; /* prep ssw */ readSeq = sequences->seqs[j].seq.s; readLen = sequences->seqs[j].seq.l; maskLen = readLen / 2; num = (int8_t*)malloc(readLen); for (m=0; ml; ++k) { int8_t *ref_num = NULL; s_align *result = NULL; char *refSeq = NULL; int32_t refLen = 0; int32_t filter = 0; int8_t flag = 2; refSeq = sequences->seqs[k].seq.s; refLen = sequences->seqs[k].seq.l; ref_num = (int8_t*)malloc(refLen); for (m=0; ml; ++j) { size_t k = 0; char *readSeq = NULL; int32_t readLen = 0; /* prep ssw */ readSeq = sequences->seqs[j].seq.s; readLen = sequences->seqs[j].seq.l; for (k=j+1; kl; ++k) { char *refSeq = NULL; int32_t refLen = 0; parasail_result_ssw_t *result = NULL; refSeq = sequences->seqs[k].seq.s; refLen = sequences->seqs[k].seq.l; /* now pssw */ result = parasail_ssw(readSeq, readLen, refSeq, refLen, gap_open, gap_extend, matrix); parasail_result_ssw_free(result); } } finish = parasail_time(); printf(" pssw: %f\n", finish-start); /* trace timing */ start = parasail_time(); for (j=0; jl; ++j) { size_t k = 0; char *readSeq = NULL; int32_t readLen = 0; readSeq = sequences->seqs[j].seq.s; readLen = sequences->seqs[j].seq.l; for (k=j+1; kl; ++k) { char *refSeq = NULL; int32_t refLen = 0; parasail_result_t *result = NULL; parasail_cigar_t *cigar = NULL; refSeq = sequences->seqs[k].seq.s; refLen = sequences->seqs[k].seq.l; result = parasail_sw_trace_striped_8(readSeq, readLen, refSeq, refLen, gap_open, gap_extend, matrix); if (parasail_result_is_saturated(result)) { parasail_result_free(result); result = parasail_sw_trace_striped_16(readSeq, readLen, refSeq, refLen, gap_open, gap_extend, matrix); } cigar = parasail_result_get_cigar(result, readSeq, readLen, refSeq, refLen, matrix); parasail_cigar_free(cigar); parasail_result_free(result); } } finish = parasail_time(); printf("trace: %f\n", finish-start); } else { for (j=0; jl; ++j) { size_t k = 0; char *readSeq = NULL; int32_t readLen = 0; int32_t maskLen = 0; s_profile *p = NULL; int8_t *num = NULL; int32_t m = 0; /* prep ssw */ readSeq = sequences->seqs[j].seq.s; readLen = sequences->seqs[j].seq.l; maskLen = readLen / 2; num = (int8_t*)malloc(readLen); for (m=0; ml; ++k) { int8_t *ref_num = NULL; s_align *result = NULL; char *refSeq = NULL; int32_t refLen = 0; int32_t filter = 0; int8_t flag = 2; parasail_result_ssw_t *presult = NULL; parasail_result_t *tresult = NULL; parasail_cigar_t *cigar = NULL; printf("read %lu ref %lu\n", (long unsigned)j, (long unsigned)k); refSeq = sequences->seqs[k].seq.s; refLen = sequences->seqs[k].seq.l; ref_num = (int8_t*)malloc(refLen); for (m=0; mscore1); printf(" ref_begin1: %d\n", result->ref_begin1); printf(" ref_end1: %d\n", result->ref_end1); printf("read_begin1: %d\n", result->read_begin1); printf(" read_end1: %d\n", result->read_end1); printf(" cigarLen: %d\n", result->cigarLen); printf(" cigar: "); print_cigar(result->cigar, result->cigarLen); align_destroy(result); free(ref_num); /* now pssw */ presult = parasail_ssw(readSeq, readLen, refSeq, refLen, gap_open, gap_extend, matrix); printf("--PSSW--\n"); printf(" score: %d\n", presult->score1); printf(" ref_begin1: %d\n", presult->ref_begin1); printf(" ref_end1: %d\n", presult->ref_end1); printf("read_begin1: %d\n", presult->read_begin1); printf(" read_end1: %d\n", presult->read_end1); printf(" cigarLen: %d\n", presult->cigarLen); printf(" cigar: "); print_cigar(presult->cigar, presult->cigarLen); parasail_result_ssw_free(presult); /* now trace */ tresult = parasail_sw_trace_striped_sat(readSeq, readLen, refSeq, refLen, gap_open, gap_extend, matrix); cigar = parasail_result_get_cigar(tresult, readSeq, readLen, refSeq, refLen, matrix); printf("--TRACE--\n"); printf(" score: %d\n", tresult->score); printf(" ref_end1: %d\n", tresult->end_ref); printf(" read_end1: %d\n", tresult->end_query); printf(" cigarLen: %d\n", cigar->len); printf(" cigar: "); print_cigar(cigar->seq, cigar->len); parasail_cigar_free(cigar); parasail_result_free(tresult); } init_destroy(p); free(num); } } parasail_sequences_free(sequences); return 0; }