#!/bin/perl #Perl script to compare restraints to a list of ones to fix. If #the restraint matches, it is replaces by the one on the list. #If the rst on the adjusted list has a bin column set to 'rm', the #restraint is removed from the list #Melanie Nelson #6/2/99 require "getopt.pl"; if ($#ARGV != 3){ $prg_name = $0; $prg_name = `basename $prg_name`; chomp ($prg_name); die<! output] EODIE } #get arguments from the command line &Getopt('rf'); $rst_list = $opt_r; $fix_list = $opt_f; #read list of adjusted restraints into an array for matching open (FIXLIST, $fix_list) || die ("Could not open list of adjusted restraints, $fix_list\n"); $x = 0; while (){ next if(/^\s*#/); next if(/^\s*$/); chomp; #for printing later $store_rst[$x] = $_; ($resnum1[$x], $resname1[$x], $atm1[$x], $resnum2[$x], $resname2[$x], $atm2[$x], $bin[$x]) = split; $x++; } #now go through the main restraint file, printing either the #original line, or the matching line from the adjusted restraint #list open (RSTLIST, $rst_list) || die("Could not open main restraint list, $rst_list\n"); while(){ next if(/^\s*#/); next if(/^\s*$/); chomp; #for easy printing, store original line #will be printed unless we match something later $print_line = $_; #printing is on by default-- only turned off if indicated by #the line in the adjusted restraint list file $print_flag = 1; ($resnum1, $resname1, $atm1, $resnum2, $resname2, $atm2, $bin) = split; #do the matching-- can assume that if residue numbers match, the #residue names will match, too #if bin column (last column) in line from adjusted list is 'rm', #flag this restraint not to be printed in the final list for ($n = 0; $n <= $#store_rst; $n++){ if (($resnum1 eq $resnum1[$n] && $atm1 eq $atm1[$n] && $resnum2 eq $resnum2[$n] && $atm2 eq $atm2[$n]) || ($resnum1 eq $resnum2[$n] && $atm1 eq $atm2[$n] && $resnum2 eq $resnum1[$n] && $atm2 eq $atm1[$n])){ if ($bin[$n] =~ 'rm'){ $print_flag = 0; } else { $print_line = $store_rst[$n]; } } } if ($print_flag != 0){ print "$print_line\n"; } }