1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 73,
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::Index::Hmmer');
23 use_ok('Bio::DB::InMemoryCache');
24 use_ok('Bio::DB::InMemoryCache');
27 my $ind = Bio::Index::Fasta->new(-filename => 'Wibbl',
30 $ind->make_index(test_input_file('multifa.seq'));
31 $ind->make_index(test_input_file('seqs.fas'));
33 ok ( -e "Wibbl" || -e "Wibbl.pag" );
34 my $seq = $ind->fetch('HSEARLOBE');
36 is($seq->primary_id(),'HSEARLOBE');
37 $seq = $ind->fetch('HSMETOO');
39 is($seq->primary_id(),'HSMETOO');
40 $seq = $ind->fetch('MMWHISK');
42 is($seq->primary_id(),'MMWHISK');
43 $seq = $ind->fetch('gi|238775|bbs|65126');
46 my $stream = $ind->get_PrimarySeq_stream();
47 $seq = $stream->next_seq;
48 isa_ok $seq, 'Bio::PrimarySeqI';
50 $ind = Bio::Index::Fasta->new(-filename => 'multifa_index',
53 $ind->make_index(test_input_file('multifa.seq.qual'));
55 ok ( -e "multifa_index" );
57 $ind = Bio::Index::Qual->new(-filename => 'multifa_qual_index',
60 $ind->make_index(test_input_file('multifa.seq.qual'));
62 ok ( -e "multifa_qual_index" );
65 isa_ok $seq, 'Bio::SeqI';
66 $seq = $ind->fetch('HSEARLOBE');
68 is($seq->primary_id(),'HSEARLOBE');
69 $seq = $ind->fetch('HSMETOO');
71 is($seq->primary_id(),'HSMETOO');
72 $seq = $ind->fetch('MMWHISK');
74 is($seq->primary_id(),'MMWHISK');
75 $seq = $ind->fetch('NONEXISTENT_SEQ');
78 $ind = Bio::Index::SwissPfam->new(-filename => 'Wibbl2',
80 $ind->make_index(test_input_file('swisspfam.data'));
82 ok ( -e "Wibbl2" || -e "Wibbl2.pag" );
84 $ind = Bio::Index::EMBL->new(-filename => 'Wibbl3',
86 $ind->make_index(test_input_file('test.embl'));
87 ok ( -e "Wibbl3" || -e "Wibbl3.pag" );
88 is ($ind->fetch('AL031232')->length, 4870);
90 $ind = Bio::Index::Swissprot->new(-filename => 'Wibbl4',
92 $ind->make_index(test_input_file('roa1.swiss'));
93 ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
94 $seq = $ind->fetch('ROA1_HUMAN');
95 is ($seq->display_id(), 'ROA1_HUMAN');
96 $seq = $ind->fetch('P09651');
97 is ($seq->display_id(), 'ROA1_HUMAN');
100 $ind = Bio::Index::Swissprot->new(-filename => 'Wibbl4',
102 $ind->id_parser(\&get_id);
103 $ind->make_index(test_input_file('roa1.swiss'));
104 ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
105 $seq = $ind->fetch('X12671');
106 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);
183 my $st_ind = Bio::Index::Stockholm->new(-filename => 'Wibbl6',
186 isa_ok $st_ind, 'Bio::Index::Stockholm';
187 $st_ind->make_index(test_input_file('testaln.stockholm'));
189 my $aln = $st_ind->fetch_aln('PF00244');
190 isa_ok($aln,'Bio::SimpleAlign');
193 my $hmmer_ind = Bio::Index::Hmmer->new(-filename => 'Wibbl7',
196 isa_ok $hmmer_ind, 'Bio::Index::Hmmer';
197 $hmmer_ind->make_index(test_input_file('hmmpfam_multiresult.out'));
199 my $hmm_result = $hmmer_ind->fetch_report('lcl|gi|340783625|Plus1');
200 is ($hmm_result->query_description, 'megaplasmid, complete sequence [UNKNOWN]');
207 return $1 if ($line =~ /product="([^"]+)"/);
208 return $1 if ($line =~ /^DR\s+EMBL;\s+([^;]+)/);
216 for my $root ( qw( Wibbl Wibbl2 Wibbl3 Wibbl4 Wibbl5 Wibbl6 Wibbl7
217 multifa_index multifa_qual_index ) ) {
218 unlink $root if( -e $root );
219 unlink "$root.pag" if( -e "$root.pag");
220 unlink "$root.dir" if( -e "$root.dir");