-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefig.cpy
323 lines (296 loc) · 8.27 KB
/
makefig.cpy
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#include <stdio.h>
#include <math.h>
#include <perdef.h>
#include <param.h>
#include <extvab.h>
#include <extfunc.h>
#define MIN_NUM 6
#define BIGGAP 5000
int min_length;
int npages = 1;
FILE *fp1;
double scale[2];
void outputline(FILE *fp, char **str, int num, int *base, int len, int size);
void output_one_length(FILE *fp, int base0, int length, char *name);
void output_repeat_legend(FILE *fp, int *startpos, int **breaks, int *numsegment, int **colorindex, int num);
void output_length_legend(FILE *fp);
int segcompar(SEGMENT *a, SEGMENT *b);
void output_legend(FILE *fp, int *repeat_length, int *multip, int num_repeat, int **repeats);
char ckname(char *name, char *str);
char concastr(char *str, char *newstr);
main(int argc, char **argv)
{
int i, j, k, l, m, n, len_seq[100], reallen[100];
char **chrname;
int *dir, **breaks, **colorindex, base[2];
int *multip, *multip2, *repeat_length, num_repeat, *startpos, *numsegment;
int num_ins, *insertpos, *insertlen;
int global_scale;
SEGMENT *segment, *insertreg, segment0;
long int START_POS;
int num_segment, num_insertreg;
int **repeats;
int range[2];
int num_chro;
char name[1000], temp[1000], c, str[500], newstr[500];
char *label, pt;
FILE *fp;
if(argc < 5) {
printf("Usage: makefig subrepeatfile graphvizgraph psblockshowfile min_length\n");
exit(-1);
}
min_length = atoi(argv[4]);
/* Input subrepeats */
fp = ckopen(argv[2], "r");
num_region = input_segment(segment, num_segment, chroname, fp);
fclose(fp);
/* Input graph */
fp = ckopen(argv[1], "r");
num_edges = input_graph(edges, sizenote, fp);
fclose(fp);
fp = ckopen(argv[3], "r");
fprintf(fp, "<html>\n<head>\n<title>Subrepeats</title>\n</head>\n<body>\n");
fprintf(fp, "<table border="1" cellspacing="0">\n");
fprintf(fp, "<tr>\n");
fprintf(fp, "<td width=\"80\" valign=\"top\" >\n");
fprintf(fp, "<p> Region </p>\n");
fprintf(fp, "</td>\n");
fprintf(fp, "<td width=\"80\" valign=\"top\" >\n");
fprintf(fp, "<p> Chromosome </p>\n");
fprintf(fp, "</td>\n");
fprintf(fp, "<td width=\"160\" valign=\"top\" >\n");
fprintf(fp, "<p> Range(from-to)<sup>1</sup> </p>\n");
fprintf(fp, "</td>\n");
fprintf(fp, "</tr>\n");
for(i = 0; i < num_region; i ++) {
fprintf(fp, "<tr>\n");
fprintf(fp, "<td width=\"80\" valign=\"top\" >\n");
fprintf(fp, "<p>%d</p>", i + 1);
fprintf(fp, "</td>\n");
fprintf(fp, "<td width=\"80\" valign=\"top\" >\n");
fprintf(fp, "<p>%s</p>\n", chroname[i]);
fprintf(fp, "</td>\n");
fprintf(fp, "<td width=\"160\" valign=\"top\" >\n");
fprintf(fp, "<p><a href=\"region-%d.html\">%d-%d</a></p>\n", i + 1,
segment[i][0].pos[0], segment[i][num_segment[i] - 1].pos[1]);
fprintf(fp, "</td>\n");
fprintf(fp, "</tr>\n");
sprintf(temp, "tmp/region-%d.html", i + 1);
fp1 = ckopen(temp, "w");
sprintf(temp, "tmp/region-%d.gvz", i + 1);
fp2 = ckopen(temp, "w");
for(j = 0; j < num_segment[i]; j ++) {
}
fclose(fp1);
fclose(fp2);
}
fprintf(fp, "<sup>1</sup> Click to links see the sub-repeats composition of each region\n");
fprintf(fp, "</table>\n");
fprintf(fp, "</body>\n</html>\n");
fclose(fp);
}
char concastr(char *str, char *newstr)
{
int i, l;
l = strlen(str);
for(i = l - 1; i >= 0; i --) {
if(str[i] == '\"') {
break;
}
}
if(i >= 0) {
strncpy(newstr, str, i + 1);
newstr[i + 1] = '\0';
strcat(newstr, ", color=red, style=bold");
strcat(newstr, &str[i + 1]);
} else {
strcpy(newstr, str);
}
}
char ckname(char *name, char *str)
{
int i, j, k, l, n;
l = strlen(str);
n = strlen(name);
for(i = 0; i < l; i ++) {
if(!strncmp(&str[i], "[label = ", 9)) {
i += 10;
break;
}
}
if(strncmp(name, &str[i], n)) {
return(0);
} else {
if(str[i + n] == ' ') {
return(1);
} else {
return(0);
}
}
}
void output_repeat_legend(FILE *fp, int *startpos, int **breaks, int *numsegment, int **colorindex, int num)
{
int i, j, k, l, m, n;
int base[50], point[4][2];
char c, name[100], temp[100];
char **str;
double label[3];
str = (char **) ckalloc(10 * sizeof(char *));
for(i = 0; i < 10; i ++) {
str[i] = (char *) ckalloc(100 * sizeof(char));
}
sprintf(str[0], "Repeat ID");
sprintf(str[1], "Length");
sprintf(str[2], "From-to");
sprintf(str[3], "Subrepeats");
sprintf(str[4], "From-to");
base[0] = 50;
base[1] = 800;
fprintf(fp, "Repeat ID Length From-to Subrepeats From-to\n");
outputline(fp, str, 5, base, 90, 10);
base[1] -= 20;
for(i = 0; i < num; i ++) {
for(j = 0; j < numsegment[i]; j ++) {
if(j == 0) {
sprintf(str[0], "R%d", i + 1);
sprintf(str[1], "%d", breaks[i][numsegment[i]]);
sprintf(str[2], "%d-%d", startpos[i], startpos[i] + breaks[i][numsegment[i]] - 1);
fprintf(fp1, "R%d %d %d-%d ", i + 1, breaks[i][numsegment[i]],
startpos[i], startpos[i] + breaks[i][numsegment[i]] - 1);
} else {
str[0][0] = str[1][0] = str[2][0] = '\0';
fprintf(fp1, " ");
}
sprintf(str[3], "%d", colorindex[i][j]);
m = (colorindex[i][j] - 1) % total_color;
c = m + 'a';
k = (colorindex[i][j] - 1) / total_color + 1;
sprintf(str[3], "%c%d", c, k);
sprintf(str[4], "%d-%d", startpos[i] + breaks[i][j], startpos[i] + breaks[i][j + 1] - 1);
fprintf(fp1, "%c%d %d-%d\n", c, k, startpos[i] + breaks[i][j], startpos[i] + breaks[i][j + 1] - 1);
base[0] = 50;
base[1] -= 10;
outputline(fp, str, 5, base, 90, 8);
if(base[1] <= 50) {
base[0] = 50;
base[1] = 800;
showpage(fp);
fprintf(fp, "%%%%Page: P%d\n", npages);
npages ++;
change_scale(fp, scale);
}
}
}
for(i = 0; i < 10; i ++) {
free((void *) str[i]);
}
free((void *) str);
}
void output_legend(FILE *fp, int *repeat_length, int *multip, int num_repeat, int **repeats)
{
int i, j, k, l, m, n;
int base[50], point[4][2];
char c, name[100], temp[100];
char **str;
double label[3];
str = (char **) ckalloc(10 * sizeof(char *));
for(i = 0; i < 10; i ++) {
str[i] = (char *) ckalloc(100 * sizeof(char));
}
sprintf(str[0], "Subrepeat ID");
sprintf(str[1], "Length");
sprintf(str[2], "Multiplicity");
sprintf(str[3], "Repeats");
sprintf(str[4], "Color coding");
base[0] = 50;
base[1] = 680;
outputline(fp, str, 5, base, 60, 10);
for(i = 0; i < num_repeat; i ++) {
m = i % total_color;
c = m + 'a';
k = i / total_color + 1;
sprintf(name, "%c%d", c, k);
strcpy(str[0], name);
sprintf(str[1], "%d", repeat_length[i]);
sprintf(str[2], "%d", multip[i]);
str[3][0] = '\0';
for(j = 0; j < min(multip[i], MIN_NUM); j ++) {
sprintf(temp, "R%d ", repeats[i][j] + 1);
strcat(str[3], temp);
}
base[0] = 50;
base[1] -= 10;
outputline(fp, str, 4, base, 60, 8);
point[0][0] = 370;
point[0][1] = base[1];
point[1][0] = 370 + length_intv(repeat_length[i]);
point[1][1] = base[1];
point[2][0] = 370 + length_intv(repeat_length[i]);
point[2][1] = base[1] + 5;
point[3][0] = 370;
point[3][1] = base[1] + 5;
for(j = 0; j < 3; j ++) {
label[j] = color_box[m][j];
}
prt_box(fp, point, label, 0);
base[0] = 370 + length_intv(repeat_length[i]) / 2;
base[1] += 2;
prt_Text(fp, name, base, 8, 0);
if(base[1] <= 50 && i < num_repeat - 1) {
base[0] = 50;
base[1] = 800;
showpage(fp);
fprintf(fp, "%%%%Page: P%d\n", npages);
npages ++;
change_scale(fp, scale);
}
}
for(i = 0; i < 10; i ++) {
free((void *) str[i]);
}
free((void *) str);
}
void outputline(FILE *fp, char **str, int num, int *base, int len, int size)
{
int i, j, k, l;
for(i = 0; i < num; i ++) {
prt_Text(fp, str[i], base, size, 0);
base[0] += len;
}
}
void output_length_legend(FILE *fp)
{
int i, j, k, l;
int base[2];
base[0] = 50;
base[1] = 835;
prt_Text(fp, "Scale of repeat length", base, 10, 0);
output_one_length(fp, 800, 10, "50-200");
output_one_length(fp, 785, 20, "201-500");
output_one_length(fp, 770, 30, "501-1000");
output_one_length(fp, 755, 40, "1001-5000");
output_one_length(fp, 740, 50, ">5000");
}
void output_one_length(FILE *fp, int base0, int length, char *name)
{
int point[4][2], base[2];
double label[3];
base[0] = 50;
base[1] = base0;
prt_Text(fp, name, base, 8, 0);
point[0][0] = 95;
point[0][1] = base0;
point[1][0] = 95 + length;
point[1][1] = base0;
point[2][0] = 95 + length;
point[2][1] = base0 + 5;
point[3][0] = 95;
point[3][1] = base0 + 5;
label[0] = label[1] = label[2] = 0;
prt_box(fp, point, label, 0);
}
int segcompar(SEGMENT *a, SEGMENT *b)
{
if(a -> pos[0] > b -> pos[0]) return(1);
else return(-1);
}