-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_antibody.pl
executable file
·666 lines (549 loc) · 20.2 KB
/
get_antibody.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#! /usr/bin/perl
use warnings;
use strict;
use lib ("/home/bsm/ucbterd/perl5/lib/perl5");
use CGI;
use Data::Dumper;
use List::MoreUtils qw (uniq);
use Scalar::Util qw(looks_like_number);
use antibody qw
(get_cluster_in_array
get_multiple_matching_files_from_directory
print_html_header
print_error
print_error_kabat
print_table
print_single_antibody
print_multiple_antibody
print_two_similar_antibody
print_two_different_antibody
check_complex
print_number
displayError
getNumberedFileArray
get_resolution
printTableKeyword
displayMessage
displayMessageSpecOrg
displayAntigenError
displayMissingFilesError);
my $cgi = new CGI;
print $cgi->header();
## Directory <Data> contains all the sub-directories for all the complexes
# numbered according to diffrent numbering schemes
my $dir = "/acrm/www/html/abs/abdb/Data";
my $logDir = "/acrm/www/html/abs/abdb/Data/Martin_logs";
my $headerFile = "header.dat";
my $headerProFile = "headerProcessed2.dat";
my $antigenChainsFile = "AntigenChains.dat";
my $antibodyChainsFile = "AntibodyChains.dat";
my ($file1, $file2, $file3);
my (@kabat_files, @chothia_files, @martin_files);
my (@kabat_clus, @chothia_clus, @martin_clus);
# Reading Kabat data
open(my $CLUSTER_K,'<',
"$dir/Redundant_files/Redundant_ALL_Kabat.txt");
opendir (my $DIR_K, "$dir/ALL_Kabat") or die
"Can not open $dir/ALL_Kabat";
my @dir_files_k = readdir ($DIR_K);
# Reading Chothia data
open(my $CLUSTER_C,
'<', "$dir/Redundant_files/Redundant_ALL_Chothia.txt");
opendir (my $DIR_C, "$dir/ALL_Chothia") or die
"Can not open $dir/ALL_Chothia";
my @dir_files_c = readdir ($DIR_C);
# Reading Martin data
open(my $CLUSTER_M,'<',
"$dir/Redundant_files/Redundant_ALL_Martin.txt");
opendir (my $DIR_M, "$dir/ALL_Martin") or die
"Can not open $dir/ALL_Martin";
my @dir_files_m = readdir ($DIR_M);
my ($pdb_id, $nameAg, $speciesAg);
my ($nameAb, $speciesAb);
$pdb_id = $cgi->param("pdbid");
$pdb_id = uc($pdb_id);
$nameAg = $cgi->param("organismAg");
$nameAg = uc($nameAg );
$nameAb = $cgi->param("organismAb");
$nameAb = uc($nameAb);
$speciesAg = $cgi->param("speciesAg");
$speciesAg = uc($speciesAg);
$speciesAb = $cgi->param("speciesAb");
$speciesAb = uc($speciesAb);
# Searcg for PDB code only
if ( ($pdb_id) and ($nameAg eq "" ) and ($speciesAg eq "") )
{
$nameAg = 0;
$speciesAg = 0;
if ($pdb_id =~ m/^[0-9]{1}[0-9A-Z]{3}$/)
{
@kabat_clus = get_cluster_in_array($pdb_id, $CLUSTER_K);
@chothia_clus = get_cluster_in_array($pdb_id, $CLUSTER_C);
@martin_clus = get_cluster_in_array($pdb_id, $CLUSTER_M);
my $clusNum = @kabat_clus;
if (!$clusNum)
{
open(my $KABAT_FAILED,'<', "$logDir/Kabat_Failed.list");
my @kabat_error = <$KABAT_FAILED>;
if (grep (/$pdb_id/, @kabat_error) )
{
print_error_kabat($pdb_id);
exit;
}
else
{
print_error($pdb_id);
exit;
}
}
else
{
# If there is only one antibody in a PDB then it just prints this message
print_html_header();
my $flag = 0;
my $tableNo = 0;
for(my $i = 0 ; $i < @kabat_clus ; ++$i)
{
my $kabatClusterRef = $kabat_clus[$i];
my $chothiaClusterRef = $chothia_clus[$i];
my $martinClusterRef = $martin_clus[$i];
my @args = ( [\@dir_files_k, $kabatClusterRef],
[\@dir_files_c, $chothiaClusterRef],
[\@dir_files_m, $martinClusterRef]
);
my ($kabat_filesRef, $chothia_filesRef, $martin_filesRef) =
getNumberedFileArray (@args);
# De-referening
@kabat_files = @{$kabat_filesRef};
@chothia_files = @{$chothia_filesRef};
@martin_files = @{$martin_filesRef};
my $cluster_size = @{$kabatClusterRef};
my $less_one = $cluster_size-1;
if ($clusNum == 1)
{
if ($cluster_size == 1)
{
print_single_antibody($cgi, $pdb_id);
print_table
( $cluster_size, $pdb_id, \@kabat_files, \@chothia_files,
\@martin_files, $cgi, $less_one );
}
elsif ( ($cluster_size == 2) )
{
# If thre are 2 antibodies in a structure and they are redundant
# e.g: 1AFV_1 and 1AFV_2
if ( (index($$kabatClusterRef[0], $pdb_id) != -1) and
(index($$kabatClusterRef[1], $pdb_id) != -1) )
{
print_two_similar_antibody($cgi, $pdb_id);
print_table
( $cluster_size, $pdb_id,
\@kabat_files, \@chothia_files,\@martin_files,
$cgi, $less_one);
}
# If thre are 2 antibodies (different) for a PDB query and there are redundant
# e.g: 1AJ7_1, 2RCS_1
else
{
if (!$flag)
{
print_two_different_antibody($cgi, $pdb_id);
$flag = 1;
}
print_table
( $cluster_size, $pdb_id, \@kabat_files, \@chothia_files,
\@martin_files, $cgi, $less_one);
}
}
else
{
if (!$flag)
{
print_multiple_antibody($cgi, $pdb_id);
$flag = 1;
}
print_table
($cluster_size, $pdb_id, \@kabat_files, \@chothia_files,
\@martin_files, $cgi, $less_one);
}
}
elsif ($clusNum == 2)
{
if ($cluster_size == 1)
{
if (!$flag)
{
print $cgi->p("The antibodies in PDB file <b>$pdb_id</b>, numbered according to 3 different numbering schemes. Non-redundant antibodies in <b>$pdb_id</b> files are shown in separate tables.");
$flag = 1;
}
print_table
( $cluster_size, $pdb_id, \@kabat_files, \@chothia_files,
\@martin_files, $cgi, $less_one );
}
elsif ($cluster_size == 2)
{
# If thre are 2 antibodies in a structure and they are redundant
# e.g: 1AFV_1 and 1AFV_2
if ( (index($$kabatClusterRef[0], $pdb_id) != -1) and
(index($$kabatClusterRef[1], $pdb_id) != -1) )
{
if (!$flag)
{
print_two_similar_antibody($cgi, $pdb_id);
$flag = 1;
}
print_table
( $cluster_size, $pdb_id, \@kabat_files, \@chothia_files,
\@martin_files, $cgi,$less_one);
}
# If thre are 2 antibodies (different) for a PDB query and there are redundant
# e.g: 1AJ7_1, 2RCS_1
else
{
if (!$flag)
{
print_two_similar_antibody($cgi, $pdb_id);
$flag = 1;
}
print_table
( $cluster_size, $pdb_id, \@kabat_files, \@chothia_files,
\@martin_files, $cgi, $less_one);
}
}
else
{
if (!$flag)
{
print_multiple_antibody($cgi, $pdb_id);
$flag = 1;
}
print_table
($cluster_size, $pdb_id,\@kabat_files, \@chothia_files,
\@martin_files, $cgi, $less_one);
}
}
else
{
# If there are more than 2 (or redundant antibodies) antibodies in one PDB
if (!$flag)
{
print_multiple_antibody($cgi, $pdb_id);
$flag = 1;
}
print_table($cluster_size, $pdb_id, \@kabat_files, \@chothia_files,
\@martin_files, $cgi, $less_one);
}
}
# To check if some of the files are missing for some reason
if ( ( @kabat_files == @chothia_files) and ( @kabat_files == @martin_files)
and (@chothia_files == @martin_files) ) {
}
else
{
displayMissingFilesError($cgi);
}
}
}
else
{
my $errorStr = "Invalid PDB code!!!";
my $errorStr2 = "Please enter valid PDB code";
displayError($errorStr, $errorStr2 );
}
exit;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if ( ($nameAb) and ($nameAg) ) {
my $errorStr = "Please search by either antibody or antigen name\n";
displayError ($errorStr,"");
exit;
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Search by antigen name
if ( ($nameAg) and ($speciesAg eq "") and ($pdb_id eq "") )
{
$speciesAg = 0;
$pdb_id = 0;
my $isNum = looks_like_number($nameAg);
if ($isNum)
{
my $errorStr = "The name keyword should be a string\n";
displayError($errorStr, "" );
exit;
}
else
{
print_html_header();
my @result = `grep -E MOLECULE $logDir/$headerFile | grep -E "$nameAg"`;
my @AgMatches;
foreach my $org (@result) {
my $PDB = substr ($org, 0, 4);
my @AgChains = split (":",`grep $PDB $logDir/$antigenChainsFile`);
my @chains = split (/\,|""/,$AgChains[1] );
foreach my $chain ( @chains) {
chomp $chain;
my $matchedAg =
`grep "^$PDB : MOLECULE : $chain :.*$nameAg" $logDir/$headerFile`;
push (@AgMatches, $matchedAg);
}
}
my @PDBcodes = uniq (map {substr ($_, 0, 4)} @AgMatches);
my $PDBnum;
my @args = ( [\@dir_files_k, \@PDBcodes],
[\@dir_files_c, \@PDBcodes],
[\@dir_files_m, \@PDBcodes]
);
my ($kabat_filesRef, $chothia_filesRef, $martin_filesRef) =
getNumberedFileArray (@args);
$PDBnum = scalar @{$kabat_filesRef};
displayMessage ($cgi, $PDBnum, $nameAg);
if ( !$PDBnum) {
exit;
}
# De-referening
@kabat_files = @{$kabat_filesRef};
@chothia_files = @{$chothia_filesRef};
@martin_files = @{$martin_filesRef};
printTableKeyword(\@kabat_files, \@chothia_files, \@martin_files);
# To check if some of the files are missing for some reason
if ( ( @kabat_files == @chothia_files) and ( @kabat_files == @martin_files)
and (@chothia_files == @martin_files) ) {
}
else {
displayMissingFilesError($cgi);
}
}
exit;
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Search by antibody name (keyword)
if ( ($nameAb) and ($speciesAg eq "") and ($pdb_id eq "") )
{
$speciesAg = 0;
$pdb_id = 0;
my $isNum = looks_like_number($nameAb);
if ($isNum)
{
my $errorStr = "The name keyword should be a string\n";
displayError($errorStr, "" );
exit;
}
else
{
print_html_header();
my @result = `grep -E MOLECULE $logDir/$headerFile | grep -E "$nameAb"`;
my @AbMatches;
foreach my $org (@result) {
my $PDB = substr ($org, 0, 4);
my @AbChains = split (":",`grep $PDB $logDir/$antibodyChainsFile`);
my @chains = split (/\,|""/,$AbChains[1] );
foreach my $chain ( @chains) {
chomp $chain;
my $matchedAb =
`grep "^$PDB : MOLECULE : $chain :.*$nameAb" $logDir/$headerFile`;
push (@AbMatches, $matchedAb);
}
}
my @PDBcodes = uniq (map {substr ($_, 0, 4)} @AbMatches);
my $PDBnum;
my @args = ( [\@dir_files_k, \@PDBcodes],
[\@dir_files_c, \@PDBcodes],
[\@dir_files_m, \@PDBcodes]
);
my ($kabat_filesRef, $chothia_filesRef, $martin_filesRef) =
getNumberedFileArray (@args);
$PDBnum = scalar @{$kabat_filesRef};
displayMessage ($cgi, $PDBnum, $nameAb);
if ( !$PDBnum) {
exit;
}
# De-referening
@kabat_files = @{$kabat_filesRef};
@chothia_files = @{$chothia_filesRef};
@martin_files = @{$martin_filesRef};
printTableKeyword(\@kabat_files, \@chothia_files, \@martin_files);
# To check if some of the files are missing for some reason
if ( ( @kabat_files == @chothia_files) and ( @kabat_files == @martin_files)
and (@chothia_files == @martin_files) ) {
}
else {
displayMissingFilesError($cgi);
}
}
exit;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Search for antibody and antigen species
if ( ( ($speciesAb) and ($speciesAg) and ($pdb_id eq "") ))
{
$pdb_id = 0;
print_html_header();
####################
my @PDBcodes = getTwoSpecies($speciesAb, $speciesAg, $antibodyChainsFile, $antigenChainsFile);
my $PDBnumS;
my @args = ( [\@dir_files_k, \@PDBcodes],
[\@dir_files_c, \@PDBcodes],
[\@dir_files_m, \@PDBcodes]
);
my ($kabat_filesRef, $chothia_filesRef, $martin_filesRef) =
getNumberedFileArray (@args);
$PDBnumS = scalar @{$kabat_filesRef};
displayMessageSpecOrg ($cgi, $PDBnumS, $speciesAb, $speciesAg);
if ( !$PDBnumS ) {
exit;
}
# De-referening
@kabat_files = @{$kabat_filesRef};
@chothia_files = @{$chothia_filesRef};
@martin_files = @{$martin_filesRef};
printTableKeyword(\@kabat_files, \@chothia_files, \@martin_files);
displayAntigenError($cgi);
# To check if some of the files are missing for some reason
if ( ( @kabat_files == @chothia_files) and ( @kabat_files == @martin_files)
and (@chothia_files == @martin_files) ) {
}
else {
displayMissingFilesError($cgi);
}
exit;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Search for antigen species only
if ( ($speciesAg) and ($nameAg eq "") and ($pdb_id eq "") )
{
$nameAg = 0;
$pdb_id = 0;
print_html_header();
my @PDBcodesS = getSpecies($speciesAg, $antigenChainsFile);
my $PDBnumS;
my @args = ( [\@dir_files_k, \@PDBcodesS],
[\@dir_files_c, \@PDBcodesS],
[\@dir_files_m, \@PDBcodesS]
);
my ($kabat_filesRef, $chothia_filesRef, $martin_filesRef) =
getNumberedFileArray (@args);
$PDBnumS = scalar @{$kabat_filesRef};
displayMessage ($cgi, $PDBnumS, $speciesAg);
if ( !$PDBnumS ) {
exit;
}
# De-referening
@kabat_files = @{$kabat_filesRef};
@chothia_files = @{$chothia_filesRef};
@martin_files = @{$martin_filesRef};
printTableKeyword(\@kabat_files, \@chothia_files, \@martin_files);
displayAntigenError($cgi);
# To check if some of the files are missing for some reason
if ( ( @kabat_files == @chothia_files) and ( @kabat_files == @martin_files)
and (@chothia_files == @martin_files) ) {
}
else {
displayMissingFilesError($cgi);
}
exit;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Search for antibody species
if ( ($speciesAb) and ($nameAg eq "") and ($pdb_id eq "") )
{
$nameAg = 0;
$pdb_id = 0;
print_html_header();
my @PDBcodesS = getSpecies ($speciesAb, $antibodyChainsFile);
my $PDBnumS;
my @args = ( [\@dir_files_k, \@PDBcodesS],
[\@dir_files_c, \@PDBcodesS],
[\@dir_files_m, \@PDBcodesS]
);
my ($kabat_filesRef, $chothia_filesRef, $martin_filesRef) =
getNumberedFileArray (@args);
$PDBnumS = scalar @{$kabat_filesRef};
displayMessage ($cgi, $PDBnumS, $speciesAb);
if ( !$PDBnumS ) {
exit;
}
# De-referening
@kabat_files = @{$kabat_filesRef};
@chothia_files = @{$chothia_filesRef};
@martin_files = @{$martin_filesRef};
printTableKeyword(\@kabat_files, \@chothia_files, \@martin_files);
# To check if some of the files are missing for some reason
if ( ( @kabat_files == @chothia_files) and ( @kabat_files == @martin_files)
and (@chothia_files == @martin_files) ) {
}
else {
displayMissingFilesError($cgi);
}
exit;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This is non-functional piece of code.. and needs to be removed
=pod
=cut
if (( $pdb_id) and (($nameAg) or ($speciesAg)) )
{
my $errorStr = "Please search by either PDB code or Keyword";
displayError ($errorStr,"");
}
else
{
my $errorStr = "Invalid PDB code or keyword!!!";
my $errorStr2 = "Please enter valid PDB code or keyword as string";
displayError ($errorStr, $errorStr2);
}
# ******************************************************
# ******************* METHODS **************************
# ******************************************************
sub getSpecies
{
my ($species, $chainsFile) = @_;
my @resultS = `grep SPECIES $logDir/$headerFile | grep "$species"`;
my @Matches;
foreach my $org (@resultS) {
my $PDB = substr ($org, 0, 4);
my @AbOrAgChains = split (":",`grep $PDB $logDir/$chainsFile`);
my @chains = split (/\,|""/,$AbOrAgChains[1] );
foreach my $chain ( @chains) {
chomp $chain;
my $matchedAbOrAg =
`grep "^$PDB : SPECIES : $chain : $species" $logDir/$headerFile`;
push (@Matches, $matchedAbOrAg);
}
}
my @PDBcodesS = uniq (map {substr ($_, 0, 4)} @Matches);
return @PDBcodesS;
}
sub getTwoSpecies
{
my ($speciesAb, $speciesAg, $AbchainsFile, $AgchainsFile) = @_;
# Grep all lines for searched species
my @resultSAb = `grep SPECIES $logDir/$headerFile | grep "$speciesAb"`;
my @Matches;
foreach my $org (@resultSAb) {
my $PDB = substr ($org, 0, 4);
# Look for chain labels for species PDB
my @AbChains = split (":",`grep $PDB $logDir/$AbchainsFile`);
my @AgChains = split (":",`grep $PDB $logDir/$AgchainsFile`);
# In case Ag has no chains, it will have space
# To remove space
if ( $AgChains[1] =~ m/\s+/) {
$AgChains[1] =~ s/\s+$//;
# next;
}
next if ( !$AgChains[1]);
my @ABchains = split (/\,|""/,$AbChains[1] );
my @AGchains = split (/\,|""/,$AgChains[1] );
my @twoSpeciesRes;
my (@ABSpecies, @AGSpecies);
for (my $i = 0; $i< scalar @ABchains; $i++ )
{
@ABSpecies = `grep "^$PDB : SPECIES : $ABchains[$i] : $speciesAb" $logDir/$headerFile`;
@AGSpecies = `grep "^$PDB : SPECIES : $AGchains[$i] : $speciesAg" $logDir/$headerFile`;
if ( ( @ABSpecies) and (@AGSpecies) ) {
push (@Matches, $PDB);
}
}
}
my @PDBcodesS = uniq (map {substr ($_, 0, 4)} @Matches);
return @PDBcodesS;
}