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
|
<?php
////////////////This code load a data file and creates input file for continuous global optimal search (our modification). execute_bn_gom.php link is for execution of structure learning and create_tiers_gom.php is for adding restrictions///////////////////////////////////
include("header_new.inc");
include("header_batchsearch.inc");
include("runtime_check.php");
$searchID="";
$UploadValue="NO";
$TextFile=$HTTP_POST_FILES["MyFile"]["name"];
/////////////Generate a random key/////////////////////
$alphas=array();
$alphas = array_merge(range('A', 'Z'), range('a', 'z'));
$al1=rand(0,51);
$al2=rand(0,51);
$al3=rand(0,51);
$alpha="$alphas[$al1]"."$alphas[$al2]"."$alphas[$al3]";
$keyval=$alpha;
if($_POST["My_key"]!="")
$keyval=$_POST["My_key"];
////////////////////max parent/////////////////////////
$type_n=array();
//Get number of parent data and key value for changes in number of parent
$type_n=explode("|",$_POST["nm_parent"]);
if($keyval=="")
$keyval=$type_n[0];
$sid=$keyval."continuous_input";
$dir="./data/";
$TextinFileFinal=$dir.$sid.".txt";
$TextinFile=$dir.$sid."_temp.txt";
$TextinFilenamelist=$dir.$keyval."name.txt";
//print default number of parents
$parent_number=4;
$pfile=$dir.$keyval."parent.txt";
$parentf=fopen($pfile,"w");
fwrite($parentf,"$parent_number\n");
//print default number of k for model averaging
$k_number=1;
$kfile=$dir.$keyval."k.txt";
$kf=fopen($kfile,"w");
fwrite($kf,"$k_number\n");
//print default threshold for model averaging
$thrfile=$dir.$keyval."thr.txt";
$kf=fopen($thrfile,"w");
fwrite($kf,"0.5\n");
if(isset($HTTP_POST_VARS["searchkey"]))
{
$searchID=$HTTP_POST_VARS["searchkey"];
}
if($searchID!="")
{
?>
<!-- Site navigation menu -->
<ul class="navbar2">
<li><a href="executionprogress.php?My_key=<?php print($keyval);?>">Perform Bayesian network modeling using default settings</a>
<li><a href="create_tiers_gom.php?My_key=<?php print($keyval);?>">Go to structure learning settings and the BNW structural constraint interface</a>
</ul>
<ul class="navbar">
<li><a href="help.php#file_format" target="_blank">Data formatting guidelines</a>
<li><a href="help.php" target="_blank">Help</a>
<li><a href="home.php">Home</a>
</ul>
<?php
}
else
{
?>
<!-- Site navigation menu -->
<ul class="navbar">
<li><a href="help.php#file_format" target="_blank">Data formatting guidelines</a>
<li><a href="help.php" target="_blank">Help</a>
<li><a href="home.php">Home</a>
</ul>
<?php
}
if(isset($HTTP_POST_VARS["MyUpload"]))
{
$UploadValue=$HTTP_POST_VARS["MyUpload"];
if ($UploadValue=="YES")
{
if($TextFile!="")
{
$sta=move_uploaded_file($HTTP_POST_FILES['MyFile']['tmp_name'],$TextinFile);
if(!$sta)
{
echo "<script type='text/javascript'> window.alert ('Sorry, error uploading $TextFile.')</script>";
flush();
exit();
}
else
{
$searchID=file_get_contents("$TextinFile");
unlink($TextinFile);
}
}
else
{
echo "<script type='text/javascript'> window.alert ('Sorry, please select upload file.')</script>";
}
}
}
?>
<div id="outernew">
<h2><font color=#33339f>Upload data file for structure learning search</font></h2>
<FORM name="key_search" enctype="multipart/form-data" ACTION="bn_file_load_gom.php" METHOD=POST>
<table align="left" cellspacing="3" cellpadding="1" border="0" width="60%">
<tr>
<td>
<INPUT style="background-color:#FFFFFF;color:#0000FF" type="file" name="MyFile" size=45 >
<INPUT TYPE="submit" value=" Upload " onclick="return Upload();">
<INPUT TYPE="hidden" NAME="My_key" value=<?php print($keyval) ?> >
<INPUT TYPE="hidden" name="MyUpload" value="NO">
</td>
</tr>
<tr>
<td align="left"><font color=#33339f><br>Content of uploaded data file:</font><br>
<textarea name="searchkey" rows="10" cols="100"><?PHP print($searchID)?> </textarea>
</td>
</tr>
<tr>
<td>
<INPUT TYPE="submit" value=" Load example data of immune responses to infection with Chlamydia psittaci " onclick="return demochl();">   
<INPUT TYPE="hidden" NAME="My_key" value=<?php print($keyval) ?> >
</td>
</tr>
<tr>
<td>
<INPUT TYPE="submit" value=" Load example data of a synthetic genetic network with 2 genotypes and 6 traits " onclick="return demo8nodes();">   
<INPUT TYPE="hidden" NAME="My_key" value=<?php print($keyval) ?> >
</td>
</tr>
<tr>
<td>
<INPUT TYPE="submit" value=" Load example data of immune-related gene in the spleens of BXD mice " onclick="return demospnl();">   
<INPUT TYPE="hidden" NAME="My_key" value=<?php print($keyval) ?> >
</td>
</tr>
<tr>
<td>
<INPUT TYPE="submit" value=" Load the ksl dataset from deal " onclick="return demoksl();">   
<INPUT TYPE="hidden" NAME="My_key" value=<?php print($keyval) ?> >
</td>
</tr>
<tr>
<td>
<INPUT TYPE="submit" value=" Load the rat dataset from deal " onclick="return demorat();">   
<INPUT TYPE="hidden" NAME="My_key" value=<?php print($keyval) ?> >
</td>
</tr>
</table>
</FORM>
</div>
<?php
//////////////////Format data for Structure learning "C" code////////
$str_arr=array();
$searchID=trim($searchID);
$str_arr=explode("\n",$searchID);
$data=array();
$fph = fopen($TextinFilenamelist,"w");
$fpmain = fopen($TextinFileFinal,"w");
$cont_arr=array();
$cont_arr_tmp=array();
$data_type=array();
$level_arr=array();
//Who is discrete? Who is continuous?
$i=0;
$lc=0;
foreach($str_arr as $line)
{
$line=trim($line);
if($lc==0)
{
fwrite($fph, "$line\n");
fprintf($fpmain, "$line\n");
$name_t=$line;
fclose($fph);
$data=explode("\t",$line);
$j=0;
foreach($data as $d_c)
{
$d_c=trim($d_c);
$level_arr[$j][0]=$d_c; //variable name y for
$data_type[$j]=0;
$j++;
}
$lcc=$j; //$lcc=number of column in the input file
}
else
{
$strline="";
$data=explode("\t",$line);
$j=0;
foreach($data as $d_c)
{
$d_c=trim($d_c);
$cont_arr[$i][$j]=$d_c;
$cont_arr_tmp[$i][$j]=$d_c;
$mystring = $d_c;
$findme = '.';
$pos = strpos($mystring, $findme);
$strline.="1\t";
if ($pos != false)
{
$data_type[$j]=1;
}
$j++;
}
$i++;
}
$lc++;
}
$lc--; //$lc=number of rows in the input file
//Now count number of labels for discrete variables and populate the $data_type[$j]
$data_count=0;
$l_type="";
for($j=0;$j<$lcc;$j++)
{
if($data_type[$j]!=1)
{
$data_count=0;
for($i=0;$i<$lc;$i++)
{
$vi=$i+1;
for($ii=$vi;$ii<$lc;$ii++)
{
if($cont_arr[$i][$j]==$cont_arr[$ii][$j] && $cont_arr[$i][$j]!=-9999)
{
$cont_arr[$ii][$j]=-9999;
}
}
}
for($i=0;$i<$lc;$i++)
{
if($cont_arr[$i][$j]!=-9999 && $cont_arr[$i][$j]!="")
{
// $data_count_l=$data_count+2;
$data_count++;
$level_arr[$j][$data_count]=$cont_arr[$i][$j];
}
}
$data_type[$j]=$data_count;
}
if($j==0)
$l_type.=$data_type[$j];
else
$l_type.="\t".$data_type[$j];
}
///////////////////Write data to files/////////////////
$fptype = fopen($dir.$keyval."type.txt","w");
$fpnode= fopen($dir.$keyval."nnode.txt","w");
fwrite($fpnode,"$lcc\n");
$fprows = fopen($dir.$keyval."nrows.txt","w");
fwrite($fprows,"$lc\n");
$flevel = fopen($dir.$keyval."nlevels.txt","w");
//print in level mapping file for discrete variables
for($j=0;$j<$lcc;$j++)
{
if($data_type[$j]>1)
{
fprintf($flevel,"%s",$level_arr[$j][0]);
$m=$data_type[$j];
for($jj=1;$jj<=$m;$jj++)
{
fprintf($flevel,"\t%s",$level_arr[$j][$jj]);
}
fprintf($flevel,"\n");
}
}
fwrite($fptype,"$name_t\n");
for($j=0;$j<$lcc;$j++)
{
fprintf($fptype,"$data_type[$j]\t");
}
fwrite($fptype,"\n");
fwrite($fpmain, "$l_type\n");
$l_c=0;
//perform discrete level replacement
for($m=0;$m<$lcc;$m++) //column
{
if($data_type[$m]>1)
{
$r=$data_type[$m];
for($j=1;$j<=$r;$j++)
{
$search=$level_arr[$m][$j];
$replace=$j."#";
for($n=0;$n<$lc;$n++) //row
{
$val=$cont_arr_tmp[$n][$m];
if($val==$search)
$cont_arr_tmp[$n][$m]=$replace; //alter levels
}
}
for($n=0;$n<$lc;$n++) //row
$cont_arr_tmp[$n][$m]=str_replace('#','',$cont_arr_tmp[$n][$m]);
}
}
//write data to output file
for($j=0;$j<$lc;$j++)
{
fprintf($fpmain,"%s",$cont_arr_tmp[$j][0]);
for($jj=1;$jj<$lcc;$jj++)
fprintf($fpmain,"\t%s",$cont_arr_tmp[$j][$jj]);
fprintf($fpmain, "\n");
}
fclose($fpmain);
////////////////empty ban and white list/////////////////////////////
$sid1=$keyval."ban";
$sid2=$keyval."white";
$wdir="./data/";
$Textban=$wdir.$sid1.".txt";
$Textwhite=$wdir.$sid2.".txt";
$fpb = fopen($Textban,"w");
$fpw = fopen($Textwhite,"w");
$datpost="From\tTo\n";
fwrite($fpb,"$datpost");
fwrite($fpw,"$datpost");
if($searchID!="")
{
$runtime=exe_time($keyval,$parent_number,$k_number);
?>
<div id="outernew">
<p><h3><?php
print("Estimated run time for current dataset using default settings: $runtime seconds");
?>
<br><br></h3>
</p>
<br>
</div>
<?php
}
?>
</body>
</html>
|