-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddTERflag.pl
More file actions
executable file
·66 lines (58 loc) · 1.91 KB
/
addTERflag.pl
File metadata and controls
executable file
·66 lines (58 loc) · 1.91 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
#!/usr/bin/perl -w
# Author: Abdullah Kahraman
# Date: 06.07.2010
use strict;
use warnings;
use Getopt::Long;
##############################################################################
##############################################################################
### Adds a TER flag after each chain in a PDB file. ###
##############################################################################
##############################################################################
my $in;
&GetOptions(
"in=s" => \$in, # PDB file with missing TER lines
) or die "\nPlease give the path to the PDB file with -in\n\n";
##############################################################################
##############################################################################
### SUBROUTINES
##############################################################################
##############################################################################
##############################################################################
##############################################################################
### MAIN
##############################################################################
##############################################################################
if(!defined $in){
die "\nPlease give the path to the PDB file with -i\n\n";
}
else{
my $preChainId = "";
my $i=0;
open(F, $in) or die "Can't open file \"$in\"\n\n";
my $output="";
while(<F>){
if(/^ATOM/){
my $chainId = substr($_, 21, 1);
if($i==0){
$preChainId = $chainId;
}
if($chainId ne $preChainId){
$output.="TER\n";
$preChainId = $chainId;
}
$output.=$_;
$i++;
}
elsif(/^TER/ or /^END/){
$i=0;
$output.=$_;
} else {
$output .= $_;
}
}
close(F);
open(O,">$in") or die "Can't override file \"$in\"\n\n";
print O $output;
close(O);
}