about summary refs log tree commit diff
path: root/sourcecodes/network_layout_inv_example.php
blob: 1e5cd51bd552b44e2f34c44bfc64ee7819703605 (plain)
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
<?php 
include("structuremap.php");

function levelmap($inx,$name,$mapdata)
{

$leve_l=array();
$leve_l=explode("\n",$mapdata);
$leve_d=array();

foreach($leve_l as $l)
{ 
  $l=trim($l);
  $leve_d=explode("\t",$l);
  $inxname=trim($leve_d[0]);
  $name=trim($name);
  if($inxname==$name)
    return $leve_d[$inx];
}
           
}

////////////////////////////////////Read data from net_figure file///////////////////////Graphp Display/////////////////////////////////////////////

$keyval=$_GET["My_key"];
$dir="./data/";

$lfile=$dir.$keyval."nlevels.txt";
$levelmap=file_get_contents($lfile);   




$matfile=$dir."$keyval"."net_figure.txt";


$data_val="";

$matrix=file("$matfile");
$matrix1=file_get_contents("$matfile");              //file("$matfile");

$str_arrmat=array();
$str_arrmat=explode("\n",$matrix1);


if($str_arrmat[2]=="" || $matrix1=="")
{
?>
<h1><font color=blue>Error: Unable to display your network structure.</font></h1>

<?php
exit;
}

$datamat=array();
$data_read=array();
 
$node=trim($str_arrmat[0]);
/*
if($node<=5)
{
  $width=200;
  $hieght=150;
  $font=14;
}
else if($node>5 && $node<=7)
{
  $width=150;
  $hieght=120;
  $font=12;

}
else if($node>7 && $node<=10)
{
  $width=110;
  $hieght=85;
  $font=10;
}
else 
{
  $width=80;
  $hieght=60;
  $font=8;
}
*/
  $width=150;
  $hieght=150;
  $font=12;

$r_index=$node+2;

for($i=0;$i<$node;$i++)
{
$datamat=explode("\t",$str_arrmat[$r_index]);
$data_read[$i][0]=trim($datamat[0]);  //name
$data_read[$i][1]=trim($datamat[1]);  //datatype
$col_in=2;
$r_index+=4;
	if($datamat[1]==1)  //type=coninuous
	{
         for($j=1;$j<=101;$j++)
         {
           $datamat=explode("\t",$str_arrmat[$r_index]);
           $data_read[$i][$col_in]=trim($datamat[0]);  //x data
         //  echo $data_read[$i][$col_in];
          // echo '&nbsp';

           $col_in++;
           $data_read[$i][$col_in]=trim($datamat[1]);  //y data
          // echo $data_read[$i][$col_in];
	   // echo '&nbsp';

           $col_in++;
           $r_index++; // increment to point next data
           // echo "<br />"; 
         } 
	}
	if($datamat[1]>1)  //type=descrete
	{
         $iter=$datamat[1];
         for($j=1;$j<=$iter;$j++)
         {
           $datamat=explode("\t",$str_arrmat[$r_index]);
           $data_read[$i][$col_in]=trim($datamat[0]);  //x data
           $data_read[$i][$col_in]=levelmap($data_read[$i][$col_in],$data_read[$i][0],$levelmap);

         //  echo $data_read[$i][$col_in];
          // echo '&nbsp';
  
           $col_in++;
           $data_read[$i][$col_in]=trim($datamat[1]);  //y data
          // echo $data_read[$i][$col_in];
           //echo '&nbsp';

           $col_in++;
           $r_index++; // increment to point next data
           //echo "<br />"; 
         } 
	}

}




////////////////////////////////////////////////Graphviz data read////////////////////////////////////////////////////////////////////////////////
$grv=$dir.$keyval."graphviz.txt";
$line=shell_exec('/usr/bin/dot -Tplain -y '.$grv);


//$grfilename=$keyval."graphviz.txt";
//$cmd="/usr/bin/dot -Tplain -y  $grfilename";
//$line=system($cmd);


