-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcase2aln.c
172 lines (148 loc) · 4.62 KB
/
case2aln.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
>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 <param.h>
#include <extfunc.h>
#define MAX_NUM 25
char inpfile[100], outfile[100], qualfile[100], overlapfile[100], seqfile[100];
int qualinp;
int min_leg;
double min_id;
void initenv(int argc, char **argv);
main(int argc, char **argv)
{
int i, j, k, l, m, n;
char **src_seq, **src_name;
int *len_seq, num_seq;
char temp[100];
ALIGN **align, *aln, *aln0;
FILE *fp;
readpar();
random1(&idum);
initenv(argc, argv);
/* Input the length of the genome (required) */
len_seq = (int *) ckalloc(2 * MAX_NUM * sizeof(int));
src_seq = (char **) ckalloc(2 * MAX_NUM * sizeof(char *));
src_name = (char **) ckalloc(MAX_NUM * sizeof(char *));
for(i = 0; i < MAX_NUM; i ++) {
src_name[i] = (char *) ckalloc(100 * sizeof(char));
}
fp = ckopen(seqfile, "r");
num_seq = readseq1by1(src_seq, src_name, len_seq, fp);
fclose(fp);
printf("Genome length: ");
for(i = 0; i < num_seq; i ++) {
printf("%d ", len_seq[i]);
}
printf("\n");
/* Make reverse complements of input sequences rev(i) --> i + num_seq */
for(i = 0; i < num_seq; i ++) {
len_seq[i + num_seq] = len_seq[i];
src_seq[i + num_seq] = (char *) ckalloc(len_seq[i] * sizeof(char));
for(j = 0; j < len_seq[i]; j ++) {
src_seq[num_seq + i][j] = rev(src_seq[i][len_seq[i] - j - 1]);
}
}
/* read in pairwise alignments produced by Evan's group */
align = (ALIGN **) ckalloc(2 * num_seq * sizeof(ALIGN *));
fp = ckopen(inpfile, "r");
n = readcase(align, src_seq, len_seq, num_seq, fp, min_leg, min_id);
fclose(fp);
printf("# alignments input: %d.\n", n);
/* Write alignments */
fp = ckopen(outfile, "w");
for(m = 0; m < 2 * num_seq; m ++) {
n = size_align(align[m]);
fwrite(&n, sizeof(int), 1, fp);
aln = align[m];
while(aln) {
fwrite(&(aln -> reads[1]), sizeof(int), 1, fp);
fwrite(&(aln -> mis_match), sizeof(int), 1, fp);
fwrite(&(aln -> length), sizeof(int), 1, fp);
fwrite(aln -> pos[0], sizeof(int), aln -> length, fp);
fwrite(aln -> pos[1], sizeof(int), aln -> length, fp);
aln0 = aln -> next;
free((void *) aln -> pos[0]);
free((void *) aln -> pos[1]);
free((void *) aln);
aln = aln0;
}
}
fclose(fp);
printf("Done...\n");
free((void **) align);
for(i = 0; i < 2 * num_seq; i ++) {
free((void *) src_seq[i]);
}
for(i = 0; i < MAX_NUM; i ++) {
free((void *) src_name[i]);
}
free((void **) src_seq);
free((void **) src_name);
free((void *) len_seq);
}
void initenv(int argc, char **argv)
{
int copt;
int inpseq, outseq;
extern char *optarg;
min_leg = 500;
min_id = 0.99;
inpseq = qualinp = outseq = 0;
while ((copt=getopt(argc,argv,"i:o:l:d:s:b:")) != EOF) {
switch(copt) {
case 'i':
inpseq = 1;
sscanf(optarg,"%s", inpfile);
continue;
case 'o':
outseq = 1;
sscanf(optarg,"%s", outfile);
continue;
case 's':
sscanf(optarg,"%s", &seqfile);
continue;
case 'l':
sscanf(optarg,"%d", &min_leg);
continue;
case 'd':
sscanf(optarg,"%lf", &min_id);
continue;
case 'b':
sscanf(optarg,"%d", &band);
continue;
default:
printf("reputer2aln -i InpFile -s seqfile -o outfile [-l min_leg -d min_id -d band_size]\n");
printf("-i InpFile: The input file name of alignments\n");
printf("-s SeqFile: The input file name of genomic sequence\n");
printf("-o OutFile: output alignment file\n");
printf("-l min_leg: minimum length of repeats.\n");
printf("-d min_id: minimum identity of repeats.\n");
exit(-1);
}
optind--;
}
if(inpseq == 0 || outseq == 0) {
printf("reputer2aln -i InpFile -s seqfile -o outfile [-l min_leg -d min_id -d band_size]\n");
printf("-i InpFile: The input file name of alignments\n");
printf("-s SeqFile: The input file name of genomic sequence\n");
printf("-o OutFile: output alignment file\n");
printf("-l min_leg: minimum length of repeats.\n");
printf("-d min_id: minimum identity of repeats.\n");
exit(-1);
}
}