-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring2aln.c
144 lines (125 loc) · 3.91 KB
/
string2aln.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
/**
>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], seqfile[100], lenfile[100], segfile[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 temp[100];
int len_seq[100], num_chro;
char **chrname;
ALIGN **align, *aln, *aln0;
FILE *fp;
readpar();
random1(&idum);
initenv(argc, argv);
/* read in chromosome length */
chrname = alloc_name(100, 100);
fp = ckopen(lenfile, "r");
num_chro = readlen(fp, len_seq, chrname);
fclose(fp);
printf("# chromosome %d\n", num_chro);
/* read in pairwise alignments */
align = (ALIGN **) ckalloc(2 * num_chro * sizeof(ALIGN *));
fp = ckopen(inpfile, "r");
n = readstring(align, fp, min_leg, min_id, len_seq, chrname, num_chro);
fclose(fp);
printf("# alignments input: %d.\n", n);
/* Write alignments */
fp = ckopen(outfile, "w");
for(m = 0; m < 2 * num_chro; 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);
/*
printf("aln %d %d length %d %d %d %d %d\n", aln -> reads[0], aln -> reads[1], aln -> length,
aln -> pos[0][aln -> length - 1], aln -> pos[0][0],
aln -> pos[1][aln -> length - 1], aln -> pos[1][0]);
getchar();
*/
aln0 = aln -> next;
free((void *) aln -> pos[0]);
free((void *) aln -> pos[1]);
free((void *) aln);
aln = aln0;
}
}
fclose(fp);
printf("Done...\n");
chrname = free_name(chrname, 100);
free((void **) align);
}
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:c:")) != 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 'c':
sscanf(optarg,"%s", lenfile);
continue;
case 'd':
sscanf(optarg,"%lf", &min_id);
continue;
default:
printf("string2aln -i InpFile -c LenFile -o outfile [-l min_leg -d min_id]\n");
printf("-i InpFile: The input file name of alignments\n");
printf("-c lenfile: inpput file for chromosome length.\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("string2aln -i InpFile -c LenFile -o outfile [-l min_leg -d min_id]\n");
printf("-i InpFile: The input file name of alignments\n");
printf("-c lenfile: inpput file for chromosome length.\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);
}
}