3 # testing StandAloneBlastPlus.pm
11 test_begin(-tests => 73,
12 -requires_module => "IPC::Run");
13 use_ok( 'Bio::Tools::Run::StandAloneBlastPlus' );
14 use_ok( 'Bio::Tools::Run::WrapperBase' );
15 use_ok( 'Bio::Tools::Run::WrapperBase::CommandExts' );
21 ok my $bpfac = Bio::Tools::Run::BlastPlus->new(-command => 'makeblastdb'),
25 test_skip( -tests => 69,
26 -requires_executable => $bpfac);
28 diag('DB and mask make tests');
30 # testing using fasta files as input...
31 ok my $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
32 -db_data => test_input_file('test-spa.fas'),
35 ok $fac->make_db, "test db made with fasta";
36 like $fac->db, qr/DB.{5}/, "temp db";
37 is ($fac->db_type, 'nucl', "right type");
40 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
42 -db_data => test_input_file('test-spa.fas'),
46 like($fac->program_version, qr/2\.\d+\.\d+/, 'program version');
47 like($fac->package_version, qr/2\.\d+\.\d+/, 'package version');
49 ok $fac->make_db, "named db made";
50 ok $fac->check_db, "check_db";
51 is $fac->db, 'test', "correct name";
52 is ref $fac->db_info, 'HASH', "dbinfo hash returned";
53 is $fac->db_type, 'nucl', "correct type";
56 -data => test_input_file('test-spa.fas'),
57 -masker => 'windowmasker'
58 ), "windowmasker mask made";
60 -data => test_input_file('test-spa.fas'),
61 -masker => 'dustmasker'
62 ), "dustmasker mask made";
65 $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
66 -db_data => test_input_file('test-spa-p.fas'),
69 ok $fac->check_db('test'), "check_db with arg";
70 is $fac->db_info('test')->{_db_type}, 'nucl', "db_info with arg";
71 ok $fac->make_db, "protein db made";
72 is $fac->db_type, 'prot', "correct type";
73 ok $fac->make_mask(-data=>$fac->db, -masker=>'segmasker'), "segmasker mask made";
76 -masker => 'segmasker'
77 ), "segmasker mask made; blastdb as data";
78 $fac->_register_temp_for_cleanup('test');
81 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
82 -db_data => test_input_file('test-spa-p.fas'),
83 -mask_file => test_input_file('segmask_data.asn'),
86 ok $fac->make_db, "protein db made with pre-built mask";
87 is $fac->db_filter_algorithms->[0]{algorithm_name}, 'seg', "db_info records mask info";
90 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
91 -db_data => test_input_file('test-spa.fas'),
92 -masker => 'windowmasker',
93 -mask_data => test_input_file('test-spa.fas'),
96 $fac->no_throw_on_crash(1);
97 ok $fac->make_db, "mask built and db made on construction (windowmasker)";
100 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
101 -db_data => test_input_file('test-spa-p.fas'),
102 -masker => 'segmasker',
103 -mask_data => test_input_file('test-spa-p.fas'),
106 $fac->no_throw_on_crash(1);
107 ok $fac->make_db, "mask built and db made on construction (segmasker)";
110 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
111 -db_data => test_input_file('test-spa.fas'),
112 -masker => 'dustmasker',
113 -mask_data => test_input_file('test-spa.fas'),
116 $fac->no_throw_on_crash(1);
117 ok $fac->make_db, "mask built and db made on construction (dustmasker)";
120 # tests with Bio:: objects as input
121 ok my $sio = Bio::SeqIO->new(-file => test_input_file('test-spa.fas'));
122 ok my $aio = Bio::AlignIO->new(-file => test_input_file('test-spa-p.fas'));
124 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
129 ok $fac->make_db, "make db from Bio::SeqIO";
132 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
137 ok $fac->make_db, "make db from Bio::AlignIO";
140 $aio = Bio::AlignIO->new(-file => test_input_file('test-aln.msf'));
141 my @seqs = $aio->next_aln->each_seq;
142 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
147 ok $fac->make_db, 'make db from \@seqs';
149 $fac->_register_temp_for_cleanup( 'aiodb', 'siodb' );
154 mkdir "./a"; mkdir "./a/b";
155 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
158 -db_data => test_input_file('test-spa.fas'),
160 ), "dbdir : ./a/b; dbname : test; create";
161 ok $fac->make_db, "make db";
162 lives_ok { Bio::Tools::Run::StandAloneBlastPlus->new(
166 lives_ok { Bio::Tools::Run::StandAloneBlastPlus->new(
168 -db_name => "a/b/test"
170 lives_ok { Bio::Tools::Run::StandAloneBlastPlus->new(
171 -db_name => "a/b/test"
173 dies_ok { Bio::Tools::Run::StandAloneBlastPlus->new(
174 -db_name => "/a/b/test"
176 $fac->_register_temp_for_cleanup('a/b/test');
180 # exception tests here someday.
183 diag("run BLAST methods");
185 $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
186 -db_data => test_input_file('test-spa.fas'),
190 ok my $result = $fac->run(-method => 'blastn',
191 -query => test_input_file('test-query.fas')
193 is $result->num_hits, 291, "default hit limit";
194 ok $result = $fac->blastn(-query => test_input_file('test-query.fas'),
195 -method_args => [ -num_alignments => 1000 ]
196 ), "return more alignments (arg spec)";
197 is $result->num_hits, 291, "got more hits";
200 my $ntseq = Bio::Seq->new(-seq => 'GACGATCCTTCGGTGAGCAAAGAAATTTTAGCAGAAGCTAAAAAGCTAAACGATGCTCAAGCACCAAAAG',
202 my $aaseq = $ntseq->translate;
204 ok $result = $fac->blastn( -query => $ntseq ), "run blastn with Bio::Seq query";
205 $fac->no_throw_on_crash(1);
206 ok $result = $fac->tblastn( -query => $aaseq ), "run tblastn";
207 is $result->num_hits, 299, "tblastn hits";
208 ok $result = $fac->tblastx( -query => $ntseq ), "run tblastx";
209 is $result->num_hits, 299, "tblastx hits";
212 ok $fac = Bio::Tools::Run::StandAloneBlastPlus->new(
213 -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',
228 ), "bl2seq (blastn)";
229 is $result->num_hits, 1, "got hit";
231 ok $result = $fac->bl2seq(-method => 'tblastx',
234 ), "bl2seq (tblastx)";
235 is $result->num_hits, 1, "got hit";
237 $seq2 = $seq2->translate(-frame => 1);
238 ok $result = $fac->bl2seq(-method => 'blastx',
241 ), "bl2seq (blastx)";
242 is $result->num_hits, 1, "got hit";
244 # There is no similarity between the sequences
245 # at these reading frames, so there should be no hits
246 my $seq1_frame0 = $seq1->translate;
247 ok $result = $fac->bl2seq(-method => 'blastp',
248 -query => $seq1_frame0,
250 ), "bl2seq (blastp)";
251 is $result->num_hits, 0, "no hit";
253 # There is similarity between the sequences
254 # at these reading frames, so there should be hits
255 $seq1 = $seq1->translate(-frame => 2);
256 ok $result = $fac->bl2seq(-method => 'blastp',
259 ), "bl2seq (blastp)";
260 is $result->num_hits, 1, "got hit";
262 # issue #12 (https://github.com/bioperl/bioperl-run/issues/12) : 4 tests
263 $sio = Bio::SeqIO->new(-file=>test_input_file('test-spa.fas'));
265 $seq1 = $sio->next_seq;
266 $seq2 = $sio->next_seq;
268 lives_ok { $fac->bl2seq(-method => 'tblastx',
271 -method_args => [ '-outfmt' => '"6 qseqid sseqid"' ]
272 ) } "bl2seq (tblastx) - multiple outfmt options";
274 lives_ok { $fac->bl2seq(-method => 'tblastx',
277 -outformat => '"6 qseqid sseqid"',
278 ) } "bl2seq (tblastx) - multiple outfmt options (use method arg)";
280 lives_ok { $fac->bl2seq(-method => 'tblastx',
283 -outformat => '6 qseqid sseqid',
284 ) } "bl2seq (tblastx) - multiple outfmt options (no explict quotes should also work)";
286 lives_ok { $fac->bl2seq(-method => 'tblastx',
290 ) } "bl2seq (tblastx) - multiple outfmt options (a single format number in quotes";