comparison swalign.h @ 18:e4d75f9efb90 draft

planemo upload commit b'4303231da9e48b2719b4429a29b72421d24310f4\n'-dirty
author nick
date Thu, 02 Feb 2017 18:44:31 -0500
parents
children
comparison
equal deleted inserted replaced
17:836fa4fe9494 18:e4d75f9efb90
1 /*
2 * Copyright (c) 2010 Nicolaus Lance Hepler
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include <float.h>
27 #include <math.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #define GAP -1.0
33 #define MATCH 2.0
34 #define MISMATCH -0.5
35 // ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz
36 #define TRANS "TVGHEFCDIJMLKNOPQYWAABSXRZ[\\]^_`tvghefcdijmlknopqywaabsxrz"
37 #define TRANS_OFFSET 65
38
39 typedef enum { false, true } bool;
40
41 typedef struct {
42 char *a;
43 unsigned int alen;
44 char *b;
45 unsigned int blen;
46 } seq_pair_t;
47
48 // An entry is a cell in the matrix.
49 // prev holds the coordinates of the previous cell in the matrix.
50 typedef struct {
51 double score;
52 unsigned int prev[2];
53 } entry_t;
54
55 typedef struct {
56 unsigned int m;
57 unsigned int n;
58 entry_t **mat;
59 } matrix_t;
60
61 typedef struct {
62 seq_pair_t *seqs;
63 int start_a;
64 int start_b;
65 int end_a;
66 int end_b;
67 int matches;
68 double score;
69 } align_t;
70
71 static char* reverse(char *str);
72
73 static char get_char_comp(char c);
74
75 char* revcomp(char *str);
76
77 static align_t *traceback(seq_pair_t *problem, matrix_t *S, bool local);
78
79 static matrix_t *create_matrix(unsigned int m, unsigned int n);
80
81 void destroy_matrix(matrix_t *S);
82
83 void print_matrix(matrix_t *matrix, seq_pair_t *seq_pair);
84
85 void destroy_seq_pair(seq_pair_t *pair);
86
87 align_t *smith_waterman(seq_pair_t *problem, bool local);
88
89 void print_alignment(align_t *result, int target_len, int query_len);