Perl Scripts

From Jacobson Lab Wiki

Jump to: navigation, search

Renaming multiple files

#!/usr/bin/perl -w
system "ls *.mae  > list";                      # create a list of all the files you want to rename
open (LIST_MAE, "<", "list") || die "could not open list";
open (NEW_LIST_MAE, ">", "tmp_file") || die "could not open new";
@infile = <LIST_MAE>;
foreach $infile (@infile) {
    chomp @infile;
    @var = split /[_\.]/, $infile;              # split file name  
    $new = "$var[0].txt";                       # new name
    chomp $new;
    print NEW_LIST_MAE "$new\n";
    system "mv $infile $new";
close LIST_MAE;

Submitting multiple ligprep jobs

#!/usr/bin/perl/ -w
system "ls *.mae  > tmp_file";
open (MAE_INPUT_LIST, "tmp_file") || die "could not open tmp_file";
@infile = <MAE_INPUT_LIST>;
foreach $infile (@infile) {
        chomp $infile;
        @var = split /\./, $infile;
        print "$var[0]\n";
        system "ligprep -HOST 8core -i 1 -imae $infile -omae ligprep_$infile"

Extracting highest Glide XP scores from many IFD output files

#!/usr/bin/perl -w
system "ls -d *workdir > list";                       #create list of all IF_*_workdir
system "rm scores";
open (WORK_LIST, "list") or die "could not open list";
@line = <WORK_LIST>;
foreach $line (@line) {                               #for each workdir
    chomp @line;
    @var = split /_/, $line;
    $name = $var[1];
    open (SUMMARY, ">>","scores") or die "could not open scores"; #output file
    open (EACH_DIR, "$line/report.csv") or
    print SUMMARY "$name\tdidn't fit\n";                          #of couldn't open report.csv file 
    @line2 = <EACH_DIR>;
    chomp @line2;
    $count = 0;
    $score = 0.0;
    foreach $line2 (@line2){                          # find score for each pose for a given ligand
        next if $line2 =~ m/Ligand/;
        @var2 = split /,/, $line2;
        if ($var2[2] < $score) {
            $score = $var2[2];
            open (TEMP_FILE, ">","temp") or die "could not open temp";
            print TEMP_FILE "$score, $count\n";       # print out highest glide score and pose number into temporary file
            close TEMP_FILE;
    open (TEMP_FILE, "temp") or die "could not open temp";
    @line3 = <TEMP_FILE>;
    foreach $line3 (@line3) {
        chomp @line3;
        @var3 = split /,/, $line3;
        $var3[0] = sprintf ("%.1f", $var3[0]);
        if ( -e "$line/report.csv") {
        print  SUMMARY "$name\t$var3[0]\t$var3[1]\n";
        close TEMP_FILE;
        close SUMMARY;
close EACH_DIR;
close WORK_LIST;

Creating a control file for each pdb in a directory

use strict;
# user parameters
my $input_directory         = './pdbs';
my $output_directory        = './output';
my $plop_data_directory     = '/home/jane/plop/data';
my $con_file_directory      = './con_files';
my $path_to_plop_executable = '/home/jane/plop/plop';
# write the con file, XXXXXX will be replaced by the name of the pdb file
my $base_con_file = "#!$path_to_plop_executable
datadir $plop_data_directory
energy parameters solvent vsgb2
jobname XXXXXX
file logfile $output_directory/XXXXXX.log
load pdb $input_directory/XXXXXX.pdb
energy calc
minimize residues all residues verbose yes
energy calc
write pdb $output_directory/XXXXXX.pdb";
# make directories
my $current_con_file;
system ("mkdir -p $con_file_directory");
system ("mkdir -p $output_directory");
my @files = `find $input_directory -name "*.pdb"|sort|xargs -n 1 -I{} basename {} .pdb`;
while(my $pdb_file = <@files>)
 print "Making con file: $pdb_file.con\n";
 $current_con_file = $base_con_file;
 $current_con_file =~ s/XXXXXX/$pdb_file/g;
 open my $con_filehandle, ">", "$con_file_directory/$pdb_file.con" or die $!;
 print $con_filehandle "$current_con_file";
 close $con_filehandle;
system ("chmod +x $con_file_directory/*.con");
Personal tools