4 test_begin( -tests => 56,
5 -requires_module => 'Bio::DB::Qual');
7 use_ok('Bio::Root::IO');
11 my $DEBUG = test_debug();
15 my $test_dbdir = setup_temp_dir('dbqual');
17 # now use this temporary dir for the db file
18 ok my $db = Bio::DB::Qual->new($test_dbdir, -reindex => 1);
19 is $db->glob, '*.{qual,QUAL,qa,QA}';
20 isa_ok $db, 'Bio::DB::Qual';
21 ok my @ids = $db->ids;
23 @ids = sort {$a <=> $b} @ids;
24 is $ids[0] , '17601976';
25 is $ids[14], '17601991';
26 my $seqid = '17601979';
28 # direct indexed qual file database access
29 is ref($db->qual($seqid)), 'ARRAY';
30 is_deeply $db->qual($seqid), [23, 32, 24, 27, 26, 27, 27, 27, 28, 23, 28, 31, 23, 27];
31 is $db->length($seqid), 14;
32 is $db->length($seqid, -1000, 1000), 14; # length() ignores start and stop
33 is $db->header($seqid), '17601979';
34 is_deeply $db->qual($seqid, 2, 11), [32, 24, 27, 26, 27, 27, 27, 28, 23, 28];
35 is_deeply $db->qual($seqid, 2, 11, 1), [32, 24, 27, 26, 27, 27, 27, 28, 23, 28];
36 is_deeply $db->qual($seqid, 11, 2), [28, 23, 28, 27, 27, 27, 26, 27, 24, 32];
37 is_deeply $db->qual($seqid, 2, 11, -1), [28, 23, 28, 27, 27, 27, 26, 27, 24, 32];
38 is_deeply $db->qual($seqid, 11, 2, -1), [32, 24, 27, 26, 27, 27, 27, 28, 23, 28];
41 is $db->get_Qual_by_id('foobarbaz'), undef;
42 ok my $obj = $db->get_Qual_by_id($seqid);
43 isa_ok $obj, 'Bio::Seq::PrimaryQual::Qual';
44 isa_ok $obj, 'Bio::Seq::QualI';
45 is ref($obj->qual($seqid)), 'ARRAY';
47 is $obj->id, '17601979';
48 is $obj->display_id, '17601979';
49 is $obj->accession_number, 'unknown';
50 like $obj->primary_id, qr/^Bio::Seq::PrimaryQual::Qual=HASH/;
51 is $obj->validate_qual( join(' ', @{$obj->qual($seqid)}) ), 1;
52 is $obj->translate, 0;
53 is $obj->qualat(12), 31;
54 is_deeply $obj->subqual(2, 11), [32, 24, 27, 26, 27, 27, 27, 28, 23, 28];
55 is $obj->header, undef;
57 ok my $truncobj = $obj->trunc(1,3);
58 isa_ok $truncobj, 'Bio::Seq::PrimaryQual::Qual';
59 isa_ok $obj, 'Bio::Seq::QualI';
60 is ref($truncobj->qual($seqid)), 'ARRAY';
61 is $truncobj->length, 3;
62 ok my $revobj = $obj->revcom;
63 isa_ok $revobj, 'Bio::Seq::PrimaryQual::Qual';
64 isa_ok $revobj, 'Bio::Seq::PrimaryQual';
65 is ref($revobj->qual), 'ARRAY';
66 is $revobj->length, 14;
71 # using get_PrimarySeq_stream streaming
72 ok my $stream = $db->get_PrimaryQual_stream;
73 ok $stream = $db->get_PrimarySeq_stream;
74 isa_ok $stream, 'Bio::DB::Indexed::Stream';
75 ok my $streamqual = $stream->next_seq;
76 isa_ok $streamqual, 'Bio::Seq::PrimaryQual';
78 # using newFh streaming
79 ok my $fh = Bio::DB::Qual->newFh($test_dbdir);
81 isa_ok $fhqual, 'Bio::Seq::PrimaryQual';
86 ok tie(%h,'Bio::DB::Qual',$test_dbdir);
88 ok $dna1 = $h{"$seqid:1,10"};
89 ok $dna2 = $h{"$seqid:10,1"};
96 # this obfuscation is to deal with lockfiles by GDBM_File which can
97 # only be created on local filesystems apparently so will cause test
98 # to block and then fail when the testdir is on an NFS mounted system
100 my $data_dir = shift;
102 my $io = Bio::Root::IO->new();
103 my $tempdir = test_output_dir();
104 my $test_dbdir = $io->catfile($tempdir, $data_dir);
105 mkdir($test_dbdir); # make the directory
106 my $indir = test_input_file($data_dir);
107 opendir(my $INDIR,$indir) || die("cannot open dir $indir");
108 # effectively do a cp -r but only copy the files that are in there, no subdirs
109 for my $file ( map { $io->catfile($indir,$_) } readdir($INDIR) ) {
110 next unless (-f $file );
111 copy($file, $test_dbdir);