File: Seq.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 (197 lines) | stat: -rw-r--r-- 5,974 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# -*-Perl-*- Test Harness script for Bioperl
# $Id: Seq.t 16090 2009-09-15 21:57:56Z cjfields $

use strict;

BEGIN { 
    use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 62);
	
	use_ok('Bio::Seq');
	use_ok('Bio::Seq::RichSeq');
	use_ok('Bio::SeqFeature::Generic');
	use_ok('Bio::Species');
	use_ok('Bio::Annotation::SimpleValue');
}

ok my $seq = Bio::Seq->new(-seq=>'ACTGTGGCGTCAACT',
                        -desc=>'Sample Bio::Seq object',
			-alphabet => 'dna',
                        -is_circular => 1
                       );

ok $seq->is_circular;
ok not $seq->is_circular(0);
ok not $seq->is_circular;

my $trunc = $seq->trunc(1,4);
is $trunc->length, 4, 'truncated sequence length';

is $trunc->seq, 'ACTG', 'truncated sequence string';

# test ability to get str function
is $seq->seq(),  'ACTGTGGCGTCAACT' ;

ok $seq = Bio::Seq->new(-seq=>'actgtggcgtcaact',
		     -desc=>'Sample Bio::Seq object',
		     -display_id => 'something',
		     -accession_number => 'accnum',
		     -alphabet => 'dna' );

is uc $seq->alphabet, 'DNA' , 'alphabet';

# basic methods

is $seq->id(), 'something',  "id";
is $seq->accession_number, 'accnum', "accession number";
is $seq->subseq(5, 9),  'tggcg', "subseq";

# check IdentifiableI and DescribableI interfaces
isa_ok $seq, 'Bio::IdentifiableI';
isa_ok $seq, 'Bio::DescribableI';
# make sure all methods are implemented
is $seq->authority("bioperl.org"), "bioperl.org";
is $seq->namespace("t"), "t";
is $seq->version(0), 0;
is $seq->lsid_string(), "bioperl.org:t:accnum";
is $seq->namespace_string(), "t:accnum.0";
is $seq->description(), 'Sample Bio::Seq object';
is $seq->display_name(), "something";

# check that feature accession works regardless of lazy things going on
is scalar($seq->top_SeqFeatures()), 0;
is scalar($seq->flush_SeqFeatures()), 0;

my $newfeat = Bio::SeqFeature::Generic->new( -start => 10,
					     -end => 12,
					     -primary => 'silly',
					     -source => 'stuff');


$seq->add_SeqFeature($newfeat);
is $seq->feature_count, 1;

my $species = Bio::Species->new
    (-verbose => 1, 
     -classification => [ qw( sapiens Homo Hominidae
			      Catarrhini Primates Eutheria
			      Mammalia Vertebrata Chordata
			      Metazoa Eukaryota )]);
$seq->species($species);
is $seq->species->binomial, 'Homo sapiens';
$seq->annotation->add_Annotation('description',
		 Bio::Annotation::SimpleValue->new(-value => 'desc-here'));
my ($descr) = $seq->annotation->get_Annotations('description');
is $descr->value(), 'desc-here';
is $descr->tagname(), 'description';

#
#  translation tests
#

my $trans = $seq->translate();
is  $trans->seq(), 'TVAST' , 'translated sequence';

# unambiguous two character codons like 'ACN' and 'GTN' should give out an amino acid
$seq->seq('ACTGTGGCGTCAAC');
$trans = $seq->translate();
is $trans->seq(), 'TVAST', 'translated sequence with unambiguous codons';

$seq->seq('ACTGTGGCGTCAACA');
$trans = $seq->translate();
is $trans->seq(), 'TVAST', 'translated sequence with unambiguous codons';

$seq->seq('ACTGTGGCGTCAACAG');
$trans = $seq->translate();
is $trans->seq(), 'TVAST', 'translated sequence with unambiguous codons';

$seq->seq('ACTGTGGCGTCAACAGT');
$trans = $seq->translate();
is $trans->seq(), 'TVASTV', 'translated sequence with unambiguous codons';

$seq->seq('ACTGTGGCGTCAACAGTA');
$trans = $seq->translate();
is $trans->seq(), 'TVASTV', 'translated sequence with unambiguous codons';

$seq->seq('AC');
is $seq->translate->seq , 'T', 'translated sequence with unambigious 2 char codon';

#difference between the default and full CDS translation

$seq->seq('atgtggtaa');
$trans = $seq->translate();
is $trans->seq(), 'MW*' , 'translated sequence with stop';

$seq->seq('atgtggtaa');
$trans = $seq->translate(undef,undef,undef,undef,1);
is $trans->seq(), 'MW', 'translated sequence';

#frame 
my $string;
my @frames = (0, 1, 2);
foreach my $frame (@frames) {
    $string .= $seq->translate(undef, undef, $frame)->seq;
    $string .= $seq->revcom->translate(undef, undef, $frame)->seq;
}
is $string, 'MW*LPHCGYHVVTT';

#Translating with all codon tables using method defaults
$string = '';
my @codontables = qw( 1 2 3 4 5 6 9 10 11 12 13 14 15 16 21 22 23);
foreach my $ct (@codontables) {
    $string .= $seq->translate(undef, undef, undef, $ct)->seq;
}
is $string, 'MW*MW*MW*MW*MW*MWQMW*MW*MW*MW*MW*MWYMW*MW*MW*MW*MW*';

# CDS translation set to throw an exception for internal stop codons
$seq->seq('atgtggtaataa');
eval {
    $seq->translate(undef, undef, undef, undef, 'CDS' , 'throw');
};
like ($@, qr/EX/);

$seq->seq('atgtggtaataa');
is( $seq->translate('J', '-',)->seq, 'MWJJ');

# tests for RichSeq
ok my $richseq = Bio::Seq::RichSeq->new( -seq => 'atgtggtaataa',
				      -accession_number => 'AC123',
				      -alphabet => 'rna',
				      -molecule => 'mRNA',		
				      -id => 'id1',
				      -dates => [ '2001/1/1' ],
				      -pid => '887821',
				      -keywords => 'JUNK1;JUNK2',
				      -division => 'Fungi',
				      -secondary_accessions => 'AC1152' );

is ($richseq->seq, 'atgtggtaataa');
is ($richseq->display_id, 'id1');
is (($richseq->get_dates)[0], '2001/1/1');
is (($richseq->get_secondary_accessions)[0], 'AC1152');
is ($richseq->accession_number, 'AC123');
is ($richseq->alphabet, 'rna');
is ($richseq->molecule, 'mRNA');
is ($richseq->pid, 887821);
is ($richseq->division, 'Fungi');
is ($richseq->keywords, 'JUNK1; JUNK2');
$richseq->seq_version('2');
is ($richseq->seq_version, 2);

# tests for subtle misbehaviors
$seq = Bio::Seq->new(-primary_id => 'blah', -accession_number => 'foo');
is ($seq->accession_number, $seq->primary_seq->accession_number);
is ($seq->primary_id, $seq->primary_seq->primary_id);
$seq->accession_number('blurb');
$seq->primary_id('bar');
is ($seq->accession_number, $seq->primary_seq->accession_number);
is ($seq->primary_id, $seq->primary_seq->primary_id);


# Bug #2864:

$seq = Bio::Seq->new(-display_id => 0, -seq => 'GATC');

is $seq->display_id, 0, "Bug #2864";