Repository navigation
Expand file tree
/
Copy pathNCBIBlastSearchEngine.pm
More file actions
executable file
·1941 lines (1586 loc) · 56.2 KB
/
Copy pathNCBIBlastSearchEngine.pm
File metadata and controls
executable file
·1941 lines (1586 loc) · 56.2 KB
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
##---------------------------------------------------------------------------##
## File:
## @(#) NCBIBlastSearchEngine.pm
## Author:
## Robert M. Hubley rhubley@systemsbiology.org
## Description:
## An implementation of SearchEngineI for the
## the NCBI Blast search engine.
##
#******************************************************************************
#* Copyright (C) Institute for Systems Biology 2003-2004 Developed by
#* Arian Smit and Robert Hubley.
#*
#* This work is licensed under the Open Source License v2.1. To view a copy
#* of this license, visit http://www.opensource.org/licenses/osl-2.1.php or
#* see the license.txt file contained in this distribution.
#*
#******************************************************************************
# Implementation Details:
#
# bless(
# 'NCBIBlastSearchEngine' );
#
###############################################################################
# ChangeLog
#
# $Log$
#
###############################################################################
# To Do:
#
#
=head1 NAME
NCBIBlastSearchEngine
=head1 SYNOPSIS
use NCBIBlastSearchEngine
Usage:
use SearchEngineI;
use NCBIBlastSearchEngine;
use SearchResultCollection;
my $NCBIEngine = NCBIBlastSearchEngine->new(
pathToEngine=>"/usr/local/ncbi/bin/rmblastn" );
$NCBIEngine->setMatrix( "/users/bob/simple.matrix" );
$NCBIEngine->setQuery( "/users/bob/query.fasta" );
$NCBIEngine->setSubject( "/users/bob/subject.fasta" );
my $searchResults = $NCBIEngine->search();
=head1 DESCRIPTION
A concrete implementation of the abstract class / interface SearchEngineI
which use the NCBI rmblastn sequence search engine.
=head1 INSTANCE METHODS
=cut
package NCBIBlastSearchEngine;
use strict;
use SearchEngineI;
use SearchResultCollection;
use Data::Dumper;
use FileHandle;
use File::Basename;
use File::Spec;
use Carp;
# For debugging only
#use Time::HiRes qw(gettimeofday);
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
require Exporter;
@ISA = qw(Exporter SearchEngineI);
@EXPORT = qw();
@EXPORT_OK = qw();
%EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
#
# Version
#
my $VERSION = 0.1;
my $CLASS = "NCBIBlastSearchEngine";
##-------------------------------------------------------------------------##
## Constructor
##-------------------------------------------------------------------------##
sub new {
my $class = shift;
my %nameValuePairs = @_;
croak $CLASS
. "::new: Missing path to search engine!\n\n"
. "use \$searchEngine = $CLASS->new( pathToEngine=>\"/usr/local/"
. "bin/rmblastn\")\n"
if ( not defined $nameValuePairs{'pathToEngine'} );
# Create ourself as a hash
my $this = {};
# Bless this hash in the name of the father, the son...
bless $this, $class;
$this->setPathToEngine( $nameValuePairs{'pathToEngine'} );
#
# Version dispatch. The 3.x series takes the same settings but spells
# them differently on the command line and has no separate database
# step, so hand the caller a subclass that knows how to drive it.
# Substituting here rather than at every call site keeps existing code
# working: callers still ask for an NCBIBlastSearchEngine, and
# isa("NCBIBlastSearchEngine") tests still match.
#
if ( $this->getMajorVersion() >= 3 && ref( $this ) eq $CLASS ) {
require RMBlastSearchEngine;
bless $this, "RMBlastSearchEngine";
}
# TODO: Figure out a better design
$this->setUseDustSeg( 1 );
# Allow import of values
if ( %nameValuePairs ) {
while ( my ( $name, $value ) = each( %nameValuePairs ) ) {
my $method = "set" . _ucFirst( $name );
unless ( $this->can( $method ) ) {
croak( $CLASS . "::set: Instance variable $name doesn't exist." . "" );
}
$this->$method( $value );
}
}
return $this;
}
##-------------------------------------------------------------------------##
## Get and Set Methods
##-------------------------------------------------------------------------##
##-------------------------------------------------------------------------##
=head2 get_setOverrideParameters()
Use: my $value = getOverrideParameters( );
Use: my $oldValue = setOverrideParameters( $value );
Get/Set the the override paramters. These are used instead
of all the SearchEngineI default parameters if set.
=cut
##-------------------------------------------------------------------------##
sub getOverrideParameters {
my $this = shift;
return $this->{'overrideParameters'};
}
sub setOverrideParameters {
my $this = shift;
my $value = shift;
my $oldValue = $this->{'overrideParameters'};
$this->{'overrideParameters'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
=head2 MaskLevelSequence()
Use: my $value = getMaskLevelSequence( );
Use: my $oldValue = setMaskLevelSequence( $value );
Get/Set the MaskLevelSequence paramter. This is the
sequence ( SearchResult::Query or SearchResult::Subject )
which will be considered when applying the mask level. The
default is SearchResult::Query.
=cut
##-------------------------------------------------------------------------##
sub getMaskLevelSequence {
my $this = shift;
return $this->{'maskLevelSequence'};
}
sub setMaskLevelSequence {
my $this = shift;
my $value = shift;
croak $CLASS
. "::setMaskLevelSequence: Invalid value ( $value ). "
. "Should be either SearchResult::Query or "
. "SearchResult::Subject\n"
if ( $value != SearchResult::Query
&& $value != SearchResult::Subject );
my $oldValue = $this->{'maskLevelSequence'};
$this->{'maskLevelSequence'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
=head2 UseDustSeg()
Use: my $value = getUseDustSeg( );
Use: my $oldValue = setUseDustSeg( $value );
Turn on / off the Dust/Seg screening of words.
=cut
##-------------------------------------------------------------------------##
sub getUseDustSeg {
my $this = shift;
return $this->{'useDustSeg'};
}
sub setUseDustSeg {
my $this = shift;
my $value = shift;
my $oldValue = $this->{'useDustSeg'};
$this->{'useDustSeg'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
=head2 TempDir()
Use: my $value = getTempDir( );
Use: my $oldValue = setTempDir( $value );
Set the directory to use as a temp directory for a search.
The default is to use the directory which contains the query sequence.
=cut
##-------------------------------------------------------------------------##
sub getTempDir {
my $this = shift;
return $this->{'tempDir'};
}
sub setTempDir {
my $this = shift;
my $value = shift;
my $oldValue = $this->{'tempDir'};
$this->{'tempDir'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
=head2 get_setAdditionalParameters()
Use: my $value = getAdditionalParameters( );
Use: my $oldValue = setAdditionalParameters( $value );
Get/Set the additional paramters. These are used in addition
to the existing parameter set.
=cut
##-------------------------------------------------------------------------##
sub getAdditionalParameters {
my $this = shift;
return $this->{'additionalParameters'};
}
sub setAdditionalParameters {
my $this = shift;
my $value = shift;
my $oldValue = $this->{'additionalParameters'};
$this->{'additionalParameters'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
=head2 get_setPathToEngine()
Use: my $value = getPathToEngine( );
Use: my $oldValue = setPathToEngine( $value );
Get/Set the fully qualified path to the search engine
binary file.
=cut
##-------------------------------------------------------------------------##
sub getPathToEngine {
my $this = shift;
return $this->{'pathToEngine'};
}
sub setPathToEngine {
my $this = shift;
my $value = shift;
croak $CLASS
. "::setPathToEngine(): Missing parameter! Must specify "
. "a path to the RMBlastN program.\n"
if ( $value =~ /^\s*$/ );
croak $CLASS. "::setPathToEngine( $value ): Program does not exist!"
if ( not -x $value || `which $value` );
$this->_probeVersion( $value );
my $oldValue = $this->{'pathToEngine'};
$this->{'pathToEngine'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
## Use: $this->_probeVersion( $pathToBinary );
##
## Ask the binary what it is, and set the version and capability flags.
## Broken out of setPathToEngine() so that a subclass driving a different
## rmblastn series can extend it.
##-------------------------------------------------------------------------##
sub _probeVersion {
my $this = shift;
my $value = shift;
# NCBI toolkit binaries accept "-version". The 3.x series uses GNU
# style long options, so try both before giving up.
my $result = `$value -version 2>&1`;
if ( $result !~ /rmblast/i ) {
$result = `$value --version 2>&1`;
}
croak $CLASS
. "::setPathToEngine( $value ): Cannot determine "
. "engine variant and version!\n"
if ( $result !~ /rmblast[n]\s*:?\s*(\S.*)/ );
$this->{'engineName'} = "rmblastn";
$this->{'version'} = $1;
# 2.x reports "2.17.1+" following the NCBI convention; 3.x reports a
# bare "3.0.4". Do not require the trailing "+". This test used to,
# which meant a 3.x binary parsed as having no version, left
# hasTabFormat unset, and fell through to the legacy report parser
# without any error.
croak $CLASS
. "::setPathToEngine( $value ): Could not parse a version number "
. "out of \""
. $this->{'version'}
. "\"!\n"
if ( $this->{'version'} !~ /(\d+)\.(\d+)\.(\d+)/ );
my $majorVer = $1;
my $minorVer = $2;
my $revision = $3;
$this->{'majorVersion'} = $majorVer;
$this->{'minorVersion'} = $minorVer;
$this->{'revision'} = $revision;
if ( $majorVer == 2 ) {
if ( $minorVer >= 13 ) {
# Since the 2.13.0+ release of RMBlast we now have:
# - pre-computed Kimura divergence, Kimura CpG adjusted,
# transitions, transversions, cpg_sites, and the cross_match
# stats (perc_sub, perc_query_gap, perc_subj_gap).
# - Ability to thread on the query sequences rather than just
# the subject sequences.
# - The ability to output tab delimited format with all the above
# fields.
$this->{'hasQueryThreading'} = 1;
$this->{'hasTabFormat'} = 1;
}
if ( $minorVer > 14 || ( $minorVer == 14 && $revision >= 1 ) ) {
$this->{'hasDBSoftMasking'} = 1;
}
}
elsif ( $majorVer == 3 ) {
# The 3.x series is a reimplementation with GNU style options and no
# separate database formatting step. RMBlastSearchEngine drives it;
# new() substitutes that class for this one.
$this->{'hasQueryThreading'} = 1;
$this->{'hasTabFormat'} = 1;
$this->{'hasDBSoftMasking'} = 1;
}
else {
# Refuse rather than guess. An unrecognized series may differ from
# both of the ones we know how to drive, and guessing wrong produces
# bad annotations with no error to show for it.
croak $CLASS
. "::setPathToEngine( $value ): Unsupported rmblastn version "
. $this->{'version'}
. ". This release can drive the 2.x and 3.x series.\n";
}
return;
}
##-------------------------------------------------------------------------##
=over 4
=item Use: my $value = getMajorVersion( );
Get the major version number of the engine binary. 2 for the NCBI
toolkit derived series, 3 for the reimplemented series.
=back
=cut
##-------------------------------------------------------------------------##
sub getMajorVersion {
my $this = shift;
return $this->{'majorVersion'};
}
##-------------------------------------------------------------------------##
=head2 get_setPathToDBFormatter()
Use: my $value = getPathToDBFormatter( );
Use: my $oldValue = setPathToDBFormatter( $value );
The program used to format a subject database for this engine. Derived
from the engine binary by default, since makeblastdb ships alongside
rmblastn, so callers need not carry a second configuration value.
=cut
##-------------------------------------------------------------------------##
sub getPathToDBFormatter {
my $this = shift;
return $this->{'pathToDBFormatter'}
if ( defined $this->{'pathToDBFormatter'} );
return dirname( $this->getPathToEngine() ) . "/makeblastdb";
}
sub setPathToDBFormatter {
my $this = shift;
my $value = shift;
my $oldValue = $this->{'pathToDBFormatter'};
$this->{'pathToDBFormatter'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
=head2 getSubjectArtifacts()
Use: my @files = getSubjectArtifacts( $path );
The files makeblastdb produces for a nucleotide database.
=cut
##-------------------------------------------------------------------------##
sub getSubjectArtifacts {
my $this = shift;
my $path = shift;
return () if ( !defined $path );
# BLASTDB version 4 and 5 suffixes, including the ones -parse_seqids
# adds, plus the log prepareSubject() writes. Not all are produced for
# every database, so callers must tolerate absent members.
return ( ( map { "$path.$_" }
qw( nhr nin nsq ndb not ntf nto njs nog nos nod
nnd nni nsd nsi nsg ) ),
"$path.makeblastdb.log" );
}
##-------------------------------------------------------------------------##
=head2 isSubjectPrepared()
Use: my $bool = isSubjectPrepared( $path );
True if $path names a formatted BLAST database.
=cut
##-------------------------------------------------------------------------##
sub isSubjectPrepared {
my $this = shift;
my $path = shift;
return 0 if ( !defined $path );
return ( -s "$path.nin"
|| -s "$path.nhr"
|| -s "$path.nsq"
|| -s "$path.nal" );
}
##-------------------------------------------------------------------------##
=head2 prepareSubject()
Use: my $subjectPath = prepareSubject( $seqFile,
[outputDir => $dir],
[dbName => $name],
[checkStale => 1],
[force => 1],
[parseSeqIDs => 1],
[dbVersion => 4] );
Run makeblastdb over $seqFile and return the database basename to hand
to setSubject(). This is not always $seqFile: when outputDir is given
the artifacts are written there, and the returned path points at that
directory, which holds the index but not the sequence file.
By default an existing database is left alone. Pass checkStale to also
rebuild when $seqFile is newer than its artifacts, or force to rebuild
unconditionally.
parseSeqIDs passes -parse_seqids, which a database needs before
setSubjectIDList() can restrict a search over it. dbVersion selects
the BLASTDB format version. Both are specific to this engine; the 3.x
engine ignores them.
=cut
##-------------------------------------------------------------------------##
sub prepareSubject {
my $this = shift;
my $seqFile = shift;
my %params = @_;
croak $CLASS
. "::prepareSubject(): Sequence file ($seqFile) does not "
. "exist or is empty!\n"
if ( !-s $seqFile );
my ( $vol, $dir, $file ) = File::Spec->splitpath( $seqFile );
my $outputDir = $params{'outputDir'};
$outputDir = ( $dir eq "" ? "." : $dir ) if ( !defined $outputDir );
$outputDir =~ s/\/+$//;
my $dbName = $params{'dbName'};
$dbName = $file if ( !defined $dbName );
my $dbPath = "$outputDir/$dbName";
if ( !$params{'force'} && $this->isSubjectPrepared( $dbPath ) ) {
my $stale = 0;
$stale =
$this->_artifactsAreStale( $seqFile,
$this->getSubjectArtifacts( $dbPath ) )
if ( $params{'checkStale'} );
if ( !$stale ) {
print $CLASS
. "::prepareSubject(): $dbPath is already prepared, skipping.\n"
if ( $this->getDEBUG() );
return $dbPath;
}
}
my $formatter = $this->getPathToDBFormatter();
croak $CLASS
. "::prepareSubject(): Cannot find the database formatting program "
. "($formatter). A 2.x rmblast installation must provide "
. "makeblastdb alongside rmblastn.\n"
if ( !-x $formatter );
my $opts = "-dbtype nucl";
$opts .= " -parse_seqids" if ( $params{'parseSeqIDs'} );
$opts .= " -blastdb_version " . $params{'dbVersion'}
if ( defined $params{'dbVersion'} );
my $log = "$dbPath.makeblastdb.log";
system( "$formatter $opts -out $dbPath -in $seqFile > $log 2>&1" ) == 0
or croak $CLASS
. "::prepareSubject(): Error running $formatter on $seqFile.\n"
. "See $log for details.\n";
return $dbPath;
}
##-------------------------------------------------------------------------##
=head2 setSubjectIDList()
Use: my $oldValue = setSubjectIDList( $file );
Restrict the search to the subjects listed in $file, one bare GI
number per line. The 2.x series reads its list in the packed format
blastdb_aliastool produces, so the text file is converted to "$file.gil"
here and that copy is removed again when the list is cleared or
replaced. The subject database must have been prepared with
parseSeqIDs for the restriction to take effect.
=cut
##-------------------------------------------------------------------------##
sub setSubjectIDList {
my $this = shift;
my $value = shift;
my $rendered = $this->{'subjectIDListRendered'};
unlink( $rendered ) if ( defined $rendered && -e $rendered );
delete $this->{'subjectIDListRendered'};
if ( defined $value ) {
croak $CLASS
. "::setSubjectIDList(): List file ($value) does not exist or "
. "is empty!\n"
if ( !-s $value );
my $aliasTool = dirname( $this->getPathToEngine() ) . "/blastdb_aliastool";
croak $CLASS
. "::setSubjectIDList(): Cannot find blastdb_aliastool ($aliasTool). "
. "A 2.x rmblast installation must provide it alongside rmblastn.\n"
if ( !-x $aliasTool );
$rendered = "$value.gil";
system( "$aliasTool -gi_file_in $value -gi_file_out $rendered "
. "> /dev/null 2>&1" ) == 0
or croak $CLASS
. "::setSubjectIDList(): Error running $aliasTool on $value.\n";
$this->{'subjectIDListRendered'} = $rendered;
}
return $this->SUPER::setSubjectIDList( $value );
}
##-------------------------------------------------------------------------##
## Use: my $file = $this->_subjectIDListForEngine();
##
## The list file in the form this engine's command line takes.
##-------------------------------------------------------------------------##
sub _subjectIDListForEngine {
my $this = shift;
return $this->{'subjectIDListRendered'};
}
##-------------------------------------------------------------------------##
## Instance Methods
##-------------------------------------------------------------------------##
##-------------------------------------------------------------------------##
=over 4
=item Use: my $value = getForceLegacyParsing( );
=item Use: my $oldValue = setForceLegacyParsing( $value );
Get/Set the use of legacy parsing when used with rmblastn 2.13.0+ or
newer. This serves to assist with debugging.
$value : Integer >= 0
=back
=cut
##-------------------------------------------------------------------------##
sub getForceLegacyParsing {
my $this = shift;
return $this->{'useLegacyParser'};
}
sub setForceLegacyParsing {
my $this = shift;
my $value = shift;
my $oldValue = $this->{'useLegacyParser'};
$this->{'useLegcyParser'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
=over 4
=item Use: my $value = getThreadByQuery( );
=item Use: my $oldValue = setThreadByQuery( $value );
Get/Set the use of threading over the query sequences. This is
used when there is a much larger query set than database.
$value : Integer >= 0
=back
=cut
##-------------------------------------------------------------------------##
sub getThreadByQuery {
my $this = shift;
return $this->{'useThreadByQuery'};
}
sub setThreadByQuery {
my $this = shift;
my $value = shift;
my $oldValue = $this->{'useThreadByQuery'};
$this->{'useThreadByQuery'} = $value;
return $oldValue;
}
##-------------------------------------------------------------------------##
=head2 getParameters()
Use: my $ncbiBlastParamString = getParameters( );
Convert object parameters into NCBI rmblastn command line parameters.
=cut
##-------------------------------------------------------------------------##
sub getParameters {
my $this = shift;
# Test if engine is available
my $engine = $this->getPathToEngine();
if ( !defined $engine || !-f "$engine" ) {
croak $CLASS
. "::search: The path to the search engine is undefined or\n"
. "is set incorrectly: $engine\n";
}
my $parameters = $this->_renderParameters( $this->_computeSearchParameters() );
my $runParameters;
if ( defined $this->{'overrideParameters'}
&& $this->{'overrideParameters'} ne "" )
{
$runParameters = $this->{'overrideParameters'};
}
else {
$runParameters = $parameters . " ";
}
if ( defined $this->{'additionalParameters'}
&& $this->{'additionalParameters'} ne "" )
{
$runParameters .= " " . $this->{'additionalParameters'};
}
return ( "$engine $runParameters" );
}
##-------------------------------------------------------------------------##
## Use: my $paramsRef = $this->_computeSearchParameters();
##
## Translate the engine-neutral SearchEngineI settings into the concrete
## values rmblastn needs, without committing to any particular spelling
## of the options. Rendering those values onto a command line is
## _renderParameters()'s job.
##
## The 2.x and 3.x series differ in option syntax but not in alignment
## semantics, so this split lets them share one copy of the score and
## x-drop translation below. Changing the numbers here changes both
## engines; changing option names changes only one.
##-------------------------------------------------------------------------##
sub _computeSearchParameters {
my $this = shift;
my %p = ( 'num_alignments' => 9999999 );
my $value;
if ( ( $value = $this->getSubject() ) ) {
# Make sure the subject has been prepared for this engine. This is
# checked here rather than in setSubject() because callers are
# permitted to set the subject before preparing it.
if ( $this->isSubjectPrepared( $value ) ) {
$p{'db'} = $value;
}
else {
croak $CLASS
. "::search: Error...subject database ($value) has not been "
. "prepared. Call prepareSubject() before searching.\n";
}
}
else {
croak $CLASS. "::search: Error subject undefined!\n";
}
if ( defined( $value = $this->_subjectIDListForEngine() ) ) {
croak $CLASS
. "::search: Error...subject ID list ($value) does not exist!\n"
if ( !-f $value );
$p{'gilist'} = $value;
}
if ( ( $value = $this->getQuery() ) ) {
if ( -f $value ) {
$p{'query'} = $value;
}
else {
croak $CLASS. "::search: Error...query ($value) does not exist!\n";
}
}
else {
croak $CLASS. "::search: Error query undefined!\n";
}
if ( defined( $value = $this->getGapInit() )
&& $value =~ /\d+/ )
{
$p{'gapopen'} = abs( $value - $this->getInsGapExt() );
}
else {
$p{'gapopen'} = 12;
}
if ( defined( $value = $this->getInsGapExt() )
&& $value =~ /\d+/ )
{
$p{'gapextend'} = abs( $value );
}
else {
$p{'gapextend'} = 2;
}
if ( ( $value = $this->getMaskLevel() ) ) {
$p{'mask_level'} = $value if ( $value > 0 );
}
if ( ( $value = $this->getScoreMode() )
&& ( $value == SearchEngineI::basicScoreMode ) )
{
# Do nothing
}
else {
$p{'complexity_adjust'} = 1;
}
if ( defined( $value = $this->getMinMatch() )
&& $value =~ /\d+/ )
{
$p{'word_size'} = $value;
}
else {
$p{'word_size'} = 14;
}
# Translate SearchEngine minScore/Bandwidth
# to RMBlast's -xdrop_ungap/-xdrop_gap_final/
# -xdrop_gap parameters. NOTE: There is much
# legacy support encoded here.
if ( defined( $value = $this->getMinScore() )
&& $value =~ /\d+/ )
{
my $minScore = $value;
## There are three approaches encoded here
## that are selectable by using +bandwidth,
## 0 bandwidth, and -bandwidth. An 'undefined'
## bandwidth defaults to the +bandwidth method.
##
## +bandwidth: use legacy MaskerAid tranlsations
## for minScore to RMBlast parameters.
## [default]
## 0 bandwidth: unused? special case
## -bandwidth: use bandwidth magnitude, in addition
## to minScore to simulate a bandwidth
## in RMBlast. This uses the gap penalties
## to work out a correct -xdrop_gap_final
## parameter.
## TODO: Document diff between xdrops for NCBI Blast
## xdrop_ungap:
## xdrop_gap:
## xdrop_gap_final:
##
# NOTE: This was assigned to the refinement case in 4.1.7
# and led to tons of refinement alignments. Reverting to
# the previous method ( bandwidth = "-1" ) for Repeatmasker
# refinement.
# NOTE: This is not equivalent
# to "undefined". It must have a value of "0".
if ( $this->getBandwidth() eq "0" ) {
$p{'xdrop_ungap'} = $minScore * 2;
$p{'xdrop_gap_final'} = $minScore * 4;
$p{'xdrop_gap'} = int( $minScore / 2 );
}
elsif ( defined( $value = $this->getBandwidth() )
&& $value < 0 )
{
# In crossmatch the bandwidth parameter is the off-diagonal
# distance tolerated. So the full band is (cm_bandwidth * 2 + 1)
# wide. Here we use bandwidth to indicate the full width of the band
# (legacy...should have used the same definition as cm) so a bandwidth
# of -29 is equivalent to the crossmatch bandwidth of 14.
$p{'xdrop_ungap'} = $minScore * 2;
# Ins/Del extension penalties are the same for RMBlast ( only cm differentiates )
# The tolerated gapped xdrop should tolerate a gap of bandwidth #. So
# Gap init penalty + (extension penalty * bandwidth )
$p{'xdrop_gap_final'} =
( abs( $value ) * abs( $this->getInsGapExt() ) ) +
abs( $this->getGapInit() );
$p{'xdrop_gap'} = int( $minScore / 2 );
}
else {
# These are inherited from MaskerAid. It's a strange choice as
# it creates a side effect on indel size. Lower minscores
# reduce the allowable indel length whereas higher minscores
# allow really large indel sizes ( assuming they also reach
# the score threshold ).
$p{'xdrop_ungap'} = $minScore * 2;
$p{'xdrop_gap_final'} = $minScore;
$p{'xdrop_gap'} = int( $minScore / 2 );
}
$p{'min_raw_gapped_score'} = $minScore;
$p{'dust'} = "no";
}
if ( $this->hasTabOutput() ) {
$p{'outfmt_fields'} = [ $this->getTabOutputFields() ];
}
#
# TODO: Is there some way we can check to see if this
# is a MT version of rmblastn? Also a good way
# to know if we should call with threads turned
# on?
if ( defined( $value = $this->getCores() ) ) {
$p{'num_threads'} = $value;
}
else {
$p{'num_threads'} = 4;
}
if ( defined( $value = $this->getThreadByQuery() ) && $value > 0 ) {
$p{'mt_mode'} = 1;
}
if ( defined( $value = $this->getMatrix() ) ) {
# Test if matrix exists
if ( -f $value ) {
# NCBIBLAST requires that the matrix filename parameter
# be relative to a directory path specified in
# environment variables.
my @path = split( /[\\\/]/, $value );
$p{'matrix'} = pop @path;
$p{'matrix_dir'} = join( "/", @path );
}
else {
croak $CLASS. "::search: Error...matrix ($value) does not exist!\n";
}
}
return ( \%p );
}
##-------------------------------------------------------------------------##
## Use: my $bool = $this->hasTabOutput();
##
## Whether this engine should be asked for tab delimited output.
##-------------------------------------------------------------------------##
sub hasTabOutput {
my $this = shift;