~ubuntu-branches/ubuntu/trusty/bioperl/trusty-proposed

« back to all changes in this revision

Viewing changes to t/Index.t

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090310071911-fukqzw54pyb1f0bd
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*-Perl-*-
2
 
# $Id: Index.t,v 1.44.2.3 2006/10/02 23:10:40 sendu Exp $
3
 
 
4
 
use strict;
5
 
use vars qw($exit $DEBUG);
6
 
BEGIN {
7
 
   eval { require Test; };
8
 
   use vars qw($NUMTESTS);
9
 
   $DEBUG = $ENV{"BIOPERLDEBUG"} || 0;
10
 
   $NUMTESTS = 50;
11
 
   if ( $@ ) {
12
 
      use lib 't';
13
 
   }
14
 
   use Test;
15
 
   eval {
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;
22
 
                require DB_File;
23
 
                require Storable;
24
 
                require File::Temp;
25
 
                require Fcntl;
26
 
        };
27
 
   if ( $@ ) {
28
 
      warn("Module DB_File or Fcntl or Storable or File::Temp not installed - skipping tests\n") if $DEBUG;
29
 
      $exit = 1;
30
 
   }
31
 
   plan tests => $NUMTESTS;
32
 
}
33
 
 
34
 
END {
35
 
        foreach ( $Test::ntest..$NUMTESTS) {
36
 
          skip("Cannot complete Index.t tests, skipping",1);
37
 
        }
38
 
}
39
 
 
40
 
exit(0) if $exit;
41
 
 
42
 
use Bio::Root::IO;
43
 
use Bio::DB::InMemoryCache;
44
 
 
45
 
eval { require Bio::DB::FileCache };
46
 
 
47
 
use vars qw ($dir);
48
 
 
49
 
($Bio::Root::IO::FILESPECLOADED && File::Spec->can('curdir') &&
50
 
($dir = File::Spec->curdir) ) || ($dir = `pwd`) || ($dir = '.');
51
 
chomp( $dir );
52
 
 
53
 
my $ind = Bio::Index::Fasta->new(-filename => 'Wibbl',
54
 
                                                                                        -write_flag => 1,
55
 
                                                                                        -verbose => 0);
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"));
58
 
 
59
 
ok ( -e "Wibbl" || -e "Wibbl.pag" );
60
 
my $seq = $ind->fetch('HSEARLOBE');
61
 
ok($seq->length,321);
62
 
$seq = $ind->fetch('HSMETOO');
63
 
ok($seq->length,134);
64
 
$seq = $ind->fetch('MMWHISK');
65
 
ok($seq->length,62);
66
 
$seq = $ind->fetch('gi|238775|bbs|65126');
67
 
ok($seq->length,70);
68
 
 
69
 
my $stream = $ind->get_PrimarySeq_stream();
70
 
$seq = $stream->next_seq;
71
 
ok ($seq->isa('Bio::PrimarySeqI'));
72
 
 
73
 
$ind = Bio::Index::Fasta->new(-filename => 'multifa_index',
74
 
                                                                                -write_flag => 1,
75
 
                                                                                -verbose => 0);
76
 
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","multifa.seq.qual"));
77
 
 
78
 
ok ( -e "multifa_index" );
79
 
 
80
 
$ind = Bio::Index::Qual->new(-filename => 'multifa_qual_index',
81
 
                                                                          -write_flag => 1,
82
 
                                                                          -verbose => 0);
83
 
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","multifa.seq.qual"));
84
 
 
85
 
ok ( -e "multifa_qual_index" );
86
 
 
87
 
ok ( defined($seq) && $seq->isa('Bio::SeqI'));
88
 
$seq = $ind->fetch('HSEARLOBE');
89
 
ok($seq->length,321);
90
 
$seq = $ind->fetch('HSMETOO');
91
 
ok($seq->length,134);
92
 
$seq = $ind->fetch('MMWHISK');
93
 
ok($seq->length,62);
94
 
$seq = $ind->fetch('NONEXISTENT_SEQ');
95
 
ok(! defined $seq);
96
 
 
97
 
$ind = Bio::Index::SwissPfam->new(-filename => 'Wibbl2',
98
 
                                                                                         -write_flag =>1);
99
 
$ind->make_index(Bio::Root::IO->catfile($dir,"t","data","swisspfam.data"));
100
 
 
101
 
ok ( -e "Wibbl2" || -e "Wibbl2.pag" );
102
 
 
103
 
$ind = Bio::Index::EMBL->new(-filename   => 'Wibbl3',
104
 
                             -write_flag =>1);
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);
108
 
 
109
 
$ind = Bio::Index::Swissprot->new(-filename   => 'Wibbl4',
110
 
                                                                                         -write_flag => 1);
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');
117
 
 
118
 
# test id_parser
119
 
$ind = Bio::Index::Swissprot->new(-filename   => 'Wibbl4',
120
 
                                                                                         -write_flag => 1);
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);
126
 
 
127
 
 
128
 
my $gb_ind = Bio::Index::GenBank->new(-filename => 'Wibbl5',
129
 
                                                                                                  -write_flag =>1,
130
 
                                                                                                  -verbose    => 0);
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");
138
 
 
139
 
my $cache = Bio::DB::InMemoryCache->new( -seqdb => $gb_ind );
140
 
 
141
 
ok ( $cache->get_Seq_by_id('AI129902') );
142
 
 
143
 
if (Bio::DB::FileCache->can('new')) {
144
 
   $cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
145
 
                                                                                                -keep  => 1,
146
 
                                                                                                -file  => 'filecache.idx');
147
 
   # problem:
148
 
   my $seq = $cache->get_Seq_by_id('AI129902');
149
 
   ok ( $seq);
150
 
   ok ( $seq->length, 37);
151
 
   ok ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
152
 
 
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;
157
 
   ok( $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');
165
 
 
166
 
   $cache = undef;
167
 
   $cache = Bio::DB::FileCache->new(-seqdb => $gb_ind,
168
 
                                                                                                -keep  => 0,
169
 
                                                                                                -file  => 'filecache.idx');
170
 
   $seq = $cache->get_Seq_by_id('AI129902');
171
 
   ok ( $seq);
172
 
   ok ( $seq->length, 37);
173
 
   ok ( lc($seq->seq()), 'ctccgcgccaactccccccaccccccccccacacccc');
174
 
 
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;
179
 
   ok( $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');
187
 
} else {
188
 
   skip('Bio::DB::FileCache not loaded because one or more of Storable, Fcntl, DB_File or File::Temp not installed',1);
189
 
}
190
 
 
191
 
# test id_parser
192
 
$gb_ind = Bio::Index::GenBank->new(-filename => 'Wibbl5',
193
 
                                                                                          -write_flag =>1,
194
 
                                                                                          -verbose    => 0);
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);
200
 
 
201
 
sub get_id {
202
 
        my $line = shift;
203
 
        return $1 if ($line =~ /product="([^"]+)"/);
204
 
        return $1 if ($line =~ /^DR\s+EMBL;\s+([^;]+)/);
205
 
}
206
 
 
207
 
END {
208
 
        cleanup();
209
 
}
210
 
 
211
 
sub cleanup {
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");
217
 
        }
218
 
}