-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkmeans_analysis.1.pl
327 lines (281 loc) · 8.28 KB
/
kmeans_analysis.1.pl
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
### Subroutines and Modules ###
use Cwd;
use File::Copy;
sub uniq {
my %seen;
grep !$seen{$_}++, @_;
}
########## global variables ####################
$usage="\nUsage: \.\/kmeans_structural_analysis\.pl \[Project\#\] \[Inhibitor 3-Letter Code\] \n\nKey_file.txt and final_trial.txt should be in current directory \n";
$proj = $ARGV[0] || die "$usage\n";
$code = $ARGV[1] || die "$usage\n";
chomp $proj;
chomp $code;
$dir = getcwd;
#### Read in Inhibitor Key File ####
$keyfile = "noncholine_key_file.txt";
#chomp $keyfile;
open(KI,"<$keyfile")|| die "\n\tError reading from $keyfile\n\n";
while (<KI>){
if (/Proj $proj/i) {
$spool = 1;
next;
}
elsif ($_ =~ /Proj\s\d/ && $_ !~ /Proj $proj/) {
$spool = 0;
}
elsif ($spool) {
undef @singroup;
$groupline = $_;
for($groupline) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
@logline = split(/ /,$groupline);
$group = "@logline[0]";
chomp $group;
$atoms = "@logline[1..$#logline]";
@singroup = split(/ /,$atoms);
if ($group eq "PheCOP"){
push (@PheCOP,@singroup);
undef @singroup;
}
elsif ($group eq "OCH1"){
push (@OCH1, @singroup);
undef @singroup;
}
elsif ($group eq "OCH2"){
push (@OCH2, @singroup);
undef @singroup;
}
elsif ($group eq "Phos"){
push (@Phos, @singroup);
undef @singroup;
}
}
}
### Find Cluster Size and Number ###
$log = "proj$proj"."/$proj"."_trial.txt";
chomp $log;
open(LOG,"<$log")|| die "\n\tError reading from $log\n\n";
while (<LOG>) {
if (/# group pop Centers/i) {
$spool = 1;
next;
}
elsif (/Clusters \/ Data points \/ P\/R\/C\/T/i) {
$spool = 0;
}
elsif ($spool) {
$var = $_;
for($var) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
@logline = split(/ /,$var);
$energy{$logline[0]} = $logline[1];
}
}
### Rename/Organize by Cluster Size ###
$k=0;
foreach my $clusternum (sort { $energy{$b} <=> $energy{$a} or $a cmp $b } keys %energy){
$clusternew{$clusternum} = $k;
#printf"%-8s %s%s\n", $clusternew{$clusternum};
$k++;
}
### Make cluster directories ###
#mkdir "$dir"."/proj$proj"."/proj$proj"."_vectors"."/clusters";
#mkdir clusters;
$clusterfolder = "$dir"."/proj$proj"."/proj$proj"."_vectors"."/clusters";
print $clusterfolder;
#for($j=0; $j<$k; $j++){
# mkdir "$clusterfolder"."/$j";
#}
### Look for a pdb's associated cluster number and move ###
seek (LOG, 0, 0);
while (<LOG>) {
if (/Clusters \/ Data points \/ P\/R\/C\/T/i) {
$spool = 1;
next;
}
elsif ($spool) {
$var2 = $_;
for($var2) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
@logline2 = split(/ /,$var2);
$frame = @logline2[21]/100;
$clone = @logline2[20];
$oldclusternum = @logline2[0];
$curlocation = "$dir"."/proj$proj"."/00$clone"."/$clone"."frame$frame".".pdb";
$newlocation = "$clusterfolder"."/$clusternew{$oldclusternum}";
#move($curlocation, $newlocation) or die "Error when moving clone:$clone frame$frame.pdb: $!";
}
}
close(LOG);
### Move into cluster folders and find distances ###
for($m=0; $m<$k; $m++){
chdir "$clusterfolder"."/$m";
$cluster = $m;
my @pdbfiles = `ls *pdb`;
$count = scalar(@pdbfiles);
$clustertotal = $count;
### Find distances for each pdb ###
foreach $pdb(@pdbfiles){
chomp $pdb;
$temp = `head -2 $pdb | tail -1`;
chomp $temp;
for($temp) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
@templine = split(/ /,$temp);
$currenttime = $templine[11];
### Open/Read pdb line and save protein coordinates ###
open(PDB,"<$pdb") || die "\n\tError reading from $pdb\n\n";
$i = 0;
while(defined($origline=<PDB>)) {
$line = $origline;
chomp $line;
for($line) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
@input = split(/ /,$line);
###Save protein coordinates###
if(@input[0] eq 'ATOM'){
$atomnum = @input[1];
$atomname = @input[2];
$resname[$atomnum] = @input[3];
$resnum[$atomnum] = @input[5];
$x[$atomnum]= @input[6];
$y[$atomnum]= @input[7];
$z[$atomnum]= @input[8];
if((@input[0] eq 'ATOM')&&(@input[3] ne 'SOL')&&(@input[3] ne '$code')&&(@input[3] ne 'UNK')&&(@input[3] ne 'CL')&&(@input[2] ne 'NA')){
$protx[$atomnum] = $x[$atomnum];
$proty[$atomnum] = $y[$atomnum];
$protz[$atomnum] = $z[$atomnum];
$i++;
}
}
}
close(PDB);
### Find the inhibitor group's atom distance from protein ###
foreach $num (@PheCOP){
for ( $i=1; $i<8310; $i++){
$X = $protx[$i]-$x[$num];
$Y = $proty[$i]-$y[$num];
$Z = $protz[$i]-$z[$num];
$D2 = $X**2 + $Y**2 + $Z**2;
$D = sqrt($D2);
if ($D < 5){
$phe = "$resname[$i]$resnum[$i]";
for($phe) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
push @pheline, $phe;
@pheorg = uniq(@pheline);
}
}
}
#maybe print pheorg?###
foreach $num (@Phos){
#print $num;
for ( $i=1; $i<8310; $i++){
$X = $protx[$i]-$x[$num];
$Y = $proty[$i]-$y[$num];
$Z = $protz[$i]-$z[$num];
$D2 = $X**2 + $Y**2 + $Z**2;
$D = sqrt($D2);
if ($D < 5){
@phoorg=();
$jj = $j - 1;
$pho = "$resname[$i]$resnum[$i]";
for($pho) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
push @pholine, $pho;
@phoorg = uniq(@pholine);
}
}
}
foreach $num (@OCH1){
#print $num;
for ( $i=1; $i<8310; $i++){
$X = $protx[$i]-$x[$num];
$Y = $proty[$i]-$y[$num];
$Z = $protz[$i]-$z[$num];
$D2 = $X**2 + $Y**2 + $Z**2;
$D = sqrt($D2);
if ($D < 5){
@oc1org=();
$jj = $j - 1;
$oc1 = "$resname[$i]$resnum[$i]";
for($oc1) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
push @oc1line, $oc1;
@oc1org = uniq(@oc1line);
}
}
}
foreach $num (@OCH2){
for ( $i=1; $i<8310; $i++){
$X = $protx[$i]-$x[$num];
$Y = $proty[$i]-$y[$num];
$Z = $protz[$i]-$z[$num];
$D2 = $X**2 + $Y**2 + $Z**2;
$D = sqrt($D2);
if ($D < 5){
@oc2org=();
$jj = $j - 1;
$oc2 = "$resname[$i]$resnum[$i]";
for($oc2) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
push @oc2line, $oc2;
@oc2org = uniq(@oc2line);
}
}
}
#print "@pheorg\n";
push(@phecluster,@pheorg);
@pheorg=();
push(@phocluster,@phoorg);
@phoorg=();
push(@oc1cluster,@oc1org);
@oc1org=();
push(@oc2cluster,@oc2org);
@oc2org=();
}
####Finding total interaction time###
print"CLUSTER GROUP: $cluster\n";
print "----------------------------------\n";
print "----------------------------------\n";
print "Interactions with Phenyl Group:\n";
$phecount{$_}++ foreach @phecluster;
foreach my $name (sort { $phecount{$b} <=> $phecount{$a} or $a cmp $b } keys %phecount){
printf"%-8s%d%s\n", $name, $phecount{$name}*100/$clustertotal,"%";
}
@phecluster = ();
print "----------------------------------\n";
print "Interactions with Phosphate Group:\n";
my %phocount;
$phocount{$_}++ foreach @phocluster;
## Maybe print here to see the output for @phocluster? ##
foreach my $name (sort { $phocount{$b} <=> $phocount{$a} or $a cmp $b } keys %phocount){
printf"%-8s%d%s\n", $name, $phocount{$name}*100/$clustertotal,"%";
}
@phocluster =();
print "----------------------------------\n";
print "Interactions with Alkyl (Left) Group:\n";
my %oc1count;
$oc1count{$_}++ foreach @oc1cluster;
foreach my $name (sort { $oc1count{$b} <=> $oc1count{$a} or $a cmp $b } keys %oc1count){
printf"%-8s%d%s\n", $name, $oc1count{$name}*100/$clustertotal,"%";
}
@oc1cluster = ();
print "----------------------------------\n";
print "Interactions with Alkyl (Right) Group:\n";
my %oc2count;
$oc2count{$_}++ foreach @oc2cluster;
foreach my $name (sort { $oc2count{$b} <=> $oc2count{$a} or $a cmp $b } keys %oc2count){
printf"%-8s%d%s\n", $name, $oc2count{$name}*100/$clustertotal,"%";
}
@oc2cluster=();
print "----------------------------------\n";
print"\n";
undef %phecount;
undef @phecount;
undef @pheline;
undef %seen;
undef @pheorg;
#this is where you left off #
undef @phecluster;
#undef &uniq;
undef *phecount;
}
### Stuff to consider ###
#for($j=1; $j<=4; $j++){
#$gnum = "group$j";
#chomp $gnum;
#foreach $num (@$gnum){
#}