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
|
<?php
include("input_validate.php");
require("terminal_commands.php");
$keyval=valid_keyval($_GET["My_key"]);
// Structure learning takes a while (C code + octave) and this page
// used to output NOTHING until it was done -- the browser sat on a
// blank page. Emit the status page FIRST and flush it, so the user
// sees what is happening, with a fallback link in case the automatic
// forward is blocked or fails.
?>
<!doctype html>
<html>
<head>
<title>Running BNW</title>
<link rel="stylesheet" type="text/css" href="my_new_style.css">
</head>
<body>
<div class="content">
<p>Structure learning is running.</p>
<p id="bnw-forwarding">Forwarding to the network diagram when done…</p>
<p>If the diagram does not open, <a href="layout_svg_no.php?My_key=<?php print($keyval);?>">click here</a>.</p>
</div>
<?php
flush();
//////////////execute c codes for local score///////////////////
//$dir="/var/lib/genenet/bnw/";
$dir="/var/lib/genenet/bnw/";
$pfile=$dir.$keyval."parent.txt";
$parentf=file_get_contents("$pfile");
//$maxp=valid_input($parentf);
$maxp=trim($parentf);
$kfile=$dir.$keyval."k.txt";
$kf=file_get_contents("$kfile");
//$maxk=valid_input($kf);
$maxk=trim($kf);
$thrfile=$dir.$keyval."thr.txt";
$thr=file_get_contents("$thrfile");
//$thr=valid_input($thr);
$thr=trim($thr);
$bnw_error = NULL;
try {
runTerminalCommand([realpath(__DIR__).'/run.sh', $keyval, $maxp, $maxk, $thr]);
/////////////////////////////////structure matrix//////////////////////////////////////////////////////////
$matfile=$dir.$keyval."structure_input.txt";
$fout=fopen($dir.$keyval."graphviz.txt","w");
$matrix1=file_get_contents("$matfile");
$str_arrmat=array();
$str_arrmat=explode("\n",$matrix1);
$datamat=array();
$data_cell=array();
$dataname=array();
$dataname=explode("\t",$str_arrmat[0]);
$n=count($dataname);
$initialstring="digraph G {\n"."size=\"6,8\"; ratio = fill;\n"."node [shape=square,width=1.5];\n";
$endstring="}";
if ($fout !== false) {
fwrite($fout,"$initialstring");
}
$g_file_name=$dir.$keyval."grviz_name_file.txt";
$grviz_name_file=fopen($g_file_name,"w");
if ($grviz_name_file !== false) {
for($i=0;$i<$n;$i++)
{
$row_name=trim($dataname[$i]);
fwrite($grviz_name_file,"$row_name\n");
}
}
for($i=1;$i<=$n;$i++)
{
$ii=$i-1;
$row_name=trim($dataname[$ii]);
$col_arr=explode("\t",$str_arrmat[$i]);
for($j=0;$j<$n;$j++)
{
$col_val=trim($col_arr[$j]);
if($col_val==1)
{
$col_name=trim($dataname[$j]);
if ($fout !== false) {
fprintf($fout,"%s -> %s;\n",$ii,$j);
}
//fprintf($fouttemp,"%s -> %s;\n",$row_name,$col_name);
}
}
}
if ($fout !== false) {
fwrite($fout,"$endstring");
fclose($fout);
}
runTerminalCommand([realpath(__DIR__.'/run_scripts/run_octave'), $keyval]);
} catch (Exception $e) {
$bnw_error = $e->getMessage();
}
if(!is_null($bnw_error))
{
// Structure learning failed: show it on the status page instead of
// a blank fatal error page with no forward.
$bnw_hint = "";
// Plain-English hints for the recurring octave failure modes
if (preg_match("/toposort|sources\\(0\\)/", $bnw_error)
|| preg_match("/subscripts must be .* integers/", $bnw_error))
$bnw_hint = "Hint: the learned network could not be laid out. This can happen when variables are identical or mirror each other (e.g. the same trait measured repeatedly), which produces a network that cannot be drawn as a directed graph. Try removing duplicate/similar variables or changing the structure learning settings.";
elseif (preg_match("/out of memory|memory exhausted/i", $bnw_error))
$bnw_hint = "Hint: the data set is too large for the available memory. Remove variables or use fewer samples.";
elseif (preg_match("/Could not open .* for input/", $bnw_error))
$bnw_hint = "Hint: the data preparation step did not produce the expected files. Check that the data is complete and try again.";
?>
<p style="color: red;">Structure learning FAILED:</p>
<?php if ($bnw_hint !== "") { ?>
<p style="color: darkgreen;"><?php print($bnw_hint); ?></p>
<?php } ?>
<pre><?php print(htmlspecialchars($bnw_error)); ?></pre>
<p><a href="bn_genenet.php">Back to the data upload page</a></p>
</div>
</body>
</html>
<?php
exit(1);
}
?>
<script>
window.open("layout_svg_no.php?My_key=<?php print($keyval);?>",'_self',false);
</script>
</body>
</html>
|