-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_align.c
120 lines (110 loc) · 3.18 KB
/
output_align.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
>HEADER
Copyright (c) 2004 Haixu Tang [email protected]
This file is part of the RepGraph package.
RepGraph is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RepGraph is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RepGraph. If not, see <http://www.gnu.org/licenses/>.
<HEADER
**/
#include <stdinc.h>
#include <extvab.h>
#include <extfunc.h>
void output_align(ALIGN *align, char **src_name, char **src_seq, int *len_seq, int num_seq);
void output_align(ALIGN *align, char **src_name, char **src_seq, int *len_seq, int num_seq)
{
int i, j, k, l, m, n, len;
int read1, read2, pos1, pos2;
int *seq1, *seq2;
char *match;
int l1, l2;
l1 = l2 = 0;
read1 = align -> reads[0];
read2 = align -> reads[1];
seq1 = (int *) ckalloc((len_seq[read1] + len_seq[read2]) * sizeof(int));
seq2 = (int *) ckalloc((len_seq[read1] + len_seq[read2]) * sizeof(int));
match = (char *) ckalloc((len_seq[read1] + len_seq[read2]) * sizeof(char));
k = 0;
for(i = 0; i < align -> length - 1; i ++) {
pos1 = align -> pos[0][i];
pos2 = align -> pos[1][i];
while(pos1 < align -> pos[0][i + 1] && pos2 < align -> pos[1][i + 1]) {
seq1[k] = pos1;
seq2[k] = pos2;
if(src_seq[read1][pos1] == src_seq[read2][pos2]) match[k] = 1;
else match[k] = 2;
k ++;
pos1 ++;
pos2 ++;
}
if(pos1 < align -> pos[0][i + 1]) {
for(j = pos1; j < align -> pos[0][i + 1]; j ++) {
seq1[k] = j;
seq2[k] = -1;
k ++;
}
}
if(pos2 < align -> pos[1][i + 1]) {
for(j = pos2; j < align -> pos[1][i + 1]; j ++) {
seq1[k] = -1;
seq2[k] = j;
k ++;
}
}
}
len = k;
if(read1 >= num_seq) {
m = reverse_read(read1, num_seq);
} else {
m = read1;
}
if(read2 >= num_seq) {
k = reverse_read(read2, num_seq);
} else {
k = read2;
}
printf("read %d %s %d %s length %d %d regions %d %d %d %d mis_match %d length %d\n", read1, src_name[m], read2,
src_name[k], len_seq[m], len_seq[k], align -> pos[0][0], align -> pos[0][align -> length - 1],
align -> pos[1][0], align -> pos[1][align -> length - 1], align -> mis_match, align -> length);
m = len / 60 + 1;
for(i = 0; i < m; i ++) {
if(i == m - 1) l = len % 60;
else l = 60;
for(j = 0; j < l; j ++) {
if(seq1[i * 60 + j] < 0) {
printf("-");
} else {
printf("%c", na_name[src_seq[read1][seq1[i * 60 + j]]]);
}
}
printf("\n");
for(j = 0; j < l; j ++) {
if(match[i * 60 + j] == 1) {
printf("|");
} else if(match[i * 60 + j] == 2) {
printf(".");
} else {
printf(" ");
}
}
printf("\n");
for(j = 0; j < l; j ++) {
if(seq2[i * 60 + j] < 0) {
printf("-");
} else {
printf("%c", na_name[src_seq[read2][seq2[i * 60 + j]]]);
}
}
printf("\n\n\n");
}
free((void *) seq1);
free((void *) seq2);
free((void *) match);
}