ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/tags/owl-for-cmview-1.9.4/modelit/server/select_templates.php
Revision: 1440
Committed: Thu Aug 18 07:03:28 2011 UTC (10 years, 11 months ago) by jmduarteg
File size: 12104 byte(s)
Log Message:
Tagging from bug fix branch for bug fixed version of CMView 1.9.4 (released as 1.1.1). Important bug fix of DaliRunner
Line User Rev File contents
1 hstehr 1299 <?php
2     include_once("inc/settings.php");
3    
4     function get_output_url($job_name) {
5     return "results/".$job_name."/";
6     }
7    
8     function get_blast_img($job_name) {
9     return get_output_url($job_name).$job_name.".blast.png";
10     }
11    
12     function get_psiblast_img($job_name) {
13     return get_output_url($job_name).$job_name.".psiblast.png";
14     }
15    
16     function get_blast_img_all($job_name) {
17     return get_output_url($job_name).$job_name.".blast.all.png";
18     }
19    
20     function get_psiblast_img_all($job_name) {
21     return get_output_url($job_name).$job_name.".psiblast.all.png";
22     }
23    
24     function get_report_file($job_name) {
25     return get_result_file($job_name,".report");
26     }
27    
28     function get_blast_file($job_name) {
29     return get_result_file($job_name,".pdb-blast.classic.out");
30     }
31    
32     function get_psiblast_file($job_name) {
33     return get_result_file($job_name,".pdb-psiblast.classic.out");
34     }
35    
36     function get_template_file($job_name) {
37     return get_result_file($job_name, ".man.templates");
38     }
39    
40     // takes an array of template ids and writes a template file for modelling
41     function write_template_file($job_name, $templates) {
42     $t_file = get_template_file($job_name);
43     $fh = fopen($t_file, 'w') or error('Unable to write template file '.$t_file);
44     foreach($templates as $num => $pdb) {
45     fwrite($fh, $pdb."\n");
46     }
47     fclose($fh);
48     }
49    
50     function read_templates($job_name) {
51     $result = array();
52     if(file_exists(get_template_file($job_name))) {
53     $result = file(get_template_file($job_name), FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
54     }
55     return $result;
56     }
57    
58     // creates the graphical output from the blast and psiblast output files
59     function render_blast($job_name) {
60     global $num_blast_hits_collapsed;
61     global $num_blast_hits_expanded;
62     global $eval_cutoff_template_selection;
63     $j = escapeshellcmd($job_name);
64     $n = $num_blast_hits_collapsed;
65     $m = $num_blast_hits_expanded;
66     $e = $eval_cutoff_template_selection;
67     $w = 900;
68     $sc_dir = $GLOBALS['script_dir'];
69     $cmd=$sc_dir.'render_blast.pl '.get_blast_file($job_name).' '.$e.' '.$n.' '.$w.' > '.get_blast_img($job_name);
70     exec($cmd);
71     $cmd=$sc_dir.'render_blast.pl '.get_psiblast_file($job_name).' '.$e.' '.$n.' '.$w.' > '.get_psiblast_img($job_name);
72     exec($cmd);
73     $cmd=$sc_dir.'render_blast.pl '.get_blast_file($job_name).' '.$e.' '.$m.' '.$w.' > '.get_blast_img_all($job_name);
74     exec($cmd);
75     $cmd=$sc_dir.'render_blast.pl '.get_psiblast_file($job_name).' '.$e.' '.$m.' '.$w.' > '.get_psiblast_img_all($job_name);
76     exec($cmd);
77     }
78    
79     if(isset($_GET['job_name'])) {
80     $job_name = $_GET['job_name'];
81     }
82    
83     if(!isset($job_name)) {
84     error("No job name specified");
85     }
86    
87     if(isset($_GET['_submit_check'])) {
88     // parse templates
89     foreach($_GET as $key => $val) {
90     if(substr($key,0,4) == "temp" && !empty($val)) {
91     $templates[$key] = $val;
92     }
93     }
94     $custom_templates = trim($_GET['custom_templates']);
95     if(isset($custom_templates) && !strlen($custom_templates)==0) {
96     $cols = split(",",$custom_templates);
97     foreach($cols as $col) {
98     $temp = trim($col);
99     if(!preg_match("/^[0-9][0-9a-z]{3}[A-Z]$/",$temp)) {
100     $form_errors['invalid_custom_template'] = strip_tags($temp);
101     } else {
102     $templates[] = $temp; # no need to escape shell args because of regexp match above
103     }
104     }
105     }
106     if(!isset($templates) || count($templates) == 0) {
107     $form_errors['no_templates'] = 1;
108     }
109    
110     // redirect to run_modeling
111     if(!isset($form_errors) && isset($templates) && count($templates) > 0) {
112     // write to template file
113     write_template_file($job_name, $templates);
114     // redirect
115     header("Location: run_modeling.php?job_name=".$job_name);
116     }
117     }
118    
119     render_blast($job_name);
120    
121     ?>
122     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
123     <html xmlns="http://www.w3.org/1999/xhtml">
124    
125     <head>
126     <title>Structure prediction server</title>
127     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
128     <link rel="stylesheet" type="text/css" href="css/default.css" />
129    
130     <script type="text/javascript">
131     // preload images
132    
133     blast_img = new Image();
134     blast_img.src = "<? echo get_blast_img($job_name); ?>";
135    
136     blast_img_all = new Image();
137     blast_img_all.src = "<? echo get_blast_img_all($job_name); ?>";
138    
139     psiblast_img = new Image();
140     psiblast_img.src = "<? echo get_psiblast_img($job_name); ?>";
141    
142     psiblast_img_all = new Image();
143     psiblast_img_all.src = "<? echo get_psiblast_img_all($job_name); ?>";
144    
145     // set up image toggling
146    
147     var blast_status = true;
148     var psiblast_status = true;
149    
150     function toggle_blast() {
151     blast_status = !blast_status;
152     if(blast_status) {
153     document.getElementById("btn_blast").src = 'images/control_blue_up.png';
154     document.getElementById('img_blast').src = '<? echo get_blast_img_all($job_name); ?>';
155     } else {
156     document.getElementById("btn_blast").src= 'images/control_blue_down.png';
157     document.getElementById('img_blast').src = '<? echo get_blast_img($job_name); ?>';
158     }
159     }
160    
161     function toggle_psiblast() {
162     psiblast_status = !psiblast_status;
163     if(!psiblast_status) {
164     document.getElementById("btn_psiblast").src='images/control_blue_up.png'
165     document.getElementById('img_psiblast').src = '<? echo get_psiblast_img_all($job_name); ?>';
166     } else {
167     document.getElementById("btn_psiblast").src='images/control_blue_down.png'
168     document.getElementById('img_psiblast').src = '<? echo get_psiblast_img($job_name); ?>';
169     }
170     }
171    
172     // show/hide parts of template table
173    
174     var show_min = <? echo $num_rows_visible_in_template_table; ?>;
175     var table_status = true;
176    
177     function toggle_table() {
178    
179     tbl = document.getElementById("template_table");
180     var len = tbl.rows.length;
181    
182     if(table_status) {
183     document.getElementById("btn_table").src='images/control_blue_up.png'
184     for(i=1 ; i< len; i++){
185     tbl.rows[i].style.display = "";
186     }
187     } else {
188     document.getElementById("btn_table").src='images/control_blue_down.png'
189     for(i=show_min+1 ; i< len; i++){
190     tbl.rows[i].style.display = "none";
191     }
192     }
193     table_status = !table_status;
194     }
195    
196     </script>
197    
198     </head>
199     <body>
200     <?php include_once("inc/owl_header.inc.php") ?>
201     <div class="main-content">
202     <?php
203     echo 'Job name='.$job_name.' [<a href="'.get_output_url($job_name).'">see raw output</a>] ';
204     echo '[<a href="'.get_output_url($job_name).$job_name.'.out.log">output log</a>]<br/>';
205     ?>
206    
207     <h3>Blast result</h3>
208     <img id="img_blast" src="<? echo get_blast_img($job_name); ?>" border="0" align="left" />
209     <a href="Javascript:toggle_blast();"><img id="btn_blast" title="show/hide more hits" src="images/control_blue_down.png" border="0" style="margin-top:10px;" /></a>
210     <div style="clear:both;"></div>
211    
212     <h3>Psiblast result</h3>
213     <img id="img_psiblast" src="<? echo get_psiblast_img($job_name); ?>" border="0" align="left" />
214     <a href="Javascript:toggle_psiblast()"><img id="btn_psiblast" title="show/hide more hits" src="images/control_blue_down.png" border="0" style="margin-top:10px;" /></a>
215     <div style="clear:both;"></div>
216    
217     <h3>Select templates</h3>
218     <form action="<?php $_SERVER['PHP_SELF'] ?>" method="GET" enctype="multipart/form-data">
219     <input type="hidden" name="job_name" value="<? echo $job_name; ?>">
220     <input type="hidden" name="_submit_check" value="1">
221     <table border=1 id="template_table" align="left" class="template_table">
222     <tbody>
223    
224     <?php
225     $lines = file(get_report_file($job_name));
226    
227     if(file_exists(get_template_file($job_name))) {
228     # modeling had already been submitted, show templates being used
229     $temps = read_templates($job_name);
230    
231     if(sizeof($lines) <= 2) {
232     echo 'No templates found!<br/><br/>';
233     // echo "<p>Templates used for modeling: ";
234     // if(count($temps) == 0) {
235     // echo "?";
236     // } else {
237     // foreach($temps as $temp) {
238     // echo $temp.' ';
239     // }
240     // echo "<br/>";
241     // }
242     // echo '</p>';
243     $no_temps = 1;
244     } else {
245     for($l = 1; $l < count($lines); $l++) {
246     $line = $lines[$l];
247     $fields = explode("\t", $line);
248     $pdb = $fields[0];
249     echo "<tr";
250     if($l-1 > $num_rows_visible_in_template_table) echo ' style="display:none" ';
251     echo ">";
252     if($l != 1) {
253     echo '<td>';
254     if(in_array($pdb,$temps)) {
255     $key = array_search($pdb, $temps);
256     unset($temps[$key]);
257     echo '<img src="images/tick.png" alt="yes" />';
258     }
259     echo '</td>';
260     } else {
261     echo '<th></th>';
262     }
263     for($i = 0; $i < count($fields); $i++){
264     if($i < 5 || $i > 6) { # skip GTG fields
265     if($l == 1) {
266     echo "<th>";
267     $field = $fields[$i];
268     if(strpos($field, "scop id") !== false) $field = "scop";
269     if(strpos($field, "title") !== false) $field = "description";
270     echo $field;
271     echo "</th>";
272     } else {
273     echo "<td>";
274     $field = trim($fields[$i]);
275     if($i == 0) $field = '<a href="http://pdbwiki.org/index.php/'.substr($pdb,0,4).'">'.$field.'</a>';
276     if($i == 7) $field = '<a href="http://scop.mrc-lmb.cam.ac.uk/scop/search.cgi?sccs='.$field.'">'.$field.'</a>';
277     echo $field;
278     echo "</td>";
279     }
280     }
281     }
282     echo "</tr>\n";
283     }
284     }
285     # link to wait for results page
286     } else {
287    
288     # do template selection
289    
290     if(sizeof($lines) <= 2) {
291     echo 'No templates found!<br/><br/>';
292     //echo '<tr><td>Enter a template to use: <input type="text" name="temp1"> e.g. 1tdrA</td></tr>';
293     $no_temps = 1;
294     } else {
295    
296     for($l = 1; $l < count($lines); $l++) {
297     $line = $lines[$l];
298     $fields = explode("\t", $line);
299     $pdb = $fields[0];
300     echo "<tr";
301     if($l-1 > $num_rows_visible_in_template_table) echo ' style="display:none" ';
302     echo ">";
303     if($l != 1) {
304     echo '<td><INPUT type="checkbox" name="temp'.$l.'" value="'.$pdb.'"></td>';
305     } else {
306     echo '<th></th>';
307     }
308     for($i = 0; $i < count($fields); $i++){
309     if($i < 5 || $i > 6) { # skip GTG fields
310     if($l == 1) {
311     echo "<th>";
312     $field = $fields[$i];
313     if(strpos($field, "scop id") !== false) $field = "scop";
314     if(strpos($field, "title") !== false) $field = "description";
315     echo $field;
316     echo "</th>";
317     } else {
318     echo "<td>";
319     $field = trim($fields[$i]);
320     if($i == 0) $field = '<a href="http://pdbwiki.org/index.php/'.substr($pdb,0,4).'">'.$field.'</a>';
321     if($i == 7) $field = '<a href="http://scop.mrc-lmb.cam.ac.uk/scop/search.cgi?sccs='.$field.'">'.$field.'</a>';
322     echo $field;
323     echo "</td>";
324     }
325     }
326     }
327     echo "</tr>\n";
328     }
329     }
330    
331     }
332     ?>
333     </tbody>
334     </table><?
335     if(!isset($no_temps)) {
336     echo '<a href="Javascript:toggle_table();"><img id="btn_table" title="show/hide more templates" src="images/control_blue_down.png" border="0"/></a>';
337     echo '<div style="clear:both;"></div>';
338     }
339     ?>
340     <?php if(!file_exists(get_template_file($job_name))) {
341     # input user templates
342     echo '<table class="template_table"><tbody><tr><td>';
343     echo 'Additional templates to use: <input type="text" name="custom_templates"> e.g. 1tdrA, 7dfrA<br/>';
344     echo '</td></tr></tbody></table>';
345    
346     # error messages
347     if(isset($form_errors['invalid_custom_template'])) {
348     echo '<span class="error_msg">Invalid template string. Please enter a comma separated list of pdb codes including chain identifier, e.g. 1tdrA </span><br/>';
349     }
350     if(isset($form_errors['no_templates'])) {
351     echo '<span class="error_msg">Please specify at least one template</span><br/>';
352     }
353    
354     # submit button
355     echo '<p><input type="submit" value="Start prediction"></p>';
356     } else {
357     # output user templates
358     echo '<table class="template_table"><tbody><tr><td>';
359     echo 'Additional templates used: ';
360     if(isset($temps) && count($temps) > 0) {
361     foreach($temps as $temp) {
362     echo "$temp ";
363     }
364     } else {
365     echo 'none';
366     }
367     echo '<br/>';
368     echo '</td></tr></tbody></table><br/>';
369    
370     echo 'Modeling job has been previously submitted with the templates marked above.';
371     echo '<div class="buttons">';
372     echo '<a href="wait_for_modeling_result.php?job_name='.$job_name.'"><img src="images/eye.png" alt="" /> Check results</a>';
373     }
374     ?>
375     </form>
376     <p>
377     <div class="buttons">
378     <a href="index.php"><img src="images/new.png" alt="" /> Start new job</a>
379     </div>
380     <div style="clear:both;"></div>
381     </div>
382     </body>
383     </html>