File: OPSIN.pm

package info (click to toggle)
smiles-scripts 0.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,296 kB
  • sloc: perl: 2,333; java: 1,231; sh: 1,154; makefile: 253
file content (43 lines) | stat: -rw-r--r-- 768 bytes parent folder | download | duplicates (2)
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
package SmilesScripts::OPSIN;

use strict;
use warnings;

use IPC::Open3;
use Symbol 'gensym';

sub new
{
    my( $class ) = @_;

    my $CHLD_ERR = gensym;
    my $pid = open3( my $CHLD_IN, my $CHLD_OUT, $CHLD_ERR, 'java -jar /usr/share/java/opsin.jar' );

    return bless { pid => $pid, stdin => $CHLD_IN, stdout => $CHLD_OUT }, $class;
}

sub IUPAC_to_SMILES
{
    my( $self, $IUPAC ) = @_;

    my $stdin = $self->{stdin};
    my $stdout = $self->{stdout};

    $IUPAC .= "\n" unless $IUPAC =~ /\n$/;

    local $\ = undef;
    print $stdin $IUPAC;
    my $SMILES = <$stdout>;
    $SMILES =~ s/\n$//;
    return $SMILES ? $SMILES : undef;
}

sub DESTROY
{
    my( $self ) = @_;
    my $stdin = $self->{stdin};
    close $stdin;
    waitpid $self->{pid}, 0;
}

1;