4 # testing StandAloneBlastPlus.pm
11 test_begin(-tests => 65,
12 -requires_modules => [qw( Bio::Tools::Run::BlastPlus)]);
15 use_ok( 'Bio::Tools::Run::StandAloneBlastPlus' );
16 use_ok( 'Bio::Tools::Run::WrapperBase' );
17 use_ok( 'Bio::Tools::Run::WrapperBase::CommandExts' );
21 ok my $bpfac = Bio::Tools::Run::BlastPlus->new(-command => 'makeblastdb'),
25 test_skip( -tests => 59,
26 -requires_executable => $bpfac);
27 diag('DB and mask make tests');
29 # testing using fasta files as input...
30 ok my $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
31 -db_data => test_input_file('test-spa.fas'),
34 ok $fac->make_db, "test db made with fasta";
35 like $fac->db, qr/DB.{5}/, "temp db";
36 is ($fac->db_type, 'nucl', "right type");
39 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
41 -db_data => test_input_file('test-spa.fas'),
45 like($fac->program_version, qr/2\.\d+\.\d+/, 'program version');
46 like($fac->package_version, qr/2\.\d+\.\d+/, 'package version');
48 ok $fac->make_db, "named db made";
49 ok $fac->check_db, "check_db";
50 is $fac->db, 'test', "correct name";
51 is ref $fac->db_info, 'HASH', "dbinfo hash returned";
52 is $fac->db_type, 'nucl', "correct type";
55 -data=>test_input_file('test-spa.fas'),
56 -masker=>'windowmasker'), "windowmasker mask made";
58 -data=>test_input_file('test-spa.fas'),
59 -masker=>'dustmasker'), "dustmasker mask made";
61 $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
62 -db_data => test_input_file('test-spa-p.fas'),
65 ok $fac->check_db('test'), "check_db with arg";
66 is $fac->db_info('test')->{_db_type}, 'nucl', "db_info with arg";
67 ok $fac->make_db, "protein db made";
68 is $fac->db_type, 'prot', "correct type";
69 ok $fac->make_mask(-data=>$fac->db, -masker=>'segmasker'), "segmasker mask made";
72 -masker=>'segmasker'), "segmasker mask made; blastdb as data";
73 $fac->_register_temp_for_cleanup('test');
76 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
77 -db_data => test_input_file('test-spa-p.fas'),
78 -mask_file => test_input_file('segmask_data.asn'),
81 ok $fac->make_db, "protein db made with pre-built mask";
82 is $fac->db_filter_algorithms->[0]{algorithm_name}, 'seg', "db_info records mask info";
87 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
88 -db_data => test_input_file('test-spa.fas'),
89 -masker=>'windowmasker',
90 -mask_data => test_input_file('test-spa.fas'),
93 $fac->no_throw_on_crash(1);
96 local $TODO = 'BLAST+ 2.2.24+ not working';
97 ok $fac->make_db, "mask built and db made on construction (windowmasker)";
101 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
102 -db_data => test_input_file('test-spa-p.fas'),
103 -masker=>'segmasker',
104 -mask_data => test_input_file('test-spa-p.fas'),
107 $fac->no_throw_on_crash(1);
109 local $TODO = 'BLAST+ 2.2.24+ not working';
110 ok $fac->make_db, "mask built and db made on construction (segmasker)";
114 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
115 -db_data => test_input_file('test-spa.fas'),
116 -masker=>'dustmasker',
117 -mask_data => test_input_file('test-spa.fas'),
120 $fac->no_throw_on_crash(1);
122 local $TODO = 'BLAST+ 2.2.24+ not working';
123 ok $fac->make_db, "mask built and db made on construction (dustmasker)";
126 # tests with Bio:: objects as input
128 ok my $sio = Bio::SeqIO->new(-file => test_input_file('test-spa.fas'));
129 ok my $aio = Bio::AlignIO->new(-file => test_input_file('test-spa-p.fas'));
131 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
136 ok $fac->make_db, "make db from Bio::SeqIO";
138 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
143 ok $fac->make_db, "make db from Bio::AlignIO";
147 $aio = Bio::AlignIO->new(-file=>test_input_file('test-aln.msf'));
148 my @seqs = $aio->next_aln->each_seq;
149 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
154 ok $fac->make_db, 'make db from \@seqs';
156 $fac->_register_temp_for_cleanup( 'aiodb', 'siodb' );
161 mkdir "./a"; mkdir "./a/b";
162 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
165 -db_data => test_input_file('test-spa.fas'),
167 ), "dbdir : ./a/b; dbname : test; create";
168 ok $fac->make_db, "make db";
169 lives_ok { Bio::Tools::Run::StandAloneBlastPlus->new(
173 lives_ok { Bio::Tools::Run::StandAloneBlastPlus->new(
175 -db_name => "a/b/test"
177 lives_ok { Bio::Tools::Run::StandAloneBlastPlus->new(
178 -db_name => "a/b/test"
180 dies_ok { Bio::Tools::Run::StandAloneBlastPlus->new(
181 -db_name => "/a/b/test"
183 $fac->_register_temp_for_cleanup('a/b/test');
187 # exception tests here someday.
190 diag("run BLAST methods");
192 $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
193 -db_data => test_input_file('test-spa.fas'),
196 ok my $result = $fac->run( -method => 'blastn', -query => test_input_file('test-query.fas')), "run blastn";
197 is $result->num_hits, 291, "default hit limit";
198 ok $result = $fac->blastn( -query => test_input_file('test-query.fas'),
199 -method_args => [ -num_alignments => 1000 ] ), "return more alignments (arg spec)";
200 is $result->num_hits, 291, "got more hits";
202 my $ntseq = Bio::Seq->new( -seq => 'GACGATCCTTCGGTGAGCAAAGAAATTTTAGCAGAAGCTAAAAAGCTAAACGATGCTCAAGCACCAAAAG', -id => 'SA009');
203 my $aaseq = $ntseq->translate;
205 ok $result = $fac->blastn( -query => $ntseq ), "run blastn with Bio::Seq query";
206 $fac->no_throw_on_crash(1);
207 ok $result = $fac->tblastn( -query => $aaseq ), "run tblastn";
208 is $result->num_hits, 299, "tblastn hits";
209 ok $result = $fac->tblastx( -query => $ntseq ), "run tblastx";
210 is $result->num_hits, 299, "tblastx hits";
213 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
214 -db_data => test_input_file('test-spa-p.fas'),
216 ok $result = $fac->blastp( -query => $aaseq ), "run blastp";
217 is $result->num_hits, 222, "blastp hits";
220 $sio = Bio::SeqIO->new(-file=>test_input_file('test-spa.fas'));
222 my $seq1 = $sio->next_seq;
223 my $seq2 = $sio->next_seq;
225 ok $result = $fac->bl2seq( -method => 'blastn',
227 -subject => $seq2 ), "bl2seq (blastn)";
228 is $result->num_hits, 1, "got hit";
229 ok $result = $fac->bl2seq( -method => 'blastx',
231 -subject => $seq2 ), "bl2seq (blastx)";
232 is $result->num_hits, 1, "got hit";
233 $seq1 = $seq1->translate;
234 $seq2 = $seq2->translate;
235 ok $result = $fac->bl2seq( -method => 'blastp',
237 -subject => $seq2 ), "bl2seq (blastp)";
238 is $result->num_hits, 1, "got hit";