1 |
<?php |
2 |
include_once("inc/settings.php"); |
3 |
session_start(); |
4 |
|
5 |
function create_output_dir($job_name) { |
6 |
$j = escapeshellcmd($job_name); |
7 |
$output_dir = get_output_dir($job_name); |
8 |
$cmd = "mkdir ".$output_dir; |
9 |
exec($cmd); |
10 |
} |
11 |
|
12 |
# writes two files |
13 |
# 1: $job_name.fa - subsequence of $sequence from $seq_from to $seq_to |
14 |
# 2: $job_name.full.fa - full $sequence with above subsequence in upper and rest in lower case |
15 |
# fasta header of 1 is the job name |
16 |
# fasta header of 2 is the subsequence index in a format like: >123-456 |
17 |
# assumes that $sequence contains only amino acid characters and $seq_from and $seq_to are valid indices counting from 1 |
18 |
function create_seq_files($job_name, $fullseq, $subseq, $seq_from, $seq_to) { |
19 |
$seq_file = get_seq_file($job_name); |
20 |
$full_seq_file = get_full_seq_file($job_name); |
21 |
|
22 |
// write subsequence |
23 |
$fh = fopen($seq_file, 'w') or die("can't open file ".$seq_file); |
24 |
fwrite($fh, ">".$job_name."\n"); |
25 |
fwrite($fh, $subseq."\n"); |
26 |
fclose($fh); |
27 |
|
28 |
// write full sequence |
29 |
$fh = fopen($full_seq_file, 'w') or die("can't open file ".$full_seq_file); |
30 |
fwrite($fh, ">".$seq_from.'-'.$seq_to."\n"); |
31 |
fwrite($fh, $fullseq."\n"); |
32 |
fclose($fh); |
33 |
} |
34 |
|
35 |
function get_seq_file($job_name) { |
36 |
$j = escapeshellcmd($job_name); |
37 |
return $GLOBALS['server_root']."results/".$j."/".$j.".fa"; |
38 |
} |
39 |
|
40 |
function get_full_seq_file($job_name) { |
41 |
$j = escapeshellcmd($job_name); |
42 |
return $GLOBALS['server_root']."results/".$j."/".$j.".full.fa"; |
43 |
} |
44 |
|
45 |
function get_error_log_url($job_name) { |
46 |
$j = escapeshellcmd($job_name); |
47 |
return "results/".$j."/".$j.".err.log"; |
48 |
} |
49 |
|
50 |
function get_error_log($job_name) { |
51 |
$j = escapeshellcmd($job_name); |
52 |
return $GLOBALS['server_root']."results/".$j."/".$j.".err.log"; |
53 |
} |
54 |
|
55 |
function get_out_log($job_name) { |
56 |
$j = escapeshellcmd($job_name); |
57 |
return $GLOBALS['server_root']."results/".$j."/".$j.".out.log"; |
58 |
} |
59 |
|
60 |
function get_ts_job_name($job_name) { |
61 |
return 'TS-'.$job_name; |
62 |
} |
63 |
|
64 |
function get_ts_lock_file($job_name) { |
65 |
return get_result_file($job_name, ".TS.lock"); |
66 |
} |
67 |
|
68 |
// writes a lock file indicating that template selection was started |
69 |
function write_ts_lock_file($job_name) { |
70 |
touch(get_ts_lock_file($job_name)); |
71 |
} |
72 |
|
73 |
function run_template_selection($job_name) { |
74 |
global $use_parallel_blast; |
75 |
global $num_blast_cpus; |
76 |
global $num_templates_in_report_file; |
77 |
global $eval_cutoff_template_selection; |
78 |
global $num_psiblast_iterations; |
79 |
write_ts_lock_file($job_name); |
80 |
$output_dir = get_output_dir($job_name); |
81 |
$seq_file = get_seq_file($job_name); |
82 |
$error_log = get_error_log($job_name); |
83 |
$output_log = get_out_log($job_name); |
84 |
|
85 |
$n = $num_blast_cpus; |
86 |
if($use_parallel_blast) { |
87 |
# multi threaded blast search (default: 8 cpus) |
88 |
$cmd = "qsub -pe threaded $n -V -N ".get_ts_job_name($job_name)." -e ".get_error_log($job_name)." -o ".get_out_log($job_name)." -q all.q /project/StruPPi/CASP8/scripts/templateSelection -i $seq_file -a $n -o $output_dir -j $num_psiblast_iterations -e $eval_cutoff_template_selection -x $num_templates_in_report_file"; |
89 |
} else { |
90 |
# single threaded blast search |
91 |
$cmd = "qsub -V -N $job_name -e ".get_output_dir($job_name)." -o ".get_output_dir($job_name)." -q all.q /project/StruPPi/CASP8/scripts/templateSelection -i $seq_file -o $output_dir -j $num_psiblast_iterations -e $eval_cutoff_template_selection -x $num_templates_in_report_file"; |
92 |
} |
93 |
|
94 |
$retval = 0; |
95 |
system($cmd,$retval); |
96 |
echo '<p></p>'; |
97 |
#echo '<p>'.$cmd.'</p>'; |
98 |
return $retval; |
99 |
} |
100 |
|
101 |
if(!isset($_SESSION['job_name']) || !isset($_SESSION['sequence'])) { |
102 |
header("Location: templates.php"); |
103 |
} else { |
104 |
$job_name = $_SESSION['job_name']; |
105 |
$sequence = $_SESSION['sequence']; // full sequence in upper case |
106 |
$seq_from = 1; |
107 |
$seq_to = strlen($sequence); |
108 |
if(array_key_exists('seqfrom',$_SESSION)) $seq_from = $_SESSION['seqfrom']; |
109 |
if(array_key_exists('seqto',$_SESSION)) $seq_to = $_SESSION['seqto']; |
110 |
|
111 |
$subseq = substr($sequence, $seq_from - 1, $seq_to-$seq_from + 1); |
112 |
$fullseq = strtolower(substr($sequence,0,$seq_from-1)).strtoupper($subseq).strtolower(substr($sequence,$seq_to)); |
113 |
} |
114 |
?> |
115 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
116 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
117 |
|
118 |
<head> |
119 |
<title>Structure prediction server</title> |
120 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
121 |
<link rel="stylesheet" type="text/css" href="css/default.css" /> |
122 |
</head> |
123 |
<body> |
124 |
<?php include_once("inc/owl_header.inc.php") ?> |
125 |
<h3>Template search</h3> |
126 |
<?php |
127 |
|
128 |
echo "<p><b>Job name:</b> ".$job_name."</p>"; |
129 |
|
130 |
echo '<p><b>Target sequence: </b>'.$subseq.'</p>'; |
131 |
|
132 |
echo '<p><b>Position in full sequence: </b>'.$seq_from.'-'.$seq_to.'</p>'; |
133 |
|
134 |
// create output dir |
135 |
create_output_dir($job_name); |
136 |
|
137 |
// write sequence to output dir |
138 |
create_seq_files($job_name, $fullseq, $subseq, $seq_from, $seq_to); |
139 |
|
140 |
if(file_exists(get_ts_lock_file($job_name))) { |
141 |
echo '<p>Job already submitted.</p>'; |
142 |
} else { |
143 |
// run templateSelection with output dir and sequence file |
144 |
$result = run_template_selection($job_name); |
145 |
if( $result != 0) { |
146 |
echo '<p><font color="red">An error occured </font>(exit status='.$result.'). See the <a href="'.get_error_log_url($job_name).'">error log</a>.</p>'; |
147 |
} |
148 |
} |
149 |
?> |
150 |
|
151 |
<div class="buttons"> |
152 |
<a href="wait_for_templates.php?job_name=<? echo $job_name; ?>"><img src="images/eye.png" alt="" /> Check results</a> |
153 |
</div> |
154 |
|
155 |
</body> |
156 |
</html> |