File: flat.t

package info (click to toggle)
bioperl 1.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 20,336 kB
  • ctags: 8,476
  • sloc: perl: 119,890; xml: 6,001; lisp: 121; makefile: 57
file content (161 lines) | stat: -rw-r--r-- 3,539 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# This is -*-Perl-*- code
## Bioperl Test Harness Script for Modules
##
# $Id: flat.t,v 1.11 2003/07/09 01:12:11 jason Exp $

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.t'

use strict;
use vars qw($NUMTESTS);

my $error;

BEGIN { 
    # to handle systems with no installed Test module
    # we include the t dir (where a copy of Test.pm is located)
    # as a fallback
    eval { require Test; };
    $error = 0;
    if( $@ ) {
	use lib 't';
    }
    use Test;

    $NUMTESTS = 16;
    plan tests => $NUMTESTS;
    eval { 
	require DB_File; 
	require Bio::DB::Flat; 
	require Bio::Root::IO; 
	1;
    };
    if( $@ ) {
	print STDERR "DB_File not loaded. This means flat.t test cannot be executed. Skipping\n";
	foreach ( $Test::ntest..$NUMTESTS ) {
	    skip('DB_File not installed',1);
	}
	$error = 1;
    }
}

if( $error ==  1 ) {
    exit(0);
}
my $testnum;
my $verbose = 0;

## End of black magic.
##
## Insert additional test code below but remember to change
## the print "1..x\n" in the BEGIN block to reflect the
## total number of tests that will be run. 


#First of all we need to create an flat db
use Bio::Root::IO;
use Cwd;
my $cd = cwd();
my $tmpdir = Bio::Root::IO->catfile($cd,qw(t tmp));
&maketmpdir();
my $db = Bio::DB::Flat->new(-directory  => $tmpdir,
                            -index      => 'bdb',
			    -dbname     => 'mydb',
			    -format     => 'fasta',
			    -verbose    => $verbose,
                 	    -write_flag => 1
                            );
ok($db);
my $dir = Bio::Root::IO->catfile($cd,qw(t data AAC12660.fa));
my $result = $db->build_index(glob($dir));
ok($result);

#Now let's get the sequence out again
my $seq = $db->get_Seq_by_id('AAC12660');
ok($seq);
ok($seq->length,504);
undef $db;
&cleanup();
&maketmpdir();
$db = Bio::DB::Flat->new(-directory  => $tmpdir,
                         -index      => 'bdb',
                         -format     => 'embl',
			 -dbname     => 'myembl',
                         -verbose    => $verbose,
                         -write_flag => 1
			 );

$dir= Bio::Root::IO->catfile($cd,qw(t data factor7.embl));

$result = $db->build_index(glob($dir));
ok($result);
$seq = $db->get_Seq_by_id('HSCFVII');
ok($seq);
ok($seq->length,12850);

# deal with wantarray conditions
$seq = $db->get_Seq_by_acc('J02933');
ok($seq && ref($seq));
ok($seq->length,12850);


undef $db;

&cleanup();
&maketmpdir();


$db = Bio::DB::Flat->new(-directory  => $tmpdir,
			 -index      => 'binarysearch',
			 -format     => 'fasta',
			 -dbname     => 'mybinfa',
			 -verbose    => $verbose,
			 -write_flag => 1
			 );

$dir= Bio::Root::IO->catfile($cd,qw(t data dbfa 1.fa));
$result = $db->build_index($dir);
ok($result);
$seq = $db->get_Seq_by_id('AW057119');
ok($seq);
ok($seq->length,808);
undef $db;

&cleanup();
&maketmpdir();
$db = Bio::DB::Flat->new(-directory  => $tmpdir,
			 -index      => 'binarysearch',
			 -format     => 'swiss',
			 -dbname     => 'mybinswiss',
			 -verbose    => $verbose,
			 -write_flag => 1
			 );
$dir= Bio::Root::IO->catfile($cd,qw(t data swiss.dat));
$result = $db->build_index($dir);

ok($result);
$seq = $db->get_Seq_by_id('ACON_CAEEL');
ok($seq);
ok($seq->length,788);

$seq = $db->get_Seq_by_id('ACON_CAEEL');
ok($seq && ref($seq));

undef $db;


&cleanup();

sub maketmpdir {
    mkdir ($tmpdir,0777);
}

sub cleanup {
    eval { 
	 Bio::Root::IO->rmtree($tmpdir) if( defined $tmpdir && -d $tmpdir);
    };
} 

END {
    &cleanup();
}