1
1
# This is -*-Perl-*- code
2
2
## Bioperl Test Harness Script for Modules
4
# $Id: DBCUTG.t,v 1.8 2003/12/18 03:03:26 jason Exp $
4
# $Id: DBCUTG.t,v 1.20.4.5 2006/11/17 09:32:42 sendu Exp $
6
5
# Before `make install' is performed this script should be runnable with
7
6
# `make test'. After `make install' it should work as `perl test.t'
9
use vars qw($NUMTESTS $DEBUG $ERROR);
9
use vars qw($NUMTESTS $DEBUG);
11
$DEBUG = $ENV{'BIOPERLDEBUG'} || 0;
13
# to handle systems with no installed Test module
14
# we include the t dir (where a copy of Test.pm is located)
16
eval { require Test; };
24
plan tests => $NUMTESTS;
28
require LWP::UserAgent;
31
warn("IO::String or LWP::UserAgent not installed. This means that the module is not usable. Skipping tests");
13
$DEBUG = $ENV{'BIOPERLDEBUG'} || 0;
15
eval {require Test::More;};
23
require LWP::UserAgent;
26
plan skip_all => 'IO::String or LWP::UserAgent not installed. This means that the module is not usable. Skipping tests';
29
plan tests => $NUMTESTS;
32
use_ok('Bio::DB::CUTG');
33
use_ok('Bio::CodonUsage::Table');
34
use_ok('Bio::CodonUsage::IO');
36
use_ok('Bio::Tools::SeqStats');
37
use_ok('Bio::Root::IO');
37
foreach ( $Test::ntest..$NUMTESTS) {
38
skip('unable to run all of the tests depending on web access',1);
42
exit 0 if $ERROR == 1;
45
require Bio::DB::CUTG;
46
require Bio::CodonUsage::Table;
47
require Bio::CodonUsage::IO;
49
require Bio::Tools::SeqStats;
53
$verbose = 1 if $DEBUG;
55
ok my $tool = Bio::WebAgent->new(-verbose =>$verbose);
58
ok $tool->delay(1), 1;
62
ok my $db = Bio::DB::CUTG->new();
63
my $cdtable = $db->get_request(-sp =>'Pan troglodytes');
66
ok $cdtable->cds_count(), 401;
67
ok int($cdtable->aa_frequency('LEU')), 9;
68
ok $cdtable->get_coding_gc('all');
69
ok $cdtable->codon_rel_frequency('ttc'), "0.68";
71
#now try reading from file
72
ok my $io = Bio::CodonUsage::IO->new
73
(-file=> Bio::Root::IO->catfile("t", "data", "MmCT"));
74
ok my $cut2 = $io->next_data();
75
ok int($cut2->aa_frequency('LEU')), 10;
77
#now try making a user defined CUT from a sequence
79
ok my $seqobj = Bio::SeqIO->new (-file=>
80
Bio::Root::IO->catfile("t", "data",
82
-format => 'fasta')->next_seq;
83
ok $seqobj->subseq(10,20), 'TTGACACCACT';
84
ok my $codcont_Ref = Bio::Tools::SeqStats->count_codons($seqobj);
85
ok $codcont_Ref->{'TGA'}, 16;
86
ok my $cut = Bio::CodonUsage::Table->new(-data=>$codcont_Ref);
87
ok $cut->codon_rel_frequency('CTG'), 0.18;
88
ok $cut->codon_abs_frequency('CTG'), 2.6;
89
ok $cut->codon_count('CTG'), 26;
90
ok $cut->get_coding_gc(1), "39.70";
92
for ( $Test::ntest..$NUMTESTS) {
93
skip("Skipping tests which require remote servers - set env variable BIOPERLDEBUG to test",1);
41
unlink(Bio::Root::IO->catfile("t","data","cutg.out"));
44
my $outfile = Bio::Root::IO->catfile("t","data","cutg.out");
45
my $verbose = 1 if $DEBUG;
47
# try reading from file
48
ok my $io = Bio::CodonUsage::IO->new
49
(-file=> Bio::Root::IO->catfile("t", "data", "MmCT"));
50
ok my $cut2 = $io->next_data();
51
is int($cut2->aa_frequency('LEU')), 10;
54
ok $io = Bio::CodonUsage::IO->new(-file => ">$outfile");
55
$io->write_data($cut2);
58
# can we read what we've written?
59
ok $io = Bio::CodonUsage::IO->new(-file => "$outfile");
60
ok $cut2 = $io->next_data();
61
is int($cut2->aa_frequency('LEU')), 10;
63
# now try making a user defined CUT from a sequence
64
ok my $seqobj = Bio::SeqIO->new (-file =>
65
Bio::Root::IO->catfile("t", "data", "HUMBETGLOA.fa"),
66
-format => 'fasta')->next_seq;
67
is $seqobj->subseq(10,20), 'TTGACACCACT';
68
ok my $codcont_Ref = Bio::Tools::SeqStats->count_codons($seqobj);
69
is $codcont_Ref->{'TGA'}, 16;
70
ok my $cut = Bio::CodonUsage::Table->new(-data=>$codcont_Ref);
71
is $cut->codon_rel_frequency('CTG'), 0.18;
72
is $cut->codon_abs_frequency('CTG'), 2.6;
73
is $cut->codon_count('CTG'), 26;
74
is $cut->get_coding_gc(1), "39.70";
75
ok my $ref = $cut->probable_codons(20);
77
# requiring Internet access, set env BIOPERLDEBUG to 1 to run
79
skip "Skipping tests which require remote servers, set BIOPERLDEBUG=1 to test", 11 unless $DEBUG;
80
ok my $tool = Bio::WebAgent->new(-verbose =>$verbose);
82
is $tool->delay(1), 1;
86
ok my $db = Bio::DB::CUTG->new();
89
eval {$cdtable = $db->get_request(-sp =>'Pan troglodytes');};
90
skip "Could not connect to server, server/network problems? Skipping those tests", 5 if $@;
92
# tests for Table.pm, the answers seem to change with time, so not specific
93
cmp_ok($cdtable->cds_count(), '>', 600);
94
cmp_ok(int($cdtable->aa_frequency('LEU')), '>', 1);
95
ok $cdtable->get_coding_gc('all');
96
cmp_ok($cdtable->codon_rel_frequency('ttc'), '<', 1);
98
## now lets enter a non-existent species ans check handling..
99
## should default to human...
100
my $db2 = Bio::DB::CUTG->new();
101
eval {$cut2 = $db2->get_request(-sp =>'Wookie magnus');};
102
skip "Could not connect to server, server/network problems? Skipping those tests", 1 if $@;
103
is $cut2->species(), 'Homo sapiens';