//shell_exec('/usr/bin/dot -Tpng -o /var/www/html/compbio/BNW/graphviz.png /var/www/html/compbio/BNW/graphviz.txt');
$str_arrname=array();
$str_arrname=explode("\n",$line);
$data=array();
$ID_data=array();
$i=0;
$ii=0;
foreach($str_arrname as $row)
{
  $i++;
  if($i>1)
  {
       
  	$data=explode(" ",$row);
       $j=0;
       $k=0;
       $flag=0;
  	foreach($data as $cell)
	{
             
             $j++;
             
             $cell=trim($cell);
             //echo $cell;
             //echo '&nbsp';
             if($j==1 && $cell=="node")
             {
                $flag=1;
             }  
               
             if($j>1 && $j<5 && $flag==1)
             {
    		  //echo $cell;
   		  //echo '&nbsp';
                if($j==2)
                   $ID_data[$ii][$k]=$cell;
                else
                   $ID_data[$ii][$k]=round($cell/10*900);
               // echo $ID_data[$ii][$k];
                //echo '&nbsp';

                $k++; 
             }
       } 
  
       if($flag==1)
       {
          $ID_data[$ii][3]=$ID_data[$ii][1]+100;
          $ID_data[$ii][4]=$ID_data[$ii][2]+150; 
          $ID_data[$ii][5]=$ID_data[$ii][1]+100;
          $ID_data[$ii][6]=$ID_data[$ii][2]; 
          $ii++;
          //echo "<br />"; 
       } 
     // echo "<br />"; 
	
  }
}

$nnode=$ii;
$edge_data=array();

$i=0;
$ii=0;

foreach($str_arrname as $row)
{
  $i++;
  if($i>1)
  {
       
  	$data=explode(" ",$row);
       $j=0;
       
       $flag=0;
       $number_of_point=0;
       $index=0; 
  	foreach($data as $cell)
	{
             $j++;
             $cell=trim($cell);
         
             if($j==1 && $cell=="edge")
             {
                $flag=1;
             }  
               
             if($j==2 && $flag==1)
             {
                
                for($k=0;$k<$nnode;$k++)
                {
                      if($cell==$ID_data[$k][0])
                      {
                          $edge_data[$ii][0]=$ID_data[$k][3];
                          $edge_data[$ii][1]=$ID_data[$k][4];
                      }                     

                }
               
             }
             else if($j==3 && $flag==1)
             {
               for($k=0;$k<$nnode;$k++)
                {
                      if($cell==$ID_data[$k][0])
                      {
                          $edge_data[$ii][2]=$ID_data[$k][5];
                          $edge_data[$ii][3]=$ID_data[$k][6];
                      }                     

                }

             }
             else if($j==4 && $flag==1)
             {
                  $edge_data[$ii][4]=$cell;
                  $number_of_point=$cell*2;
                  $index=5;
             }
             else if($j>4 && $number_of_point>0 && $flag==1)
             {
                if(($j%2)!=0)
                  $edge_data[$ii][$index]=round($cell/10*900)+60;//+30+30;
                else
                  $edge_data[$ii][$index]=round($cell/10*900)+48;//+18+30;

                $number_of_point--;
                $index++;
             }


             
       } 
       if($flag==1)
       {
          $ii++;
          //echo "<br />"; 
       } 
 	
  }
}


$nedges=$ii;

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
 <script type="text/javascript">
  google.load('visualization', '1', {packages: ['corechart']});
 </script>
 

<?php 
$data_val="";

