1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,132 @@ |
1 |
+#include <stdio.h> |
|
2 |
+#include <stdlib.h> |
|
3 |
+#define R 10 // rayon |
|
4 |
+ |
|
5 |
+long int fact(n) |
|
6 |
+{ |
|
7 |
+if (n==1) |
|
8 |
+ return 1; |
|
9 |
+else |
|
10 |
+return (n*fact(n-1)); |
|
11 |
+} |
|
12 |
+ |
|
13 |
+int max_trace(int nbloci)// only for 2 gives max of comb possible... |
|
14 |
+{ |
|
15 |
+int i,j; |
|
16 |
+int n=0; |
|
17 |
+for (i=1;i<nbloci;i++) |
|
18 |
+ { |
|
19 |
+ j= fact(nbloci) /(float)(fact(i) * fact(nbloci-i)); |
|
20 |
+ printf("%d\n",j); |
|
21 |
+ if (j >n) n=j; |
|
22 |
+ } |
|
23 |
+return n; |
|
24 |
+} |
|
25 |
+ |
|
26 |
+ |
|
27 |
+void svg_header(FILE *f,int w, int h,char *s) |
|
28 |
+{ |
|
29 |
+fprintf(f,"<?xml version=\"1.0\"?>\n"); |
|
30 |
+fprintf(f,"<svg width=\"%d\" height=\"%d\">\n",w,h); |
|
31 |
+fprintf(f,"<title>%s</title>\n",s); |
|
32 |
+} |
|
33 |
+ |
|
34 |
+ |
|
35 |
+void read (FILE *f) |
|
36 |
+{ |
|
37 |
+ char *ligne,*ptr, *sep=" ,\t"; |
|
38 |
+ int nbl=0; |
|
39 |
+ char **pheno; |
|
40 |
+ float *fitness; |
|
41 |
+ fscanf(f,"%[^\n]\n",ligne); |
|
42 |
+ ptr = strtok(ligne, sep); |
|
43 |
+ while ( ptr != NULL ) { |
|
44 |
+ nbl++; |
|
45 |
+ nba=atoi(ptr); //je dis quil ont tous le meme nbr dalles... |
|
46 |
+ ptr = strtok(NULL, sep); |
|
47 |
+ } |
|
48 |
+ |
|
49 |
+ |
|
50 |
+ nbp=pow(nba,nbl); |
|
51 |
+ pheno=(char *)malloc(sizeof(char *) *nbp ); |
|
52 |
+ for (i=0;i>nbp;i++) |
|
53 |
+ pheno[i]=malloc(sizeof(char)*nbl); |
|
54 |
+ for (i=0;i<nbp;i++) |
|
55 |
+ { |
|
56 |
+ for (j=0;j<nbl;j++) |
|
57 |
+ fscanf(f,"%d",&pheno[i][j]); |
|
58 |
+ fscanf(f,"%f",&fitness[i]); |
|
59 |
+ } |
|
60 |
+ |
|
61 |
+} |
|
62 |
+/*draws a line of circles 1st one center is x,y*/ |
|
63 |
+void draw_geno(FILE *f,int x, int y,int *pheno, float f, int nbloci) |
|
64 |
+{ |
|
65 |
+ int i,j; |
|
66 |
+ char *colors[2]={"white","black"}; |
|
67 |
+//char *colors[15]={"white","black","aqua","blue", "fuchsia", "gray", "green", "lime","maroon", "navy", "olive", "purple", "red", "silver", "teal", "yellow"}; |
|
68 |
+ for (i=0;i<nbloci;i++) |
|
69 |
+ { |
|
70 |
+ fprintf(f,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" style=\"stroke: black; fill: %s\" />",x+(i*2*R)+1,y,R,colors[(int)pheno[i]]); |
|
71 |
+ } |
|
72 |
+ fprintf(f,"<text x=\"%d\" y=\"%d\"style=\"text-anchor: middle\">%f</text>\n",x+((nbloci*R)/2.0),y+R+12,f); |
|
73 |
+} |
|
74 |
+ |
|
75 |
+/*draws a set of genotype with same nubr of mut*/ |
|
76 |
+} |
|
77 |
+ |
|
78 |
+void drawLand(struct landscape land,FILE *f) |
|
79 |
+{ |
|
80 |
+int c,*g; |
|
81 |
+FILE *f; |
|
82 |
+int x,y; |
|
83 |
+int width,height,middle; |
|
84 |
+int width_geno=R*land.nlocus; |
|
85 |
+int height_geno=R*5; |
|
86 |
+ |
|
87 |
+int margin_left=10; |
|
88 |
+int margin_up=10; |
|
89 |
+ |
|
90 |
+width=width_geno*land.nlocus*2; |
|
91 |
+height=R*land.nlocus*land.nlocus*4; |
|
92 |
+middleY=height/2.0; |
|
93 |
+void svg_header(f,width, height,"what a beautifull view") |
|
94 |
+ |
|
95 |
+ for (i=0;i<land.ngenotypes;i++) |
|
96 |
+ { |
|
97 |
+ c=int2nbmut(land,i); |
|
98 |
+ g=int2genotype( land, i, g); |
|
99 |
+ x=margin_left+(c*2*width_geno); |
|
100 |
+ y=margin_up+(c*2*height_geno); |
|
101 |
+ if (land.fitness[i]>=0) |
|
102 |
+ draw_geno(f,x, y,g, land.fitness[i],land.nlocus) |
|
103 |
+ |
|
104 |
+ } |
|
105 |
+fprintf(f,"</SVG>\n"); |
|
106 |
+ |
|
107 |
+} |
|
108 |
+ |
|
109 |
+ |
|
110 |
+int main(int argc,char **argv) |
|
111 |
+{ |
|
112 |
+ char *file, type; |
|
113 |
+ FILE *f; |
|
114 |
+ struct landscape land; |
|
115 |
+ |
|
116 |
+ if (argc!=3) printf("Usage %s [G|g] <nom fichier>\n",argv[0]); |
|
117 |
+ type =*argv[1]; |
|
118 |
+ if (type !='g' && type !='G') printf("Usage %s [G|g] <nom fichier>\n",argv[0]); |
|
119 |
+ |
|
120 |
+ land= ReadFile (argv[2]); |
|
121 |
+ sprintf(file_out,"%s.svg",argv[2]); |
|
122 |
+ f=fopen(file_out,"w"); |
|
123 |
+ if (type=='g') |
|
124 |
+ drawLand(land,f) |
|
125 |
+ else |
|
126 |
+ drawGraph(land,f); |
|
127 |
+ |
|
128 |
+ |
|
129 |
+ exit(0); |
|
130 |
+ |
|
131 |
+} |
|
132 |
+ |