2
# $Id: Index.t,v 1.44.2.3 2006/10/02 23:10:40 sendu Exp $
5
use vars qw($exit $DEBUG);
7
eval { require Test; };
8
use vars qw($NUMTESTS);
9
$DEBUG = $ENV{"BIOPERLDEBUG"} || 0;
16
require Bio::Index::Fasta;
17
require Bio::Index::Qual;
18
require Bio::Index::SwissPfam;
19
require Bio::Index::EMBL;
20
require Bio::Index::GenBank;
21
require Bio::Index::Swissprot;
28
warn("Module DB_File or Fcntl or Storable or File::Temp not installed - skipping tests\n") if $DEBUG;
31
plan tests => $NUMTESTS;
35
foreach ( $Test::ntest..$NUMTESTS) {
36
skip("Cannot complete Index.t tests, skipping",1);
43
use Bio::DB::InMemoryCache;
45
eval { require Bio::DB::FileCache };
49
($Bio::Root::IO::FILESPECLOADED && File::Spec->can('curdir') &&
50
($dir = File::Spec->curdir) ) || ($dir = `pwd`) || ($dir = '.');
53
my $ind = Bio::Index::Fasta->new(-filename => 'Wibbl',
56
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","multifa.seq"));
57
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","seqs.fas"));
59
ok ( -e "Wibbl" || -e "Wibbl.pag" );
60
my $seq = $ind->fetch('HSEARLOBE');
62
$seq = $ind->fetch('HSMETOO');
64
$seq = $ind->fetch('MMWHISK');
66
$seq = $ind->fetch('gi|238775|bbs|65126');
69
my $stream = $ind->get_PrimarySeq_stream();
70
$seq = $stream->next_seq;
71
ok ($seq->isa('Bio::PrimarySeqI'));
73
$ind = Bio::Index::Fasta->new(-filename => 'multifa_index',
76
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","multifa.seq.qual"));
78
ok ( -e "multifa_index" );
80
$ind = Bio::Index::Qual->new(-filename => 'multifa_qual_index',
83
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","multifa.seq.qual"));
85
ok ( -e "multifa_qual_index" );
87
ok ( defined($seq) && $seq->isa('Bio::SeqI'));
88
$seq = $ind->fetch('HSEARLOBE');
90
$seq = $ind->fetch('HSMETOO');
92
$seq = $ind->fetch('MMWHISK');
94
$seq = $ind->fetch('NONEXISTENT_SEQ');
97
$ind = Bio::Index::SwissPfam->new(-filename => 'Wibbl2',
99
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","swisspfam.data"));
101
ok ( -e "Wibbl2" || -e "Wibbl2.pag" );
103
$ind = Bio::Index::EMBL->new(-filename => 'Wibbl3',
105
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","test.embl"));
106
ok ( -e "Wibbl3" || -e "Wibbl3.pag" );
107
ok ($ind->fetch('AL031232')->length, 4870);
109
$ind = Bio::Index::Swissprot->new(-filename => 'Wibbl4',
111
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","roa1.swiss"));
112
ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
113
$seq = $ind->fetch('ROA1_HUMAN');
114
ok ($seq->display_id(), 'ROA1_HUMAN');
115
$seq = $ind->fetch('P09651');
116
ok ($seq->display_id(), 'ROA1_HUMAN');
119
$ind = Bio::Index::Swissprot->new(-filename => 'Wibbl4',
121
$ind->id_parser(\&get_id);
122
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","roa1.swiss"));
123
ok ( -e "Wibbl4" || -e "Wibbl4.pag" );
124
$seq = $ind->fetch('X12671');
125
ok ($seq->length,371);
128
my $gb_ind = Bio::Index::GenBank->new(-filename => 'Wibbl5',
131
$gb_ind->make_index(Bio::Root::IO->catfile($dir,"t","data","roa1.genbank"));
132
ok ( -e "Wibbl5" || -e "Wibbl5.pag" );
133
$seq = $gb_ind->fetch('AI129902');
134
ok ($seq->length, 37);
135
ok ($seq->species->binomial, 'Homo sapiens');
136
$seq = $gb_ind->fetch(3598416);
137
ok ($seq->seq,"CTCCGCGCCAACTCCCCCCACCCCCCCCCCACACCCC");
139
my $cache = Bio::DB::InMemoryCache->new( -seqdb => $gb_ind );
141
ok ( $cache->get_Seq_by_id('AI129902') );
143
if (Bio::DB::FileCache->can('new')) {
144
$cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
146
-file => 'filecache.idx');
148
my $seq = $cache->get_Seq_by_id('AI129902');
150
ok ( $seq->length, 37);
151
ok ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
153
my ( $f1 ) = $seq->get_SeqFeatures();
154
ok ( ($f1->each_tag_value('sex'))[0], 'female');
155
ok ( ($f1->each_tag_value('lab_host'))[0], 'DH10B');
156
my $species = $seq->species;
158
ok( $species->binomial, 'Homo sapiens');
159
ok( $species->species(), 'sapiens');
160
ok( $species->genus(), 'Homo');
161
# changes in GenBank file SOURCE line
162
# this is now the abbreviated name
163
ok defined($species->name('abbreviated'));
164
ok ($species->name('abbreviated')->[0], 'human');
167
$cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
169
-file => 'filecache.idx');
170
$seq = $cache->get_Seq_by_id('AI129902');
172
ok ( $seq->length, 37);
173
ok ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
175
( $f1 ) = $seq->get_SeqFeatures();
176
ok ( ($f1->each_tag_value('sex'))[0], 'female');
177
ok ( ($f1->each_tag_value('lab_host'))[0], 'DH10B');
178
$species = $seq->species;
180
ok( $species->binomial, 'Homo sapiens');
181
ok( $species->species(), 'sapiens');
182
ok( $species->genus(), 'Homo');
183
# changes in GenBank file SOURCE line
184
# this is now the abbreviated name
185
ok defined($species->name('abbreviated'));
186
ok ($species->name('abbreviated')->[0], 'human');
188
skip('Bio::DB::FileCache not loaded because one or more of Storable, Fcntl, DB_File or File::Temp not installed',1);
192
$gb_ind = Bio::Index::GenBank->new(-filename => 'Wibbl5',
195
$gb_ind->id_parser(\&get_id);
196
$gb_ind->make_index(Bio::Root::IO->catfile($dir,"t","data","roa1.genbank"));
197
ok ( -e "Wibbl5" || -e "Wibbl5.pag" );
198
$seq = $gb_ind->fetch('alpha D-globin');
199
ok ($seq->length,141);
203
return $1 if ($line =~ /product="([^"]+)"/);
204
return $1 if ($line =~ /^DR\s+EMBL;\s+([^;]+)/);
212
for my $root ( qw( Wibbl Wibbl2 Wibbl3 Wibbl4 Wibbl5
213
multifa_index multifa_qual_index ) ) {
214
unlink $root if( -e $root );
215
unlink "$root.pag" if( -e "$root.pag");
216
unlink "$root.dir" if( -e "$root.dir");