for($i=0;$i<$nnode;$i++)
 {
////////////////////////////select node //////////////////////////////////////
 $name=$ID_data[$i][0];
 $fname="draw_".$name."()";
 $data_val.=$name;
 for($j=0;$j<$node;$j++)
 {
    if($data_read[$j][0]==$name)
    {
       $s_i=$j;
       break;
    } 
 }
 
/////////////////////////////////Display nodes//////////////////////////////////////////////////////////
?>    
 <script type="text/javascript">


<?php
  $node_type=$data_read[$s_i][1];
  if($node_type>1) //discrete node
  { 
?>
  
 
  function <?php print($fname);?> {
  // Create and populate the data table.
 
  var data = google.visualization.arrayToDataTable([
   ['<?php print($name);?>', ''],
  <?php
  $c_i=2; 

  for($j=0;$j<$node_type-1;$j++) 
  {     
       $val1=trim($data_read[$s_i][$c_i]);


       $c_i++;
       $val2=trim($data_read[$s_i][$c_i]);
       $c_i++;
       $data_val.="\t".$val2;
        
  ?>
   ['<?php print($val1);?>', <?php print($val2);?>],

  <?php
  }
  if($j==$node_type-1)
  {
        $val1=trim($data_read[$s_i][$c_i]);


       $c_i++;
       $val2=trim($data_read[$s_i][$c_i]);
       $c_i++;
       $data_val.="\t".$val2."\n";
  ?> 
    ['<?php print($val1);?>', <?php print($val2);?>]
<?php
  }
?>
  ]);
      
        // Create and draw the visualization.
      
      var cnode="<?php print($name); ?>";
       var keyv="<?php print($keyval);?>";  
        var chart = new google.visualization.BarChart(document.getElementById('<?php print($name);?>'));
        function selectHandler() {
          var selectedItem = chart.getSelection()[0];
          if (selectedItem) {
            var topping = data.getValue(selectedItem.row, 0);
            
            var s = window.prompt('Selected evidence ' + topping + ' for ' + cnode + '. Enter new evidence ', topping );
           
            window.location.href = "add_inv_example.php?name=" + cnode + "&evidence=" + s + "&My_key=" + keyv;
           

  
              //alert('The user selected ' + topping + topname);
          }
        } 
         chart.draw(data,
                 {title:"<?php print($name);?>", titleTextStyle: {fontSize: <?php print($font);?>},
                  width:<?php print($width);?>, height:<?php print($hieght);?>,
                  vAxis: {title: "State", textStyle: {fontSize:<?php print($font);?>}},
		    hAxis: {title: "Fraction", minValue: 0, maxValue: 1, gridlines: {count: 3}}, legend: {position: 'none'},
                  backgroundColor: {stroke: 'black', strokeWidth: 5}}
            );
        google.visualization.events.addListener(chart, 'select', selectHandler);  

  }
<?php
 }
 else //continuous node
 {
?>
  function <?php print($fname);?> {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
   ['<?php print($name);?>', ''],
  <?php
  $c_i=2;
  for($j=0;$j<100;$j++) 
  {
       $val1=trim($data_read[$s_i][$c_i]);
       $val1=map($name,$val1,$keyval);

       $c_i++;
       $val2=trim($data_read[$s_i][$c_i]);
       $c_i++;         
       $data_val.="\t".$val2;
  ?>
   ['<?php print($val1);?>', <?php print($val2);?>],

  <?php
  }
  if($j==100)
  {
       $val1=trim($data_read[$s_i][$c_i]);
       $val1=map($name,$val1,$keyval);

       $c_i++;
       $val2=trim($data_read[$s_i][$c_i]);
       $c_i++;
       $data_val.="\t".$val2."\n";
  ?> 
    ['<?php print($val1);?>', <?php print($val2);?>]
<?php
  }
?>
  ]);
      
        // Create and draw the visualization.
      var cnode="<?php print($name); ?>";
      var keyv="<?php print($keyval);?>";

        var chart = new google.visualization.LineChart(document.getElementById('<?php print($name);?>'));

        function selectHandler() {
          var selectedItem = chart.getSelection()[0];
          if (selectedItem) {
           
            var topping = data.getValue(selectedItem.row, 0);
            var s = window.prompt('Selected evidence ' + topping + ' for ' + cnode + '. Enter new evidence ', topping );
            window.location.href = "add_inv_example.php?name=" + cnode + "&evidence=" + s + "&My_key=" + keyv;  

          }
        }
            chart.draw(data, {curveType: "function",
                  title:"<?php print($name);?>", titleTextStyle: {fontSize: <?php print($font);?>},
			legend: {position: 'none'},
                  width:<?php print($width);?>, height:<?php print($hieght);?>,
                  hAxis: {maxValue: 1, minValue: 0},
			vAxis: {maxValue: 1, minValue: 0},
                  backgroundColor: {stroke: 'black', strokeWidth: 5}}
            );
           google.visualization.events.addListener(chart, 'select', selectHandler); 
       }

<?php
 }
?>
</script>
<?php
///////////////////////////end of display nodes////////////////////////////////////////////////
}


///////////////////////////////////write data to file///////////////////////////////////////////////////////////


?>



