-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanAltLoc.pl
More file actions
executable file
·79 lines (69 loc) · 2.12 KB
/
cleanAltLoc.pl
File metadata and controls
executable file
·79 lines (69 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl -w
# Author: Abdullah Kahraman
# Date: 11.07.2009
use strict;
use warnings;
use Getopt::Long;
##############################################################################
### cleans alternative location problems in PDB files. ###
##############################################################################
&GetOptions(
) or die "\nTry \"$0 -h\" for a complete list of options\n\n";
##############################################################################
##############################################################################
### SUBROUTINES
##############################################################################
##############################################################################
##############################################################################
##############################################################################
### MAIN
##############################################################################
##############################################################################
if(!defined $ARGV[0]){
print STDERR "Please specify pdb file as 1st parameter. Additionally, a 2nd parameter causes the output into the same file as the input\n.";
exit;
}
open(F,$ARGV[0]) or die "Couldn't open file \"$ARGV[0]\"\n";
my %h;
my $model = "";
my $i = 0;
my %line;
while(<F>){
if(/^MODEL /){
$model = $_;
$model =~ s/.*(\d+)\s+/$1/;
}
if(/^ATOM/){
my $altLoc = substr($_, 16, 1);
$altLoc = "_" if($altLoc eq " ");
my $atom = substr($_,11,5).substr($_,17,9);
if(exists $h{$atom}) {
if($altLoc eq "_") {
$h{$atom}=$_;
$line{$i++} = $atom;
} else {
if(substr($h{$atom}, 16, 1) ne "_") {
if(ord($altLoc) < ord(substr($h{$atom}, 16, 1))) {
$h{$atom}=$_;
$line{$i++} = $atom;
}
}
}
} else {
$h{$atom}=$_;
$line{$i++} = $atom;
}
}
}
close(F);
if(@ARGV>1){
open(O,">$ARGV[0]") or die "ERROR: Failed to create output file $ARGV[0]\n";
}
foreach my $i(sort{$a cmp $b} keys %line){
if(@ARGV > 1) {
print O $h{$line{$i}};
} else {
print $h{$line{$i}};
}
}
close(O) if(@ARGV>1);