URLify
[bioperl-live.git] / t / RemoteDB / CUTG.t
blobd4c133e77f217dd1f6f2f9026cec426dcfa3d79f
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7         use lib '.';
8         use Bio::Root::Test;
9         
10         test_begin(-tests => 37,
11                            -requires_modules => [qw(IO::String LWP::UserAgent)]);
12         
13         use_ok('Bio::DB::CUTG');
14         use_ok('Bio::CodonUsage::Table');
15         use_ok('Bio::CodonUsage::IO');
16     use_ok('Bio::SeqIO');
17     use_ok('Bio::Tools::SeqStats');
20 my $outfile = test_output_file();
21 my $verbose = test_debug();
23 # try reading from file
24 ok my $io = Bio::CodonUsage::IO->new
25   (-file=> test_input_file('MmCT'));
26 ok  my $cut2 = $io->next_data();
27 is int($cut2->aa_frequency('LEU')), 10;
29 # write
30 ok $io = Bio::CodonUsage::IO->new(-file => ">$outfile");
31 $io->write_data($cut2);
32 ok -e $outfile;
34 # can we read what we've written?
35 ok $io = Bio::CodonUsage::IO->new(-file => "$outfile");
36 ok $cut2 = $io->next_data();
37 is int($cut2->aa_frequency('LEU')), 10;
39 # now try making a user defined CUT from a sequence
40 ok my $seqobj = Bio::SeqIO->new (-file =>test_input_file('HUMBETGLOA.fa'),
41                                                         -format => 'fasta')->next_seq;
42 is $seqobj->subseq(10,20), 'TTGACACCACT';
43 ok my $codcont_Ref = Bio::Tools::SeqStats->count_codons($seqobj);
44 is $codcont_Ref->{'TGA'}, 16;
45 ok my $cut = Bio::CodonUsage::Table->new(-data=>$codcont_Ref);
46 is $cut->codon_rel_frequency('CTG'), 0.18;
47 is $cut->codon_abs_frequency('CTG'), 2.6;
48 is $cut->codon_count('CTG'), 26;
49 is $cut->get_coding_gc(1), "39.70";
50 ok my $ref = $cut->probable_codons(20);
52 # Examples:
53 # http://www.kazusa.or.jp/codon/cgi-bin/spsearch.cgi?species=Pan+troglodytes&c=s
54 # http://www.kazusa.or.jp/codon/cgi-bin/showcodon.cgi?species=37011&aa=1&style=GCG
55 # requiring Internet access, set env BIOPERLDEBUG to 1 to run
56 SKIP: {
57         test_skip(-tests => 14, -requires_networking => 1);
58         ok my $tool = Bio::WebAgent->new(-verbose => $verbose);
59         ok $tool->sleep;
60         is $tool->delay(1), 1;
61         ok $tool->sleep;
63         # get CUT from web
64         ok my $db = Bio::DB::CUTG->new();
65         $db->verbose($verbose ? $verbose : -1);
66         my $cdtable;
67         eval {$cdtable = $db->get_request(-sp =>'Pan troglodytes');};
68         skip "Server/network problems? Skipping those tests\n$@", 9 if $@;
69         
70         # tests for Table.pm, the answers seem to change with time, so not specific
71         cmp_ok($cdtable->cds_count(), '>', 10);
72         cmp_ok(int($cdtable->aa_frequency('LEU')), '>', 1);
73         ok $cdtable->get_coding_gc('all');
74         cmp_ok($cdtable->codon_rel_frequency('ttc'), '<', 1); 
75     
76         ## now lets enter a non-existent species ans check handling..
77         ## should default to human...
78         my $db2 = Bio::DB::CUTG->new();
79         $db2->verbose($verbose ? $verbose : -1);
80         eval {$cut2 = $db2->get_request(-sp =>'Wookie magnus');};
81         skip "Server/network problems? Skipping those tests\n$@", 5 if $@;
82         is $cut2->species(), 'Homo sapiens';
83         
84         $db = Bio::DB::CUTG->new();
85         $db->verbose($verbose ? $verbose : -1);
86         eval {$cdtable = $db->get_request(-sp =>'Homo sapiens');};
87         skip "Server/network problems? Skipping those tests\n$@", 4 if $@;
88         
89         # tests for Table.pm, the answers seem to change with time, so not specific
90         cmp_ok($cdtable->cds_count(), '>', 10);
91         cmp_ok(int($cdtable->aa_frequency('LEU')), '>', 1);
92         ok $cdtable->get_coding_gc('all');
93         cmp_ok($cdtable->codon_rel_frequency('ttc'), '<', 1); 
95         my $db3 = Bio::DB::CUTG->new(-sp =>'Bacillus subtilis', -gc => 1);
96         $db3->verbose($verbose ? $verbose : -1);
97         my $cut3;
98         eval {$cut3 = $db3->get_request();};
99         skip "Server/network problems? Skipping those tests\n$@", 5 if $@;
100         print $cut3->codon_rel_frequency('ATG');