README: mentioning other make targets seem unnecessary
[rangi.git] / genrq.c
blob8050c99be3483e2728811387773754637531ddce
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #define NLEN 64
6 #define NODES 20000
7 #define EDGES 400000
8 #define THRESH 0.0000001
9 #define NCOLORS 512
11 static char nodes[NODES][NLEN]; /* vertex names */
12 static int nnodes;
14 /* find network protein */
15 static int id(char *s)
17 int i;
18 for (i = 0; i < nnodes; i++)
19 if (!strcmp(nodes[i], s))
20 return i;
21 return -1;
24 /* find protein id; insert it if not there */
25 static int id_def(char *s)
27 int idx = id(s);
28 if (idx < 0) {
29 idx = nnodes++;
30 strcpy(nodes[idx], s);
32 return idx;
35 static void readnetwork(FILE *fin)
37 char s1[NLEN], s2[NLEN];
38 double w;
39 while (fscanf(fin, "%s %s %lf", s1, s2, &w) == 3) {
40 id_def(s1);
41 id_def(s2);
45 static void queries(int sz)
47 int sel[NODES] = {0};
48 int idx;
49 int i;
50 for (i = 0; i < sz; i++) {
51 do {
52 idx = rand() % nnodes;
53 } while (sel[idx]);
54 sel[idx] = 1;
55 printf("\%s\t", nodes[idx]);
57 printf("\n");
60 static void printhelp(void)
62 printf("usage: genrq -s size -n count\n\n");
63 printf("options:\n");
64 printf("\t-s size \tthe number of proteins in each query\n");
65 printf("\t-n count \tthe number of queries to generate\n");
66 exit(0);
69 int main(int argc, char *argv[])
71 int i;
72 int count = 0;
73 int size = 7;
74 for (i = 1; i < argc; i++) {
75 if (argv[i][0] != '-' || argv[i][1] == 'h') {
76 printhelp();
77 exit(0);
79 if (argv[i][1] == 'n')
80 count = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
81 if (argv[i][1] == 's')
82 size = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
84 readnetwork(stdin);
85 for (i = 0; i < count; i++)
86 queries(size);
87 return 0;