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
|
#!/usr/bin/perl -T
use strict;
use warnings;
use lib 'lib/perl5';
use CGI qw(:standard -nosticky -utf8);
use Chemistry::OpenSMILES::Parser;
use File::Basename qw( dirname );
use IPC::Run qw( run );
use URL::Encode qw( url_params_mixed );
my $params = url_params_mixed( $ENV{QUERY_STRING} );
my $SMILES;
eval {
die 'SMILES string not supplied via \'smiles\' query string parameter' if !$params->{smiles};
$SMILES = $params->{smiles};
$SMILES = $SMILES->[0] if ref $SMILES eq 'ARRAY';
my $parser = Chemistry::OpenSMILES::Parser->new;
$parser->parse( $SMILES );
};
if( $@ ) {
print header( -type => 'text/html',
-charset => 'utf-8',
-status => 400 ),
start_html,
$@,
end_html,
"\n";
exit;
}
$ENV{PATH} = '/usr/local/bin:/usr/bin:/bin';
my $bindir = dirname( dirname __FILE__ ) . '/bin';
if( $bindir ne '/usr/lib/bin' && $bindir ne '/usr/local/lib/bin' ) {
$ENV{PATH} = $bindir . ':' . $ENV{PATH};
}
my( $STDIN, $STDOUT, $STDERR );
run [ 'cdkdepict' ], \$SMILES, \$STDOUT, \$STDERR;
if( $STDERR ) {
print header( -type => 'text/html',
-charset => 'utf-8',
-status => 400 ),
start_html,
$STDERR,
end_html,
"\n";
} else {
print header( -type => 'image/svg+xml',
-charset => 'utf-8' ),
$STDOUT;
}
|