#!/bin/perl ##################################################################### # Global Constants ##################################################################### require "flush.pl"; # setup minimal Daylight environment $ENV{DY_ROOT} = "/daylight/v451mug"; $ENV{DY_LICENSEDATA} = "/daylight/v451mug/dy_license.dat"; $StartupDir = `pwd`; chop $StartupDir; $BinDir = "$StartupDir/bin"; $TPLDir = "$StartupDir/tpl"; $TmpDir = "$StartupDir/tmp/$$"; $TmpFile = "$TmpDir/Temp"; # Cleanup old temporary files `find $StartupDir/tmp -mtime +1 -type d -print | xargs -l1 rm -rf`; require "$BinDir/password.pl"; &ReadParse(); $ENV{PATH} = $ENV{PATH} . ":$BinDir"; umask 0000; mkdir($TmpDir,0777); chdir($TmpDir); $SIG{'HUP'} = 'CleanUp'; $SIG{'INT'} = 'CleanUp'; $SIG{'QUIT'} = 'CleanUp'; $SIG{'ABRT'} = 'CleanUp'; $SIG{'KILL'} = 'CleanUp'; $SIG{'BUS'} = 'CleanUp'; $SIG{'SEGV'} = 'CleanUp'; $SIG{'PIPE'} = 'CleanUp'; $SIG{'ALRM'} = 'CleanUp'; $SIG{'TERM'} = 'CleanUp'; #----------------------------------------------------------------- # Main Program #----------------------------------------------------------------- $path = $ENV{'PATH_INFO'}; $smiles = $in{'SMILES'}; $sim_limit = 50; if ($in{'sim_limit'} >= 0) { $sim_limit = $in{'sim_limit'}; } $smiles =~ s/\s//g; # Now, we create the actual results frame document. open(RESULTS, ">$TmpFile.results.html"); print RESULTS <<"end_tag"; Poor Man's Synthesis Planning - Search Results end_tag if ($smiles eq "") { print RESULTS <<"end_tag"; No SMILES end_tag close (RESULTS); exit; } $proc_id = $$; $result = ""; $lastdb = ""; $regno_links = ""; $regno_form = ""; $ndbs = 0; if ($in{'ccr'} eq "ccr") { $dbs[$ndbs] = 'ccr'; $ndbs++; } if ($in{'chemsynth_demo'} eq "chemsynth_demo") { $dbs[$ndbs] = 'chemsynth_demo'; $ndbs++; } if ($in{'pcb'} eq "pcb") { $dbs[$ndbs] = 'pcb'; $ndbs++; } open(TARGET, ">$TmpFile.target.html"); print TARGET <<"end_tag"; Poor Man's Synthesis Planning - Search Results Sorry! No Query Display! end_tag close(TARGET); $found = 0; $found_any = 0; foreach $db (@dbs) { $xrefdb = $db . "_xref"; $sourcedb = $db; $shared = $in{'shared'}; $command = "$BinDir/pmsp " . "\'$smiles\' " . "challenge $xrefdb pmsp pmsp " . ">$TmpFile.pmsp " . "2>$TmpFile.pmsp.err"; `$command`; open (PMSP_RESULT, "<$TmpFile.pmsp"); while ( ) { chop; if (&WriteTableRow("$sourcedb", $_)) { $found = 1; } } close (PMSP_RESULT); if ($found) { print RESULTS "

Database: $db

\n"; print RESULTS "\n"; &WriteEntries(); print RESULTS "
\n"; $found_any = 1; $found = 0; } } print RESULTS <<"end_tag"; end_tag close (RESULTS); # Here, we create the frame set document. # This document refers to a temporary file that contains # the actual search results. # HTML header print ("Content-type: text/html\n\n"); print <<"end_tag"; Poor Man's Synthesis Planning - Search Results end_tag if ($found_any) { print "\n"; } else { print "\n"; } print <<"end_tag"; end_tag &CleanUp; exit; sub bymerrit { $cmp = (-1)*(length($smi{$a}) <=> length($smi{$b})); if ($cmp == 0) { $cmp = ($smi{$a} <=> $smi{$b}); if ($cmp == 0) { $cmp = $merrit{$a} <=> $merrit{$b}; } } $cmp; } #----------------------------------------------------------------- # WriteEntries #----------------------------------------------------------------- # Writes a form containing the hits as hiddenfields sub WriteEntries { @sorted_rows = sort (bymerrit @table_rows); # print RESULTS "

\n"; print RESULTS @sorted_rows; undef @table_rows; } sub byhitsim { $hit_sim{$a} <=> $hit_sim{$b}; } # Writes a Poor Man's Synthesis Planning row if similarity # of product is high enough. sub WriteTableRow { local($db, $answer) = @_; $hit_found = 0; ($info, $smi, $hits) = split(/\t/, $answer, 3); ($d1, $ncyc, $d1, $nccmake, $d1, $nqcmake, $d1, $nchange) = split(/[=,]/, $info); # Make clear text reaction type info $info = ""; if ($ncyc == 1) { $info .= "Closes 1 ring bond.
"; } elsif ($ncyc > 1) { $info .= "Closes $ncyc ring bonds.
"; } if ($nccmake == 1) { $info .= "Creates 1 carbon-carbon bond.
"; } elsif ($nccmake > 1) { $info .= "Creates $nccmake carbon-carbon bonds.
"; } if ($nqcmake == 1) { $info .= "Creates 1 carbon-hetero atom bond.
"; } elsif ($nqcmake > 1) { $info .= "Creates $nqcmake carbon-hetero atom bonds.
"; } if ($nchange == 1) { $info .= "Changes the bond order of 1 bond.
"; } elsif ($nchange > 1) { $info .= "Changes the bond order of $nchange bonds.
"; } if ($info eq "") { $info = "Removes one or more functional groups.
"; } $hits =~ s/\t/
\n/g; @hits = split(/\s/, $hits); foreach $hit (@hits) { ($id, $sim, $share) = split(/[|%]/, $hit); $hit_sim{$hit} = (-1)*$sim; } @sorted_hits = sort (byhitsim @hits); $regno_links = ""; $i=0; $maxsim = 0; $has_unshared = 0; foreach $hit (@sorted_hits) { ($id, $sim, $share) = split(/[|%][|%]*/, $hit); if ($maxsim < $sim) {$maxsim = $sim} if (($sim > $sim_limit) && ($shared eq "shared" || $share == 1)) { if ($share == 1) {$has_unshared = 1;} $stext = ""; if ($share > 1) { $stext = "s"; } $regno_links .= "" . "$id" . sprintf("%3.0f", $sim) . "% $stext "; $i = $i+1; if ($i >= 3) { $i = 0; $regno_links .= "
\n"; } } } if (($maxsim > $sim_limit) && ($shared eq "shared" || ($has_unshared > 0))) { $hit_found = 1; # print "\n"; # print "\n\n"; # print "\n"; $this_row = "\n"; $this_row .= "\n"; $this_row .= "\n"; $this_row .= "\n"; $this_row .= "\n"; @table_rows = (@table_rows, $this_row); $smi{$this_row} = $smi; $merrit{$this_row} = sprintf("-%02.0f", $maxsim); } $hit_found; } #----------------------------------------------------------------- # CleanUp #----------------------------------------------------------------- # clean up everything: unlock the pipes, remove the tempfiles, exit sub CleanUp { exit; unlink <$TmpDir/*>; system "rm -rf $TmpDir"; exit; }
$info$regno_links
" . #"" . #"\n" . " $smi " . #"" . "$info" . "$regno_links