-
Notifications
You must be signed in to change notification settings - Fork 12
/
consurf
executable file
·1868 lines (1598 loc) · 84.7 KB
/
consurf
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
#####################################################################################################
#
# This Script implement the ConSurf system for Identification of Functional Regions in Proteins
#
# ConSurf: Using Evolutionary Data to Raise Testable Hypotheses about Protein Function
# Celniker G., Nimrod G., Ashkenazy H., Glaser F., Martz E., Mayrose I., Pupko T., and Ben-Tal N. 2013.
# Isr. J. Chem. 2013 March 10, doi: 10.1002/ijch.201200096
#
# ConSurf 2010: calculating evolutionary conservation in sequence and structure of proteins and nucleic acids.
# Ashkenazy H., Erez E., Martz E., Pupko T. and Ben-Tal N. 2010
# Nucl. Acids Res. 2010; DOI: 10.1093/nar/gkq399; PMID: 20478830
#
# ConSurf: the projection of evolutionary conservation scores of residues on protein structures
# Landau M., Mayrose I., Rosenberg Y., Glaser F., Martz E., Pupko T., and Ben-Tal N.
# Nucl. Acids Res. 33:W299-W302. (2005)
# Bioinformatics 19: 163-164. (2003)
# http://consurf.tau.ac.il/
#
#
# It is mainly Based on the Rate4Site Algorithm for detecting conserved amino-acid sites by computing
# the relative evolutionary rate for each site in the multiple sequence alignment (MSA).
#
# Comparison of site-specific rate-inference methods: Bayesian methods are superior
# Mayrose, I., Graur, D., Ben-Tal, N., and Pupko, T.
# Mol Biol Evol. 21:1781-1791. (2004).
# http://www.tau.ac.il/~itaymay/cp/rate4site.html
#
# For any questions or suggestions please contact us: [email protected]
#
#
#####################################################################################################
use strict;
use Storable;
use Bio::SeqIO;
use Bio::AlignIO;
use Bio::Align::AlignI;
use Bio::SimpleAlign;
use Getopt::Long;
use File::Path qw(make_path);
use Pod::Usage;
our $config;
my $consurf_utildir;
our $VERSION = "__PACKAGE_VERSION__";
BEGIN {
use Config::IniFiles;
my ( $defaultconfig, $etcconfig );
if ( -e "__pkgdatadir__/consurfrc.default" ) {
$defaultconfig =
Config::IniFiles->new( -file => "__pkgdatadir__/consurfrc.default" );
}
if ( -e "__sysconfdir__/consurfrc" ) {
$etcconfig = Config::IniFiles->new(
-file => "__sysconfdir__/consurfrc",
-import => $defaultconfig
);
}
else { $etcconfig = $defaultconfig; }
if ( ( $ENV{CONSURFCONF} && -e "$ENV{CONSURFCONF}" )
|| -e "$ENV{HOME}/.consurfrc" )
{
$config = Config::IniFiles->new(
-file => $ENV{CONSURFCONF} || "$ENV{HOME}/.consurfrc",
-import => $etcconfig
);
}
else { $config = $etcconfig; }
$consurf_utildir = $config->val( 'consurf', 'consurf_utildir' );
}
use lib glob($consurf_utildir);
use CONSURF_CONSTANTS;
use CONSURF_FUNCTIONS;
use prepareMSA;
use MSA_parser;
use TREE_parser;
use pdbParser;
use cp_rasmol_gradesPE_and_pipe;
my %FORM=();
my %VARS=();
my ( $dbg, $quiet, $version, $help, $man );
if (@ARGV < 1){ die "Usage: $0 [OPTIONS]\n";}
my $result = GetOptions(
# Mandatory Argumants
"PDB=s"=>\$VARS{pdb_file_name}, # PDB File
"CHAIN=s"=>\$FORM{chain}, # Chain ID
"Out_Dir=s"=>\$VARS{out_dir}, # Output Path
"Seq_File=s"=>\$VARS{protein_seq}, # Seq File in FASTA format - For ConSeq mode
# Given MSA mode parameters
"MSA:s"=>\$VARS{user_msa_file_name}, # <MSA File Name> (MANDATORY IF -m NOT USED)
"SEQ_NAME:s"=>\$FORM{msa_SEQNAME}, # <"Query sequence name in MSA file"> (MANDATORY IF -m NOT USED)
"Tree:s"=>\$VARS{user_tree_file_name}, # <Phylogenetic Tree (in Newick format)> (optional)
# Building MSA mode
"m"=>\$FORM{buildMSA}, # Builed MSA mode
"MSAprogram:s"=>\$FORM{MSAprogram}, # ["CLUSTALW"] or ["MUSCLE"] (default: MUSCLE)
"DB:s"=>\$FORM{database}, # ["SWISS-PROT"] or ["UNIPROT"] (default: UniProt)
"MaxHomol:s"=>\$FORM{MAX_NUM_HOMOL}, #1 <Max Number of Homologs to use for ConSurf Calculation> (deafult: 50)
"Iterat:s"=>\$FORM{iterations}, # <Number of PsiBlast iterataion> (default: 1)
"ESCORE:s"=>\$FORM{ESCORE}, # <Minimal E-value cutoff for Blast search> (default: 0.001)
"BlastFile:s"=>\$VARS{usr_BLAST_out_file}, # pre-calculated blast file provided by the user
# Rate4Site Parameters
"Algorithm:s"=>\$FORM{algorithm}, # [LikelihoodML] or [Bayesian] (default: Bayesian)
"Matrix:s"=>\$FORM{matrix}, # [JTT] or [mtREV] or [cpREV] or [WAG] or [Dayhoff] (default JTT)
"w|workdir:s" => \$VARS{working_dir} ,
"h|help"=>\$help, # shows Help
'debug!' => \$dbg,
'quiet!' => \$quiet,
"v|version" => \$version,
"man" => \$man
) or pod2usage(2);
if( $help ) { pod2usage(0); }
pod2usage(-verbose => 2) if $man;
if ($version){
print STDERR qq|This is ConSurf version __PACKAGE_VERSION__
Copyright 2003, Ben-Tal et al
Please see COPYING file for license information
Complete documentation for ConSurf should be found on
this system using "man consurf".
|;
exit (0);
}
my $submission_time;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$submission_time = $hour . ':' . $min . ':' . $sec;
my $curr_time = $submission_time." $mday-".($mon+1)."-".($year+1900);
$VARS{submission_time}=$submission_time;
if (! $quiet){
$quiet = $config->val( 'consurf', 'quiet' );
}
if ($dbg){
$quiet=0
};
my $welcome_message = <<EOF;
ConSurf Version __PACKAGE_VERSION__
====================================
Process Started at $VARS{submission_time}
EOF
print $welcome_message if (!$quiet);
if ( $VARS{working_dir} ) {
$VARS{working_dir} = glob($VARS{working_dir});
if (! -e ($VARS{working_dir}) ){
make_path ($VARS{working_dir})
|| die ("Cannot create non existing path:".$VARS{working_dir}." .".$!);
}
}
else {
$VARS{working_dir} = File::Temp::tempdir( CLEANUP => !$dbg );
}
$VARS{working_dir} =~ s!/*$!/!;
warn ("Work dir: ".$VARS{working_dir}) if ($dbg);
if ((defined $VARS{protein_seq}) and (defined $VARS{protein_seq}) and (defined $VARS{pdb_file_name}))
{
die "===[FATAL ERROR] Can't Give Both PDB and Seq\n";
}
if (!defined $VARS{user_msa_file_name})
{
if ((!defined $VARS{pdb_file_name} or !defined $FORM{chain} or ! defined $VARS{working_dir}) and (!defined $VARS{protein_seq} or !defined $VARS{working_dir}))
{
die "===[FATAL ERROR] Missing Arguments; If -m is used [-PDB with -CHAIN, or -Seq_File] and -Out_Dir must be specified\n"
}
}
if (defined $VARS{pdb_file_name})
{
$VARS{pdb_file_name} = glob($VARS{pdb_file_name});
}
if (defined $VARS{protein_seq})
{
$VARS{protein_seq} = glob($VARS{protein_seq});
}
if (defined $VARS{pdb_file_name} and ! -e $VARS{pdb_file_name}){
die "===[FATAL ERROR] Non existent input:". $VARS{pdb_file_name} ."\n";
}
if (defined $VARS{protein_seq} and ! -e $VARS{protein_seq}){
die "===[FATAL ERROR] Non existent input:". $VARS{protein_seq} ."\n";
}
# copy input file to temp dir
use File::Copy;
use File::Basename;
if (defined $VARS{pdb_file_name})
{
my $t_file = basename( $VARS{pdb_file_name} );
copy ($VARS{pdb_file_name}, $VARS{working_dir}. $t_file );
$VARS{pdb_file_name} = $VARS{working_dir}. $t_file;
}
elsif (defined $VARS{protein_seq})
{
my $t_file = basename( $VARS{protein_seq} );
copy ($VARS{protein_seq}, $VARS{working_dir}. $t_file );
$VARS{protein_seq} = $t_file;
}
if (!$FORM{buildMSA})
{
if (!defined $VARS{user_msa_file_name} or !$FORM{msa_SEQNAME})
{
die "===[FATAL ERROR] Missing Arguments; -MSA,-SEQ_NAME must be given in MSA mode\n"
}
$VARS{protein_MSA}=$VARS{user_msa_file_name};
}
if (defined $FORM{buildMSA}) # MSA Mode
{
if ((defined $FORM{MSAprogram}) and ($FORM{MSAprogram} ne "") and ($FORM{MSAprogram} ne""))
{
print "-MSAprogram can be only CLUSTALW or MUSCLE (default: MUSCLE) and not $FORM{MSAprogram}\n";
exit
}
if (defined ($FORM{database}) and ($FORM{database} ne "UNIPROT") and ($FORM{database} ne "SWISS-PROT"))
{
print "-DB can be only UNIPROT/SWISS-PROT\n";
exit;
}
}
if ((defined $FORM{algorithm}) and ($FORM{algorithm} ne "LikelihoodML") and ($FORM{algorithm} ne "Bayesian"))
{
print "-Algorithm can be only LikelihoodML or Bayesian and Not $FORM{algorithm}\n";
exit;
}
if ((defined $FORM{matrix}) and ($FORM{matrix} ne "JTT") and ($FORM{matrix} ne "mtREV") and ($FORM{matrix} ne "cpREV") and ($FORM{matrix} ne "WAG") and ($FORM{matrix} ne "Dayhoff") and ($FORM{matrix} ne "LG"))
{
print "-Matrix Can only be JTT or mtREV or cpREV or WAG or Dayhoff, or LG (default JTT) and not $FORM{matrix}\n";
exit;
}
if ((defined $VARS{user_tree_file_name}) and defined ($FORM{buildMSA}))
{
print "===[WARNNING] The given tree would be ignored in Building MSA mode\n";
$VARS{user_tree_file_name}="";
}
# Defaults , NOTE SOME OF THEM ARE IGNORED DURING THE PROGRAM BY IF ELSE MECHANISM
$FORM{iterations} = 1 if !defined($FORM{iterations});
$FORM{ESCORE} = 0.001 if !defined($FORM{ESCORE});
$FORM{MAX_NUM_HOMOL} = 150 if !defined($FORM{MAX_NUM_HOMOL});
$FORM{database}="UNIPROT" if !defined ($FORM{database});
$FORM{algorithm}="Bayesian" if !defined ($FORM{algorithm});
$FORM{MSAprogram}="MUSCLE" if !defined ($FORM{MSAprogram});
$FORM{matrix}="JTT" if !defined ($FORM{matrix});
$VARS{user_tree_file_name}="" if !defined ($VARS{user_tree_file_name});
# Construct the output dir
use Cwd;
my $tmp_dir = cwd().'/consurf-'.join('-',$hour,$min,$sec ).'/';
if ( $VARS{out_dir} ) {
$VARS{out_dir} = glob($VARS{out_dir}).'/';
if (! -e ($VARS{out_dir}) ){
my $answer;
if ($quiet){
$answer = 'y';
}else{
print "Output dir $VARS{out_dir} does not exist. Create it? (Y/N) ";
$answer = <>;
}
if ($answer =~ m/y/i){
make_path ($VARS{out_dir})
|| die ("Cannot create output dir:".$VARS{out_dir}." .".$!);
}else {
$VARS{out_dir} = $tmp_dir;
make_path ($VARS{out_dir})
|| die ("Cannot create output dir:".$VARS{out_dir}." .\nSystem message: ".$!);
}
}
}else{
$VARS{out_dir} = $tmp_dir;
make_path ($VARS{out_dir})
|| die ("Cannot create output dir:".$VARS{out_dir}." .\nSystem message: ".$!);
}
print "Output files could be found in output directory: ".$VARS{out_dir}."\n" if (!$quiet);
if (defined $VARS{pdb_file_name}) # ConSurf mode
{
if ($VARS{pdb_file_name}=~/([A-Za-z0-9]{4})(.[A-Za-z0-9]+)?$/)
{
$FORM{pdb_ID}=$1;
}
$VARS{run_log} = "$VARS{working_dir}/$FORM{pdb_ID}_$FORM{chain}_ConSurf.log";
$VARS{protein_seq} = "$FORM{pdb_ID}_$FORM{chain}_protein_seq.fas"; # a fasta file with the protein sequence - from PDB or from protein seq input
$VARS{CONSURF_CONSEQ}="CONSURF";
}
else # ConSeq mode
{
if ($FORM{buildMSA}) # Build MSA mode
{
# check how many sequences in the file and extract seq_name
open (my $PROTEIN_SEQ,"$VARS{working_dir}$VARS{protein_seq}") || die "Can't open PROTEIN_SEQ: '$VARS{working_dir}$VARS{protein_seq}' $!";
my $NumOfInSeq=0;
while (my $line=<$PROTEIN_SEQ>)
{
if ($line=~/^>/)
{
$VARS{protein_query_seq}="";
$NumOfInSeq++;
if ($line=~/^>(\w+)\|(\w+)/) # NCBI style
{
$VARS{Seq_Name}=$2;
}
elsif ($line=~/^>(\w+)/) # FreeStyle
{
$VARS{Seq_Name}=$1;
}
$line=<$PROTEIN_SEQ>;
while ((defined $line) and (substr($line,0,1) ne ">" )) {
chomp $line;
$VARS{protein_query_seq}.= $line;
$line = <$PROTEIN_SEQ>;
}
}
}
close ($PROTEIN_SEQ);
if ($NumOfInSeq>1)
{
die "More than one sequence file was provided in '$VARS{protein_seq}' while only one is allowed...\b";
}
if (!exists $VARS{Seq_Name})
{
my ($name,$path,$suffix) = fileparse($VARS{Seq_Name});
$VARS{Seq_Name}=$name;
}
}
else # msa_mode
{
if ($FORM{msa_SEQNAME}=~/^(\w+)\|(\w+)/) # NCBI style
{
$VARS{Seq_Name}=$2;
}
elsif ($FORM{msa_SEQNAME}=~/^(\w+)/) # free style
{
$VARS{Seq_Name}=$1;
}
else
{
my ($name,$path,$suffix) = fileparse($VARS{user_msa_file_name});
$VARS{Seq_Name}=$name;
}
}
#mkdir "$VARS{working_dir}/$VARS{Seq_Name}" || die "Can't create dir: $VARS{working_dir}/$VARS{Seq_Name}$!"; # Seq Name
# $VARS{working_dir}="$VARS{working_dir}/$VARS{Seq_Name}";
$VARS{run_log} = "$VARS{working_dir}/$VARS{Seq_Name}_ConSurf.log";
# Validate_Seq(); # TO DO
# $VARS{protein_seq}="$VARS{working_dir}/$VARS{protein_seq_name}";
$VARS{running_mode}="_mode_no_pdb_no_msa";
$VARS{CONSURF_CONSEQ}="CONSEQ";
}
print "Debug log can be found in: ".$VARS{run_log}."\n" if ($dbg);
# general vars
$VARS{msa_format} = ""; # will be either: pir, fasta, nexus, clustalw, gcg, gde.
&open_log_file();
## This Script Run ConSurf Calculation Given MSA and PDB ID
my @gradesPE_Output = (); # an array to hold all the information that should be printed to gradesPE
# in each array's cell there is a hash for each line from r4s.res.
# POS: position of that aa in the sequence ; SEQ : aa in one letter ;
# GRADE : the given grade from r4s output ; COLOR : grade according to consurf's scale
my %residue_freq = (); # for each position in the MSA, detail the residues
my %position_totalAA = (); # for each position in the MSA, details the total number of residues
# these arrays will hold for each grade, the residues which corresponds to it.
# there are 2 arrays: in the @isd_residue_color, a grade with insufficient data, *, will classify to grade 10
# in the @no_isd_residue_color, the grade will be given regardless of the * mark
# PLEASE NOTE : the [0] position in those arrays is empty, because each position corresponds a color on a 1-10 scale
my @no_isd_residue_color = ();
my @isd_residue_color = ();
# these variables will be used in the pipe block, for view with FGiJ.
# $seq3d_grades_isd : a string. each position in the string corresponds to that ATOM (from the PDB) ConSurf grade. For Atoms with insufficient data - the grade will be 0
# $seq3d_grades - same, only regardeless of insufficient data
my ($seq3d_grades_isd, $seq3d_grades);
#These variables will hold the length of pdb ATOMS and the lenght of SEQRES/MSA_REFERENCE seq
# The data is filled by cp_rasmol_gradesPE_and_pipe::match_seqres_pdb
my ($length_of_seqres,$length_of_atom);
# programs
# my $rate4s = CONSURF_CONSTANTS::RATE4SITE;
# my $rate4s_slow = CONSURF_CONSTANTS::RATE4SITE_SLOW;
my $rate4s = $config->val( 'programs', 'RATE4SITE' );
my $rate4s_slow = $config->val( 'programs', 'RATE4SITE_SLOW' );
# outputs
if ($VARS{CONSURF_CONSEQ} eq "CONSURF")
{
$VARS{r4s_log} = "$FORM{pdb_ID}_$FORM{chain}_r4s.log";
$VARS{r4s_out} = "$FORM{pdb_ID}_$FORM{chain}_r4s.res";
$VARS{r4s_slow_log} = "$FORM{pdb_ID}_$FORM{chain}_r4s_slow.log";
$VARS{atom_positionFILE} = "$FORM{pdb_ID}_$FORM{chain}_atom_pos.txt";
$VARS{gradesPE} = $VARS{out_dir}."/$FORM{pdb_ID}_$FORM{chain}_consurf.grades";
$VARS{r4s_tree} = $FORM{pdb_ID}."_".$FORM{chain}."_Tree.txt";
$VARS{insufficient_data_pdb} = "";
if ($FORM{buildMSA})
{
$VARS{running_mode}="_mode_pdb_no_msa";
}
if ((!$FORM{buildMSA}) and ($VARS{user_tree_file_name} eq ""))
{
$VARS{running_mode}="_mode_pdb_msa";
}
elsif ((!$FORM{buildMSA}) and ($VARS{user_tree_file_name} ne ""))
{
$VARS{running_mode}="_mode_pdb_msa_tree";
}
}
elsif ($VARS{CONSURF_CONSEQ} eq "CONSEQ")
{
if ($FORM{buildMSA})
{
$VARS{running_mode}="_mode_no_pdb_no_msa";
}
elsif ($VARS{user_tree_file_name} ne "")
{
$VARS{running_mode}="_mode_msa_tree";
}
else
{
$VARS{running_mode}="_mode_msa";
}
$VARS{r4s_log} = "$VARS{Seq_Name}_r4s.log";
$VARS{r4s_out} = "$VARS{Seq_Name}_r4s.res";
$VARS{r4s_slow_log} = "$VARS{Seq_Name}_r4s_slow.log";
$VARS{atom_positionFILE} = "$VARS{Seq_Name}_atom_pos.txt";
$VARS{gradesPE} = "$VARS{Seq_Name}_consurf.grades";
$VARS{r4s_tree}="$VARS{Seq_Name}_Tree.txt";
$VARS{Colored_Seq_HTML}="$VARS{Seq_Name}_ColoredSeq.html";
}
$VARS{insufficient_data}="no";
print "Running mode is: $VARS{running_mode} (with ConSurf/ConSeq mode: $VARS{CONSURF_CONSEQ})\n" if ($dbg);
#---------------------------------------------
# mode : include pdb
#---------------------------------------------
# create a pdbParser, to get various info from the pdb file
if ($VARS{running_mode} eq "_mode_pdb_no_msa" or $VARS{running_mode} eq "_mode_pdb_msa" or $VARS{running_mode} eq "_mode_pdb_msa_tree"){
$VARS{pdb_file} = new pdbParser;
$VARS{pdb_file}->read($VARS{pdb_file_name});
print $VARS{pdb_file}."\n" if ($dbg);
# FIRST check if there is no seqres
($VARS{SEQRES_seq}, $VARS{ATOM_seq}) = &get_seqres_atom_seq();
&analyse_seqres_atom();
}
#---------------------------------------------
# mode : no msa - with PDB or without PDB
#---------------------------------------------
if ($VARS{running_mode} eq "_mode_pdb_no_msa" or $VARS{running_mode} eq "_mode_no_pdb_no_msa"){
print "No msa mode - with PDB or without PDB MODE\n" if ($dbg);
# if there is pdb : we compare the atom and seqres
if ($VARS{running_mode} eq "_mode_pdb_no_msa" and (defined($VARS{SEQRES_seq}) and length($VARS{SEQRES_seq}) > 0)){
# align seqres and pdb sequences
&compare_atom_seqres_or_msa("SEQRES");
$VARS{BLAST_out_file} = "$FORM{pdb_ID}_$FORM{chain}.protein_query.blast"; # file to hold blast output
$VARS{BLAST_last_round} = "$FORM{pdb_ID}_$FORM{chain}.last_round.blast"; # file to hold blast output, last round
}
else
{
$VARS{BLAST_out_file} = "$VARS{Seq_Name}.protein_query.blast"; # file to hold blast output
$VARS{BLAST_last_round} = "$VARS{Seq_Name}.last_round.blast"; # file to hold blast output, last round
}
# print "How many?".CONSURF_CONSTANTS::BLAST_MAX_HOMOLOGUES_TO_DISPLAY."\n";
# $VARS{max_homologues_to_display} = CONSURF_CONSTANTS::BLAST_MAX_HOMOLOGUES_TO_DISPLAY;
$VARS{max_homologues_to_display} =
$config->val( 'params', 'BLAST_MAX_HOMOLOGUES_TO_DISPLAY' );
# USER CAN SPECIFY THE DB TO USE HERE!!!!
$VARS{protein_db} = $config->val( 'databases', 'SWISSPROT_DB' );
# if ($FORM{database} eq "SWISS-PROT"){
# $VARS{protein_db} = CONSURF_CONSTANTS::SWISSPROT_DB;}
# else{
# $VARS{protein_db} = CONSURF_CONSTANTS::UNIPROT_DB;}
# create the seqres fasta file, run blast
if (defined $VARS{usr_BLAST_out_file})
{
print "Starting from predefined BLAST file: $VARS{usr_BLAST_out_file}\n" if ($dbg);
copy ($VARS{usr_BLAST_out_file},"$VARS{working_dir}/$VARS{BLAST_out_file}");
}
else
{
&run_blast();
}
&extract_round_from_blast();
# choosing homologs, create fasta file for all legal homologs
my %blast_hash = ();
my %cd_hit_hash = ();
# $VARS{hit_redundancy} = CONSURF_CONSTANTS::FRAGMENT_REDUNDANCY_RATE;
# $VARS{hit_overlap} = CONSURF_CONSTANTS::FRAGMENT_OVERLAP;
# $VARS{hit_min_length} = CONSURF_CONSTANTS::FRAGMENT_MINIMUM_LENGTH;
# $VARS{min_num_of_hits} = CONSURF_CONSTANTS::MINIMUM_FRAGMENTS_FOR_MSA;
# $VARS{low_num_of_hits} = CONSURF_CONSTANTS::LOW_NUM_FRAGMENTS_FOR_MSA;
# $VARS{HITS_fasta_file} = "$FORM{pdb_ID}_$FORM{chain}.homolougs.fas";
# $VARS{HITS_rejected_file} = "$FORM{pdb_ID}_$FORM{chain}.rejected_homolougs.fas";
$VARS{hit_redundancy} = $config->val( 'params', 'FRAGMENT_REDUNDANCY_RATE' );
$VARS{hit_overlap} = $config->val( 'params', 'FRAGMENT_OVERLAP' );
$VARS{hit_min_length} = $config->val( 'params', 'FRAGMENT_MINIMUM_LENGTH' );
$VARS{min_num_of_hits} = $config->val( 'params', 'MINIMUM_FRAGMENTS_FOR_MSA' );
$VARS{low_num_of_hits} = $config->val( 'params', 'LOW_NUM_FRAGMENTS_FOR_MSA' );
if ($VARS{CONSURF_CONSEQ} eq "CONSURF")
{
$VARS{HITS_fasta_file} = "$FORM{pdb_ID}_$FORM{chain}.homolougs.fas";
$VARS{HITS_rejected_file} = "$FORM{pdb_ID}_$FORM{chain}.rejected_homolougs.fas";
$VARS{cd_hit_out_file} = "$FORM{pdb_ID}_$FORM{chain}.cdhit.out";
$VARS{FINAL_sequences} = "$FORM{pdb_ID}_$FORM{chain}.final_homolougs.fas";
$VARS{protein_MSA} = "$FORM{pdb_ID}_$FORM{chain}_query_msa.aln";
}
else
{
$VARS{HITS_fasta_file} = "$VARS{Seq_Name}.homolougs.fas";
$VARS{HITS_rejected_file} = "$VARS{Seq_Name}.rejected_homolougs.fas";
$VARS{cd_hit_out_file} = "$VARS{Seq_Name}.cdhit.out";
$VARS{FINAL_sequences} = "$VARS{Seq_Name}.final_homolougs.fas";
$VARS{protein_MSA} = "$VARS{Seq_Name}_query_msa.aln";
}
&choose_homologoues_from_blast(\%blast_hash);
# screen homolougs by redundancy rate, according to clusters (CD-HIT)
my $num_of_unique_seq=cluster_homologoues(\%cd_hit_hash, \%blast_hash);
$VARS{unique_seqs}=$num_of_unique_seq;
&choose_final_homologoues(\%cd_hit_hash, \%blast_hash);
&create_MSA;
if ($VARS{running_mode} eq "_mode_pdb_no_msa")
{
$VARS{msa_SEQNAME}="Input_pdb_SEQRES_A"; #CONSIDER TO CHANGE
}
}
#---------------------------------------------
# mode : include msa
#---------------------------------------------
elsif ($VARS{running_mode} eq "_mode_pdb_msa" or $VARS{running_mode} eq "_mode_msa" or $VARS{running_mode} eq "_mode_pdb_msa_tree" or $VARS{running_mode} eq "_mode_msa_tree"){
print "msa mode - with PDB or without PDB\n" if ($dbg);
# check that there are at least 5 sequecnes in the MSA
# extract the query sequence from the MSA
# change the MSA sequences names to numbers
# change the MSA format to clustalw
# align the seqres/atom sequence with that of the query
&determine_msa_format();
my %MSA_sequences = (); # a hash to hold all the MSA sequences, : key - sequence id, value - sequence
if ($VARS{CONSURF_CONSEQ} eq "CONSURF")
{
$VARS{user_msa_fasta} = "$FORM{pdb_ID}_$FORM{chain}_msa_file.fas"; # if the file is not in fasta format, we create a fasa copy of it
}
else
{
$VARS{user_msa_fasta} = "$VARS{Seq_Name}_msa_file.fas"; # if the file is not in fasta format, we create a fasa copy of it
}
&get_info_from_msa(\%MSA_sequences);
$VARS{query_string} = $FORM{msa_SEQNAME};
$VARS{MSA_query_seq} = $MSA_sequences{$VARS{query_string}};
$VARS{MSA_query_seq} =~ s/\-//g; # remove gpas from the query sequence
#---------------------------------------------
# mode : include tree
#---------------------------------------------
if ($VARS{running_mode} eq "_mode_pdb_msa_tree" or $VARS{running_mode} eq "_mode_msa_tree"){
&check_validity_tree_file();
my %tree_nodes = (); # a hash to hold all the nodes in the tree (as keys)
&extract_nodes_from_tree(\%tree_nodes);
#foreach my $node (sort (keys %tree_nodes)){
# print OUTPUT "NODE: $node <br />";
#}
&check_msa_tree_match(\%MSA_sequences, \%tree_nodes);
}
&compare_atom_seqres_or_msa("MSA") if ($VARS{running_mode} eq "_mode_pdb_msa" or $VARS{running_mode} eq "_mode_pdb_msa_tree");
$VARS{protein_MSA} = $VARS{user_msa_fasta};
$VARS{msa_SEQNAME}=$FORM{msa_SEQNAME};
}
&run_rate4site;
&assign_colors_according_to_r4s_layers(\@gradesPE_Output);
&read_residue_variety(\%residue_freq, \%position_totalAA); # put value in $VARS{num_of_seqs_in_MSA}
#---------------------------------------------
# mode : include pdb
#---------------------------------------------
# in order to create 3D outputs, we need to compare the ATOM to the sequence from rate4site
if ($VARS{running_mode} eq "_mode_pdb_no_msa" or $VARS{running_mode} eq "_mode_pdb_msa" or $VARS{running_mode} eq "_mode_pdb_msa_tree"){
&create_atom_position_file; # this file will be used later to create the output which aligns rate4site sequence with the ATOM records
my %r4s2pdb = (); # key: poistion in SEQRES/MSA, value: residue name with position in atom (i.e: ALA22:A)
if ((defined($VARS{SEQRES_seq}) and length($VARS{SEQRES_seq})>0))
{
&match_pdb_to_seq(\%r4s2pdb);
}
elsif ((defined $VARS{pairwise_aln}) and (-e "$VARS{working_dir}/$VARS{pairwise_aln}"))
{
&match_pdb_to_seq(\%r4s2pdb);
}
else # NO SEQRES
{
&fill_r4s2pdb(\%r4s2pdb); # fill $length_of_atom
$length_of_seqres=0;
}
&create_gradesPE(\%r4s2pdb);
$VARS{ATOMS_with_ConSurf_Scores} = $VARS{out_dir}. "ATOMS_section_With_ConSurf.pdb";
$VARS{ATOMS_with_ConSurf_Scores_isd} = $VARS{out_dir}. "ATOMS_section_With_ConSurf_isd.pdb";
# $VARS{gradesPE} = $VARS{out_dir}.$VARS{gradesPE};
print "\nInput for PDB PIPE maker: Chain: ".$FORM{chain}."; PDB: ". $VARS{pdb_file_name}." Grades file: ".$VARS{gradesPE}."\n" if ($dbg);
my @ans1=cp_rasmol_gradesPE_and_pipe::ReplaceTempFactConSurfScore($FORM{chain},$VARS{pdb_file_name},$VARS{gradesPE},$VARS{ATOMS_with_ConSurf_Scores},$VARS{ATOMS_with_ConSurf_Scores_isd});
unless ($ans1[0] eq "OK") {print("cp_rasmol_gradesPE_and_pipe::ReplaceTempFactConSurf FAILED: @ans1") if ($dbg);}
$VARS{insufficient_data} = $ans1[1];
# 1. ATOM FILE WITH R4S scores - needed for pymol
# $VARS{ATOMS_with_R4S_Scores}= $VARS{out_dir}. "ATOMS_section_With_R4S.pdb";
# my %Rate4Site_Grades=();
# print "\nCalling:cp_rasmol_gradesPE_and_pipe::read_Rate4Site_gradesPE($VARS{gradesPE},\%Rate4Site_Grades)\n" if ($dbg);
# cp_rasmol_gradesPE_and_pipe::read_Rate4Site_gradesPE($VARS{gradesPE},\%Rate4Site_Grades);
# # print "Calling:cp_rasmol_gradesPE_and_pipe::replace_tempFactor($VARS{pdb_file_name},$FORM{chain},\%Rate4Site_Grades,$VARS{ATOMS_with_R4S_Scores})\n" if ($dbg);
# cp_rasmol_gradesPE_and_pipe::replace_tempFactor("$VARS{pdb_file_name}",$FORM{chain},\%Rate4Site_Grades,$VARS{ATOMS_with_R4S_Scores});
# 2. create RASMOL (was on &create_rasmol)
#---------------------------------------------
# print 2 rasmol files, one showing insufficient data, one hiding it.
#---------------------------------------------
$VARS{rasmolFILE}=$VARS{out_dir}."rasmol.scr";
$VARS{rasmol_isdFILE} = $VARS{out_dir}."rasmol_isd.scr";
print "Calling cp_rasmol_gradesPE_and_pipe::print_rasmol for files $VARS{rasmolFILE} and $VARS{rasmol_isdFILE}\n" if ($dbg);
my @ans2 = cp_rasmol_gradesPE_and_pipe::print_rasmol($VARS{rasmolFILE}, "no",\@no_isd_residue_color, $FORM{chain}, "no"); #Without isd residue Color
unless ($ans2[0] eq "OK") {print "cp_rasmol_gradesPE_and_pipe::print_rasmol FAILED: @ans2" if ($dbg);}
if ( $VARS{insufficient_data} eq "yes"){
@ans2 = cp_rasmol_gradesPE_and_pipe::print_rasmol($VARS{rasmol_isdFILE}, "yes",\@isd_residue_color, $FORM{chain}, "no"); #With isd Residue Color
unless ($ans2[0] eq "OK") {print "cp_rasmol_gradesPE_and_pipe::print_rasmol FAILED: @ans2" if ($dbg);}
}
}
#---------------------------------------------
# mode : ConSeq - NO PDB
#---------------------------------------------
if ($VARS{running_mode} eq "_mode_msa" or $VARS{running_mode} eq "_mode_no_pdb_no_msa" or $VARS{running_mode} eq "_mode_msa_tree") #ConSeq Mode
{
# $VARS{Solv_ACC_Pred}="Solv_Acc_Pred.PACC"; # To Do: Buried exposed file to be predicted
my @msa_format=MSA_parser::determine_msa_format("$VARS{working_dir}/$VARS{protein_MSA}");
if ($msa_format[0] eq "err"){
my $msa_info_msg = "<a href =\"http://www.ebi.ac.uk/help/formats.html\">Read more on MSA formats</a><br />\n";
&exit_on_error('user_error',"The uploaded <a href=\"$VARS{user_msa_file_name}\">MSA file</a> is not in one of the formats supported by ConSurf: NBRF/PIR, Pearson (Fasta), Nexus, Clustal, GCG/MSF.<br /><br />\nPlease check the following items and try to run ConSurf again:<br />\n1. The file should be saved as plain text (e.g. file type 'txt' in windows or 'MS-Dos' from Word in Mac).<br />\n2. The file should not contain unnecessary characters (You can check it with 'Notepad' editor).<br />\n3. The same sequence name must not be repeated more then once.<br />\n".$msa_info_msg);
}
else{
print LOG "determine_msa_format : MSA format is : $msa_format[1]\n";
$VARS{msa_format} = $msa_format[1];
}
#predict_solvent_accesibility(); #To Do: run the algorithm to calculate burried/exposed
my %Pos_Solv_Acc_Pred = (); # To Do: fill the hash - key: poistion in SEQRES/MSA, value: PACC Solv Acc Pred (b/e)
#read_Solv_Acc_Pred(\%Pos_Solv_Acc_Pred);
create_gradesPE_ConSeq(\%Pos_Solv_Acc_Pred);
print "Calling cp_rasmol_gradesPE_and_pipe::ConSeq_HTML_Output(\@gradesPE_Output,\%Pos_Solv_Acc_Pred,\"$VARS{working_dir}/$VARS{Colored_Seq_HTML}\",\"yes\")\n" if ($dbg);
# cp_rasmol_gradesPE_and_pipe::ConSeq_HTML_Output(\@gradesPE_Output,\%Pos_Solv_Acc_Pred,"$VARS{working_dir}/$VARS{Colored_Seq_HTML}"); # To use when buried exposed is available
cp_rasmol_gradesPE_and_pipe::ConSeq_HTML_Output(\@gradesPE_Output,\%Pos_Solv_Acc_Pred,"$VARS{working_dir}/$VARS{Colored_Seq_HTML}","yes");
my $Protein_Length=$#gradesPE_Output+1;
}
# print a file that details percentage of each AA in the MSA - (&print_residue_precentage())
#------------------------------------------------------------------
####################################################################
$VARS{MSA_percentage_FILE}=$VARS{out_dir}."msa_aa_variety_percentage.csv";
print "Calling cp_rasmol_gradesPE_and_pipe::print_precentage(\%residue_freq, \%position_totalAA, $VARS{MSA_percentage_FILE},\@gradesPE_Output)\n" if ($dbg);
my @ans3 = cp_rasmol_gradesPE_and_pipe::print_precentage(\%residue_freq, \%position_totalAA, $VARS{MSA_percentage_FILE},\@gradesPE_Output);
unless ($ans3[0] eq "OK") {print "cp_rasmol_gradesPE_and_pipe::print_precentage FAILED: @ans3" if ($dbg);}
# Organize outputs
copy ($VARS{working_dir}.'/'. $VARS{protein_MSA}, $VARS{out_dir}.'/'. $VARS{protein_MSA} );
if ($FORM{buildMSA}){copy ($VARS{working_dir}.'/'. $VARS{HITS_rejected_file}, $VARS{out_dir}.'/'. $VARS{HITS_rejected_file} );}
copy ($VARS{working_dir}.'/'. $VARS{r4s_tree}, $VARS{out_dir}.'/'. $VARS{r4s_tree} );
my $final_output_message="";
if ($VARS{CONSURF_CONSEQ} eq "CONSURF")
{
$VARS{chimera_script_src} = $consurf_utildir.'/chimera_consurf.cmd';
$VARS{pymol_script_src} = $consurf_utildir.'/consurf_new.py';
$VARS{chimera_script_target} = $VARS{out_dir}.'chimera_consurf.cmd';
$VARS{pymol_script_target} = $VARS{out_dir}.'consurf_new.py';
copy ( $VARS{chimera_script_src}, $VARS{chimera_script_target} );
copy ( $VARS{pymol_script_src} , $VARS{pymol_script_target} );
$final_output_message = <<EOF;
Consurf run completed successfuly!
Here is a list of files that could be found in the output dir
$VARS{out_dir}
|
|-- $VARS{out_dir}/$VARS{protein_MSA}\tMultiple Sequence Alignment
|-- $VARS{gradesPE}\tAmino acid conservation scores, confidence intervals and conservation colors
|-- $VARS{MSA_percentage_FILE}\tResidue variety per position in the MSA
|-- $VARS{r4s_tree}\tPhylogenetic tree
|-- $VARS{ATOMS_with_ConSurf_Scores}\tPDB with conservation scores for presentation using the Chimera and Pymol viewers
|-- $VARS{ATOMS_with_ConSurf_Scores_isd}\tPDB with conservation scores for presentation using the Chimera and Pymol viewers (/without/ insufficient data annotations)
|-- $VARS{rasmolFILE}\tRasMol script required to present the results using the RasMol viewer
|-- $VARS{rasmol_isdFILE}\tRasMol script required to present the results using the RasMol viewer (without insufficient data annotations)
|-- $VARS{chimera_script_target}\tChimera script required to present the results using the Chimera viewer
|-- $VARS{pymol_script_target}\tPymol script required to present the results using the Pymol viewer (without insufficient data annotations)
EOF
}
if ($VARS{CONSURF_CONSEQ} eq "CONSEQ")
{
copy ($VARS{working_dir}.'/'. $VARS{Colored_Seq_HTML}, $VARS{out_dir}.'/'. $VARS{Colored_Seq_HTML} );
copy ($VARS{working_dir}.'/'.$VARS{gradesPE}, $VARS{out_dir}.'/'.$VARS{gradesPE});
$VARS{MSA_percentage_FILE}="msa_aa_variety_percentage.csv";
$final_output_message = <<EOF;
Consurf run completed successfuly!
Here is a list of files that could be found in the output dir
$VARS{out_dir}
|
|-- $VARS{protein_MSA}\tMultiple Sequence Alignment
|-- $VARS{gradesPE}\tAmino acid conservation scores, confidence intervals and conservation colors
|-- $VARS{MSA_percentage_FILE}\tResidue variety per position in the MSA
|-- $VARS{r4s_tree}\tPhylogenetic tree
|-- $VARS{Colored_Seq_HTML}\tThe sequence colored by ConSurf scores
EOF
}
if ($FORM{buildMSA})
{
$final_output_message =$final_output_message ." |-- $VARS{HITS_rejected_file}\tRejected seqeunces\n\n";
}
print $final_output_message if (!$quiet);
exit (0);
### SUBRUTINES #####
####################
sub create_working_dir{
if (!-d $VARS{working_dir}){
mkdir $VARS{working_dir} or &exit_on_error('sys_error', "create_working_dir : the directory $VARS{working_dir} was not created $!");
}
chmod 0755, $VARS{working_dir};
}
#---------------------------------------------
sub analyse_seqres_atom{
# there is no ATOM field in the PDB
if ($VARS{ATOM_seq} eq ""){
&exit_on_error('user_error',"There is no ATOM derived information in the PDB file. Please refer to the OVERVIEW for detailed information about the PDB format.");
}
# there is no SEQRES field in the PDB
if ($VARS{SEQRES_seq} eq ""){
my $msg = "Warning: There is no SEQRES derived information in the PDB file. The calculation will be based on the ATOM derived sequence. ";
if ($VARS{running_mode} eq "_mode_pdb_no_msa"){
$msg.= "If this sequence is incomplete, we recommend to re-run the server using an external multiple sequence alignment file, which is based on the complete protein sequence.";
}
print LOG "analyse_seqres_atom : There is no SEQRES derived information in the PDB file.\n";
print_message_to_output($msg);
}
# if modified residues exists, print them to the screen
if (defined($VARS{pdb_file}->get("MODIFIED_COUNT$FORM{chain}.raw")) and $VARS{pdb_file}->get("MODIFIED_COUNT$FORM{chain}.raw")> 0 ){
# if (defined($VARS{SEQRES_seq}) and length($VARS{SEQRES_seq}) > 0 and ($VARS{pdb_file}->get("MODIFIED_COUNT$FORM{chain}.raw") / length($VARS{SEQRES_seq}) > CONSURF_CONSTANTS::MAXIMUM_MODIFIED_PERCENT) ){
if (
defined( $VARS{SEQRES_seq} )
and length( $VARS{SEQRES_seq} ) > 0
and ( $VARS{pdb_file}->get("MODIFIED_COUNT$FORM{chain}.raw") /
length( $VARS{SEQRES_seq} ) >
$config->val( 'databases', 'MAXIMUM_MODIFIED_PERCENT' ))
){
&exit_on_error('user_error', "Too many modified residues were found in SEQRES field.");
}
print LOG "analyse_seqres_atom : modified residues found\n";
}
# print "The Atoms are fine !!!\n ".$VARS{ATOM_seq} if ($dbg);
}
#---------------------------------------------
sub compare_atom_seqres_or_msa{
my $what_to_compare = shift;
# in case there are both seqres and atom fields, checks the similarity between the 2 sequences.
my $atom_length = length($VARS{ATOM_seq});
# print "\n".$atom_length."\n" if ($dbg);
my ($other_query_length, $other_query_seq, %query_line);
my $two_fastas = "PDB_$what_to_compare"."_$FORM{pdb_ID}_$FORM{chain}.fasta2"; #CHANGHING THE NAMES
my $clustalw_out = "PDB_$what_to_compare"."_$FORM{pdb_ID}_$FORM{chain}.out";
$VARS{pairwise_aln} = "PDB_$what_to_compare"."_$FORM{pdb_ID}_$FORM{chain}.aln";
if ($what_to_compare eq "SEQRES"){
if ($VARS{SEQRES_seq} eq ""){
$other_query_length = 0;}
else{
$other_query_length = length($VARS{SEQRES_seq});}
$other_query_seq = $VARS{SEQRES_seq};
}
else{
$other_query_length = length ($VARS{MSA_query_seq});
$other_query_seq = $VARS{MSA_query_seq};
}
my $alignment_score;
my $atom_line = "sequence extracted from the ATOM field of the PDB file";
$query_line{SEQRES} = "sequence extracted from the SEQRES field of the PDB file";
$query_line{MSA} = "sequence extracted from the MSA file";
# compare the length of ATOM and SEQRES. output a message accordingly
if ($other_query_length!=0 and $other_query_length < $atom_length){
print_message_to_output("The ".$query_line{$what_to_compare}." is shorter than the $atom_line. The $what_to_compare sequence has $other_query_length residues and the ATOM sequence has $atom_length residues. The calculation continues nevertheless.");
}
if ($atom_length < $other_query_length){
if ($atom_length < ($other_query_length * 0.2)){
exit_on_error('user_error', "The $atom_line is significantly shorter than the ".$query_line{$what_to_compare}.". The $what_to_compare sequence has $other_query_length residues and the ATOM sequence has only $atom_length residues.");
}
else{
print_message_to_output("The $atom_line is shorter than the ".$query_line{$what_to_compare}.". The $what_to_compare sequence has $other_query_length residues and the ATOM sequence has $atom_length residues. The calculation continues nevertheless.");
}
}
# run clustalw to see the match between ATOM and SEQRES sequences
print LOG "compare_atom_seqres_or_msa : run clustalw to see the match between ATOM and $what_to_compare sequences\n";
open FAS, ">$VARS{working_dir}/$two_fastas" or exit_on_error('sys_error', "compare_atom_seqres_or_msa : Cannot open the file $two_fastas for writing $!");
print FAS ">".$what_to_compare."_$FORM{chain}\n$other_query_seq\n>ATOM_$FORM{chain}\n$VARS{ATOM_seq}\n";
close FAS;
my $command = $config->val( 'programs', 'MUSCLE' )." -in ".$VARS{working_dir}."/".$two_fastas." -out $VARS{working_dir}/$VARS{pairwise_aln} -clwstrict -quiet";
print LOG "compare_atom_seqres_or_msa : run $command\n";
warn $command if ($dbg);
`$command`;
if (!-e "$VARS{working_dir}/$VARS{pairwise_aln}" or -z "$VARS{working_dir}/$VARS{pairwise_aln}"){
exit_on_error('sys_error',"compare_atom_seqres_or_msa : pairwise alignment output was not created: $VARS{pairwise_aln}");
}
# Use Bio::AlignIO to read in the alignment
my $str = Bio::AlignIO->new(-file => "$VARS{working_dir}/$VARS{pairwise_aln}");
my $aln = $str->next_aln();
$alignment_score = $aln->overall_percentage_identity;
$alignment_score = sprintf "%.3f", $alignment_score;
if ($alignment_score < 100){
if ($alignment_score < 60){
exit_on_error('user_error',"The Score of the alignment between the ".$query_line{$what_to_compare}." and the $atom_line is ONLY $alignment_score% identity. See $VARS{pairwise_aln} pairwise alignment.");
}
else{
print_message_to_output("The Score of the alignment between the ".$query_line{$what_to_compare}." and the $atom_line is $alignment_score% identity. See $VARS{pairwise_aln} pairwise alignment. The calculation continues nevertheless.");
}
}
}
#------------------------------------------
# In PDB mode: create a fasta file with the protein SEQRES sequence (if no seqres - than with the ATOM sequence)
# run blast according to user's input
sub run_blast{
unless ($VARS{running_mode} eq "_mode_no_pdb_no_msa"){
open FAS, ">$VARS{working_dir}/$VARS{protein_seq}" or exit_on_error('sys_error',"run_blast : cannot open the file $VARS{working_dir}/$VARS{protein_seq} for writing $!");
if ($VARS{SEQRES_seq} eq ""){
print FAS ">PDB_ATOM\n$VARS{ATOM_seq}\n";
}
else{
print FAS ">PDB_SEQRES\n$VARS{SEQRES_seq}\n";
}
close FAS;
if (!-e "$VARS{working_dir}/$VARS{protein_seq}" or -z "$VARS{working_dir}/$VARS{protein_seq}"){
exit_on_error('sys_error',"run_blast : the file $VARS{working_dir}/$VARS{protein_seq} was not created");
}
}
print "{protein_db}\n";
my $cmd = $config->val( 'programs', 'BLASTPGP' )." -i $VARS{working_dir}/$VARS{protein_seq} -e $FORM{ESCORE} -d $VARS{protein_db} -o $VARS{working_dir}/$VARS{BLAST_out_file} -j $FORM{iterations} -v $VARS{max_homologues_to_display} -b $VARS{max_homologues_to_display} -F F";
print LOG "run_blast : running: $cmd\n";
$cmd .= " 2>&1 1>/dev/null" if ($quiet);
warn "$cmd\n" if ($dbg);
my $ans = `$cmd`;
print LOG "run_blast : ans from blast run: $ans\n" if $ans ne "";
if (!-e "$VARS{working_dir}/$VARS{BLAST_out_file}" or (-e "$VARS{working_dir}/$VARS{BLAST_out_file}" and -z "$VARS{working_dir}/$VARS{BLAST_out_file}")){
exit_on_error('sys_error',"run_blast : run of blast fail. $VARS{working_dir}/$VARS{BLAST_out_file} is zero or not exists");
}
}
#---------------------------------------------
# read the blast result and extract last roun number (if exists)
# create a "shorter" blast file - to include only the information from blast's last round
sub extract_round_from_blast{
my $last_round_number = 0;
my $found_converged = 0;
my $ret = "";
my @ans = prepareMSA::get_blast_round("$VARS{working_dir}/$VARS{BLAST_out_file}");
if ($ans[0] eq "err"){
exit_on_error('sys_error',"extract_round_from_blast : $ans[1]");
}
elsif($ans[0] eq "no_hits"){
my $err = "No Blast hits were found. You may try to";
if ($FORM{database} eq "SWISS-PROT"){
$err.=":\n1. run your query using UniProt database.\n2. ";
}
$err.= " increase the Evalue.\n";
exit_on_error('user_error',$err);
}
else{
$last_round_number = $ans[0];
$found_converged = $ans[1];
}
# if there is more than 1 round, extract blast hits only from the last round
if ($last_round_number>1){
@ans = prepareMSA::print_blast_according_to_round("$VARS{working_dir}/$VARS{BLAST_out_file}", $last_round_number, "$VARS{working_dir}/$VARS{BLAST_last_round}");
if ($ans[0] eq "err"){
exit_on_error('sys_error',"extract_round_from_blast : $ans[1]");
}
if (-e "$VARS{working_dir}/$VARS{BLAST_last_round}" and !-z "$VARS{working_dir}/$VARS{BLAST_last_round}"){
my $cmd = "mv $VARS{working_dir}/$VARS{BLAST_last_round} $VARS{working_dir}/$VARS{BLAST_out_file}";
warn $cmd if ($dbg);
# chdir $VARS{working_dir};
`$cmd`;
}
else{
print LOG "extract_round_from_blast : the file $VARS{working_dir}/$VARS{BLAST_last_round} was not created. The hits will be collected from the original blast file";
}
}
}
#---------------------------------------------
sub choose_homologoues_from_blast{
my $ref_blast_hash = shift;
print LOG "choose_homologoues_from_blast : running prepareMSA::choose_homologoues_from_blast\n";
my @ans = prepareMSA::choose_homologoues_from_blast("$VARS{working_dir}/", "$VARS{working_dir}/$VARS{protein_seq}", $VARS{hit_redundancy}, $VARS{hit_overlap}, $VARS{hit_min_length}, $VARS{min_num_of_hits}, "$VARS{working_dir}/$VARS{BLAST_out_file}", $VARS{HITS_fasta_file}, $VARS{HITS_rejected_file}, $ref_blast_hash);
if ($ans[0] eq "sys"){
exit_on_error('sys_error',$ans[1]);
}
elsif ($ans[0] eq "user"){
exit_on_error('user_error',"According to the parameters of this run, $ans[1] You can try to:\n1. Re-run the server with a multiple sequence alignment file of your own.\n2. Decrease the Evalue.\n");
}
if (!-e "$VARS{working_dir}/$VARS{HITS_fasta_file}" or -z "$VARS{working_dir}/$VARS{HITS_fasta_file}"){
exit_on_error('sys_error',"choose_homologoues_from_blast : the file $VARS{working_dir}/$VARS{HITS_fasta_file} was not created or contains no data");
}
}
#---------------------------------------------
sub cluster_homologoues{
my $ref_cd_hit_hash = shift;
my $ref_blast_hash = shift;
my $msg = "";
print LOG "cluster_homologoues : running prepareMSA::create_cd_hit_output\n";
my @ans = prepareMSA::create_cd_hit_output(
"$VARS{working_dir}/", $VARS{HITS_fasta_file},
$VARS{cd_hit_out_file}, $VARS{hit_redundancy} / 100,
$config->val( 'programs', 'CD_HIT' ),
$ref_cd_hit_hash,
"from_ibis",
$dbg
);
if ($ans[0] eq "sys"){
exit_on_error('sys_error',$ans[1]);
}
my $total_num_of_hits = keys (%$ref_cd_hit_hash);
my $num_of_blast_hits = keys (%$ref_blast_hash);
$FORM{MAX_NUM_HOMOL}=$total_num_of_hits if (($FORM{MAX_NUM_HOMOL} eq 'all') or ($FORM{MAX_NUM_HOMOL} eq "ALL"));
# less seqs than the minimum: exit
if ($total_num_of_hits < $VARS{min_num_of_hits}){
if ($total_num_of_hits<=1){
$msg = "There is only 1 ";