clean up XMFA parsing, allow spaces in parsing (ende++, from IRC)
[bioperl-live.git] / t / DBCUTG.t
blob31a1d744ad230d97719d72d3c990d55fd55429f0
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7         use lib 't/lib';
8         use BioperlTest;
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 # requiring Internet access, set env BIOPERLDEBUG to 1 to run
53 SKIP: {
54         test_skip(-tests => 14, -requires_networking => 1);
55         ok my $tool = Bio::WebAgent->new(-verbose => $verbose);
56         ok $tool->sleep;
57         is $tool->delay(1), 1;
58         ok $tool->sleep;
60         # get CUT from web
61         ok my $db = Bio::DB::CUTG->new();
62         $db->verbose($verbose ? $verbose : -1);
63         my $cdtable;
64         eval {$cdtable = $db->get_request(-sp =>'Pan troglodytes');};
65         skip "Server/network problems? Skipping those tests\n$@", 5 if $@;
66         
67         # tests for Table.pm, the answers seem to change with time, so not specific
68         cmp_ok($cdtable->cds_count(), '>', 10);
69         cmp_ok(int($cdtable->aa_frequency('LEU')), '>', 1);
70         ok $cdtable->get_coding_gc('all');
71         cmp_ok($cdtable->codon_rel_frequency('ttc'), '<', 1); 
72     
73         ## now lets enter a non-existent species ans check handling..
74         ## should default to human...
75         my $db2 = Bio::DB::CUTG->new();
76         $db2->verbose($verbose ? $verbose : -1);
77         eval {$cut2 = $db2->get_request(-sp =>'Wookie magnus');};
78         skip "Server/network problems? Skipping those tests\n$@", 1 if $@;
79         is $cut2->species(), 'Homo sapiens';
80         
81         $db = Bio::DB::CUTG->new();
82         $db->verbose($verbose ? $verbose : -1);
83         eval {$cdtable = $db->get_request(-sp =>'Homo sapiens');};
84         skip "Server/network problems? Skipping those tests\n$@", 4 if $@;
85         
86         # tests for Table.pm, the answers seem to change with time, so not specific
87         cmp_ok($cdtable->cds_count(), '>', 10);
88         cmp_ok(int($cdtable->aa_frequency('LEU')), '>', 1);
89         ok $cdtable->get_coding_gc('all');
90         cmp_ok($cdtable->codon_rel_frequency('ttc'), '<', 1);