#!/usr/bin/perl # Randal R. Ketchem, Ph.D. 619.784.9879 (voice1) # Department of Molecular Biology, MB-9 619.784.8754 (voice2) # The Scripps Research Institute 619.784.9985 (FAX) # 10550 N. Torrey Pines Road ketchemr@scripps.edu (email) # La Jolla, CA 92037-1027 http://www.scripps.edu/~ketchemr # 7col.comb file # 2 ALA MB 7 GLN HN 6.0 # met_cnstr_vols:12 # 2 ALA MB 7 GLN QPG 6.0 # met_cnstr_vols:144 $prgName = `basename $0`; chop($prgName); if($#ARGV != 0) { die <) { next if(/^\s*#/); next if(/^\s*$/); # First grab the atom specifications. ($resNum1, $resName1, $atomName1, $resNum2, $resName2, $atomName2) = split(' '); # Check for atom to identical atom. next if("$resNum1 $resName1 $atomName1" eq "$resNum2 $resName2 $atomName2"); # If residue one is less, it goes first. if($resNum1 < $resNum2) { $line = "$resNum1 $resName1 $atomName1"; $line .= " $resNum2 $resName2 $atomName2"; } # If residue two is less, it goes first. elsif($resNum1 > $resNum2) { $line = "$resNum2 $resName2 $atomName2"; $line .= " $resNum1 $resName1 $atomName1"; } # They must be on the same residue. Sort by atom name. else { $line1 = "$resNum1 $resName1 $atomName1"; $line2 = "$resNum2 $resName2 $atomName2"; @lines = sort($line1, $line2); $line = join(' ', @lines); } # Each occurance of $line is counted. ++$dup{$line}; # And saved in its entirety. $save{$line} .= $_; } # For every %save entry... Duplicates are a single entry separated by '\n'. foreach $key (keys %save) { # If the entry contains more than one line. if($dup{$key} > 1) { # Place the separate lines in an array. Sort the lines by distance so that # the line with the longer distance is first. @lines = sort by_distance split('\n', $save{$key}); # Print the first line. print "$lines[0]\n"; # Print the other lines in the duplicate group commented. for($count = 1; $count <= $#lines; ++$count) { print "#$lines[$count]\n"; } } # If the line is not duplicated, print it out normally. else { print "$save{$key}"; } } # Sort by distance subroutine. sub by_distance { @a = split(' ', $a); @b = split(' ', $b); # Column 7 is the distance. $a[6] <=> $b[6]; }