File: table.t

package info (click to toggle)
bioperl 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,768 kB
  • ctags: 12,005
  • sloc: perl: 174,299; xml: 13,923; sh: 1,941; lisp: 1,803; asm: 109; makefile: 53
file content (156 lines) | stat: -rw-r--r-- 5,177 bytes parent folder | download
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
# -*-Perl-*- Test Harness script for Bioperl
# $Id: table.t 15112 2008-12-08 18:12:38Z sendu $

use strict;

BEGIN {     
    use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 450,
			   -requires_module => 'IO::Scalar');
	
	use_ok('Bio::Tools::CodonTable');
	use_ok('Bio::SeqIO::table');
}

my @names = qw(A6
               A6r
               A6ps1
               A6ps2
               CaMK2d
               CaMKK2
               AMPKa1
               AMPKa2
               MARK3
               MARK2);
my @accs = qw(SK001
              SK512
              SK752
              SK766
              SK703
              SK482
              SK032
              SK033
              SK096
              SK120);
my @num_anns = (5, 5, 5, 5, 6, 7, 7, 7, 7, 7);
my @psg = (0, 0, 1, 1, 0, 0, 0, 0, 0, 0);
my @rs = (0, 0, 0, 0, 1, 1, 1, 1, 1, 1);

ok my $seqin = Bio::SeqIO->new(-file => test_input_file("test.tsv"),
			    -format  => 'table',
                            -species => "Homo sapiens",
                            -delim   => "\t",
                            -header  => 1,
                            -display_id => 1,
                            -accession_number => 2,
                            -seq => 7,
                            -annotation => 1,
                            -trim => 1);
run_tests([@names],[@accs],[@num_anns],[@psg],[@rs]);

$seqin->close();

ok $seqin = Bio::SeqIO->new(-file => test_input_file("test.tsv"),
                         -format  => 'table',
                         -species => "Homo sapiens",
                         -delim   => "\t",
                         -header  => 1,
                         -display_id => 1,
                         -accession_number => 2,
                         -seq => 7,
                         -colnames => "[Family,Subfamily,Pseudogene?,Protein,Novelty]",
                         -trim => 1);
run_tests([@names],[@accs],[4,4,4,4,4,5,5,5,5,5],[@psg],[@rs]);

$seqin->close();

ok $seqin = Bio::SeqIO->new(-file => test_input_file("test.tsv"),
                         -format  => 'table',
                         -species => "Homo sapiens",
                         -delim   => "\t",
                         -header  => 1,
                         -display_id => 1,
                         -accession_number => 2,
                         -seq => 7,
                         -annotation => "[4,5,6,8,10]",
                         -trim => 1);
run_tests([@names],[@accs],[4,4,4,4,4,5,5,5,5,5],[@psg],[@rs]);

$seqin->close();

# need Spreadsheet::ParseExcel installed for testing Excel format
SKIP: {
	test_skip(-tests => 112, -requires_module => 'Spreadsheet::ParseExcel');

	ok $seqin = Bio::SeqIO->new(-file => test_input_file("test.xls"),
							 -format  => 'excel',
							 -species => "Homo sapiens",
							 -header  => 1,
							 -display_id => 1,
							 -accession_number => 2,
							 -seq => 7,
							 -annotation => 1,
							 -trim => 1);
	run_tests([@names],[@accs],[@num_anns],[@psg],[@rs]);
	
	$seqin->close();
}

sub run_tests {
    my ($names_,$accs_,$num_anns_,$psg_,$rs_) = @_;

    my @names = @$names_;
    my @accs = @$accs_;
    my @num_anns = @$num_anns_;
    my @psg = @$psg_;
    my @rs = @$rs_;

    my $n = 0;
    my $translator = Bio::Tools::CodonTable->new(-id => 1);
    while (my $seq = $seqin->next_seq()) {
        $n++;
        is ($seq->display_id, shift(@names));
        is ($seq->accession_number, shift(@accs));
        ok ($seq->species);
        is ($seq->species->binomial, "Homo sapiens");
        my @anns = $seq->annotation->get_Annotations();
        is (scalar(@anns), shift(@num_anns));
        @anns = grep { $_->value eq "Y"; 
                     } $seq->annotation->get_Annotations("Pseudogene?");
        is (scalar(@anns), shift(@psg));
        
        # check sequences and that they translate to what we expect
        if (($n >= 5) && ($seq->display_id ne "MARK3")) {
            my $dna = $seq->seq;
            my $protein = "";
            my $frame = 0;
            while ($frame <= 2) {
                my $inframe = substr($dna,$frame);
                # translate to protein
                my $protseq = $translator->translate($inframe);
                # chop off everything after the stop and before the first Met
                while ($protseq =~ /(M[^\*]+)/g) {
                    $protein = $1 if length($1) > length($protein);
                }
                $frame++;
            }
            # retrieve expected result from annotation and compare
            my ($protann) = $seq->annotation->get_Annotations("Protein");
            ok (defined $protann);
            is ($protein, $protann->value);
        }
        
        @anns = grep { $_->value eq "Known - Refseq"; 
                     } $seq->annotation->get_Annotations("Novelty");
        is (scalar(@anns), shift(@rs));
        @anns = $seq->annotation->get_Annotations("Subfamily");
        is (scalar(@anns), ($n <= 5) ? 0 : 1);
        @anns = $seq->annotation->get_Annotations("Family");
        is (scalar(@anns), 1);
        is (substr($anns[0]->value,0,4), ($n <= 4) ? "A6" : "CAMK");    
    }
    
    is ($n, 10);
}