1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 76);
13 use_ok('Bio::Seq::RichSeq');
14 use_ok('Bio::SeqFeature::Generic');
15 use_ok('Bio::Species');
16 use_ok('Bio::Annotation::SimpleValue');
19 ok my $seq = Bio::Seq->new(-seq=>'ACTGTGGCGTCAACT',
20 -desc=>'Sample Bio::Seq object',
24 isa_ok($seq,"Bio::AnnotatableI");
27 ok not $seq->is_circular(0);
28 ok not $seq->is_circular;
30 my $trunc = $seq->trunc(1,4);
31 is $trunc->length, 4, 'truncated sequence length';
33 is $trunc->seq, 'ACTG', 'truncated sequence string';
35 # test ability to get str function
36 is $seq->seq(), 'ACTGTGGCGTCAACT' ;
38 ok $seq = Bio::Seq->new(-seq=>'actgtggcgtcaact',
39 -desc=>'Sample Bio::Seq object',
40 -display_id => 'something',
41 -accession_number => 'accnum',
44 is uc $seq->alphabet, 'DNA' , 'alphabet';
48 is $seq->id(), 'something', "id";
49 is $seq->accession_number, 'accnum', "accession number";
50 is $seq->subseq(5, 9), 'tggcg', "subseq";
52 # check IdentifiableI and DescribableI interfaces
53 isa_ok $seq, 'Bio::IdentifiableI';
54 isa_ok $seq, 'Bio::DescribableI';
55 # make sure all methods are implemented
56 is $seq->authority("bioperl.org"), "bioperl.org";
57 is $seq->namespace("t"), "t";
58 is $seq->version(0), 0;
59 is $seq->lsid_string(), "bioperl.org:t:accnum";
60 is $seq->namespace_string(), "t:accnum.0";
61 is $seq->description(), 'Sample Bio::Seq object';
62 is $seq->display_name(), "something";
64 # check that feature accession works regardless of lazy things going on
65 is scalar($seq->top_SeqFeatures()), 0;
66 is scalar($seq->flush_SeqFeatures()), 0;
68 my $newfeat = Bio::SeqFeature::Generic->new( -start => 10,
74 $seq->add_SeqFeature($newfeat);
75 is $seq->feature_count, 1;
77 my $species = Bio::Species->new
79 -classification => [ qw( sapiens Homo Hominidae
80 Catarrhini Primates Eutheria
81 Mammalia Vertebrata Chordata
82 Metazoa Eukaryota )]);
83 $seq->species($species);
84 is $seq->species->binomial, 'Homo sapiens';
85 $seq->annotation->add_Annotation('description',
86 Bio::Annotation::SimpleValue->new(-value => 'desc-here'));
87 my ($descr) = $seq->annotation->get_Annotations('description');
88 is $descr->value(), 'desc-here';
89 is $descr->tagname(), 'description';
95 my $trans = $seq->translate();
96 is $trans->seq(), 'TVAST' , 'translated sequence';
98 # unambiguous two character codons like 'ACN' and 'GTN' should give out an amino
99 # acid ...with the addendum that there should be no assumption by the method
100 # to complete the codon unless specified, using the -complete_codons flag.
102 $seq->seq('ACTGTGGCGTCAACN');
103 $trans = $seq->translate();
104 is $trans->seq(), 'TVAST', 'translated sequence with explicit unambiguous codons';
106 $seq->seq('ACTGTGGCGTCAAC');
107 $trans = $seq->translate();
108 is $trans->seq(), 'TVAS', 'translated sequence with unknown unambiguous codons';
110 $seq->seq('ACTGTGGCGTCAAC');
111 $trans = $seq->translate(-complete_codons => 1);
112 is $trans->seq(), 'TVAST', 'translated sequence with unknown unambiguous codons, completed';
114 $seq->seq('ACTGTGGCGTCAACA');
115 $trans = $seq->translate();
116 is $trans->seq(), 'TVAST', 'translated sequence with unambiguous codons';
118 $seq->seq('ACTGTGGCGTCAACAG');
119 $trans = $seq->translate();
120 is $trans->seq(), 'TVAST', 'translated sequence with unambiguous codons';
122 $seq->seq('ACTGTGGCGTCAACAGT');
123 $trans = $seq->translate(-complete_codons => 1);
124 is $trans->seq(), 'TVASTV', 'translated sequence with unknown unambiguous codons, completed';
126 $seq->seq('ACTGTGGCGTCAACAGTA');
127 $trans = $seq->translate();
128 is $trans->seq(), 'TVASTV', 'translated sequence with unambiguous codons';
131 is $seq->translate(-complete_codons => 1)->seq , 'T', 'translated sequence with unknown unambiguous codons, completed';
133 #difference between the default and full CDS translation
135 $seq->seq('atgtggtaa');
136 $trans = $seq->translate();
137 is $trans->seq(), 'MW*' , 'translated sequence with stop';
139 $seq->seq('atgtggtaa');
140 $trans = $seq->translate(undef,undef,undef,undef,1);
141 is $trans->seq(), 'MW', 'translated sequence';
145 my @frames = (0, 1, 2);
146 foreach my $frame (@frames) {
147 $string .= $seq->translate(undef, undef, $frame)->seq;
148 $string .= $seq->revcom->translate(undef, undef, $frame)->seq;
150 is $string, 'MW*LPHCGYHVVTT';
152 #Translating with all codon tables using method defaults
154 my @codontables = qw(0 1 2 3 4 5 6 9 10 11 12 13 14 16 21
155 22 23 24 25 26 27 28 29 30 31);
156 foreach my $ct (@codontables) {
157 $string .= $seq->translate(undef, undef, undef, $ct)->seq;
159 is $string, 'MW*MW*MW*MW*MW*MW*MWQMW*MW*MW*MW*MW*MWYMW*MW*MW*MW*MW*MW*MW*MWQMWQMWYMWEMWE';
161 # CDS translation set to throw an exception for internal stop codons
162 $seq->seq('atgtggtaataa');
164 $seq->translate(undef, undef, undef, undef, 'CDS' , 'throw');
168 $seq->seq('atgtggtaataa');
169 is( $seq->translate('J', '-',)->seq, 'MWJJ');
172 ok my $richseq = Bio::Seq::RichSeq->new( -seq => 'atgtggtaataa',
173 -accession_number => 'AC123',
177 -dates => [ '2001/1/1' ],
179 -keywords => 'JUNK1;JUNK2',
180 -division => 'Fungi',
181 -secondary_accessions => 'AC1152' );
183 is ($richseq->seq, 'atgtggtaataa');
184 is ($richseq->display_id, 'id1');
185 is (($richseq->get_dates)[0], '2001/1/1');
186 is (($richseq->get_secondary_accessions)[0], 'AC1152');
187 is ($richseq->accession_number, 'AC123');
188 is ($richseq->alphabet, 'rna');
189 is ($richseq->molecule, 'mRNA');
190 is ($richseq->pid, 887821);
191 is ($richseq->division, 'Fungi');
192 is ($richseq->keywords, 'JUNK1; JUNK2');
193 $richseq->seq_version('2');
194 is ($richseq->seq_version, 2);
196 # Test adding a feature to a RichSeq type, then
197 # trunc() and see if the feature vanishes (we shouldn't
198 # be using clone() for RichSeq types)
199 $richseq->add_SeqFeature($newfeat);
200 is $richseq->feature_count, 1;
201 my $newrichseq = $richseq->trunc(1,5);
202 is $newrichseq->feature_count, 0, "Don't use clone for trunc of Bio::Seq::RichSeq";
203 is $newrichseq->length, 5;
205 # tests for subtle misbehaviors
206 $seq = Bio::Seq->new(-primary_id => 'blah', -accession_number => 'foo');
207 is ($seq->accession_number, $seq->primary_seq->accession_number);
208 is ($seq->primary_id, $seq->primary_seq->primary_id);
209 $seq->accession_number('blurb');
210 $seq->primary_id('bar');
211 is ($seq->accession_number, $seq->primary_seq->accession_number);
212 is ($seq->primary_id, $seq->primary_seq->primary_id);
217 $seq = Bio::Seq->new(-display_id => 0, -seq => 'GATC');
219 is $seq->display_id, 0, "Bug #2864";
221 # transcribe/rev_transcribe
223 $seq = Bio::Seq->new( -id => 'seq1', -alphabet=>'dna',
224 -seq=> 'attTcgcatgT' );
225 ok my $xseq = $seq->transcribe;
226 is $xseq->alphabet, 'rna';
227 ok !($xseq->seq =~ /[tT]/);
228 is $xseq->seq, 'auuUcgcaugU';
229 ok !$xseq->transcribe;
230 ok $seq = $xseq->rev_transcribe;
231 is $seq->seq, 'attTcgcatgT';
232 is $seq->alphabet, 'dna';