[Bio] / DrugTargets / pass_pdb.pl Repository:
ViewVC logotype

View of /DrugTargets/pass_pdb.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Tue Aug 23 16:53:58 2005 UTC (14 years, 3 months ago) by fangfang
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -0 lines
Avoid re-run pass for failed pdb entries.

$usage = "pass_pdb [-pdb=Dir] [-dest=Dir] [-frame=Num] [-zoom=Percent] [-redo] PDB_Ent1 PDB_Ent2 ...\n ";

(@ARGV >= 1) || die "Usage: $usage";

my $pdb_dir  = "/home/fangfang/public_html/PDB-U";
my $dest_dir = "/home/fangfang/public_html/PDB-P"; 
#my $pdb_dir  = "/home/fangfang/seed/PDB";
#my $dest_dir = "/home/fangfang/seed/PDB-P";
my $rasmol   = "/home/fangfang/bin/rasmol";
my $pass     = "/home/fangfang/bin/pass"; 
my $zoom     = 0;
my $nframe   = 20;
my $redo     = 0;
 
while ($ARGV[0] =~ /^-/) {
    if ($ARGV[0] =~ /-pdb=(\S+)/) {
	$pdb_dir = $1;
	$pdb_dir =~ s/\/$//;
    } elsif ($ARGV[0] =~ /-dest=(\S+)/) {
	$dest_dir = $1;
	$dest_dir =~ s/\/$//;
    } elsif ($ARGV[0] =~ /-frame=(\d+)/) {
	if ($1 > 0) {$nframe = $1;}
    } elsif ($ARGV[0] =~ /-zoom=(\d+)/) {
	$zoom = ($1 >= 200) ? 199 : $1;
    } elsif ($ARGV[0] =~ /-redo/) {
	$redo = 1;
    } else {
	$trouble = 1;
	print STDERR "Invalid flag '$ARGV[0]'.\n";
    }
    shift @ARGV;
}
die "\nUsage: $usage\n" if $trouble;

(-e $pdb_dir && -r $pdb_dir) || die "PDB directory '$pdb_dir' not found or not readable.\n\n";

if (-e $dest_dir) {
    (-w $dest_dir) || die "Directory '$dest_dir' not writable.\n\n";
} else {
    system "mkdir -p $dest_dir -m 777";
    chdir "$dest_dir" || die "Can't chdir to $\n\n";
}

$| = 1;

foreach (@ARGV) {
    next unless ($_ =~ /(\d\w{3})/);

    $id = $1;
    $pdb = "pdb$id.ent";
    $pdbp = "pdb$id.pass";
    next if ($seen{$pdb});
    $seen{$pdb} = 1;

    #print STDERR $pdb ;
    chdir "$dest_dir";
    next if (!$redo && -e $pdbp);
    system "mkdir $pdbp -m 777" unless (-e $pdbp);
    (-w $pdbp) || die "Directory '$pdbp' not writable.\n\n"; 
    chdir "$pdbp" || die "Cannot chdir to '$pdbp'.\n\n";
    next if (!$redo && -e "done.log");

    # Run PASS on the PDB file
    system "$pass $pdb_dir/$pdb -rasmol -outdir $dest_dir/$pdbp > $dest_dir/$pdbp/pdb$id\_pass.log";    
    #print "$pass $pdb_dir/$pdb -rasmol -outdir $dest_dir/$pdbp > $dest_dir/$pdbp/pdb$id\_pass.log";    
    
    if (`cat pdb$id\_pass.log | grep PASSed` !~ /PASSed out/) {
	#print STDERR "\t PASS failed.\n"; 
	next;
    } else {
	#print STDERR "\n";
    }

    open(RAS_IN, "pdb$id\_pass.ras");
    my @lines = <RAS_IN>;
    close(RAS_IN);

    open(RAS_OUT, ">pdb$id\_pass_ras.spt");

    print RAS_OUT "set write on\n";

    my $ngif = 0;

    while ($line = shift @lines) {
	print RAS_OUT $line;
	if ($line =~ /select\s(\d+)-(\d+)/i) {
	    $probe = $1;
	    $pocket = $2;
	} else {
	    if ($zoom) { print RAS_OUT "zoom $zoom\n"; }
	    print RAS_OUT "refresh\n";
	    printf RAS_OUT "save gif pdb$id\_pass_%02d.gif\n", $ngif++;	    
	}
    }

    print RAS_OUT "select $pocket-$pocket\n";
    print RAS_OUT "color white\n";
    if ($zoom) { print RAS_OUT "zoom $zoom\n"; }
    print RAS_OUT "refresh\n";
    printf RAS_OUT "save gif pdb$id\_pass_%02d.gif\n", $ngif++;	    
    
    my $sofar = $ngif;

    for ($i=0; $i<$nframe; $i++) {
	printf RAS_OUT "rotate y %d\n", 360/$nframe;
	if ($zoom) { print RAS_OUT "zoom $zoom\n"; }
	print RAS_OUT "refresh\n";
	printf RAS_OUT "save gif pdb$id\_pass_%02d.gif\n", $ngif++;
    }

    print RAS_OUT "exit\n";
    close(RAS_OUT);

    system "$rasmol -nodisplay < pdb$id\_pass_ras.spt > $dest_dir/$pdbp/pdb$id\_rasmol.log";

    my $gifall = "pdb$id\_pass_all.gif";
    my $cmd = "convert -delay 500 ";
    for ($i=0; $i<$sofar; $i++) {
	my $gifname = sprintf("pdb$id\_pass_%02d.gif", $i);
	$cmd .= "$gifname ";
    }
    system "$cmd $gifall";

    $cmd = "convert -loop 0 -delay 50 $gifall ";
    for ($i=$sofar; $i<$ngif; $i++) {
	my $gifname = sprintf("pdb$id\_pass_%02d.gif", $i);
	$cmd .= "$gifname ";
    }
    system "$cmd $gifall"; 

    open(LOG, ">done.log");
    printf LOG "asps   = %d\n", (-e "pdb$id\_asps.pdb") ? `cat pdb$id\_asps.pdb |wc -l` : 0;
    printf LOG "ligs   = %d\n", (-e "pdb$id\_lig1.pdb") ? `ls pdb$id\_lig* |wc -l` : 0;
    printf LOG "probe  = %d\n", $probe;
    printf LOG "pocket = %d\n", $pocket;
    printf LOG "zoom   = %d\n", $zoom ? $zoom : 100; 
    close(LOG);

}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3