File: smi_isomorphism

package info (click to toggle)
smiles-scripts 0.3.0%2Bsvn878%2Bbranch%2Bsystem%2Bdeps-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,860 kB
  • sloc: perl: 1,889; java: 1,218; sh: 1,092; makefile: 246
file content (68 lines) | stat: -rwxr-xr-x 1,931 bytes parent folder | download
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
#!/usr/bin/perl

use strict;
use warnings;

use File::Basename qw( basename );
use Getopt::Long::Descriptive;
use SmilesScripts::Isomorphism qw( smi_compare );

my $basename = basename $0;
my( $opt, $usage ) = describe_options( <<"END" . 'OPTIONS',
USAGE
    $basename [<args>] [<files>]

DESCRIPTION
    $basename reads in files with three tab-separated columns:

    <ID> <SMILES_1> <SMILES_2>

    The program then attempts to detect isomorphism between <SMILES_1> and
    <SMILES_2> on each line. If immediate isomorphism is not detected,
    step-by-step simplifications are performed in order to lead both
    SMILES to isomorphism.

END
    [ 'remove-alkali-bonds',
      'add alkali bond removal to the list of simplifications' ],
    [ 'print-side-of-superfluous-moieties',
      'identify which of the compared sides has superfluous molecular entities' ],
    [ 'check-isomorphism',
      'perform an extra isomorphism check on molecular entities detected ' .
      'as isomorphic by comparing their canonical representations' ],
    [],
    [ 'help', 'print usage message and exit', { shortcircuit => 1 } ],
);

if( $opt->help ) {
    print $usage->text;
    exit;
}

my $options = {};
$options->{check_isomorphism} = 1         if $opt->check_isomorphism;
$options->{remove_alkali_bonds} = 1       if $opt->remove_alkali_bonds;
$options->{superfluous_moieties_side} = 1 if $opt->print_side_of_superfluous_moieties;

PAIR:
while( <> ) {
    next if /^#/;
    s/\n$//;

    my( $id, $first_smiles, $second_smiles ) = split "\t", $_;

    local $SIG{__WARN__} = sub {
        print STDERR "$basename: $ARGV($.) $id: $_[0]"
    };

    my $reason;
    eval {
        $reason = smi_compare( $first_smiles, $second_smiles, $options );
    };
    if( $@ ) {
        print STDERR "$basename: $ARGV($.) $id: $@";
    } else {
        local $\ = "\n";
        print join "\t", $id, $first_smiles, $second_smiles, $reason;
    }
}