File: table.t

package info (click to toggle)
bioperl 1.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 35,788 kB
  • sloc: perl: 94,019; xml: 14,811; makefile: 20
file content (171 lines) | stat: -rw-r--r-- 5,485 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
162
163
164
165
166
167
168
169
170
171
# -*-Perl-*- Test Harness script for Bioperl

use strict;

BEGIN {
    use Bio::Root::Test;

    test_begin(-tests => 351,
			   -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]);

# Tests to check that 'description' is read from 'table' format
ok $seqin = Bio::SeqIO->new(
    -file   => test_input_file("test-1.tab"),
    -format => 'table',
    -header => 1,
    -display_id => 1,
    -accession_number => 1,
    -seq => 3,
    -desc => 2
);
ok($seqin);
my $seq = $seqin->next_seq;
ok($seq);
is( $seq->desc, 'd1');
is( $seq->display_id, 'n1');
is( $seq->seq, 'aaaa');
$seq = $seqin->next_seq;
ok($seq);
is( $seq->desc, 'd2');
is( $seq->display_id, 'n2');
is( $seq->seq, 'tttt');

$seqin->close();

# Tests to check that we can _not_ write to 'table' format
ok $seqin = Bio::SeqIO->new(
    -file   => test_input_file("test-1.tab.gb"),
    -format => 'genbank'
);
ok($seqin);
$seq = $seqin->next_seq;
ok($seq);
my $tmpfile = test_output_file();
my $seqout = Bio::SeqIO->new( -format => 'table', -file => ">$tmpfile" );
# dies_ok not available
# dies_ok { $seqout->write_seq($seq) } "write_seq() not implemented";

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);
}