-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkpdbfinder
executable file
·3677 lines (3293 loc) · 108 KB
/
mkpdbfinder
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
# -*-Perl-*-
# $Id: mkpdbfinder,v 3.00 2000/05/31 15:42:46 elmar Exp $
#############################################################################
# reads in a file list from stdin and spits out a table with information about
# each chain in the given pdbfiles.
#############################################################################
#
# Usage:
# src/mkpdblist | nohup nice src/mkpdbfinder > PDBFIND.TXT 2> pdbfinder.err &
#
# (C) 1994-1996 by Rob W.W. Hooft, Michael Scharf, Gert Vriend and Chris Sander
# Updated to V3.0 in May 2000,V3.1 in January 2001 by Elmar Krieger
#
# This file is freely redistributable, but only in unmodified form.
# This copyright notice must be preserved on each copy. The latest
# version of the resulting database should always be available by FTP from
# ftp.embl-heidelberg.de. It is distributed as part of the WHAT IF
# program. Proper acknowledgement is required.
#
#
# Please note: The database version number is not a unique identification for
# the database, only for this script.
#
# v10.1: Sep 12, 2013 CB
# No longer treat electron microscopy as OTHER.
#
# v10.0:Apr 12, 2018 EK
# Modified the 'mmcif_first_revdate' subroutine.
# This fixes the problem that mmCIF files like 4V8S have date "?" in PDBFIND.TXT.
#
# v9.0: Sep 12, 2013 CB
# Added the 'read_mmcif' subroutine, which replaces 'read_pdb' if instead a mmCIF file must be parsed.
# This method executes the 'clean_protein' subroutine in the end, just like 'read_pdb' does.
#
# V8.0: Author field was suddenly truncated, fixed.
# Added options for new way of generating PDBFINDER (using separate files)
#
# V7.2: Cope with new nucleic acid names in the remediated PDB format: DA,DT,DG,DC
#
# V7.1: Allow to print Het-IDs '0', do not print empty chains
#
# V5.1: Jun 9, 2005 EK
# Added the 'Alternates' field that counts the number of residues with alternate
# locations, i.e. another residue at the same spot. This help to identify errors
# like the one in 1GTV, where two alternate chain conformations are labeled
# chain 'A' and 'B', leading to many problems (incorrect DSSP assignment etc,
# partly biased WHAT_CHECKs etc).
#
# V4.1: Nov 16, 2004 EK
# The secondary structure content statistics now also consider unusual amino acids.
#
# V3.3: Oct 13, 2003 EK
# Date field now contains release date from first REVDAT entry instead of
# deposition date from HEADER field.
#
# Dec 10, 2001 EK
# Found out that the script forgets the second in a pair of residues
# with the same number. Fixed.
#
# Nov 27, 2001 EK
# Found out that the script forgets chains with identifier zero '0'
# like in 1pov. Fixed.
#
# V3.2: Jun 22, 2001 EK
# The chains are now written in the same sequence as in the PDB file
# for consistency with other programs. (e.g. A,B,D,C in 1HQ6)
#
# V3.1: Jan 10, 2001 EK
# Chain breaks are now additionally detected based on the length
# of the peptide bond (CA-CA didn't work for 1A7S,PRO 44)
#
# V3.0: May 29, 2000 EK
# Several changes made to ensure proper sequence extraction from PDB files
#
# V2.8: Jan 18, 1995 RWWH
# Two R-factor corrections. R-factor to 3 decimal places. Under CVS,
# so this will be the last log of this style.
#
# V2.7: Nov 7, 1995 RWWH
# First shot at parsing new-style SOURCE and COMPND records. Bug fix in
# HET parsing (recognizes one more nonsense string). Add expression
# system parsing also for older PDB files. Changes in R-factor parsing
# to allow for newer PDB files. Changes in Upper/Lowercase parsing.
#
# V2.6: Apr 6, 1995 RWWH
# Added interpretation of 'SEE REMARK #' in HET. Changed some warnings,
# tidying up STDERR a bit. Made reuse of overlay possible.
#
# V2.5: Mar 28th, 1995 RWWH
# Added 'Ref-Prog' field.
#
# V2.4: Feb 20th, 1995 RWWH
# Removed two lines from overlay (deleted entries). Introduced new
# method 'OTHER', and made all other methods use it.
#
# V2.3: Jan 17th, 1995 RWWH
# Detect overlapping residues, invalidating the second one.
# Detect and count chainbreaks. No longer warn if "_mod" files are used.
#
# V2.2: Sep 12th-Oct 5th, 1994 RWWH
# Renamed database to PDBFINDER. Add HET groups that are missing from
# PDB files. Add overlay possibility for HET names. Correct a bug
# in the interpretation of UNK residues. More security warnings. Removed
# E.C. from source if specified in Enzyme-Code field. Got more E.C.
# numbers out. Moved E.C. number to be subfield of Compound. Dates into
# overlay. Warn if E.C. code not standard. Do not apply overlay if
# it does not match. Warn if "_mod" files are used.
#
# V2.1: Aug 31st, 1994 RWWH
# Make script more secure. Put "warn" commands in all places where
# things have once gone wrong. Add a few fields. Remove some bugs.
# Removed "E.C." literal from enzyme code.
#
# V2.0: Script by Michael Scharf (July 5th, 1994)
# with Modifications marked "#RWWH" by Rob Hooft.
#
$gVERSION='v9.0 - 2013-09-12';
# mmCIF parser:
#use STAR::Parser;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
use File::Basename;
# Add some option handling
use Getopt::Std;
my %opts;
getopts('HA:', \%opts);
my $suppress_header = $opts{H};
my $assemble_dir = $opts{A};
# some global assocative arrays:
# path list for mmCIF files
@gMMCIFPATH=(".","/srv/data/mmCIF/");
# list of possible mmCIF extensions
@gMMCIFEXT=(".cif",".cif.gz");
# path list for PDB files
#@gPDBPATH=(".","/data/srs/pdb/","/elmar/pdb/","/data/pdb/","/mnt/dosc/yasara/pdb/");
@gPDBPATH=(".","/srv/data/pdb/flat/");
# list of possible PDB extensions
@gPDBEXT=("",".brk",".brk_mod",".ent",".ent.gz",".pdb");
@gPDBPREFIX=("","pdb");
#path list for DSSP files
@gDSSPPATH=(".","/srv/data/dssp/","/elmar/dssp/");
# list of possible DSSP extensions
@gDSSPEXT=("",".dssp",".dssp_pre",".dssp_mod",".dssp_pre_mod");
#path list for HSSP files
#@gHSSPPATH=(".","/data/hssp/","/elmar/hssp/");
@gHSSPPATH=(".","/srv/data/hssp/");
# list of possible HSSP extensions
#@gHSSPEXT=("",".hssp",".hssp_pre",".hssp_mod",".hssp_pre_mod");
@gHSSPEXT=(".hssp.bz2",".hssp");
#path list for Structure Factor files
@gSFPATH=(".","/srv/data/rcsb/structure_factors/divided/");
# list of possible structure-factor extensions
@gSFEXT=("sf.ent","sf.ent.gz");
# list of possible structure-factor prefixes
@gSFPREFIX=("r");
# Where is the enzyme database?
@ENZYMEPATH=("/srv/data/enzyme/enzyme.dat");
$gHELIX='HGI'; # list of characters of DSSP summary colums. e.g 'HG' or 'H'
$gBETA='BE';
#
# the following associations associate 3 letter code with one letter code
#
%G_STD_AMINO_ACID=(
"ALA",'A',
"ARG",'R',
"ASN",'N',
"ASP",'D',
"CYS",'C',
"GLN",'Q',
"GLU",'E',
"GLY",'G',
"HIS",'H',
"ILE",'I',
"LEU",'L',
"LYS",'K',
"MET",'M',
"PHE",'F',
"PRO",'P',
"SER",'S',
"THR",'T',
"TRP",'W',
"TYR",'Y',
"VAL",'V'
);
%G_IGNORE= (
"ACE",'?'
);
%G_AMINO_ACID=(
%G_STD_AMINO_ACID,
"ASX",'B', # for dssp
"GLX",'Z', # for dssp
"UNK",'X'
);
%G_WATER=(
"HOH",'w',
"H2O",'w',
"WAT",'w',
"DOD",'w'
);
%G_NUCLEIC=(
" A",'a',
" DA",'a',
" +A",'a',
"1MA",'a',
" C",'c',
" DC",'c',
" +C",'c',
"5MC",'c',
"5NC",'c',
"OMC",'c',
" G",'g',
" DG",'g',
" +G",'g',
" I",'?',
"1MG",'g',
"2MG",'g',
"M2G",'g',
"7MG",'g',
"OMG",'g',
" YG",'g',
" T",'t',
" DT",'t',
" +T",'t',
" U",'u',
" +U",'u',
"H2U",'u',
"5MU",'u',
"PSU",'u',
"UKN",'?',
);
%G_MONTH=(
"JAN","01",
"FEB","02",
"MAR","03",
"APR","04",
"MAY","05",
"JUN","06",
"JUL","07",
"AUG","08",
"SEP","09",
"OCT","10",
"NOV","11",
"DEC","12"
);
%G_MAX_MONTH=(
"JAN",31,
"FEB",29,
"MAR",31,
"APR",30,
"MAY",31,
"JUN",30,
"JUL",31,
"AUG",31,
"SEP",30,
"OCT",31,
"NOV",30,
"DEC",31
);
# List of known refinement programs.
%known_programs = (
'AMBER', 'AMBER',
'AMORE', 'AMORE',
'ARP', 'ARP',
'ATOM', 'ATOM',
'CALIBA', 'CALIBA',
'CCP4', 'CCP4',
'CEDAR', 'CEDAR',
'CHARMM', 'CHARMM',
'CNS', 'CNS',
'CORELS', 'CORELS',
'CORMA', 'CORMA',
'CRLS', 'CRLS',
'CRYLSQ', 'CRYLSQ',
'DERIV', 'DERIV',
'DGII', 'DGII',
'DIAMOND', 'DIAMOND',
'DIANA', 'DIANA',
'DINOSAUR', 'DINOSAUR',
'DISCOVER', 'DISCOVER',
'DISGEO', 'DISGEO',
'DISMAN', 'DISMAN',
'DSPACE', 'DSPACE',
'ECEPP', 'ECEPP',
'EMBOSS', 'EMBOSS',
'EREF', 'EREF',
'FANTOM', 'FANTOM',
'FREF', 'FREF',
'FRODO', 'FRODO',
'GENERATE', 'GENERATE',
'GPRLSA', 'GPRLSA',
'GRINCH', 'GRINCH',
'GROMOS', 'GROMOS',
'GROMOS-', 'GROMOS',
'GROMOS-MDX', 'GROMOS-MDX',
'HABAS', 'HABAS',
'HAFFIX', 'HAFFIX',
'HKSCAT', 'HKSCAT',
'INSIGHTII', 'INSIGHTII',
'IRMA', 'IRMA',
'JACK-LEVITT', 'EREF',
'LOOP', 'LOOP',
'MANOSK', 'MANOSK',
'MARDIGRAS', 'MARDIGRAS',
'MIDGE', 'MIDGE',
'MM', 'MM',
'MODELFIT', 'MODELFIT',
'MUMOD', 'MUMOD',
'NCS', 'NCS',
'NOEMOL', 'NOEMOL',
'NUCLIN', 'NUCLIN',
'NUCLIN-NUCLSQ', 'NUCLIN/NUCLSQ',
'NUCLSQ', 'NUCLSQ',
'OMIT', 'OMIT',
'OPAL', 'OPAL',
'PHENIX', 'PHENIX',
'PIKSOL', 'PIKSOL',
'PRESTO', 'PRESTO',
'PROFFT', 'PROFFT',
'PROLSQ', 'PROLSQ',
'PROTEIN', 'PROTEIN',
'PROTIN', 'PROTIN',
'PSFRODO', 'PSFRODO',
'QUANTA', 'QUANTA',
'REFMAC', 'REFMAC',
'RESLSQ', 'RESLSQ',
'RESTRAIN', 'RESTRAIN',
'ROTLSQ', 'ROTLSQ',
'RSREF', 'RSREF',
'SCATT', 'SCATT',
'SFALL', 'SFALL',
'SFRK', 'SFRK',
'SHELX', 'SHELX',
'SHELX-', 'SHELX',
'SHELXL', 'SHELXL',
'SHELXL-', 'SHELXL',
'STEREOSEARCH', 'STEREOSEARCH',
'STEROSEARCH', 'STEREOSEARCH',
'TNT', 'TNT',
'TOM', 'TOM',
'ULTIMA', 'ULTIMA',
'VEMBED', 'VEMBED',
'XPLOR', 'X-PLOR',
'X-PLOR', 'X-PLOR',
'XEASY', 'XEASY',
'YASAP', 'YASAP',
'YASARA','YASARA',
);
# global to hold per chain compound information
my $CH_CMP;
# EK: print a warning message to mkpdbfinder.err
# The old way of using warn to print to STDERR had to be removed due to
# various problems with output redirection from Python scripts
# (PDBFINDER is called from what_modelbase.py)
sub warning {
open(LOG, ">>pdbfinder.err");
print LOG @_;
close(LOG);
}
# read the data from the __END__ lines
sub init_overlay {
local($id,$oldval,$newval);
# read hand edited stuff from this file after the __END__ line...
while(<DATA>) {
chop;
next if ( /^\#/);
next if ( /^\s*$/);
die "Syntax error in overlay : $_"
unless /^([^ ]+) \"(([^\"\t]+)\t+)?([^\"\t]*)\"/;
$id=$1;
$oldval=$3;
$newval=$4;
#print "Debug: \"$id\" \"$oldval\" \"$newval\"\n";
$gOVERLAY{$id}=$newval;
$gEXPECT{$id}=$oldval;
}
}
sub init_enzyme {
local($ENZid,$file);
$enzyme_initialized++;
for $file (@ENZYMEPATH) {
if (-r $file) {
open(ENZ,"<$file") || die "Could not open enzyme data file\n";
while (<ENZ>) {
if (/^ID\s+(.*)$/) {
$ENZid=$1;
} elsif (/^DE\s+DELETED ENTRY/) {
$ENZ{$ENZid}="deleted" if $ENZid;
$ENZid="";
} elsif (/^DE\s+TRANSFERRED ENTRY:\s+(.*)$/) {
$ENZ{$ENZid}="transferred to $1" if $ENZid;
$ENZid="";
} elsif (/^\/\//) {
$ENZ{$ENZid}=1 if $ENZid;
}
}
close(ENZ);
return;
}
}
}
sub scan_enzyme {
local ($id)=@_;
if (!$enzyme_initialized) { &init_enzyme; }
if ($ENZ{$id}) {
if ($ENZ{$id}==1) {
return 0;
} else {
warning "$PID: Enzyme code check fails: $id $ENZ{$id}\n";
if ($ENZ{$id}=~/^T/) {
return 1;
} else {
return 2;
}
}
} elsif ($id=~/-$/) {
return 0; # Assume wild-card exists.
} else {
warning "$PID: Enzyme code check fails: Nonexisting $id\n";
return 3;
}
}
sub assemble_file
{
my ($data_dir) = @_;
&print_head;
opendir(my $dh, $data_dir) or die "Could not open directory $data_dir: $!\n";
my @files = sort grep { -f "$data_dir/$_" } readdir($dh);
closedir($dh);
foreach my $file (@files) {
open(my $h, "<$data_dir/$file") or die "Could not read file $file: $!\n";
while (my $line = <$h>) { print $line; }
close($h);
}
&print_tail;
}
#############################################################################
# Main program
{
local($file,$pdbfile,$mmciffile,$dsspfile,$hsspfile,$numfiles);
if (defined $assemble_dir) {
&assemble_file($assemble_dir);
exit;
}
&print_head unless $suppress_header;
&init_overlay();
# Process all files mentioned on input
while ($infiles=<>) {
@infiles=split(' ',$infiles);
foreach $file (@infiles) {
$numfiles++;
$file=~ tr/ \t\n//d; #get rid of any whitespace...
&clean_protein();
# get the brookhaven 4 letter code from the filename!
$id=&strip_extension(&strip_path($file));
$PID=$id;
$PID=~tr/a-z/A-Z/;
warning "PDB or mmCIF file not found for $file\n"
unless ( ($pdbfile=&find_file($file,*gPDBPATH,*gPDBEXT,*gPDBPREFIX)) or ($mmciffile=&find_file($file,*gMMCIFPATH,*gMMCIFEXT)) );
$PDB_FILE=&strip_path($pdbfile);
$MMCIF_FILE=&strip_path($mmciffile);
#warning "$PDB_FILE = $pdbfile" if ($pdbfile=~/_mod/);
$nodssp++
unless ($dsspfile=&find_file($id,*gDSSPPATH,*gDSSPEXT));
$DSSP_FILE=&strip_path($dsspfile);
#warning "$DSSP_FILE = $dsspfile" if ($dsspfile=~/_mod/);
$nohssp++
unless ($hsspfile=&find_file($id,*gHSSPPATH,*gHSSPEXT));
$HSSP_FILE=&strip_path($hsspfile);
#warning "$HSSP_FILE = $hsspfile" if ($hsspfile=~/_mod/);
$nosf++
unless ($sffile=&find_file($id,*gSFPATH,*gSFEXT,*gSFPREFIX));
$HSSP_FILE=&strip_path($hsspfile);
&read_dssp($dsspfile) if $dsspfile;
&read_hssp($hsspfile) if $hsspfile;
&read_sf($sffile) if $sffile;
if ($pdbfile)
{
&read_pdb($pdbfile);
}
elsif($mmciffile)
{
&read_mmcif($mmciffile);
}
}
}
&print_tail unless $suppress_header;
if ($METHOD=~/MODEL/) {
warning "Model $PID has not been renamed\n" unless ($pdbfile=~/_mod/);
} else {
warning "Non-Model $PID has been renamed to _mod\n" if ($pdbfile=~/_mod/);
}
#RWWH: Make sure there were no typos
if ($numfiles>5) {
foreach $f (sort keys %gOVERLAY) {
warning "Unused overlay line : $f $gOVERLAY{$f}\n" unless $gOverUsed{$f};
}
}
}
#RWWH Header of the file
sub print_head {
local($host,$date);
print "//PDBFINDER - $gVERSION\n";
if (open(H,'hostname|')) {
$host=<H>;
chop $host;
close(H);
}
if (open(D,'date|')) {
$date=<D>;
chop $date;
close(D);
}
print "//$date for $ENV{USER} on $host\n";
print "//\n";
print "// This file is PDBFIND.TXT\n";
print "//\n";
print "// Important change: Starting with 2003/10/13, the Date field contains the\n";
print "// release date (in PDB REVDAT 1) and not the deposition date (in PDB HEADER)\n";
print "//\n";
print "// (C) 1996-2003 by Rob W.W. Hooft, Chris Sander, Michael Scharf and\n";
print "// Gert Vriend. Updated to V8.0 in Nov 2011 by M.L. Hekkelman\n";
print "//\n";
print "// This copyright notice must be preserved on each copy. The latest\n";
print "// version of this database should always be available by FTP from\n";
print "// ftp://ftp.cmbi.umcn.nl/pub/molbio/data/pdbfinder\n";
print "// It is distributed as part of the WHAT IF program. Proper acknowledgement\n";
print "// is required.\n";
print "//\n";
}
#RWWH Tail of the file
sub print_tail {
local($date);
if (open(D,'date|')) {
$date=<D>;
chop $date;
close(D);
}
print "// Finished processing $date\n";
}
sub strip_path {
local($file)=@_;
# get rid of the path
$file=~ s/^.*\///;
$file;
}
sub strip_extension {
local($file)=@_;
# get rid of the extension
$file =~ s/pdb([0-9][0-9a-z]{3})\.ent/$1/i;
$file=~ s/\..*$//;
$file;
}
# searches a given name in some paths ...
sub find_file {
local($name,*Path,*Ext,*inPrefix)=@_;
local($path,$ext,$fn);
# maybe we got a full name?
if(-e $name) {
return $name;
}
if ($#inPrefix>=0) {
@Prefix=@inPrefix;
} else {
@Prefix=("");
}
# try all paths
foreach $path (@Path) {
# try all extensions
foreach $ext (@Ext) {
# try all prefixes
foreach $prefix (@Prefix) {
$fn="$path/$prefix$name$ext";
# does the file exist?
if (-e $fn) {
$fn =~ s,//,/,g; #globally substitute // by /
return $fn;
}
$fn="$path/".substr($name,1,2)."/$prefix$name$ext";
# does the file exist?
if (-e $fn) {
$fn =~ s,//,/,g; #globally substitute // by /
return $fn;
}
}
}
}
return "";
}
sub clean_dssp {
undef %DSSP_STRUC; # secondary structure indexed by resid
undef %DSSP_LINK1; # bp1
undef %DSSP_LINK2; # bp2
undef %DSSP_CIS; # cysteins in DSSP
}
sub clean_sf {
undef $minh;
undef $mink;
undef $minl;
undef $maxh;
undef $maxk;
undef $maxl;
undef $nrefl;
undef $sftype;
}
sub clean_hssp {
undef $HSSP_NALIGN; # Total number of alignments
undef %SWISSID;
}
sub clean_protein {
undef $PID; # 4 letter code of this protein
undef @COMPND; # holds the COMPND record
undef $CH_CMP; # holds per chain COMPND info (MLH)
undef @SOURCE; # holds the SOURCE record
undef $EXPSYS; # Holds the expression system
undef @AUTHOR; # holds the Authors
undef @ECODES; # Enzyme Code (EC...)
undef @HEADER; # holds the HEADER record
undef $DATE; # originally held the DATE from the HEADER, but now the relase date from REVDAT
undef $PDB_FILE; # holds filename.extension but no path!
undef $MMCIF_FILE; # holds filename.extension but no path!
undef $DSSP_FILE; # holds filename.extension but no path!
undef $HSSP_FILE; # holds filename.extension but no path!
undef $RESOLUTION; # resolution in Angstrom; extracted from REMARK records
undef $PROGRAM; # Refinement programs separated by "/"
undef $NMODELS; # Number of NMR Models
undef $R_FACTOR; # R-factor (0..1); extracted from REMARK records
undef $FREE_R; # Free R-factor
undef $METHOD; # can become [X|NMR|MODEL|ED]
undef @CHAINS; # an array with all its chain id's
undef @REMARK; # all remarks indexed by remark number
#RWWH Added interpretation of HET records.
undef $N_HET; # Number of HET groups.
undef @HET_CODE; # HET code, indexed by HET number
undef @HET_NAME; # HET name, indexed by HET number
undef @HET_NATOM; # Number of atoms in HET group, indexed by HET number
undef @HET_ID; # ID of hetgroup
undef @HET_CHAIN; # Chain of HET
undef %HET_REVERSE;# HET number corresponding to ID.
#----------------------------------------------------------------------
#
# Items with information about each chain indexed by $CHAIN (1 character)
#
undef %CHAINS; # how often each chain occurs
undef %N_AMINO_ACIDS; # Number of residues of ANY type
undef %N_NUCLEIC; # Number of nucleic residues
undef %N_WATER; # Number of water molecules
undef %N_SUBSTRATE; # Number of other residues
undef %N_STD_AA; # the 20 aa's. Only ATOM records are considered.
undef %N_NONSTD_AA; # things with a backbone in ATOM or HETATM lines
undef %N_BACKBONE; # residues which contain the following 4 atoms:
# ' N ', ' CA ', ' C ', ' O '
undef %N_SIDECHAIN; # residues with a backbone with at least
# one sidechain atom.
# GLY are per definition complete (they count here)!
undef %N_CA; # stdandard AA's where only the ' CA ' atom is present
undef %N_UNK; # aa residues called UNK in ATOM lines
undef %N_GLY; # number of GLY residues
undef %N_ALA; # number of ALA residues
undef %N_SEC_STRUC; # number of AA with DSSP defined sec structure
undef %N_HELIX; # number of AA in DSSP helix ($gHELIX)
undef %N_A_HELIX; # number of AA in DSSP alpha helix H
undef %N_G_HELIX; # number of AA in DSSP g Helix
undef %N_I_HELIX; # number of AA in DSSP I Helix
undef %N_BETA; # number of AA in DSSP beta ($gBETA)
undef %N_B_BETA; # number of AA in DSSP B beta
undef %N_E_BETA; # number of AA in DSSP E beta
undef %N_PAR_HB; # number of h-bonds parallel in DSSP
undef %N_ANT_HB; # number of h-bonds anti parallel in DSSP
undef %N_CYSS; # cysteins involved in SS-bond
undef %SEQUENCE; # non standard AA's are X unknowns are U
# Nucleic sequences are lowercase!
undef $ignorechainflag;# EK: Do not add a chain to output
#---------------------------------------------------------------------
&clean_dssp;
&clean_hssp;
&clean_sf;
&clean_chain;
&clean_residue;
}
sub clean_chain {
undef $CH_N_AMINO_ACIDS;
undef $CH_N_SUBSTRATE;
undef $CH_N_WATER;
undef $CH_N_NUCLEIC;
undef $CH_N_STD_AA;
undef $CH_N_NONSTD_AA;
undef $CH_N_BACKBONE;
undef $CH_N_SIDECHAIN;
undef $CH_N_CA;
undef $CH_N_UNK;
undef $CH_N_GLY;
undef $CH_N_ALA;
undef $CH_N_SEC_STRUC;
undef %CH_SEC_STRUC;
undef $CH_N_HELIX;
undef $CH_N_BETA;
undef $CH_N_PAR_HB;
undef $CH_N_ANT_HB;
undef $CH_N_CYSS;
undef $CH_SEQUENCE;
$CHAIN="None"; # the current chain id, undef cannot be used
undef $CHAINBREAK;
}
sub clean_residue {
# counts of different atoms for the current residue:
# clean all atom counts for this residue
$N_N=0;
$N_CA=0;
$N_C=0;
$N_O=0;
$N_OXT=0;
$N_OTHER=0;
$N_ATOM=0; # number of atoms in ATOM lines
$N_HETATM=0; # number of atoms in HETATM lines
$DNA_BBFLAGS=0; # remember which DNA backbone atoms have been found
undef $RESIDUE_ID; # identifier of current residue
undef $RESIDUE; # 3 letter code of the currend residue
undef $CHAINBREAKFLAG; # EK: This flag is set if there is a chain break before the residue
}
sub extract_general_info {
&extract_resolution(@REMARK[2]);
&extract_rfactor(@REMARK[3]);
&extract_freer(@REMARK[3]);
$PROGRAM=&extract_program(@REMARK[3]);
# MUST BE AFTER rfactor and resolution !!!!
&extract_method(@REMARK[4] . @REMARK[5]);
# apply overlay...
$METHOD =&get_overlay($PID,'MET',$METHOD);
#
# R-factors for NMR are impossible to handle. All different
#
if ($METHOD eq 'NMR') {
undef $RESOLUTION;
undef $R_FACTOR;
undef $FREE_R;
}
#
# Overlay for R and Resolution.
#
$R_FACTOR =&get_overlay($PID,'RFA',$R_FACTOR);
$RESOLUTION=&get_overlay($PID,'RES',$RESOLUTION);
}
sub extract_resolution {
local($line)=@_;
local(@resolutions);
# iterate over the remark line and take each potential candidate
while ($line =~ /RESOLUTION[.]?\s*([0-9+.\/]+)\s*ANGSTROM/) {
if ($1 == 0.0) {
warning "Zero resolution in $PID\n";
} else {
push(@resolutions,$1);
}
$line=$'; # take the rest as next search string
if(@resolutions) {
$RESOLUTION=join("/",@resolutions);
}
}
}
sub extract_rfactor {
local($remark)=@_;
local(@rfactors,$context,$prev,$foll,$match);
# iterate over the remark line and take each number as potential candidate
while($remark =~ /\b\d*\.?\d+/){
$remark=$'; # take the rest as next search string
$context.=$`; # save the stuff before the number as context
$prev=$context; # the stuff before the number
$match=$&;
$context.=$&; # add the match to the context
#print STDERR substr($prev,length($prev)-70)."\n\n";
if($prev =~ /(FREE\s*)?\bR
(\s*-?\s*(VALUE|FACTOR))?
(\s*\(WORKING\s\+\sTEST\sSET,\sNO\sCUTOFF\))?
(\s*\((WITH|NO)\sSIGMA\sCUTOFF\))?
(\s*\(WORKING\sSET\))?
(\s*\(WORKING\s\+\sTEST\sSET\))?
(\s*\(F\>4SIG\(F\)\))?
(\s*\(NO\sCUTOFF\))?
(\s*\(WORKING\sSET,\sNO\sCUTOFF\))?
(\s*(IS|OF|LESS)[\sA-Z]*)?
(\s*:)?
\s*$/x
||$prev =~ /\bR\s*=\s*$/ ) {
next if (length($1)>0);
# numbers > 1 will be divided by 100!
if($match>1) {
$match=sprintf("%.3f",$match/100);
}
# collect all potential candidates..
#print STDERR substr($prev,length($prev)-70)." ====> $match\n";
push(@rfactors,$match);
}
}
if(@rfactors) {
$R_FACTOR=join("/",@rfactors);
}
#print "$R_FACTOR\n";
}
sub extract_freer {
local($remark)=@_;
local(@freer,$context,$prev,$foll,$match);
# iterate over the remark line and take each number as potential candidate
while($remark =~ /\b\d*\.?\d+/){
$remark=$'; # take the rest as next search string
$context.=$`; # save the stuff befor the number as context
$prev=$context; # the stuff befor the number
$match=$&;
$context.=$&; # add the match to the context
#print STDERR substr($prev,length($prev)-70)."\n";
if($prev =~ /\bFREE\sR
(\s*-?\s*(VALUE|FACTOR))
(\s*\((WITH|NO)\sSIGMA\sCUTOFF\))?
(\s*\(WORKING\sSET\))?
(\s*\(F\>4SIG\(F\)\))?
(\s*\(NO\sCUTOFF\))?
(\s*\(WORKING\sSET,\sNO\sCUTOFF\))?
(\s*:)?
\s+$/x) {
# collect all potential candidates..
#print STDERR substr($prev,length($prev)-70)." ====> $match\n";
push(@freer,$match);
}
if(@freer) {
$FREE_R=join("/",@freer);
}
}
}
sub extract_program {
local($r)=@_;
local($program,$collect,$newcollect);
$r=~s/\s+/ /g;
$r=~s/INSIGHT II/INSIGHTII/g;
$collect="";
for (;;) {
$program="";
if ($r=~/PROGRAM\s+:\s+([-A-Z]+)/) {
$program=$1;
$r=~s/PROGRAM\s+:\s+//;
} elsif ($r=~/PROGRAM 1 ([-A-Z]+)/) {
$program=$1;
$r=~s/PROGRAM 1//g; # only one program from these lines...
} elsif ($r=~/PROGRAM 2 ([-A-Z]+)/) {
$program=$1;
$r=~s/PROGRAM 2//g;
} elsif ($r=~/PROGRAM 3 ([-A-Z]+)/) {
$program=$1;
$r=~s/PROGRAM 3//g;
} elsif ($r=~/PROGRAM 4 ([-A-Z]+)/) {
$program=$1;
$r=~s/PROGRAM 4//g;
} elsif ($r=~s/PROGRAMS [\*\"\']?([A-Z]+)[\*\"\']? AND [\*\"\']?([A-Z]+)//) {
$program="$1/$2";
} elsif ($r=~s/(PROGRAMS?|PACKAGE) [\*\"\']?([^ \d\*\(\)\";\,\.\']+)//) {
$program=$2;
} elsif ($r=~s/\(?\*([-A-Z]+)\*\)?//) {
$program=$1;
} elsif ($r=~s/\(\"([-A-Z]+)\"\)//) {
$program=$1;
} elsif ($r=~s/THE [\"\*]?([^ \*\(\)\,\"]+)[\"\*]? (PRO(GRAM|CEDURE)|PACKAGE)//) {
$program=$1;
} elsif ($r=~s/USING \*?([-A-Z]+)\*?//) {
$program=$1;
} elsif ($r=~s/JACK.*LEVITT//) {
$program='EREF';
} elsif ($r=~s/BRUNGER// && !$program=~/CNS/) {
$program='X-PLOR';
} elsif ($r=~s/DIAMOND// && $r=~s/REAL[- ]SPACE//) {
$program='DIAMOND';
} elsif ($r=~s/KONNERT// && $r=~s/HENDRICKSON//) {
if ($r=~/NUCLEIC/) {
$program='NUCLSQ';
} else {
$program='PROLSQ';
}
} elsif ($r=~s/USING \*?([-A-Z]+)\*?//) {
$program=$1;
}
last unless ($program);
if ($program=~/LSQ$/) {
$r=~s/KONNERT//g; # Prevent the other ones from appearing too...
}
$collect.="/$program" if index($collect,$program)<$[;
$program=~s/(\W)/\\\1/g;
}
$collect=~s/^\///;
#print "Collected : $collect\n";
if ($collect) {
$newcollect="";
foreach $program (split('/',$collect)) {
if (defined $known_programs{$program}) {
$newcollect.="/$known_programs{$program}"
if index($newcollect,$known_programs{$program})<$[;
}
}
$newcollect=~s/^\///;
return $newcollect;
} elsif ($r=~/REFINEMENT\.? NONE/) {
return "NONE";
} else {
return "";
}
}
sub extract_method {
local($line)=@_;
local($wasnot)=0;
unless ($METHOD) { #might have been defined in a EXPDTA line
$wasnot=1;
if($RESOLUTION || $R_FACTOR) {
# What else can it be if there is resolution or rfactor?
$METHOD='X-RAY';
} elsif ($line =~ /NMR/) {
# If they use the word NMR and don't give a resolution
# or rfactor nor put a EXPDTA line then I think it's a
# NMR-structure ;-)
$METHOD='NMR';
}
#RWWH New rule: If we don't know, it's a model.....
unless ($METHOD) {
$METHOD='MODEL';
}
}
# make the output more compact!
if($METHOD =~/NMR/) {
$METHOD='NMR';
} elsif ($METHOD =~/X-RAY/) {