<script type="text/javascript">
function canvas_arrow(context, fromx, fromy, tox, toy){
    var headlen = 15;
    var dx = tox-fromx;
    var dy = toy-fromy;
    var angle = Math.atan2(dy,dx);
    context.moveTo(fromx,fromy);
    context.lineTo(tox,toy);
    context.lineTo(tox-headlen*Math.cos(angle-Math.PI/6),toy-headlen*Math.sin(angle-Math.PI/6));
    context.moveTo(tox,toy);
    context.lineTo(tox-headlen*Math.cos(angle+Math.PI/6),toy-headlen*Math.sin(angle+Math.PI/6));
}
</script>

<script type="text/javascript">
function canvas_arrow_head(context, fromx, fromy, tox, toy){
    var headlen = 15;
    var dx = tox-fromx;
    var dy = toy-fromy;
    var angle = Math.atan2(dy,dx);
    context.moveTo(tox,toy);
    context.lineTo(tox-headlen*Math.cos(angle-Math.PI/6),toy-headlen*Math.sin(angle-Math.PI/6));
    context.moveTo(tox,toy);
    context.lineTo(tox-headlen*Math.cos(angle+Math.PI/6),toy-headlen*Math.sin(angle+Math.PI/6));
}
</script>


</head>

<body>
<canvas id="test" width="3000" height="3000" style="position:absolute">
<script>
function canvas_arrow_draw(n, polypts,context){

//Create jsGraphics object
var headlen = 10;
/*
var hexno=new String;
arr=new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
var n1=Math.round(Math.random()*15);
var n2=Math.round(Math.random()*15);
var n3=Math.round(Math.random()*15);
var n4=Math.round(Math.random()*15);
var n5=Math.round(Math.random()*15);
var n6=Math.round(Math.random()*15);
hexno="#"+arr[n1]+""+arr[n2]+""+arr[n3]+""+arr[n4]+""+arr[n5]+""+arr[n6];
*/
hexno="black";
var polypoints = new Array();
var n2=n*2;


var sx=polypts[0];
var sy=polypts[1];
 
var sx1=polypts[n2-4];
var sy1=polypts[n2-3];
var ex1=polypts[n2-2];
var ey1=polypts[n2-1];

context.beginPath();
canvas_arrow_head(context,sx1,sy1,ex1,ey1);

context.moveTo(polypts[0],polypts[1]);
nm=n%3;
ni=(n-nm)/3;

for(i=0;i<ni;i++)
{
  i11=i*6+2;
  i12=i*6+3;
  i21=i*6+4;
  i22=i*6+5;
  i31=i*6+6;
  i32=i*6+7;

  context.bezierCurveTo(polypts[i11],polypts[i12],polypts[i21],polypts[i22],polypts[i31],polypts[i32]);
  context.moveTo(polypts[i31],polypts[i32]);

 // polypoints[i] = new jxPoint(polypts[i1], polypts[i2]);
}


if(nm==2)
{
  context.moveTo(polypts[i21],polypts[i22]);
  context.bezierCurveTo(polypts[i31],polypts[i32],sx1,sy1,ex1,ey1);
  context.moveTo(ex1,ey1);

}

 context.strokeStyle = hexno;
 context.stroke();

}


var canvas=document.getElementById("test");
var context = canvas.getContext("2d");
context.lineWidth = 3;

<?php
for($i=0;$i<$nedges;$i++)
{

   $n=$edge_data[$i][4]; 
   $n2=$n*2;
   
?>
var polypoints = new Array();
var j=0;
var n="<?php print($n);?>";
<?php
for($j=0;$j<$n2;$j++)
{
$inx=$j+5;
$data=$edge_data[$i][$inx];

?>
	polypoints[j] = "<?php print($data);?>";

       j++;
<?php
}
?>
canvas_arrow_draw(n,polypoints,context);
<?php
}
?>



</script>
</canvas>


<?php 
for($i=0;$i<$nnode;$i++)
{
  $x=$ID_data[$i][1]-8; $y=$ID_data[$i][2]-20; 

  $name=$ID_data[$i][0];
?>

<script type="text/javascript">
   google.setOnLoadCallback(draw_<?php print($name)?>);
</script>
<div id="<?php print($name)?>" style="left: <?php print($x)?>px; top: <?php print($y)?>px; width:<?php print($width);?>; height:<?php print($hieght);?>; position: absolute"></div>

<?php 
}
?>


</body>



</html>