Submit a new job
Job result:
$result_dir="/home/thesards/allali/W3/migal/results/";
function rl_path($path){
return str_replace("/home/thesards/allali/W3/migal/","",$path);
}
// Check if job is not already computed...
if (isset($HTTP_GET_VARS['id']))
$job_id=$HTTP_GET_VARS['id'];
else {
// Generate an id:
do {
$job_id=md5(uniqid(""));
$f=fopen("./results/".$job_id.".tmp","x");
}
while($f==FALSE);
touch("./results/".$job_id.".tmp");
fclose($f);
}
// Check if job_id is valid:
ctype_xdigit($job_id) or die("error: 'id' get variable invalid");
// Job Associated files
$job_files= array("state"=> $result_dir.$job_id,
"tmp"=>$result_dir.$job_id.".tmp",
"password" => $result_dir."/pwd/".$job_id,
"output"=>$result_dir.$job_id.".out",
"align"=>$result_dir.$job_id.".align",
"error"=>$result_dir.$job_id.".err",
"rna1"=>$result_dir.$job_id.".rna1",
"rna2"=>$result_dir.$job_id.".rna2",
"ps1"=>$result_dir.$job_id."_ps1.ps",
"ps2"=>$result_dir.$job_id."_ps2.ps",
"img1"=>$result_dir.$job_id."_ps1.jpg",
"img2"=>$result_dir.$job_id."_ps2.jpg",
"ps1_colored_0"=>$result_dir.$job_id."_ps1_migal_0.ps",
"ps2_colored_0"=>$result_dir.$job_id."_ps2_migal_0.ps",
"img1_0"=>$result_dir.$job_id."_img1_0.jpg",
"img2_0"=>$result_dir.$job_id."_img2_0.jpg",
"ps1_colored_1"=>$result_dir.$job_id."_ps1_migal_1.ps",
"ps2_colored_1"=>$result_dir.$job_id."_ps2_migal_1.ps",
"img1_1"=>$result_dir.$job_id."_img1_1.jpg",
"img2_1"=>$result_dir.$job_id."_img2_1.jpg",
"ps1_colored_2"=>$result_dir.$job_id."_ps1_migal_2.ps",
"ps2_colored_2"=>$result_dir.$job_id."_ps2_migal_2.ps",
"img1_2"=>$result_dir.$job_id."_img1_2.jpg",
"img2_2"=>$result_dir.$job_id."_img2_2.jpg",
"ps1_colored_3"=>$result_dir.$job_id."_ps1_migal_3.ps",
"ps2_colored_3"=>$result_dir.$job_id."_ps2_migal_3.ps",
"img1_3"=>$result_dir.$job_id."_img1_3.jpg",
"img2_3"=>$result_dir.$job_id."_img2_3.jpg",
"swf"=>$result_dir.$job_id."_swf.jpg",
"swf0"=>$result_dir.$job_id."_swf0.jpg",
"swf1"=>$result_dir.$job_id."_swf1.jpg",
"swf2"=>$result_dir.$job_id."_swf2.jpg",
"swf3"=>$result_dir.$job_id."_swf3.jpg"
);
$BIN_DIR="/home/thesards/allali/W3/migal/bin/";
// Check if job is already finished
if (file_exists($job_files["state"])==False){
$stats=fopen("./results/pwd/stats","a");
fwrite($stats,"\n----\njob:".$job_id."\n".date("D M j G:i:s T Y")."\n".$_SERVER["REMOTE_ADDR"]);
fclose($stats);
$migal_command=$BIN_DIR."migal -M --all-ps --filter-ps --auto-psdk ".$job_files["rna1"]." ".$job_files["rna2"]." ";
ignore_user_abort(TRUE); // Continue to run script if user close page...
// Check POST VARIABLES
// print_r($_POST);
foreach(array("rna1_data","rna1_type","rna2_data","rna2_type","indelonce","hairpinstrict","align","tuning","password","mail","forester") as $vname){
isset($_POST[$vname]) or die("error: missing post var or job not finished");
}
//print_r($_FILES);
foreach(array("rna1_ps","rna1_file","rna2_ps","rna2_file") as $fname){
isset($_FILES[$fname]) or die("error: missing post var");
if ($_FILES[$fname]["error"]==0)
if (is_uploaded_file($_FILES[$fname]["tmp_name"])==False)
die("error: hacking attempted");
}
if (!function_exists("file_put_contents")){
function file_put_contents($filename,$str){
$h=fopen($filename,"w");
if ($h==FALSE) return FALSE;
if (fwrite($h,$str)==FALSE) return FALSE;
if (fclose($h)==FALSE) return FALSE;
return TRUE;
}
}
// Move DATA:
foreach(array(array("file"=>"rna1_file","dest"=>$job_files["rna1"],"field"=>"rna1_data"),array("file"=>"rna2_file","dest"=>$job_files["rna2"],"field"=>"rna2_data")) as $rna){
switch($_FILES[$rna["file"] ]["error"]){
case 0:
move_uploaded_file($_FILES[$rna["file"] ]["tmp_name"],$rna["dest"])
or die("error while moving rna data file");
break;
case 4:
file_put_contents($rna["dest"],$_POST[$rna["field"] ]);
break;
default:
die("error in rna file transfert");
break;
}
}
// First RNA Data Type:
in_array($_POST["rna1_type"],array("ct","bpseq","parenthesis","xml")) or die("invalid value for type parameter");
$migal_command=$migal_command." --type1 ".$_POST["rna1_type"];
// Second RNA Data Type:
in_array($_POST["rna2_type"],array("ct","bpseq","parenthesis","xml")) or die("invalid value for type parameter");
$migal_command=$migal_command." --type2 ".$_POST["rna2_type"];
// Check input file format...
$output=array();
exec($BIN_DIR."rnaconverter -a -f ".$_POST["rna1_type"]." ".$job_files["rna1"],$output,$rt_value);
if ($rt_value!=0)
die("Invalid format for the first RNA, you must supply a valid secondary structure:
Error message is:
".implode("
",$output));
$output=array();
exec($BIN_DIR."rnaconverter -a -f ".$_POST["rna2_type"]." ".$job_files["rna2"],$output,$rt_value);
if ($rt_value!=0)
die("Invalid format for the second RNA, you must supply a valid secondary structure:
Error message is:
".implode("
",$output));
// First RNA PS:
$generate=true;
if ($_FILES["rna1_ps"]["error"]==0){
move_uploaded_file($_FILES["rna1_ps"]["tmp_name"],$job_files["ps1"]);
$migal_command=$migal_command." --ps1 ".$job_files["ps1"];
// Check first PS format:
$output=array();
exec($BIN_DIR."check_ps ".$job_files["ps1"],$output,$rt_value);
if ($rt_value!=0){
echo "Invalid format for the first Postscript, only few ps format are supported:
Error message is:
".implode("
",$output);
echo "
A postscript is generated using RNAplot";
$generate=true;
}
else
$generate=false;
}
elseif ($_FILES["rna1_ps"]["error"]!=4)
die("error in first rna postscript file transfert");
if ($generate){
// No PS file supplied, build one with RNAplot
$tmp_dir='/tmp/'.$job_id;
$command='mkdir '.$tmp_dir.' ; cd '.$tmp_dir.' ; '.$BIN_DIR.'rnaconverter -a -f '.$_POST["rna1_type"].' -d '.$job_files["rna1"].' -o toto ; grep -v "^>" toto | '.$BIN_DIR.'RNAplot --post " " -o ps ; mv rna.ps '.$job_files["ps1"].' ; rm -rf '.$tmp_dir ;
exec($command,$output,$returnValue);
$migal_command=$migal_command." --ps1 ".$job_files["ps1"];
}
// Second RNA PS:
$generate=true;
if ($_FILES["rna2_ps"]["error"]==0){
move_uploaded_file($_FILES["rna2_ps"]["tmp_name"],$job_files["ps2"]);
$migal_command=$migal_command." --ps2 ".$job_files["ps2"];
// Check ps format
$output=array();
exec($BIN_DIR."check_ps ".$job_files["ps2"],$output,$rt_value);
if ($rt_value!=0){
echo "Invalid format for the second Postscript, only few ps format are supported:
Error message is:
".implode("
",$output);
echo "
A postscript is generated using RNAplot";
$generate=true;
}
else
$generate=false;
}
elseif ($_FILES["rna2_ps"]["error"]!=4)
die("error in second rna postscript file transfert");
if ($generate){
// No PS file supplied, build one with RNAplot
$tmp_dir='/tmp/'.$job_id;
$command='mkdir '.$tmp_dir.' ; cd '.$tmp_dir.' ; '.$BIN_DIR.'rnaconverter -a -f '.$_POST["rna2_type"].' -d '.$job_files["rna2"].' -o toto ; grep -v "^>" toto | '.$BIN_DIR.'RNAplot --post " " -o ps ; mv rna.ps '.$job_files["ps2"].' ; rm -rf '.$tmp_dir ;
exec($command,$output,$returnValue);
$migal_command=$migal_command." --ps2 ".$job_files["ps2"];
}
// Tuning Parameter:
in_array($_POST["tuning"],array(0.005,0.01,0.015)) or die("invalid value for tuning parameter");
$migal_command=$migal_command." -t ".$_POST["tuning"];
// Indel Once:
in_array($_POST["indelonce"],array("yes","no")) or die("invalid value for indel-once parameter");
if ($_POST["indelonce"]=="yes")
$migal_command=$migal_command." --indel-once ";
// Hairpin Strict
in_array($_POST["hairpinstrict"],array("yes","no")) or die("invalid value for hairpin strict parameter");
if ($_POST["hairpinstrict"]=="yes")
$migal_command=$migal_command." --hairpin-strict ";
// Hairpin Strict
in_array($_POST["forester"],array("yes","no")) or die("invalid value for hairpin strict parameter");
if ($_POST["forester"]=="yes")
$migal_command=$migal_command." --forester ";
// Alignment:
in_array($_POST["align"],array("yes","no")) or die("invalid value for align parameter");
if ($_POST["align"]=="yes")
$migal_command=$migal_command." --align ".$job_files["align"]." ";
// Password:
if ($_POST["password"]!="")
file_put_contents($job_files["password"],$_POST["password"]);
// Run MiGaL
// Use pipe to get process output
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to
);
//
$migal_process=proc_open($migal_command,$descriptorspec,$pipes);
($migal_process!=FALSE) or die("migal command failed: \n".$migal_command);
stream_set_blocking($pipes[1],0);
stream_set_blocking($pipes[2],0);
$job_out=fopen($job_files["output"],"w");
$job_err=fopen($job_files["error"],"w");
$url="http://igm.univ-mlv.fr/~allali/migal/result.php?id=".$job_id;
if ($_POST["password"]!="")
$url=$url."&pwd=".$_POST["password"];
?>
Job URL (bookmark for later use):
Job in progress:
$count=0;
while(feof($pipes[2])==False or feof($pipes[1])==False){
flush();
ob_flush();
sleep(1);
echo ".";
$count++;
if ($count==90){
$count=-40;
echo "\n";
}
while(($s=fread($pipes[1],10000))!="")
fwrite($job_out,$s);
while(($s=fread($pipes[2],10000))!="")
fwrite($job_err,$s);
}
// Close open file
fclose($job_out);
fclose($job_err);
fclose($pipes[0]);fclose($pipes[1]);fclose($pipes[2]);
echo "Done.
Converting Poscript files: ...";flush();ob_flush();
// Move colored PS if any
foreach(array(array("source"=>$job_files["ps1"]."_MiGaL.ps","dest"=>$job_files["ps1_colored_3"],"convert"=>$job_files["img1_3"]),
array("source"=>$job_files["ps1"]."_MiGaL_0.ps","dest"=>$job_files["ps1_colored_0"],"convert"=>$job_files["img1_0"]),
array("source"=>$job_files["ps1"]."_MiGaL_1.ps","dest"=>$job_files["ps1_colored_1"],"convert"=>$job_files["img1_1"]),
array("source"=>$job_files["ps1"]."_MiGaL_2.ps","dest"=>$job_files["ps1_colored_2"],"convert"=>$job_files["img1_2"]),
array("source"=>$job_files["ps2"]."_MiGaL.ps","dest"=>$job_files["ps2_colored_3"],"convert"=>$job_files["img2_3"]),
array("source"=>$job_files["ps2"]."_MiGaL_0.ps","dest"=>$job_files["ps2_colored_0"],"convert"=>$job_files["img2_0"]),
array("source"=>$job_files["ps2"]."_MiGaL_1.ps","dest"=>$job_files["ps2_colored_1"],"convert"=>$job_files["img2_1"]),
array("source"=>$job_files["ps2"]."_MiGaL_2.ps","dest"=>$job_files["ps2_colored_2"],"convert"=>$job_files["img2_2"]))
as $data){
if (file_exists($data["source"])){
rename($data["source"],$data["dest"]);
exec('cd results; /usr/bin/convert -geometry 512x768 "'.$data["dest"].'" "'.$data["convert"].'" 2>&1 ;',$output,$returnValue);
exec('gzip '.$data["dest"]);
echo "...";flush();ob_flush();
}
}
// Make the compositions:
echo "...";flush();ob_flush();
exec('cd results; /usr/bin/convert -geometry 512x768 "'.$job_files["ps1"].'" "'.$job_files["img1"].'" 2>&1 ;',$output);
exec('gzip '.$job_files["ps1"]);
echo "...";flush();ob_flush();
exec('cd results; /usr/bin/convert -geometry 512x768 "'.$job_files["ps2"].'" "'.$job_files["img2"].'" 2>&1 ;',$output);
exec('gzip '.$job_files["ps2"]);
echo "...";flush();ob_flush();
exec('cd results; /usr/bin/montage -geometry 512x768 "'.$job_files["img1"].'" "'. $job_files["img2"].'" "'.$job_files["swf"].'" 2>&1 ',$output);
echo "...";flush();ob_flush();
exec('cd results; /usr/bin/montage -geometry 512x768 "'.$job_files["img1_0"].'" "'. $job_files["img2_0"].'" "'.$job_files["swf0"].'" 2>&1 ',$output);
echo "...";flush();ob_flush();
exec('cd results; /usr/bin/montage -geometry 512x768 "'.$job_files["img1_1"].'" "'. $job_files["img2_1"].'" "'.$job_files["swf1"].'" 2>&1 ',$output);
echo "...";flush();ob_flush();
exec('cd results; /usr/bin/montage -geometry 512x768 "'.$job_files["img1_2"].'" "'. $job_files["img2_2"].'" "'.$job_files["swf2"].'" 2>&1 ',$output);
echo "...";flush();ob_flush();
exec('cd results; /usr/bin/montage -geometry 512x768 "'.$job_files["img1_3"].'" "'. $job_files["img2_3"].'" "'.$job_files["swf3"].'" 2>&1 ',$output);
echo "Done
";flush();ob_flush();
// Check exit value:
$return_value=proc_close($migal_process);
if (ctype_space($_POST["mail"])==False){
if (mail($_POST["mail"],"migal job finished",$url,"From: allali@univ-mlv.fr\r\nReply-To:allali@univ-mlv.fr\r\n")==FALSE)
echo "
error while sending mail!
";
}
else if (trim($_POST["mail"])!="")
echo "
mail send to : ".$_POST["mail"]."
";
if ($return_value!=0){
echo "
error in migal, check output and error!
";
file_put_contents($job_files["state"],"return value: \n".$return_value."
error in migal, check output and error!
"."\n command run: \n".$migal_command) or die("error writing job state");
}
else
file_put_contents($job_files["state"],"return value: \n".$return_value."\n command run: \n".$migal_command) or die("error writing job state");
//file_put_contents($job_files["state"],"ok") or die("error writing job state");
?>
}
// Check PASSWORD:
file_exists($job_files["state"]) or die("error: job not finished");
if (file_exists($job_files["password"])){
if (isset($HTTP_GET_VARS["pwd"]))
$pass=$HTTP_GET_VARS["pwd"];
elseif (isset($_POST["password"]))
$pass=$_POST["password"];
else
die("error: job protected by password, please supply it (i.e. result.php?pwd=xxx)");
(file_get_contents($job_files["password"])==$pass) or die("error: password invalid");
}
$url="http://igm.univ-mlv.fr/~allali/migal/result.php?id=".$job_id;
if (isset($pass)) $url=$url."&pwd=".$pass;
?>
Job URL is:
Job return state:
Click on me to show/hide the return value and command ran
$state=file_get_contents($job_files["state"]);
print str_replace("\n","\n
",$state);
?>
Input data:
" alt="first RNA data">first RNA file
" alt="second RNA data">second RNA file
$error=file_get_contents($job_files["error"]);
if (trim($error)!=""){
echo '
MiGaL process error:
';
echo '
';
print str_replace("\n","\n
",$error);
echo '
';
}
?>
MiGaL process output:
click on me to show/hide the output with the comparison SCORES
$output=file_get_contents($job_files["output"]);
print str_replace("\n","\n
",$output);
?>
if (file_exists($job_files["align"])==TRUE){
?>
Alignment:
" alt="Sequences alignment" >
RNA sequence alignment
}
if (file_exists($job_files["ps1_colored_0"].".gz")==TRUE){
?>
Flash Animation
// Get scores from output:
$output=file_get_contents($job_files["output"]);
$scores=array();
for($i=0;$i<=3;$i++){
preg_match('/SCORE LAYER '.$i.' :([0-9.]*)/',$output,$matches);
$scores[$i]=$matches[1];
preg_match("/SCORE LAYER ".$i." NORM:([0-9.]*)/",$output,$matches);
$scores[$i."N"]=$matches[1];
}
echo '
view the animation';
?>
Pictures:
(click on picture to download postscript file)
Level 0:
" alt="img">
" width="200px" alt="img">
" alt="img">
" width="200px" alt="img">
Level 1:
" alt="img">
" width="200px" alt="img">
" alt="img">
" width="200px" alt="img">
Level 2:
" alt="img">
" width="200px" alt="img">
" alt="img">
" width="200px" alt="img">
Level 3:
" alt="img">
" width="200px" alt="img">
" alt="img">
" width="200px" alt="img">
}
exec("chmod o+r results/*");
?>
Please, send your comments to allali@labri.fr