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
|
#!/igs/local/bin/perl
#Perl Wrapper for the html version of T-Coffee
#Environement variables
$USER_BIN="$HOME/bin/";
#MAIN VARIABLES:
use Env qw(HOME);
if ( $HOME eq ""){$HOME=`pwd`;chop ($HOME);$HOME=~s/public_html.*//;}
$USER_BIN="$HOME/bin/";
$WWW_HOME="http://igs-server.cnrs-mrs.fr/~cnotred/";
$WWW_FILE_HOME="$HOME/public_html/";
$USER_BIN="$HOME/bin/";
$html_page="/t_coffee.html";
$programme="t_coffee";
$SCRATCH_AREA="$WWW_FILE_HOME/tmp/";
$CALLING_PAGE ="$WWW_HOME/$html_page";
#Set the programme so that it uses the right bin
#[CUSTOMIZE HERE FOR YOUR ARCHITECTURE]
$machine=`/bin/uname -s`;
chop ($machine);
$ENV{MAC}=$machine;
use Env qw(MAC);
if ($MAC eq "IRIX64" || $MAC eq "SGI64" || $MAC eq "SGI" || $MAC eq "IRIX")
{$ENV{OS}="Irix";}
elsif ($MAC eq "SunOS" || $MAC eq "SUN")
{$ENV{OS}="Sun";}
elsif ($MAC eq "Linux")
{$ENV{OS}="Linux";}
else
{
&output_error_page ( "The machine $MAC on which this program should run is unknown[FATAL]\n");
}
use Env qw(OS);
#Define the Programs and various addresses [CUSTOMIZE HERE]
#Your binaries
$ENV{USER_BIN}="$HOME/bin/$OS/";#Your binaries
$ENV{ALN_TAB}="$USER_BIN";
use Env qw(USER_BIN);
use Env qw(PATH);
$ENV{PATH}=".:/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/usr/bin/X11:$USER_BIN"; #The Binary Paths
$programme="$programme";
#check the required programs are installed
$t_coffee_exec=`which t_coffee`;
chop($t_coffee_exec);
if ( !(-e $t_coffee_exec))
{
&output_error_page ( "$programme is not Installed home=[$HOME] [$t_coffee_exec] Path=[$PATH][FATAL]\n", $CALLING_PAGE);
die;
}
if ($ENV{'REQUEST_METHOD'} eq "GET")
{
$request=$ENV {'QUERRY_STRING'};
@parameter_list=split(/&/,$request);
foreach (@parameter_list)
{
($name, $value)=split (/=/);
if (!$arg{$name}{number}) {$arg{$name}{number}=0;}
$arg{$name}{$arg{$name}{number}}=$value;
$arg{$name}{number}++;
}
$request=$ENV{'QUERRY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
{
read(STDIN, $request, $ENV{'CONTENT_LENGTH'}) || output_error_page( "Could not read querry\n", $CALLING_PAGE);
@parameter_list=split (/-{2,}\d+.*\n/, $request);
foreach $val (@parameter_list)
{
$val=~s/(Content.*)\n.*\n//g;
$param_line=$1;
if ($param_line=~/filename/)
{
$param_line=~/.*name="(.*)"; filename="(.*)".*/;
$param_name="$1";
if ($2 ne "" && $2 ne "no_value")
{
if (($file=&make_random_file($val)) ne "no_file")
{
$arg{$param_name}{$arg{$param_name}{number}++}=$file;
if ( $param_name eq "-in"){$sequence_in=1;}
}
}
}
else
{
$param_line=~/.*name="(.*)".*/;
$param_name="$1";
if ($param_name eq "data")
{
if (($file=&make_random_file($val)) ne "no_file")
{
$arg{"-in"}{$arg{"-in"}{number}++}=$file;
$sequence_in=1;
}
}
elsif ($param_name=~/\B-[^-]*/)
{
$val=~s/\s//g;
if ( !$arg{flag}{$param_name}){$arg{flag}{$param_name}=1;$flag_list[$nflags++]=$param_name;}
if ( $val ne "" && $val ne "no_value")
{
$arg{$param_name}{$arg{$param_name}{number}++}=$val;
}
}
else
{
$val=~s/\s//g;
$arg{$param_name}{0}=$val;
}
}
}
}
#1 CHECK FOR COMPULSORY PARAMETERS
if ( $sequence_in!=1)
{
&output_error_page ( "You did not provide any Data", $CALLING_PAGE);
die;
}
if ( !$arg{'e-mail'}{0})
{
&output_error_page ( "You did not provide your Email", $CALLING_PAGE);
die;
}
#2 Set The Run Name
$flag_list[$nflags++]="-run_name";
$arg{-run_name}{number}=1;
$arg{-run_name}{0}=&make_random_file_name;
$run_name=$arg{-run_name}{0};
#2 PROCESS THE PARAMETER LIST
$command="#!\/bin\/sh\/n";
$command=$command."source $HOME/.cshrc\n";
$command=$command.$programme;
foreach $flag (@flag_list)
{
$command="$command $flag=";
for ( $a=0; $a<$arg{$flag}{number};$a++)
{$command="$command $arg{$flag}{$a}";}
}
#3 list of the output files
$output_file{++$n_output_file}{name}="$run_name"."_result.html";
$output_file{ $n_output_file}{description}="Results";
$output_file{ $n_output_file}{format}="html";
$output_file{++$n_output_file}{name}="$run_name.tc_log";
$output_file{ $n_output_file}{description}="log of t_coffee";
$output_file{ $n_output_file}{format}="ascii";
for ( $a=0; $a< $arg{'-output'}{number}; $a++)
{
if ($arg{'-output'}{$a} eq "clustalw"){$extention="aln";}
else {$extention=$arg{'-output'}{$a}};
$output_file{++$n_output_file}{name}="$run_name.$extention";
$output_file{ $n_output_file}{description}="Multiple Alignment";
$output_file{ $n_output_file}{format}="$extention";
}
$output_file{++$n_output_file}{name}="$run_name.dnd";
$output_file{ $n_output_file}{description}="Dendrogram used for Progressive Alignment";
$output_file{ $n_output_file}{format}="Phyllip";
$output_file{n_output_file}=$n_output_file;
$output_file{command}=$command;
&submit ("$command -out_lib=no -quiet stderr >$run_name.tc_log 2>$run_name.tc_log" );
%output_file=&make_output (%output_file);
#Make the Output
print "Content-type: text/html\n\n";
print "<html><body bgcolor=#FFFFFF><table bgcolor=#FFFFFF border=8 cellpadding=8 align=center width=60%>";
print "<tr><td><h4>The computation is now finished. Click <a href=$output_file{1}{url}>[HERE]</a>to see the results<\/h4><\/td><\/tr><\/table><\/body><\/html>";
#Clean
for ( $a=0; $a<$n_tmp_files; $a++ )
{
unlink ($tmp_files[$a]);
}
sub submit
{
my $command=@_[0];
system $command;
}
sub make_random_file
{
my $content=@_[0];
my $name;
my $cnt;
if (($content=~/\S/g)==0)
{
return "no_file";
}
$rand_number=int(rand 100000)+1 ;
$name= &make_random_file_name();
$name="$name.tcoffee_file";
$tmp_files[$n_tmp_files++]=$name;
open NEW_FILE,">$name";
print NEW_FILE "$content";
close (NEW_FILE);
$cnt=chmod 0777, $name;
return $name;
}
sub make_random_file_name
{
my $name;
my $rand_number;
$rand_number=int(rand 100000)+1 ;
$name="$SCRATCH_AREA/$rand_number"."$$";
return $name;
}
sub output_error_page
{
my $myerror=@_[0];
my $back=@_[1];
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<H1><pre> ERROR </pre></H1>\n";
print "<H3><pre>$myerror\n\n</pre></H3>\n";
print "<a href=$back>BACK</a></pre>\n";
print "</head>\n";
print "</html>\n";
exit;
}
sub make_output
{
my %loc_output=@_;
my $n;
$n=$loc_output{'n_output_file'};
for ($a=0; $a<=$n; $a++)
{
if ($loc_output{$a}{name}=~/score_html/)
{
$new_name=$loc_output{$a}{name};
$new_name=~s/score_html/html/;
open (IN, $loc_output{$a}{name});
open (OUT, ">$new_name");
while(<IN>){print OUT "$_";}
close (IN);
close (OUT);
unlink ( $loc_output{$a}{name});
$loc_output{$a}{name}=$new_name;
}
chmod 0777, $loc_output{$a}{name};
$loc_output{$a}{url}=$loc_output{$a}{name};
$loc_output{$a}{url}=~s/$WWW_FILE_HOME/$WWW_HOME/;
}
open (RESULT, ">$loc_output{1}{name}");
print RESULT "<html><body bgcolor=#FFFFFF><table bgcolor=#FFFFFF border=8 cellpadding=8 align=center width=60%>";
print RESULT "<tr><td align=center><h1>Ouput of T-Coffee<\/td><\/tr><\/table>";
print RESULT "<H4> Your data will remain available on this server over the next 3 days. It will then be deleted. Do not forget to bookmark this <a href=$loc_output{1}{url}>URL</a>($loc_output{1}{url}) or save it for further reference </h4>";
print RESULT "<table bgcolor=#FFFFFF border=8 cellpadding=8 align=center width=80%>";
print RESULT "<tr align=center><td><h1>Type<\/h1><\/td><td><h1>Format<\/h1><\/td><td><h1>Status<\/h1><\/td><\/tr>";
for ($a=0; $a<=$n; $a++)
{
if ( -e $loc_output{$a}{name})
{print RESULT "<tr><td><h4><A href=$loc_output{$a}{url}>$loc_output{$a}{description}<\/a><\/td><td>$loc_output{$a}{format}<\/td><td><font color=green> PRODUCED</font><\/tr>";}
elsif ($loc_output{$a}{name})
{print RESULT "<tr><td><h4>$loc_output{$a}{description}<\/td><td>$loc_output{$a}{format}<\/td><td><font color=red>NOT PRODUCED</font><\/tr>";}
}
print RESULT "</table>";
print RESULT "<H1><a href=$CALLING_PAGE>BACK<\/a><\/H1>";
print RESULT "</body>";
print RESULT "</html>";
close RESULT;
chmod 0777, $loc_output{1}{name};
return %loc_output;
}
sub output_file
{
my $file_type =@_[0];
my $file_www_ref =@_[1];
my $file_format =@_[2];
print "<pre>\t<a href=$file_www_ref>$file_type<\/a><\/pre>\n";
return;
}
sub html_output
{
if (!$header)
{
print "Content-type: text/html\n\n<html>\n<head><H1>T-COFFEE RESULTS</H1></head>";
$header=1;
}
print "@_[0]\n";
}
|