1
# -*-Perl-*- Test Harness script for Bioperl
2
# $Id: SeqUtils.t 15112 2008-12-08 18:12:38Z sendu $
10
test_begin(-tests => 41);
12
use_ok('Bio::PrimarySeq');
13
use_ok('Bio::SeqUtils');
14
use_ok('Bio::LiveSeq::Mutation');
15
use_ok('Bio::SeqFeature::Generic');
16
use_ok('Bio::Annotation::SimpleValue');
19
my ($seq, $util, $ascii, $ascii_aa, $ascii3);
21
# Entire alphabet now IUPAC-endorsed and used in GenBank (Oct 2006)
22
$ascii = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
23
$ascii_aa = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
26
'AlaAsxCysAspGluPheGlyHisIleXleLysLeuMetAsnPylProGlnArgSerThrSecValTrpXaaTyrGlx';
28
$seq = Bio::PrimarySeq->new('-seq'=> $ascii,
29
'-alphabet'=>'protein',
32
# one letter amino acid code to three letter code
33
ok $util = Bio::SeqUtils->new();
34
is $util->seq3($seq), $ascii3;
37
is (Bio::SeqUtils->seq3($seq), $ascii3);
38
is (Bio::SeqUtils->seq3($seq, undef, ','),
39
'Ala,Asx,Cys,Asp,Glu,Phe,Gly,His,Ile,Xle,Lys,'.
40
'Leu,Met,Asn,Pyl,Pro,Gln,Arg,Ser,Thr,Sec,Val,Trp,Xaa,Tyr,Glx');
42
$seq->seq('asd-KJJK-');
43
is (Bio::SeqUtils->seq3($seq, '-', ':'),
44
'Ala:Ser:Asp:Ter:Lys:Xle:Xle:Lys:Ter');
46
# three letter amino acid code to one letter code
47
ok (Bio::SeqUtils->seq3in($seq, 'AlaPYHCysAspGlu'));
48
is $seq->seq, 'AXCDE';
49
is (Bio::SeqUtils->seq3in($seq, $ascii3)->seq, $ascii_aa);
52
# Tests for multiframe translations
55
$seq = Bio::PrimarySeq->new('-seq'=> 'agctgctgatcggattgtgatggctggatggcttgggatgctgg',
59
my @a = $util->translate_3frames($seq);
62
# print 'ID: ', $a->id, ' ', $a->seq, "\n";
65
@a = $util->translate_6frames($seq);
68
# print 'ID: ', $a->id, ' ', $a->seq, "\n";
72
# test for valid AA return
75
my @valid_aa = sort Bio::SeqUtils->valid_aa;
77
is($valid_aa[1], 'A');
79
@valid_aa = sort Bio::SeqUtils->valid_aa(1);
81
is ($valid_aa[1], 'Arg');
83
my %valid_aa = Bio::SeqUtils->valid_aa(2);
84
is keys %valid_aa, 54;
85
is($valid_aa{'C'}, 'Cys');
86
is( $valid_aa{'Cys'}, 'C');
94
$seq = Bio::PrimarySeq->new('-seq'=> 'aggt',
99
Bio::SeqUtils->mutate($seq,
100
Bio::LiveSeq::Mutation->new(-seq => 'c',
104
is $seq->seq, 'agct';
106
# insertion and deletion
108
Bio::LiveSeq::Mutation->new(-seq => 'tt',
112
Bio::LiveSeq::Mutation->new(-pos => 2,
117
Bio::SeqUtils->mutate($seq, @mutations);
118
is $seq->seq, 'agct';
120
# insertion to the end of the sequence
121
Bio::SeqUtils->mutate($seq,
122
Bio::LiveSeq::Mutation->new(-seq => 'aa',
127
is $seq->seq, 'agctaa';
132
# testing Bio::SeqUtils->cat
137
my $primseq1 = Bio::PrimarySeq->new(-id => 1, -seq => 'acgt', -description => 'master');
138
my $primseq2 = Bio::PrimarySeq->new(-id => 2, -seq => 'tgca');
140
Bio::SeqUtils->cat($primseq1, $primseq2);
141
is $primseq1->seq, 'acgttgca';
142
is $primseq1->description, 'master';
144
#should work for Bio::LocatableSeq
145
#should work for Bio::Seq::MetaI Seqs?
150
my $seq1 = Bio::Seq->new(-id => 1, -seq => 'aaaa', -description => 'first');
151
my $seq2 = Bio::Seq->new(-id => 2, -seq => 'tttt', -description => 'second');
152
my $seq3 = Bio::Seq->new(-id => 3, -seq => 'cccc', -description => 'third');
156
my $ac2 = Bio::Annotation::Collection->new();
157
my $simple1 = Bio::Annotation::SimpleValue->new(
158
-tagname => 'colour',
161
my $simple2 = Bio::Annotation::SimpleValue->new(
162
-tagname => 'colour',
165
$ac2->add_Annotation('simple',$simple1);
166
$ac2->add_Annotation('simple',$simple2);
167
$seq2->annotation($ac2);
169
my $ac3 = Bio::Annotation::Collection->new();
170
my $simple3 = Bio::Annotation::SimpleValue->new(
171
-tagname => 'colour',
174
$ac3->add_Annotation('simple',$simple3);
175
$seq3->annotation($ac3);
178
ok (Bio::SeqUtils->cat($seq1, $seq2, $seq3));
179
is $seq1->seq, 'aaaattttcccc';
180
is scalar $seq1->annotation->get_Annotations, 3;
184
my $ft2 = Bio::SeqFeature::Generic->new( -start => 1,
187
-primary => 'source',
191
my $ft3 = Bio::SeqFeature::Generic->new( -start => 3,
194
-primary => 'hotspot',
197
$seq2->add_SeqFeature($ft2);
198
$seq2->add_SeqFeature($ft3);
201
ok (Bio::SeqUtils->cat($seq1, $seq2));
202
is $seq1->seq, 'aaaattttcccctttt';
203
is scalar $seq1->annotation->get_Annotations, 5;
206
my $protseq = Bio::PrimarySeq->new(-id => 2, -seq => 'MVTF'); # protein seq
209
Bio::SeqUtils->cat($seq1, $protseq);
218
$seq = Bio::PrimarySeq->new('-seq'=> 'aaaaaaaaaa',
223
$util = Bio::SeqUtils->new(-verbose => 0);
224
ok my $newseq = $util->evolve($seq, 60, 4);
228
$seq2 = Bio::Seq->new(-id => 2, -seq => 'ggttaaaa', -description => 'second');
229
$ac3 = Bio::Annotation::Collection->new();
230
$simple3 = Bio::Annotation::SimpleValue->new(
231
-tagname => 'colour',
234
$ac3->add_Annotation('simple',$simple3);
235
$seq2->annotation($ac3);
236
$ft2 = Bio::SeqFeature::Generic->new( -start => 1,
239
-primary => 'source',
243
$ft3 = Bio::SeqFeature::Generic->new( -start => 5,
246
-primary => 'hotspot',
248
$seq2->add_SeqFeature($ft2);
249
$seq2->add_SeqFeature($ft3);
251
my $trunc=Bio::SeqUtils->trunc_with_features($seq2, 2, 7);
252
is $trunc->seq, 'gttaaa';
253
my @feat=$trunc->get_SeqFeatures;
254
is $feat[0]->location->to_FTstring, '<1..3';
255
is $feat[1]->location->to_FTstring, 'complement(4..>6)';
257
my $revcom=Bio::SeqUtils->revcom_with_features($seq2);
258
is $revcom->seq, 'ttttaacc';
259
my @revfeat=$revcom->get_SeqFeatures;
260
is $revfeat[0]->location->to_FTstring, 'complement(5..8)';
261
is $revfeat[1]->location->to_FTstring, '1..4';