1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 65,
10 -requires_modules => [qw(DB_File
14 use_ok('Bio::Index::Fasta');
15 use_ok('Bio::Index::Qual');
16 use_ok('Bio::Index::SwissPfam');
17 use_ok('Bio::Index::EMBL');
18 use_ok('Bio::Index::GenBank');
19 use_ok('Bio::Index::Swissprot');
20 use_ok('Bio::DB::InMemoryCache');
21 use_ok('Bio::DB::InMemoryCache');
24 my $ind = Bio::Index::Fasta->new(-filename => 'Wibbl',
27 $ind->make_index(test_input_file('multifa.seq'));
28 $ind->make_index(test_input_file('seqs.fas'));
30 ok ( -e "Wibbl" || -e "Wibbl.pag" );
31 my $seq = $ind->fetch('HSEARLOBE');
33 is($seq->primary_id(),'HSEARLOBE');
34 $seq = $ind->fetch('HSMETOO');
36 is($seq->primary_id(),'HSMETOO');
37 $seq = $ind->fetch('MMWHISK');
39 is($seq->primary_id(),'MMWHISK');
40 $seq = $ind->fetch('gi|238775|bbs|65126');
43 my $stream = $ind->get_PrimarySeq_stream();
44 $seq = $stream->next_seq;
45 isa_ok $seq, 'Bio::PrimarySeqI';
47 $ind = Bio::Index::Fasta->new(-filename => 'multifa_index',
50 $ind->make_index(test_input_file('multifa.seq.qual'));
52 ok ( -e "multifa_index" );
54 $ind = Bio::Index::Qual->new(-filename => 'multifa_qual_index',
57 $ind->make_index(test_input_file('multifa.seq.qual'));
59 ok ( -e "multifa_qual_index" );
62 isa_ok $seq, 'Bio::SeqI';
63 $seq = $ind->fetch('HSEARLOBE');
65 is($seq->primary_id(),'HSEARLOBE');
66 $seq = $ind->fetch('HSMETOO');
68 is($seq->primary_id(),'HSMETOO');
69 $seq = $ind->fetch('MMWHISK');
71 is($seq->primary_id(),'MMWHISK');
72 $seq = $ind->fetch('NONEXISTENT_SEQ');
75 $ind = Bio::Index::SwissPfam->new(-filename => 'Wibbl2',
77 $ind->make_index(test_input_file('swisspfam.data'));
79 ok ( -e "Wibbl2" || -e "Wibbl2.pag" );
81 $ind = Bio::Index::EMBL->new(-filename => 'Wibbl3',
83 $ind->make_index(test_input_file('test.embl'));
84 ok ( -e "Wibbl3" || -e "Wibbl3.pag" );
85 is ($ind->fetch('AL031232')->length, 4870);
88 test_skip(-tests => 5, -requires_module => 'Data::Stag');
89 $ind = Bio::Index::Swissprot->new(-filename => 'Wibbl4',
91 $ind->make_index(test_input_file('roa1.swiss'));
92 ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
93 $seq = $ind->fetch('ROA1_HUMAN');
94 is ($seq->display_id(), 'ROA1_HUMAN');
95 $seq = $ind->fetch('P09651');
96 is ($seq->display_id(), 'ROA1_HUMAN');
99 $ind = Bio::Index::Swissprot->new(-filename => 'Wibbl4',
101 $ind->id_parser(\&get_id);
102 $ind->make_index(test_input_file('roa1.swiss'));
103 ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
104 $seq = $ind->fetch('X12671');
105 is ($seq->length,371);
109 my $gb_ind = Bio::Index::GenBank->new(-filename => 'Wibbl5',
112 $gb_ind->make_index(test_input_file('roa1.genbank'));
113 ok ( -e "Wibbl5" || -e "Wibbl5.pag" );
114 $seq = $gb_ind->fetch('AI129902');
115 is ($seq->length, 37);
116 is ($seq->species->binomial, 'Homo sapiens');
117 $seq = $gb_ind->fetch(3598416);
118 is ($seq->seq,"CTCCGCGCCAACTCCCCCCACCCCCCCCCCACACCCC");
120 my $cache = Bio::DB::InMemoryCache->new( -seqdb => $gb_ind );
122 ok ( $cache->get_Seq_by_id('AI129902') );
125 test_skip(-tests => 22, -requires_module => 'Bio::DB::FileCache');
127 $cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
129 -file => 'filecache.idx');
131 my $seq = $cache->get_Seq_by_id('AI129902');
133 is ( $seq->length, 37);
134 is ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
136 my ( $f1 ) = $seq->get_SeqFeatures();
137 is ( ($f1->get_tag_values('sex'))[0], 'female');
138 is ( ($f1->get_tag_values('lab_host'))[0], 'DH10B');
139 my $species = $seq->species;
141 is( $species->binomial, 'Homo sapiens');
142 is( $species->species(), 'sapiens');
143 is( $species->genus(), 'Homo');
144 # changes in GenBank file SOURCE line
145 # this is now the abbreviated name
146 ok defined($species->name('abbreviated'));
147 is ($species->name('abbreviated')->[0], 'human');
150 $cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
152 -file => 'filecache.idx');
153 $seq = $cache->get_Seq_by_id('AI129902');
155 is ( $seq->length, 37);
156 is ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
158 ( $f1 ) = $seq->get_SeqFeatures();
159 is ( ($f1->get_tag_values('sex'))[0], 'female');
160 is ( ($f1->get_tag_values('lab_host'))[0], 'DH10B');
161 $species = $seq->species;
163 is( $species->binomial, 'Homo sapiens');
164 is( $species->species(), 'sapiens');
165 is( $species->genus(), 'Homo');
166 # changes in GenBank file SOURCE line
167 # this is now the abbreviated name
168 ok defined($species->name('abbreviated'));
169 is ($species->name('abbreviated')->[0], 'human');
173 $gb_ind = Bio::Index::GenBank->new(-filename => 'Wibbl5',
176 $gb_ind->id_parser(\&get_id);
177 $gb_ind->make_index(test_input_file('roa1.genbank'));
178 ok ( -e "Wibbl5" || -e "Wibbl5.pag" );
179 $seq = $gb_ind->fetch('alpha D-globin');
180 is ($seq->length,141);
184 return $1 if ($line =~ /product="([^"]+)"/);
185 return $1 if ($line =~ /^DR\s+EMBL;\s+([^;]+)/);
193 for my $root ( qw( Wibbl Wibbl2 Wibbl3 Wibbl4 Wibbl5
194 multifa_index multifa_qual_index ) ) {
195 unlink $root if( -e $root );
196 unlink "$root.pag" if( -e "$root.pag");
197 unlink "$root.dir" if( -e "$root.dir");