1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 69,
11 -requires_modules => [qw(DB_File
15 use_ok('Bio::Index::Fasta');
16 use_ok('Bio::Index::Qual');
17 use_ok('Bio::Index::SwissPfam');
18 use_ok('Bio::Index::EMBL');
19 use_ok('Bio::Index::GenBank');
20 use_ok('Bio::Index::Stockholm');
21 use_ok('Bio::Index::Swissprot');
22 use_ok('Bio::DB::InMemoryCache');
23 use_ok('Bio::DB::InMemoryCache');
26 my $ind = Bio::Index::Fasta->new(-filename => 'Wibbl',
29 $ind->make_index(test_input_file('multifa.seq'));
30 $ind->make_index(test_input_file('seqs.fas'));
32 ok ( -e "Wibbl" || -e "Wibbl.pag" );
33 my $seq = $ind->fetch('HSEARLOBE');
35 is($seq->primary_id(),'HSEARLOBE');
36 $seq = $ind->fetch('HSMETOO');
38 is($seq->primary_id(),'HSMETOO');
39 $seq = $ind->fetch('MMWHISK');
41 is($seq->primary_id(),'MMWHISK');
42 $seq = $ind->fetch('gi|238775|bbs|65126');
45 my $stream = $ind->get_PrimarySeq_stream();
46 $seq = $stream->next_seq;
47 isa_ok $seq, 'Bio::PrimarySeqI';
49 $ind = Bio::Index::Fasta->new(-filename => 'multifa_index',
52 $ind->make_index(test_input_file('multifa.seq.qual'));
54 ok ( -e "multifa_index" );
56 $ind = Bio::Index::Qual->new(-filename => 'multifa_qual_index',
59 $ind->make_index(test_input_file('multifa.seq.qual'));
61 ok ( -e "multifa_qual_index" );
64 isa_ok $seq, 'Bio::SeqI';
65 $seq = $ind->fetch('HSEARLOBE');
67 is($seq->primary_id(),'HSEARLOBE');
68 $seq = $ind->fetch('HSMETOO');
70 is($seq->primary_id(),'HSMETOO');
71 $seq = $ind->fetch('MMWHISK');
73 is($seq->primary_id(),'MMWHISK');
74 $seq = $ind->fetch('NONEXISTENT_SEQ');
77 $ind = Bio::Index::SwissPfam->new(-filename => 'Wibbl2',
79 $ind->make_index(test_input_file('swisspfam.data'));
81 ok ( -e "Wibbl2" || -e "Wibbl2.pag" );
83 $ind = Bio::Index::EMBL->new(-filename => 'Wibbl3',
85 $ind->make_index(test_input_file('test.embl'));
86 ok ( -e "Wibbl3" || -e "Wibbl3.pag" );
87 is ($ind->fetch('AL031232')->length, 4870);
90 test_skip(-tests => 5, -requires_module => 'Data::Stag');
91 $ind = Bio::Index::Swissprot->new(-filename => 'Wibbl4',
93 $ind->make_index(test_input_file('roa1.swiss'));
94 ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
95 $seq = $ind->fetch('ROA1_HUMAN');
96 is ($seq->display_id(), 'ROA1_HUMAN');
97 $seq = $ind->fetch('P09651');
98 is ($seq->display_id(), 'ROA1_HUMAN');
101 $ind = Bio::Index::Swissprot->new(-filename => 'Wibbl4',
103 $ind->id_parser(\&get_id);
104 $ind->make_index(test_input_file('roa1.swiss'));
105 ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
106 $seq = $ind->fetch('X12671');
107 is ($seq->length,371);
111 my $gb_ind = Bio::Index::GenBank->new(-filename => 'Wibbl5',
114 $gb_ind->make_index(test_input_file('roa1.genbank'));
115 ok ( -e "Wibbl5" || -e "Wibbl5.pag" );
116 $seq = $gb_ind->fetch('AI129902');
117 is ($seq->length, 37);
118 is ($seq->species->binomial, 'Homo sapiens');
119 $seq = $gb_ind->fetch(3598416);
120 is ($seq->seq,"CTCCGCGCCAACTCCCCCCACCCCCCCCCCACACCCC");
122 my $cache = Bio::DB::InMemoryCache->new( -seqdb => $gb_ind );
124 ok ( $cache->get_Seq_by_id('AI129902') );
127 test_skip(-tests => 22, -requires_module => 'Bio::DB::FileCache');
129 $cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
131 -file => 'filecache.idx');
133 my $seq = $cache->get_Seq_by_id('AI129902');
135 is ( $seq->length, 37);
136 is ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
138 my ( $f1 ) = $seq->get_SeqFeatures();
139 is ( ($f1->get_tag_values('sex'))[0], 'female');
140 is ( ($f1->get_tag_values('lab_host'))[0], 'DH10B');
141 my $species = $seq->species;
143 is( $species->binomial, 'Homo sapiens');
144 is( $species->species(), 'sapiens');
145 is( $species->genus(), 'Homo');
146 # changes in GenBank file SOURCE line
147 # this is now the abbreviated name
148 ok defined($species->name('abbreviated'));
149 is ($species->name('abbreviated')->[0], 'human');
152 $cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
154 -file => 'filecache.idx');
155 $seq = $cache->get_Seq_by_id('AI129902');
157 is ( $seq->length, 37);
158 is ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
160 ( $f1 ) = $seq->get_SeqFeatures();
161 is ( ($f1->get_tag_values('sex'))[0], 'female');
162 is ( ($f1->get_tag_values('lab_host'))[0], 'DH10B');
163 $species = $seq->species;
165 is( $species->binomial, 'Homo sapiens');
166 is( $species->species(), 'sapiens');
167 is( $species->genus(), 'Homo');
168 # changes in GenBank file SOURCE line
169 # this is now the abbreviated name
170 ok defined($species->name('abbreviated'));
171 is ($species->name('abbreviated')->[0], 'human');
175 $gb_ind = Bio::Index::GenBank->new(-filename => 'Wibbl5',
178 $gb_ind->id_parser(\&get_id);
179 $gb_ind->make_index(test_input_file('roa1.genbank'));
180 ok ( -e "Wibbl5" || -e "Wibbl5.pag" );
181 $seq = $gb_ind->fetch('alpha D-globin');
182 is ($seq->length,141);
185 my $st_ind = Bio::Index::Stockholm->new(-filename => 'Wibbl6',
188 isa_ok $st_ind, 'Bio::Index::Stockholm';
189 $st_ind->make_index(test_input_file('testaln.stockholm'));
191 my $aln = $st_ind->fetch_aln('PF00244');
192 isa_ok($aln,'Bio::SimpleAlign');
196 return $1 if ($line =~ /product="([^"]+)"/);
197 return $1 if ($line =~ /^DR\s+EMBL;\s+([^;]+)/);
205 for my $root ( qw( Wibbl Wibbl2 Wibbl3 Wibbl4 Wibbl5 Wibbl6
206 multifa_index multifa_qual_index ) ) {
207 unlink $root if( -e $root );
208 unlink "$root.pag" if( -e "$root.pag");
209 unlink "$root.dir" if( -e "$root.dir");