1# -*-Perl-*- Test Harness script for Bioperl
2# $Id: Blast.t 16293 2009-10-27 20:03:02Z cjfields $
3
4use strict;
5use File::Spec;
6use File::Temp;
7
8
9BEGIN {
10    use Bio::Root::Test;
11
12    test_begin(-tests => 27,
13               -requires_module => 'IO::String');
14
15    use_ok('Cwd');
16    use_ok('Bio::SearchIO');
17    use_ok('Bio::Index::BlastTable');
18}
19
20                       # -m 9                -m 8
21my @test_cases = qw(multi.blast.m9      multi.blast.m8);
22
23for my $file (@test_cases) {
24    my $dir = File::Temp->newdir();
25    my $basename = 'Wibbl';
26    my $filepath = File::Spec->catfile($dir, $basename);
27
28    my $index = Bio::Index::BlastTable->new(-filename => $filepath,
29                                            -write_flag => 1);
30    ok($index);
31    $index->id_parser(\&my_id_parser);
32    $index->make_index(test_input_file($file));
33    ($index->dbm_package eq 'SDBM_File') ?
34        (ok(-e "$filepath.pag" && -e "$filepath.dir")) :
35        (ok(-e $filepath));
36
37    foreach my $id ( qw(SP130_MOUSE IKZF1_MOUSE) ) {
38        my $fh = $index->get_stream($id);
39        ok($fh);
40        ok( ! eof($fh) );
41        my $report = Bio::SearchIO->new(-noclose => 1,
42                       -format  => 'blasttable',
43                       -fh      => $fh);
44        my $result = $report->next_result;
45        like($result->query_name, qr/$id/);
46        ok( $result->next_hit);
47
48        like( $index->fetch_report($id)->query_name, qr/$id/);
49    }
50}
51
52# test id_parser
53sub my_id_parser {
54    if ($_[0] =~ /^\S+\|(\S+)/) {
55        return $1;
56    } else {
57        return;
58    }
59}
60