6 eval { require Test; };
7 use vars qw($NUMTESTS);
13 plan tests => $NUMTESTS;
17 use Bio::Index::Fasta;
18 use Bio::Index::SwissPfam;
20 use Bio::Index::GenBank;
21 use Bio::Index::Swissprot;
22 use Bio::DB::InMemoryCache;
26 eval { require Bio::DB::FileCache };
31 ($Bio::Root::IO::FILESPECLOADED && File::Spec->can('cwd') && ($dir = File::Spec->cwd) ) ||
32 ($dir = `pwd`) || ($dir = '.');
35 foreach ( $Test::ntest..$NUMTESTS) {
36 skip('Bio::DB::FileCache not loaded because one or more of Storable, DB_File or File::Temp not installed',1);
39 foreach my $root ( qw( Wibbl Wibbl2 Wibbl3 Wibbl4 Wibbl5
41 if( -e "$root" ) { unlink $root;}
42 if( -e "$root.pag") { unlink "$root.pag";}
43 if( -e "$root.dir") { unlink "$root.dir";}
49 my $ind = Bio::Index::Fasta->new(-filename => 'Wibbl',
52 $ind->make_index(Bio::Root::IO->catfile($dir,"t","data","multifa.seq"));
53 $ind->make_index(Bio::Root::IO->catfile($dir,"t","data","seqs.fas"));
54 $ind->make_index(Bio::Root::IO->catfile($dir,"t","data","multi_1.fa"));
57 ok ( -e "Wibbl" || -e "Wibbl.pag" );
64 'gi|238775|bbs|65126' => 70,
67 my $ind = Bio::Index::Abstract->new(-FILENAME => 'Wibbl');
70 while (my($name, $length) = each %t_seq) {
71 my $seq = $ind->fetch($name);
72 if( defined($seq) and $seq->isa('Bio::SeqI') ) {
73 my $r_length = $seq->length;
74 unless ($r_length == $length) {
75 warn "$name - retrieved length '$r_length' doesn't match known length '$length'\n";
79 warn "Didn't get sequence '$name' from index\n";
85 my $stream = $ind->get_PrimarySeq_stream();
87 while( my $seq2 = $stream->next_seq ) {
88 unless ($seq2->isa('Bio::PrimarySeqI')) {
90 last; # no point continuing...
97 my $ind = Bio::Index::SwissPfam->new(-filename=>'Wibbl2',
99 $ind->make_index(Bio::Root::IO->catfile($dir,"t","data","swisspfam.data"));
100 ok ( -e "Wibbl2" || -e "Wibbl2.pag" );
104 my $ind = Bio::Index::EMBL->new(-filename=>'Wibbl3',
106 $ind->make_index(Bio::Root::IO->catfile($dir,"t","data","test.embl"));
107 ok ( -e "Wibbl3" || -e "Wibbl3.pag" );
108 ok $ind->fetch('AL031232')->length, 4870;
112 my $ind = Bio::Index::Swissprot->new(-filename=>'Wibbl4',
114 $ind->make_index(Bio::Root::IO->catfile($dir,"t","data","roa1.swiss"));
115 ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
116 ok ($ind->fetch('P09651')->display_id(), 'ROA1_HUMAN');
121 $gb_ind = Bio::Index::GenBank->new(-filename=>'Wibbl5',
124 $gb_ind->make_index(Bio::Root::IO->catfile($dir,"t","data","roa1.genbank"));
125 ok ( -e "Wibbl5" || -e "Wibbl5.pag" );
126 my $seq =$gb_ind->fetch('AI129902');
127 ok ($seq->length, 37);
128 ok ($seq->species->binomial, 'Homo sapiens');
131 my $cache = Bio::DB::InMemoryCache->new( -seqdb => $gb_ind );
133 ok ( $cache->get_Seq_by_id('AI129902') );
135 if (Bio::DB::FileCache->can('new')) {
137 $cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
139 -file => 'filecache.idx');
140 my $seq = $cache->get_Seq_by_id('AI129902');
142 ok ( $seq->length, 37);
143 ok ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
145 my ( $f1 ) = $seq->get_SeqFeatures();
146 ok ( ($f1->each_tag_value('sex'))[0], 'female');
147 ok ( ($f1->each_tag_value('lab_host'))[0], 'DH10B');
148 my $species = $seq->species;
150 ok( $species->binomial, 'Homo sapiens');
151 ok( $species->species(), 'sapiens');
152 ok( $species->genus(), 'Homo');
153 ok ($species->common_name(), 'human');
156 $cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
158 -file => 'filecache.idx');
159 $seq = $cache->get_Seq_by_id('AI129902');
161 ok ( $seq->length, 37);
162 ok ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
164 ( $f1 ) = $seq->get_SeqFeatures();
165 ok ( ($f1->each_tag_value('sex'))[0], 'female');
166 ok ( ($f1->each_tag_value('lab_host'))[0], 'DH10B');
167 $species = $seq->species;
169 ok( $species->binomial, 'Homo sapiens');
170 ok( $species->species(), 'sapiens');
171 ok( $species->genus(), 'Homo');
172 ok ($species->common_name(), 'human');
174 skip('Bio::DB::FileCache not loaded because one or more of Storable, DB_File or File::Temp not installed',1);