Skip to content

Instantly share code, notes, and snippets.

@hryk
Created August 31, 2010 00:44
Show Gist options
  • Select an option

  • Save hryk/558321 to your computer and use it in GitHub Desktop.

Select an option

Save hryk/558321 to your computer and use it in GitHub Desktop.
wrapper for AREAIMOL (in CCP4)
#!/usr/local/bin/perl
use strict;
use warnings;
use Carp;
use IPC::Run qw/start pump finish timeout run/;
use Getopt::Long;
use Term::ProgressBar;
use File::Which;
use FindBin qw/$Bin/;
use Data::Dumper;
use Array::Utils qw/:all/;
use lib qq{$Bin/../../lib};
use PPS::Config qw/$Root $Config/;
use Bio::PDB::DB::File;
my $option = {
'input' => undef,
'help' => 0,
'verbose' => 0,
'areaimol' => which('areaimol') || undef
};
GetOptions(
"help" => \$option->{'help'},
"verbose" => \$option->{'verbose'},
"input=s" => \$option->{'input'},
"areaimol=s" => \$option->{'areaimol'},
);
# Checking options ...
if (! defined $option->{areaimol}) {
die "AREAIMOL Not Found.\n".
"Install from http://www.ccp4.ac.uk/index.php";
}
if ((!defined $option->{'input'} or
! -f $option->{'input'})
and scalar(@ARGV) <= 0) {
die "No Input.\nSpecify PDB code by --input or -- CODE ";
}
my $codes = (defined $option->{'input'}) ?
read_input($option->{'input'}) : [@ARGV];
main($option, $codes);
sub main {
my $option = shift;
my $codes = shift;
my $pdb = Bio::PDB::DB::File->new($Config->pdb_info);
for my $code (@$codes) {
print "Run areaimol on $code ...";
# Copy and Unarchive PDB File to Tempolary directory.
my $fh = $pdb->get_as_object($code); # preload.
my $path_in = $pdb->get_cache_path($code);
print "Not found : $code\n" and next if ! defined $path_in;
my $dir_out = $Config->{areaimol}->{root}->subdir($pdb->directory_name_for($code));
$dir_out->mkpath() if (! -d $dir_out);
my $path_out = $dir_out->file($pdb->file_name_for($code));
# Run Areaimol
my ($in, $out , $err);
print $option->{'areaimol'}." XYZIN $path_in XYZOUT $path_out\n";
my $h = start [
$option->{'areaimol'},
'XYZIN', $path_in ,
'XYZOUT', $path_out->stringify ], \$in, \$out, \$err;
$in .= "MODE ALL\n";
pump $h while length $in;
$in .= "VERB\n";
pump $h while length $in;
$in .= "OUTPUT\n";
pump $h while length $in;
$in .= "END\n";
pump $h while length $in;
finish $h or carp "$! $? $err";
print "done.\n";
}
}
sub read_input {
my $path_string = shift;
my $path = Path::Class::File->new($path_string);
my $io = $path->openr() or die "Cannot open : $path\n";
my @codes;
while (<$io>) {
chomp;
push @codes, $_;
}
[ unique @codes ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment