-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbl2aln.c
126 lines (107 loc) · 3.16 KB
/
bl2aln.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
/**
>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>
char inpfile[100], outfile[100], qualfile[100], overlapfile[100];
int qualinp;
int min_leg;
double min_id;
void initenv(int argc, char **argv);
int main(int argc, char **argv)
{
int i, j, k, l, m, n;
char **src_seq, **src_name;
char temp[100];
ALIGN **align, *aln, *aln0;
FILE *fp;
readpar();
random1(&idum);
initenv(argc, argv);
/* read in pairwise alignments by BLAST */
align = (ALIGN **) ckalloc(2 * sizeof(ALIGN *));
fp = ckopen(inpfile, "r");
n = readblast(align, fp, min_leg, min_id);
fclose(fp);
printf("# alignments input: %d.\n", n);
/* Write alignments */
fp = ckopen(outfile, "w");
for(m = 0; m < 2; 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);
return 0;
}
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:")) != EOF) {
switch(copt) {
case 'i':
inpseq = 1;
sscanf(optarg,"%s", inpfile);
continue;
case 'o':
outseq = 1;
sscanf(optarg,"%s", outfile);
continue;
case 'l':
sscanf(optarg,"%d", &min_leg);
continue;
case 'd':
sscanf(optarg,"%lf", &min_id);
continue;
default:
printf("bl2aln -i InpFile -o outfile [-l min_leg -d min_id]\n");
printf("-i InpFile: The input file name of reads\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("bl2aln -i InpFile -o outfile [-l min_leg -d min_id]\n");
printf("-i InpFile: The input file name of reads\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);
}
}