-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_fragments.pl
executable file
·1985 lines (1728 loc) · 62.1 KB
/
make_fragments.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
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/perl -w
use strict;
# Resolve symlinks to find source deploymnet
use FindBin qw( $RealBin );
my $Bin = $RealBin;
use constant VERSION => 3.10;
$| = 1; # disable stdout buffering
# Install and build Rosetta and that's it. See fragments.README.
#
# This script initially installs all other dependencies. The installation takes
# a long time due to downloading and formatting the NCBI non-redundant sequence
# database. If you have any dependencies already installed, you can optionally
# modify the configuration below. The installation requires ~73+ Gigs of free
# disk space.
###############################################################################
# OPTIONAL USER CONFIGURATION -- ONLY CHANGE THIS SECTION IF NECESSARY
###############################################################################
# REQUIRED
# Rosetta https://www.rosettacommons.org
#
# The script "install_dependencies.pl" installs external dependencies:
# ./blast ftp://ftp.ncbi.nih.gov/blast/executables/release/2.2.17/
# ./databases/nr ftp://ftp.ncbi.nih.gov/blast/db/FASTA/nr.gz
# ./psipred http://bioinfadmin.cs.ucl.ac.uk/downloads/psipred/
# ./databases/nr_pfilt from ./databases/nr using ./psipred/bin/pfilt
# ./sparks-x http://sparks-lab.org/yueyang/server/SPARKS-X/
# ./csblast https://github.com/cangermueller/csblast
# ROSETTA
my $FRAGMENT_PICKER = "$Bin/../../main/source/bin/fragment_picker.boost_thread.linuxgccrelease";
my $FRAGMENT_PICKER_NUM_CPUS = 8; # number of processors to use
my $ROSETTA_DATABASE = "$Bin/../../main/database"; # rosetta database
my $VALL = "$Bin/vall.jul19.2011"; # template database
# BLAST path (Requires non-blast+ NCBI version)
my $BLAST_DIR = "$Bin/blast";
my $BLAST_NUM_CPUS = 8; # number of processors to use (blastpgp -a option)
# NR database path
my $NR = "$Bin/databases/nr";
# spine-x/sparks (for phi, psi, and solvent accessibility predictions)
my $SPARKS = "$Bin/sparks-x/bin/buildinp_query.sh";
# PSIPRED (for secondary structure prediction)
my $PSIPRED_DIR = "$Bin/psipred";
my $PSIPRED_USE_weights_dat4 = 0; # set to 0 if using psipred version 3.2+
# CSBLAST/CSBUILD (for de-novo sequence profile generation)
my $CSBLAST_DIR = "$Bin/csblast";
# pfilt filtered NR database used for PSIPRED (see PSIPRED readme)
# $NR will be used if empty
my $PFILTNR = "$Bin/databases/nr_pfilt";
my $INTERNET_HOST = "localhost";
### EXTRA OPTIONAL FEATURES ###################################################
###############################################################################
# This is an optional script that YOU must provide to launch parallel jobs on
# your cluster. The script should take any command as the argument(s).
# If the script does not exist, jobs will run serially.
# Requires: http://search.cpan.org/CPAN/authors/id/D/DL/DLUX/Parallel-ForkManager-0.7.5.tar.gz
my $SLAVE_LAUNCHER = "";
my $SLAVE_LAUNCHER_MAX_JOBS = 40; # depends on your available machines/cpus
## for SLAVE_LAUNCHER parallel jobs
my $SLAVE_MAX_WAIT = 96 * 60 * 60;
my $SLAVE_MAX_ATTEMPTS = 2;
# pdb2vall.py script for adding specific PDBs to the vall (-add_pdbs_to_vall)
# --no_structure_profile option is added to reduce the run time
# This feature is not supported yet in the Rosetta release
my $PDB2VALL = "$Bin/pdb2vall/pdb2vall.py --no_structure_profile";
my $PDB2VALL_IGNORE_ERRORS = 1; # ignore pdb2vall jobs that fail
# The following can be ignored unless you want to use the secondary structure prediction
# quota system with Psipred, SAM, and Porter. The porter should be in psipred_ss2 format
# using 'ss_pred_converter.py'.
# SAM install path
# http://compbio.soe.ucsc.edu/sam2src/
my $SAM_DIR = "";
# SAM predict-2nd install path
# Secondary structure prediction software using SAM sequence alignment
# http://users.soe.ucsc.edu/~karplus/predict-2nd/
my $SAM_PREDICT_2ND_DIR = "";
# PORTER (secondary structure prediction software)
# http://distill.ucd.ie/porter/
my $PORTER = "";
my $INSTALL_DEPENDENCIES = "standard"; # "overwrite";
my $INSTALL_DEPENDENCIES_DATABASE = "nr"; # "uniref50" # "uniref90"
### YOU CAN IGNORE THE REST ###################################################
###############################################################################
use File::Path;
use File::Copy qw/ copy /;
use File::Basename;
use Time::Local;
use Cwd qw/ cwd abs_path /;
use bytes;
my %options;
# initialize options
my %opts = &getCommandLineOptions();
$options{fastafile} = abs_path( $opts{f} );
$options{rundir} = cwd(); # get the full path (needed for sam stuff)
$options{homs} = 1;
$options{frags} = 1;
$options{csbuild_profile} = 0;
$options{psipredfile} = "";
$options{samfile} = "";
$options{porterfile} = "";
$options{psipred} = 1; # use psipred by default
$options{porter} = 0; # skip porter by default
$options{sam} = 0; # skip sam by default
$options{id} = "temp";
$options{chain} = "_";
$options{runid} = "temp_";
$options{cleanup} = 1;
$options{torsion_bin} = 0;
$options{exclude_homologs_by_pdb_date} = 0;
$options{old_name_format} = 0;
$options{add_pdbs_to_vall} = "";
my @cleanup_files = ();
my @fragsizes = ( 3, 9 ); #4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 );
my @add_vall_files = ();
my @use_vall_files = ();
my @pdbs_to_vall = ();
$options{n_frags} = 200;
$options{n_candidates} = 1000;
foreach my $key ( keys %opts ) {
$options{$key} = $opts{$key};
}
$options{DEBUG} = 1 if ( $options{verbose} );
### check for dependencies and install if necessary
$BLAST_DIR = "$Bin/blast" if (!-d "$BLAST_DIR/bin" || !-d "$BLAST_DIR/data");
$SPARKS = "$Bin/sparks-x/bin/buildinp_query.sh" if (!-s $SPARKS);
$PSIPRED_DIR = "$Bin/psipred" if (!-d "$PSIPRED_DIR/bin" || !-d "$PSIPRED_DIR/data");
my @POSSIBLE_NR_LOCATIONS = (
$NR,
"$Bin/databases/nr",
"$Bin/../../../databases/nr/nr",
"/scratch/robetta/local_db/nr/nr",
"/work/robetta/databases/local_db/nr/nr"
);
my $skip_nr = "";
foreach my $n (@POSSIBLE_NR_LOCATIONS) {
if (-s "$n.pal") {
$NR = $n;
$skip_nr = "skip_nr";
last;
}
}
foreach my $n (@POSSIBLE_NR_LOCATIONS) {
if (-s $n."_pfilt.pal") {
$PFILTNR = $n."_pfilt";
last;
}
}
my $must_install = 0;
if (!-d "$BLAST_DIR/bin" || !-d "$BLAST_DIR/data") {
print "Dependency 'blast' does not exist!\n";
$must_install = 1;
} elsif (!-s $SPARKS) {
print "Dependency 'sparks-x' does not exist!\n";
$must_install = 1;
} elsif (!-d "$PSIPRED_DIR/bin" || !-d "$PSIPRED_DIR/data") {
print "Dependency 'psipred' does not exist!\n";
$must_install = 1;
}
if (!$options{csbuild_profile}) {
if (!-s "$NR.pal") {
print "Dependency 'nr' does not exist!\n";
$NR = "$Bin/databases/nr";
$must_install = 1;
} elsif (!-s "$PFILTNR.pal") {
print "Dependency 'nr_pfilt' does not exist!\n";
$PFILTNR = "$Bin/databases/nr_pfilt";
$skip_nr = "";
$must_install = 1;
}
} else {
$skip_nr = "skip_nr";
}
if ($must_install && $INSTALL_DEPENDENCIES) {
print "\n";
print "Running install_dependencies.pl\n";
print "Note: the NCBI non-redundant (nr) sequence database is very large.\n";
print "Please be patient.....\n\n";
system("$Bin/install_dependencies.pl $INSTALL_DEPENDENCIES $INSTALL_DEPENDENCIES_DATABASE $skip_nr");
print "\n";
}
## THESE FILE LOCATIONS DEPEND ON THE SOFTWARE PACKAGE
my $PSIBLAST = "$BLAST_DIR/bin/blastpgp -a $BLAST_NUM_CPUS ";
my $MAKEMAT = "$BLAST_DIR/bin/makemat"; # makemat utility (part of NCBI tools)
my $PSIPRED = "$PSIPRED_DIR/bin/psipred"; # psipred
my $PSIPASS2 = "$PSIPRED_DIR/bin/psipass2"; # psipass2 (part of psipred pkg)
my $PSIPRED_DATA = "$PSIPRED_DIR/data"; # dir containing psipred data files.
my $SAM = "$SAM_DIR/bin/target99"; # sam target99
my $SAM_uniqueseq = "$SAM_DIR/bin/uniqueseq"; # sam uniqueseq
my $CSBUILD = "$CSBLAST_DIR/bin/csbuild";
# check for picker
if (!-s $FRAGMENT_PICKER) {
warn "WARNING! $FRAGMENT_PICKER does not exist. Trying default.\n";
$FRAGMENT_PICKER =~ s/fragment_picker[^\/]*(\.[^\.]+)$/fragment_picker$1/;
if (!-s $FRAGMENT_PICKER) {
$FRAGMENT_PICKER =~ s/fragment_picker(\.[^\.]+)$/fragment_picker.default$1/;
}
die "ERROR! $FRAGMENT_PICKER does not exist.\n" if (!-s $FRAGMENT_PICKER);
}
# check nr database
if (!$options{csbuild_profile}) {
if (!-s $PFILTNR) {
$PFILTNR = $NR;
print_debug("nr_pfilt database missing so using nr: $NR");
}
(-s $NR) or die "ERROR! $NR does not exist.\n";
}
# for homolog detection
my $VALL_BLAST_DB = "$VALL.blast";
$VALL_BLAST_DB =~ s/\.gz\.blast$/\.blast/;
my $PDB_SEQRES = "$Bin/pdb_seqres.txt";
if ( !$options{homs} ) {
if (!-s "$VALL_BLAST_DB.phr") {
system("gunzip $VALL_BLAST_DB.gz") if (-s "$VALL_BLAST_DB.gz");
system("$BLAST_DIR/bin/formatdb -i $VALL_BLAST_DB") if (-s $VALL_BLAST_DB);
}
if (!-s $PDB_SEQRES) {
if ($INTERNET_HOST) {
my $pwd = cwd();
system("ssh $INTERNET_HOST 'cd $pwd; wget ftp://ftp.rcsb.org/pub/pdb/derived_data/pdb_seqres.txt'");
} else {
system("wget ftp://ftp.rcsb.org/pub/pdb/derived_data/pdb_seqres.txt");
}
if (!-s "pdb_seqres.txt") { die "ERROR! wget ftp://ftp.rcsb.org/pub/pdb/derived_data/pdb_seqres.txt failed\n"; }
system("mv pdb_seqres.txt $PDB_SEQRES") if (!-s $PDB_SEQRES);
}
if (!-s "$PDB_SEQRES.phr") {
warn "WARNING! $PDB_SEQRES does not seem to be formated. Trying to format.\n";
system("$BLAST_DIR/bin/formatdb -i $PDB_SEQRES");
}
}
if ( defined( $opts{frag_sizes} ) ) {
@fragsizes = split( /,/, $opts{frag_sizes} );
print_debug( "fragment sizes: " . join( " ", @fragsizes ) );
}
if ( exists $opts{add_vall_files} ) {
foreach my $vall ( split( /,/, $opts{add_vall_files} ) ) {
push( @add_vall_files, $vall ) if ( -s $vall );
}
}
if ( exists $opts{use_vall_files} ) {
foreach my $vall ( split( /,/, $opts{use_vall_files} ) ) {
push( @use_vall_files, $vall ) if ( -s $vall );
}
}
if ( defined $opts{add_pdbs_to_vall} ) {
if ( !$PDB2VALL ) {
print_debug(
"ignoring -add_pdbs_to_vall option: PDB2VALL not configured");
}
else {
@pdbs_to_vall = split( /,/, $opts{add_pdbs_to_vall} );
# make sure the PDB code is lower case
for (my $i=0;$i<=$#pdbs_to_vall;$i++) {
substr($pdbs_to_vall[$i],0,4) = lc substr($pdbs_to_vall[$i],0,4);
}
print_debug( "pdbs to vall: " . join( " ", @pdbs_to_vall ) );
}
}
mkpath( $options{rundir} );
$options{rundir} = abs_path( $options{rundir} );
chop( $options{rundir} ) if ( substr( $options{rundir}, -1, 1 ) eq '/' );
&checkExist( 'd', $options{rundir} );
if ( !defined( $opts{id} ) ) {
print_debug("no id specified. parsing filename instead.");
( $options{id} ) = $options{fastafile} =~ /(\w+\.\w+)$/;
( $options{id} ) = $options{id} =~ /^(\w+)/;
if ( length( $options{id} ) != 5 ) {
print_debug("cannot parse id from filename so using 't001_'");
$options{id} = 't001_';
}
$options{chain} = substr( $options{id}, 4, 1 );
$options{id} = substr( $options{id}, 0, 4 );
print_debug("ID: $options{id} CHAIN: $options{chain}");
}
else {
chomp $opts{id};
print_debug("id specified by user: $opts{id}");
if ( length( $opts{id} ) != 5 ) {
die("The id you specify must be 5 characters long.\n");
}
if ( $opts{id} =~ /\W+/ ) {
die("Only alphanumeric characters and _ area allowed in the id.\n");
}
$options{id} = substr( $opts{id}, 0, 4 );
$options{chain} = substr( $opts{id}, 4, 1 );
if ( -s "$options{id}$options{chain}.fasta" ) {
my @diff = `diff $options{id}$options{chain}.fasta $options{fastafile}`;
if ( scalar @diff ) {
die
"ERROR! $options{id}$options{chain}.fasta already exists but does not match $options{fastafile}: $options{id}$options{chain}.fasta is autogenerated and should not exist\n";
}
}
print_debug("using $options{fastafile} as query fasta");
print_debug("ID: $options{id} CHAIN: $options{chain}");
}
$options{runid} = "$options{id}$options{chain}";
if ( abs_path( $options{fastafile} ) ne abs_path("$options{runid}.fasta") ) {
copy( $options{fastafile}, "$options{runid}.fasta" );
$options{fastafile} = "$options{runid}.fasta";
}
# determine what ss predictions to run
foreach my $ss_pred (qw/ porter sam psipred /) {
if ( $options{$ss_pred} ) {
my $fn_key = join '', ( $ss_pred, 'file' );
my $fn = $options{$fn_key};
$options{$ss_pred} = file_overrides_option( $fn, $ss_pred );
}
}
my $abs_path_fasta = abs_path( $options{fastafile} );
$options{fastafile} = basename( $options{fastafile} );
if ( $abs_path_fasta ne abs_path("$options{rundir}/$options{fastafile}") ) {
copy( $options{fastafile}, "$options{rundir}/" )
or die "Error copying $options{fastafile} into $options{rundir}!\n";
}
print "picking fragments with options:\n", options_to_str( \%options ), "\n";
print_debug("FILENAME: $options{fastafile}");
# main
chdir( $options{rundir} );
if ( -f "$options{runid}.make_fragments.success" ) {
print_debug("done! $options{runid}.make_fragments.success exists");
exit(0);
}
# get the sequence from the fasta file
my $sequence = read_fasta( $options{fastafile} );
print_debug("Sequence: $sequence");
# Run csbuild to generate sequence profile (.check) and pssm (.pssm)
# This bypasses psiblast calls for profile generation in sparks and psipred
if ($options{csbuild_profile}) {
print_debug("Generating structure profile & pssm via csbuild.");
system("$CSBUILD -i $options{fastafile} -I fas -D $CSBLAST_DIR/data/K4000.crf -o $options{runid}.check -O chk");
system("cp $options{runid}.check sstmp.chk");
system("echo sstmp.chk > sstmp.pn");
system("echo $options{fastafile} > sstmp.sn");
system("$MAKEMAT -P sstmp");
(-s "sstmp.mtx") or die "ERROR! Failed to create .mtx file: makemat failed!\n";
my $placeholder = "$Bin/pdb2vall/structure_profile_scripts/placeholder_seqs/placeholder_seqs";
if (!-s "$placeholder.phr") {
system("$BLAST_DIR/bin/formatdb -o T -i $placeholder");
}
my $blast = "$options{runid}.blast";
open(F, ">$blast") or die "ERROR! cannot open $blast: $!\n";
my $aacnt = 0;
my $totalaacnt = 0;
foreach my $aa (split(//,$sequence)) {
$aacnt++;
$totalaacnt++;
if ($aacnt == 1) {
printf F "%-14.14s", $options{runid};
}
if ($aacnt >= 101) {
print F "$aa\n\n";
$aacnt = 0;
next;
}
print F $aa;
print F "\n\n" if ($totalaacnt >= length($sequence));
}
close(F);
system("$PSIBLAST -i $options{fastafile} -B $blast -Q $options{runid}.pssm -t 1 -j 1 -h 0.001 -e 0.001 -b 0 -k 0 -d $placeholder");
(-s "$options{runid}.pssm") or die "ERROR! failed to create single sequence pssm file: blastpgp failed!\n";
system("cp $options{runid}.pssm $options{fastafile}.pssm");
}
# run sparks
if ($SPARKS) {
unless ( &nonempty_file_exists( $options{fastafile} . ".phipsi" ) ) {
print_debug(
"Running sparks for phi, psi, and solvent accessibility predictions"
);
my $sparks_result = system("$SPARKS $options{fastafile}");
if (!($sparks_result == 0 && -s $options{fastafile} . ".phipsi" )) {
if (length($SPARKS) > 100) {
print "sparks path length > 100 characters, which may cause internal errors. Try moving to a shorter path prefix.\n";
}
die("sparks failed!\n");
}
}
}
# run blast
unless ( &nonempty_file_exists("$options{runid}.check") ) {
print_debug("Running psiblast for sequence profile");
print_debug("Using nr: $NR");
if (
!&try_try_again(
"$PSIBLAST -t 1 -i $options{fastafile} -F F -j2 -o $options{runid}.blast -d $NR -v10000 -b10000 -K1000 -h0.0009 -e0.0009 -C $options{runid}.check -Q $options{runid}.pssm",
2,
["$options{runid}.check"],
[
"$options{runid}.check", "$options{runid}.blast",
"$options{runid}.pssm", "error.log"
]
)
)
{
die("checkpoint psi-blast failed!\n");
}
}
unless ( &nonempty_file_exists("$options{runid}.checkpoint") ) {
# parse & fortran-ify the checkpoint matrix.
my @checkpoint_matrix;
@checkpoint_matrix = &parse_checkpoint_file("$options{runid}.check");
@checkpoint_matrix =
&finish_checkpoint_matrix( $sequence, @checkpoint_matrix );
&write_checkpoint_file( "$options{runid}.checkpoint", $sequence,
@checkpoint_matrix );
}
push( @cleanup_files, ( "$options{runid}.pssm", "error.log" ) );
# Secondary Structure Prediction methods
if ( $options{psipred}
|| ( $options{psipredfile} && -s $options{psipredfile} ) )
{
if ( $options{psipredfile} && -s $options{psipredfile} ) {
$options{psipred} = 1;
system("cp $options{psipredfile} $options{runid}.psipred_ss2");
}
else {
# run psi-blast for psipred
unless ( &nonempty_file_exists("sstmp.chk") )
{
print_debug("Running psi-blast for psipred, using $PFILTNR.");
my $psiblast_success = &try_try_again(
"$PSIBLAST -t 1 -b10000 -v10000 -j3 -h0.001 -d $PFILTNR -i $options{fastafile} -C sstmp.chk -Q sstmp.ascii -o ss_blast",
2, [ "sstmp.chk", "sstmp.ascii" ], [ "sstmp.chk", "sstmp.ascii", "ss_blast" ]);
$psiblast_success or die("psipred psi-blast failed!\n");
push( @cleanup_files, ( "ss_blast", "sstmp.chk", "sstmp.ascii" ) );
} else {
print_debug("Using existing sstmp.chk");
}
unless ( &nonempty_file_exists("sstmp.mtx") ) {
&run( "echo $options{fastafile} > psitmp.sn", ("psitmp.sn") );
&run( "echo sstmp.chk > psitmp.pn", ("psitmp.pn") );
if (
!&try_try_again(
"$MAKEMAT -P psitmp",
2, ["sstmp.mtx"], ["sstmp.mtx"]
)
)
{
die("psipred: makemat failed.");
}
} else {
print_debug("Using existing sstmp.mtx");
}
unless ( &nonempty_file_exists("psipred_ss") ) {
my $psipredcmd =
($PSIPRED_USE_weights_dat4)
? "$PSIPRED sstmp.mtx $PSIPRED_DATA/weights.dat $PSIPRED_DATA/weights.dat2 $PSIPRED_DATA/weights.dat3 $PSIPRED_DATA/weights.dat4 > psipred_ss"
: "$PSIPRED sstmp.mtx $PSIPRED_DATA/weights.dat $PSIPRED_DATA/weights.dat2 $PSIPRED_DATA/weights.dat3 > psipred_ss";
if (
!&try_try_again(
$psipredcmd, 2, ["psipred_ss"], ["psipred_ss"]
)
)
{
die("psipred failed.");
}
}
unless ( &nonempty_file_exists("$options{runid}.psipred_ss2") ) {
if (
!&try_try_again(
"$PSIPASS2 $PSIPRED_DATA/weights_p2.dat 1 1.0 1.0 psipred_ss2 psipred_ss > psipred_horiz",
2,
[ "psipred_ss2", "psipred_horiz" ],
[ "psipred_ss2", "psipred_horiz" ]
)
)
{
die("psipred/psipass2 failed.");
}
rename( "psipred_horiz", "$options{runid}.psipred" )
or die(
"couldn't move psipred_horiz to $options{runid}.psipred: $!\n");
if ( !scalar(`grep 'PSIPRED VFORMAT' psipred_ss2`) ) {
open( FILE, "psipred_ss2" );
my @ss2 = <FILE>;
close(FILE);
open( FILE, ">$options{runid}.psipred_ss2" );
print FILE
"# PSIPRED VFORMAT (PSIPRED V2.6 by David Jones)\n\n";
print FILE @ss2;
close(FILE);
}
else {
rename( "psipred_ss2", "$options{runid}.psipred_ss2" )
or die(
"couldn't move psipred_ss2 to $options{runid}.psipred_ss2: $!\n"
);
}
}
}
if ( &nonempty_file_exists("$options{runid}.psipred_ss2") ) {
print_debug("psipred file ok.");
}
else {
print "psipred run failed!\n";
}
push( @cleanup_files, ( glob("psitmp*"), "psipred_ss", "sstmp.mtx" ) );
}
if ( $options{porter} || ( $options{porterfile} && -s $options{porterfile} ) ) {
if ( $options{porterfile} && -s $options{porterfile} ) {
$options{porter} = 1;
if (&is_ss2_format($options{porterfile})) {
system("cp $options{porterfile} $options{runid}.porter_ss2");
} else {
(system("$Bin/ss_pred_converter.py -p $options{porterfile} > $options{runid}.porter_ss2") == 0 && -s "$options{runid}.porter_ss2") or
die "ERROR! $options{porterfile} conversion to ss2 format failed. Check porter file format.\n";
}
}
if ( &nonempty_file_exists("$options{runid}.porter_ss2") ) {
print_debug("porter file ok.");
}
else {
print_debug("Running porter.");
if (
!&try_try_again(
"$PORTER $options{fastafile}", 2,
["$options{runid}.porter_ss2"], ["$options{runid}.porter_ss2"]
)
) { die("porter failed!\n"); }
}
}
# sam -- target99 alignment and predict2nd with 6 state neural net - condensed output to 3 state
if ( $options{sam} || ( $options{samfile} && -s $options{samfile} ) ) {
if ( $options{samfile} && -s $options{samfile} ) {
$options{sam} = 1;
if (&is_ss2_format($options{samfile})) {
system("cp $options{samfile} $options{runid}.rdb_ss2");
} elsif (&is_sam_6state($options{samfile})) {
# condense to 3 state prediction
my $rows;
open IN, "<$options{samfile}" or die "Cannot open file $options{samfile}: $!\n";
@{$rows} = <IN>;
close(IN);
$rows = &condense_rdb6_rdb($rows);
open OUT, ">$options{runid}.rdb"
or die "Cannot open file $options{runid}.rdb: $!\n";
print OUT @{$rows};
close(OUT);
# convert rdb to rdb_ss2
&convert_sam_ss("$options{runid}.rdb");
die("SAM failed!\n") if ( !-s "$options{runid}.rdb_ss2" );
} else {
(system("$Bin/ss_pred_converter.py -s $options{samfile} > $options{runid}.rdb_ss2") == 0 && -s "$options{runid}.rdb_ss2") or
die "ERROR! $options{samfile} conversion to ss2 format failed. Check sam file format.\n";
}
}
if ( &nonempty_file_exists("$options{runid}.rdb_ss2") ) {
print_debug("sam file ok.");
}
else {
print_debug("Running sam.");
my $target99_out = "$options{runid}.target99";
my $target99_a2m_file = $target99_out . ".a2m";
if (
!&try_try_again(
"$SAM -seed $options{fastafile} -out " . $target99_out, 2,
[$target99_a2m_file], []
)
)
{
die "sam target99 failed!\n";
}
## run uniqueseq
my $uniqueseq_a2m_id = "$options{runid}.uniqueseq";
my $uniqueseq_a2m_file = $uniqueseq_a2m_id . ".a2m";
if (
!&try_try_again(
"$SAM_uniqueseq $uniqueseq_a2m_id -percent_id 0.9 -alignfile "
. $target99_a2m_file,
2,
[$uniqueseq_a2m_file],
[$uniqueseq_a2m_file]
)
)
{
die "sam uniqueseq failed!\n";
}
## run predict-2nd
chop($SAM_PREDICT_2ND_DIR)
if ( substr( $SAM_PREDICT_2ND_DIR, -1, 1 ) eq '/' );
# create samscript
my $sam_6state = "$options{rundir}/$options{runid}.sam_6state";
my $sam_ebghtl = "$options{rundir}/$options{runid}.sam_ebghtl";
my $sam_log = "$options{rundir}/$options{runid}.sam_log";
my $samscript_txt_buf =
qq{ReadAlphabet $SAM_PREDICT_2ND_DIR/std.alphabet
ReadAlphabet $SAM_PREDICT_2ND_DIR/DSSP.alphabet
ReadNeuralNet $SAM_PREDICT_2ND_DIR/overrep-3617-IDaa13-7-10-11-10-11-7-7-ebghtl-seeded3-stride-trained.net
ReadA2M $options{rundir}/$uniqueseq_a2m_file
PrintRDB $sam_6state
PrintPredictionFasta $sam_ebghtl
};
my $samscript_txt = "$options{rundir}/$options{runid}.samscript.txt";
open( SAMSCRIPT, '>' . $samscript_txt );
print SAMSCRIPT $samscript_txt_buf;
close(SAMSCRIPT);
# get into $SAM_PREDICT_2ND_DIR so sam can read file recode3.20comp
chdir $SAM_PREDICT_2ND_DIR;
if (
!&try_try_again(
"$SAM_PREDICT_2ND_DIR/predict-2nd -noalph < $samscript_txt >& $sam_log",
2,
[$sam_6state],
[$sam_6state]
)
)
{
die "sam predict-2nd failed!\n";
}
chdir $options{rundir};
# condense to 3 state prediction
my $rows;
open IN, "<$sam_6state" or die "Cannot open file $sam_6state: $!\n";
@{$rows} = <IN>;
close(IN);
$rows = &condense_rdb6_rdb($rows);
open OUT, ">$options{runid}.rdb"
or die "Cannot open file $options{runid}.rdb: $!\n";
print OUT @{$rows};
close(OUT);
# convert rdb to rdb_ss2
&convert_sam_ss("$options{runid}.rdb");
if ( !-s "$options{runid}.rdb_ss2" ) {
die("SAM failed!\n");
}
print_debug("sam file ok.");
push @cleanup_files,
(
$samscript_txt, $sam_log, $sam_6state, $sam_ebghtl,
$target99_a2m_file, $uniqueseq_a2m_file, "$target99_out.cst"
);
}
}
# Vall and homolog searches
my %excluded_homologs;
if (-s "$options{runid}.homolog") {
open(F, "$options{runid}.homolog") or die "ERROR! cannot open $options{runid}.homolog: $!\n";
while (<F>) {
if (/^(\S{5})/) {
$excluded_homologs{$1} = 1;
} elsif (/^(\S{4})/) {
$excluded_homologs{$1} = 1;
}
}
close(F);
}
if ( !$options{homs} ) {
print_debug("excluding homologs.");
unless ( &nonempty_file_exists("$options{runid}.outn") ) {
if (
!&try_try_again(
"$PSIBLAST -t 1 -i $options{fastafile} -j 1 -R $options{runid}.check -o $options{runid}.outn -e 0.05 -d $VALL_BLAST_DB",
2,
["$options{runid}.outn"],
["$options{runid}.outn"]
)
)
{
die("homolog vall blast failed!\n");
}
}
unless ( &nonempty_file_exists("$options{runid}.outn.pdb") ) {
if (
!&try_try_again(
"$PSIBLAST -t 1 -i $options{fastafile} -j 1 -R $options{runid}.check -o $options{runid}.outn.pdb -e 0.05 -d $PDB_SEQRES",
2,
["$options{runid}.outn.pdb"],
["$options{runid}.outn.pdb"]
)
)
{
die("homolog pdb blast failed!\n");
}
}
&exclude_blast( $options{runid} );
&exclude_pdbblast( $options{runid} );
&exclude_outn( $options{runid} );
}
my %exclude_homologs_by_pdb_date_pdbs;
my %exclude_homologs_by_pdb_date_checked_pdbs;
my $cutoff_date_str;
if ( $options{exclude_homologs_by_pdb_date} ) {
my $exclude_homologs_by_pdb_date = $options{exclude_homologs_by_pdb_date};
print_debug("exclude_homologs_by_pdb_date: $exclude_homologs_by_pdb_date");
my ($cutoff_m,$cutoff_d,$cutoff_y);
# mm/dd/yy format
if ( $exclude_homologs_by_pdb_date =~ /^(\d\d)\/(\d\d)\/(\d\d)$/ ) {
$cutoff_m = $1;
$cutoff_d = $2;
$cutoff_y = $3;
# yyyymmdd format
} elsif ( $exclude_homologs_by_pdb_date =~ /^(\d\d\d*)(\d\d)(\d\d)$/ ) {
$cutoff_y = $1;
$cutoff_m = $2;
$cutoff_d = $3;
} else {
die "ERROR! $exclude_homologs_by_pdb_date date format is incorrect: must be mm/dd/yy or yyyymmdd\n";
}
# try to convert 2 digit year to full calendar year - hacky
$cutoff_date_str = &convert_twodigit_to_full_calendar_year( $cutoff_y, $cutoff_m, $cutoff_d );
# update pdb_revdat.txt
print_debug("Getting latest pdb_revdat.txt....");
system("$Bin/update_revdat.pl $INTERNET_HOST");
my %month_str_to_num = (
'JAN' => '01',
'FEB' => '02',
'MAR' => '03',
'APR' => '04',
'MAY' => '05',
'JUN' => '06',
'JUL' => '07',
'AUG' => '08',
'SEP' => '09',
'OCT' => '10',
'NOV' => '11',
'DEC' => '12');
open( F, "$Bin/pdb_revdat.txt" )
or die "ERROR! cannot open $Bin/pdb_revdat.txt: $!\n";
foreach my $l (<F>) {
if ($l =~ /^(\S{4})\s+REVDAT\s+(\d+)\s+(\d+)\-(\w\w\w)\-(\d+)\s+\S{4}\s+(\d+)/) {
#2w6x REVDAT 1 22-DEC-09 2W6X 0
my $rcode = lc $1;
my $rnum = $2;
my $rday = $3;
my $rmonth = $month_str_to_num{$4};
my $ryear = $5;
my $rstatus = $6;
$rday = "00$rday";
$rday =~ s/^.*(\d\d)\s*$/$1/gs;
# try to convert 2 digit year to full calendar year
my $rtmpdate = &convert_twodigit_to_full_calendar_year( $ryear, $rmonth, $rday );
if ($rstatus eq '0' && $rtmpdate > $cutoff_date_str ) {
$exclude_homologs_by_pdb_date_pdbs{$rcode} = $rtmpdate;
}
$exclude_homologs_by_pdb_date_checked_pdbs{$rcode} = 1;
}
}
close(F);
}
sub convert_twodigit_to_full_calendar_year {
my ($twodigit, $tmpmonth, $tmpday) = @_;
# try to convert 2 digit year to full calendar year - hacky
# current date GMT (UTC) PDB gets updated Wed UTC +0 (-8/7 PST depending on daylight savings)
my ($sec,$min,$hour,$currentmday,$currentmonth,$currentyear,$wday,$yday,$isdst) = gmtime(time);
$currentyear += 1900;
$currentmonth++;
my $mday = "00$currentmday";
my $mmonth = "00$currentmonth";
$mday =~ s/^.*(\d\d)\s*$/$1/gs;
$mmonth =~ s/^.*(\d\d)\s*$/$1/gs;
my $current_date_str = $currentyear.$mmonth.$mday;
my $tmpyear = ($twodigit < 100) ? $twodigit + 2000 : $twodigit;
my $tmpdate = $tmpyear.$tmpmonth.$tmpday;
if ($tmpdate > $current_date_str) {
$tmpyear = ($twodigit < 100) ? $twodigit + 1900 : $twodigit;
$tmpdate = $tmpyear.$tmpmonth.$tmpday;
}
return $tmpdate;
}
my @valls = ($VALL);
if ( scalar @use_vall_files ) {
@valls = @use_vall_files;
}
push( @valls, @add_vall_files ) if ( scalar @add_vall_files );
my $nativeexists = 0;
if ( -s "$options{runid}.pdb" ) {
print_debug("native pdb exists: $options{runid}.pdb.");
$nativeexists = 1;
}
# pdbs to vall
if ( scalar @pdbs_to_vall ) {
print_debug("pdbs_to_vall");
my $pdbs2valldir = "$options{rundir}/$options{runid}\_pdbs_to_vall";
( -d $pdbs2valldir || mkdir($pdbs2valldir) )
or die "ERROR! cannot mkdir $pdbs2valldir: $!\n";
chdir($pdbs2valldir);
if ( !-s "$options{runid}\_pdbs_to_vall.vall" ) {
if ( !-e $SLAVE_LAUNCHER ) { # run in series
foreach my $pdb (@pdbs_to_vall) {
my $cmd = "$PDB2VALL -p $pdb";
produce_output_with_cmd( $cmd, "$pdb.vall",
$PDB2VALL_IGNORE_ERRORS );
}
}
else {
my ( @commands, @results );
foreach my $pdb (@pdbs_to_vall) {
push( @commands, "$SLAVE_LAUNCHER $PDB2VALL -p $pdb" );
push( @results, "$pdb.vall" );
}
&run_in_parallel(
\@commands, \@results,
"pdb2vall_parallel_job", $SLAVE_LAUNCHER_MAX_JOBS,
$SLAVE_MAX_WAIT, $SLAVE_MAX_ATTEMPTS,
$PDB2VALL_IGNORE_ERRORS
);
}
}
# create one template vall - overwrite if exists
open( F, ">$options{runid}\_pdbs_to_vall.vall" )
or die "ERROR! cannot open $options{runid}\_pdbs_to_vall.vall: $!\n";
foreach my $pdb (@pdbs_to_vall) {
next if ( $PDB2VALL_IGNORE_ERRORS && !-s "$pdb.vall" );
print_debug("adding $pdb.vall");
open( NF, "$pdb.vall" ) or die "ERROR! cannot open $pdb.vall: $!\n";
foreach my $nf (<NF>) {
print F $nf;
}
close(NF);
}
close(F);
if ( -s "$options{runid}\_pdbs_to_vall.vall" ) {
push( @valls, "$pdbs2valldir/$options{runid}\_pdbs_to_vall.vall" );
}
else {
warn
"WARNING! pdb2vall output $options{runid}\_pdbs_to_vall.vall does not exist.\n";
}
chdir($options{rundir});
}
# check valls for date filtering
if ( $options{exclude_homologs_by_pdb_date} ) {
chdir($options{rundir});
my %appended;
open( EXCL, ">$options{runid}.homolog_by_pdb_date_$cutoff_date_str" ) or die "ERROR! cannot open!\n";
open( EXCL2, ">>$options{runid}.homolog" );
print EXCL "# excluded because release date > $cutoff_date_str or missing in pdb_revdat.txt\n";
foreach my $v (@valls) {
if (-s "$v.gz") {
open(F, "gzip -dc $v.gz |") or die "ERROR! cannot open $v.gz: $!\n";
} else {
open(F, $v) or die "ERROR! cannot open $v: $!\n";
}
while (<F>) {
next if (/^#/);
if (/^(\S{4})\S\s+\S/) {
my $pdbcode = lc $1;
next if (exists $appended{$pdbcode});
if (!exists $exclude_homologs_by_pdb_date_checked_pdbs{$pdbcode}) {
print_debug("excluding $pdbcode because it is missing in pdb_revdat.txt");
print EXCL "$pdbcode\n";
print EXCL2 "$pdbcode\n" if (!exists $excluded_homologs{$pdbcode});
$appended{$pdbcode} = 1;
} elsif (exists $exclude_homologs_by_pdb_date_pdbs{$pdbcode}) {
print_debug("excluding $pdbcode released: $exclude_homologs_by_pdb_date_pdbs{$pdbcode}");
print EXCL "$pdbcode\n";
print EXCL2 "$pdbcode\n" if (!exists $excluded_homologs{$pdbcode});
$appended{$pdbcode} = 1;
}
}
}
close(F);
}
close(EXCL);
close(EXCL2);
}
my $valls_str = join ' ', @valls;
chdir($options{rundir});
if ( !$options{frags} ) {
cleanup(@cleanup_files);
exit 0;
}
# picker
foreach my $size (@fragsizes) {
my $ss_pred_cnt = 0;
my $score_def;
my $sparkscmd = "";
my $nativecmd = "";
# score file (small fragments)
if ( $size <= 4 ) {
$score_def = <<SCORE;
# score name priority wght min_allowed extras
ProfileScoreL1 700 1.0 -
ProfileScoreStructL1 100 1.4 -
SCORE
if ($SPARKS) {
$score_def .= "SolventAccessibility 500 0.5 -\n";
$score_def .= "Phi 300 3.9 -\n";
$score_def .= "Psi 200 0.9 -\n";
$sparkscmd =