about summary refs log tree commit diff
path: root/sourcecodes/cross_valid.php
blob: 9ed8ab073f2c1c6cc37cf8dee43d4c8ab5b84859 (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
<head>
<meta http-equiv='cache-control' content='no-cache'> 
<meta http-equiv='expires' content='0'> 
<meta http-equiv='pragma' content='no-cache'> 
<script src="./scripts/d3.v4.min.js"></script>
<script src="./scripts/create_table.js"></script>
<?php 
include("header_new.inc");
include("header_batchsearch.inc");
include("input_validate.php");
$keyval=$_GET["My_key"];
if($keyval!='') {
  $keyval = valid_keyval($keyval);
}
?>
</head>

<?php
$varName = "";
$varNameErr = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $keyval=$_POST["My_key"];
  if($keyval!='') {
    $keyval = valid_keyval($keyval);
  }
  if (empty($_POST["varName"])) {
    $varNameErr = "Entering a variable name is required";
  } else {
    //    $varName = test_input($_POST["varName"]);
    $varName = valid_input($_POST["varName"]);
    $varNameErr = "1";
    // check if name only contains letters and whitespace
    //if (!preg_match("/^[\w]*$/",$varName)) {
    //  $varNameErr = "The input string contains characters that are not allowed"; 
    //}
  }
}


function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>


<?php
$varName_file = "/tmp/bnw/".$keyval."name.txt";
$varName_line = file_get_contents($varName_file);
$varNamesArr = explode("\t",$varName_line);
?>





<!-- Site navigation menu -->
<ul class="navbar2">
  <li class="noHover"><p>Network ID:<br><?php print($keyval);?></p></li>
  <li><a href="javascript:void(0);"
  NAME="Network" title="Network" onClick=window.open("layout.php?My_key=<?php print($keyval);?>","_self");>Return to network</a>
  <li><a href="javascript:void(0);"
  NAME="CV_predictions" title="CV_pred" onClick=window.open("cv_predictions.php?My_key=<?php print($keyval);?>","_self");>Return to validation and predictions menu</a>
  <li><a href="help.php">Help</a>
  <li><a href="home.php">Home</a>
</ul>

<body>

<!-- Main content -->
<div id="outer">

<?php
  //  $filename1="./data/".$keyval."looCV.txt";
  //  $filename2="./data/".$keyval."looCV_temp.txt";
  $dir="/tmp/bnw/";
$filename1=$dir.$keyval."looCV.txt";
$filename2=$dir.$keyval."looCV_temp.txt";
   $plotly_file=$dir.$keyval."loo_plotly.html";
   $plotly_file_local = "./data/".$keyval."loo_plotly.html";
   $pred_file_local = "./data/".$keyval."looCV.txt";
if(file_exists($filename2))
 {?>
<br>
  <h2> Leave-one-out cross-validation results are being calculated</h2>
<br>
     <a href=<?php $ref="cv_predictions.php?".$keyval; print($ref);?>Refresh to update status</a>
<br>
<?php
 }
 else if(file_exists($filename1))
 {?>
     <div>
	  <object type="text/html" data=<?php print($plotly_file_local);?> width="800" height="500" >
         </object>
     </div>
     <div class="d3_table" id="table_div1">
     <script type="text/javascript">
	d3.text("<?php print($pred_file_local);?>", function(error,raw) {
	    var dsv=d3.dsvFormat("\t")
	    var data=dsv.parse(raw)
	      var caption_text=data.pop()
	      if (error) throw error;
	    tabulate_caption("#table_div1",data,caption_text.CaseRow);
	  });
</script>
</div>
<br>
    <a class=button2 href=<?php print($pred_file_local);?>>Download cross-validation results</a>
<br>
<br>
<h3>Perform leave-one-out cross-validation of another network variable<br></h3>
<p><span class="error"></span></p>
<FORM METHOD="post" id=form ACTION="<?php $location = htmlspecialchars($_SERVER["PHP_SELF"]); echo ''.$location.'#form';?>">
<p style='font-size:18px'>Select variable name:</p>
<select style='font-size:18px' Name="varName">
 <?php foreach($varNamesArr as $entry){
     echo "<option value='".$entry."'>$entry</option>";
   }?>
</select>
<input type='hidden' name='My_key' value='<?php print($keyval)?>'>
<input class=button2 type="submit" name="submit" value="Submit" style="font-size:18px">
<br><br>
</FORM>
</FORM>
</p>
<br>
<?php
     } else {
?>
<h2>Perform leave-one-out cross-validation of network</h2>
<p align="justify" style='font-size:18px'> 
  Select the variable that you want to examine the predictions of below.
<br>
<br>
<p><span class="error"></span></p>
<FORM METHOD="post" ACTION="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<p style='font-size:18px'> Select variable name:</p><br>
<select style='font-size:18px' Name="varName">
 <?php foreach($varNamesArr as $entry){
     echo "<option value='".$entry."'>$entry</option>";
   }?>
</select>
<input type='hidden' name='My_key' value='<?php print($keyval)?>'>
<input class=button2 type="submit" name="submit" value="Submit" style="font-size:18px">
</FORM>
</p>
<br>

<?php
}

if($varNameErr=="1")
{
  $command = './run_scripts/run_loo '.$keyval.' '.$varName;
  //  $command = 'sh plotly_loo.sh'
  $output = shell_exec("$command > /dev/null 2 > /dev/null &");
  $pred_link='cv_predictions.php?My_key='.$keyval;
  sleep(1);
  echo "<br>";
  echo "<a class=button3 href=$pred_link>Calculation submitted. Click here to return to cross-validation and predictions menu.</a><br><br>";
}
?>

</div>
</body>