2 ## Bioperl Test Harness Script for Modules
8 # to handle systems with no installed Test module
9 # we include the t dir (where a copy of Test.pm is located)
11 eval { require Test; };
21 use Bio::LiveSeq::Mutation;
24 my ($seq, $util, $ascii, $ascii_aa, $ascii3);
26 # Entire alphabet now IUPAC-endorsed and used in GenBank (Oct 2006)
27 $ascii = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
28 $ascii_aa = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
31 'AlaAsxCysAspGluPheGlyHisIleXleLysLeuMetAsnPylProGlnArgSerThrSecValTrpXaaTyrGlx';
33 $seq = Bio::PrimarySeq->new('-seq'=> $ascii,
34 '-alphabet'=>'protein',
37 # one letter amino acid code to three letter code
38 ok $util = new Bio::SeqUtils;
39 ok $util->seq3($seq), $ascii3;
42 ok (Bio::SeqUtils->seq3($seq), $ascii3);
43 ok (Bio::SeqUtils->seq3($seq, undef, ','),
44 'Ala,Asx,Cys,Asp,Glu,Phe,Gly,His,Ile,Xle,Lys,'.
45 'Leu,Met,Asn,Pyl,Pro,Gln,Arg,Ser,Thr,Sec,Val,Trp,Xaa,Tyr,Glx');
47 $seq->seq('asd-KJJK-');
48 ok (Bio::SeqUtils->seq3($seq, '-', ':'),
49 'Ala:Ser:Asp:Ter:Lys:Xle:Xle:Lys:Ter');
51 # three letter amino acid code to one letter code
52 ok (Bio::SeqUtils->seq3in($seq, 'AlaPYHCysAspGlu')),
53 ok $seq->seq, 'AXCDE';
54 ok (Bio::SeqUtils->seq3in($seq, $ascii3)->seq, $ascii_aa);
58 # Tests for multiframe translations
61 $seq = Bio::PrimarySeq->new('-seq'=> 'agctgctgatcggattgtgatggctggatggcttgggatgctgg',
65 my @a = $util->translate_3frames($seq);
68 # print 'ID: ', $a->id, ' ', $a->seq, "\n";
71 @a = $util->translate_6frames($seq);
74 # print 'ID: ', $a->id, ' ', $a->seq, "\n";
78 # test for valid AA return
81 my @valid_aa = sort Bio::SeqUtils->valid_aa;
83 ok ($valid_aa[1], 'A');
85 @valid_aa = sort Bio::SeqUtils->valid_aa(1);
87 ok ($valid_aa[1], 'Arg');
89 my %valid_aa = Bio::SeqUtils->valid_aa(2);
90 ok keys %valid_aa, 54;
91 ok($valid_aa{'C'}, 'Cys');
92 ok( $valid_aa{'Cys'}, 'C');
100 $seq = Bio::PrimarySeq->new('-seq'=> 'aggt',
105 Bio::SeqUtils->mutate($seq,
106 Bio::LiveSeq::Mutation->new(-seq => 'c',
110 ok $seq->seq, 'agct';
112 # insertion and deletion
114 Bio::LiveSeq::Mutation->new(-seq => 'tt',
118 Bio::LiveSeq::Mutation->new(-pos => 2,
123 Bio::SeqUtils->mutate($seq, @mutations);
124 ok $seq->seq, 'agct';
126 # insertion to the end of the sequence
127 Bio::SeqUtils->mutate($seq,
128 Bio::LiveSeq::Mutation->new(-seq => 'aa',
133 ok $seq->seq, 'agctaa';
138 # testing Bio::SeqUtils->cat
141 use Bio::Annotation::SimpleValue;
142 use Bio::Seq::RichSeq;;
147 my $primseq1 = new Bio::PrimarySeq(-id => 1, -seq => 'acgt', -description => 'master');
148 my $primseq2 = new Bio::PrimarySeq(-id => 2, -seq => 'tgca');
150 Bio::SeqUtils->cat($primseq1, $primseq2);
151 ok $primseq1->seq, 'acgttgca';
152 ok $primseq1->description, 'master';
154 #should work for Bio::LocatableSeq
155 #should work for Bio::Seq::MetaI Seqs?
160 my $seq1 = new Bio::Seq(-id => 1, -seq => 'aaaa', -description => 'first');
161 my $seq2 = new Bio::Seq(-id => 2, -seq => 'tttt', -description => 'second');
162 my $seq3 = new Bio::Seq(-id => 3, -seq => 'cccc', -description => 'third');
166 my $ac2 = new Bio::Annotation::Collection;
167 my $simple1 = Bio::Annotation::SimpleValue->new(
168 -tagname => 'colour',
171 my $simple2 = Bio::Annotation::SimpleValue->new(
172 -tagname => 'colour',
175 $ac2->add_Annotation('simple',$simple1);
176 $ac2->add_Annotation('simple',$simple2);
177 $seq2->annotation($ac2);
179 my $ac3 = new Bio::Annotation::Collection;
180 my $simple3 = Bio::Annotation::SimpleValue->new(
181 -tagname => 'colour',
184 $ac3->add_Annotation('simple',$simple3);
185 $seq3->annotation($ac3);
188 ok (Bio::SeqUtils->cat($seq1, $seq2, $seq3));
189 ok $seq1->seq, 'aaaattttcccc';
190 ok scalar $seq1->get_Annotations, 3;
194 use Bio::SeqFeature::Generic;
196 my $ft2 = new Bio::SeqFeature::Generic ( -start => 1,
199 -primary => 'source',
203 my $ft3 = new Bio::SeqFeature::Generic ( -start => 3,
206 -primary => 'hotspot',
209 $seq2->add_SeqFeature($ft2);
210 $seq2->add_SeqFeature($ft3);
213 ok (Bio::SeqUtils->cat($seq1, $seq2));
214 ok $seq1->seq, 'aaaattttcccctttt';
215 ok scalar $seq1->get_Annotations, 5;
218 my $protseq = new Bio::PrimarySeq(-id => 2, -seq => 'MVTF'); # protein seq
221 Bio::SeqUtils->cat($seq1, $protseq);
223 ok 1 if $@; # did throw
225 #use Data::Dumper; print Dumper $seq1;
236 $seq = Bio::PrimarySeq->new('-seq'=> 'aaaaaaaaaa',
241 $util = new Bio::SeqUtils(-verbose => 0);
242 ok my $newseq = $util->evolve($seq, 60, 4);
246 $seq2 = new Bio::Seq(-id => 2, -seq => 'ggttaaaa', -description => 'second');
247 $ac3 = new Bio::Annotation::Collection;
248 $simple3 = Bio::Annotation::SimpleValue->new(
249 -tagname => 'colour',
252 $ac3->add_Annotation('simple',$simple3);
253 $seq2->annotation($ac3);
254 $ft2 = new Bio::SeqFeature::Generic ( -start => 1,
257 -primary => 'source',
261 $ft3 = new Bio::SeqFeature::Generic ( -start => 5,
264 -primary => 'hotspot',
266 $seq2->add_SeqFeature($ft2);
267 $seq2->add_SeqFeature($ft3);
269 my $trunc=Bio::SeqUtils->trunc_with_features($seq2, 2, 7);
270 ok $trunc->seq, 'gttaaa';
271 my @feat=$trunc->get_SeqFeatures;
272 ok $feat[0]->location->to_FTstring, '<1..3';
273 ok $feat[1]->location->to_FTstring, 'complement(4..>6)';
275 my $revcom=Bio::SeqUtils->revcom_with_features($seq2);
276 ok $revcom->seq, 'ttttaacc';
277 my @revfeat=$revcom->get_SeqFeatures;
278 ok $revfeat[0]->location->to_FTstring, 'complement(5..8)';
279 ok $revfeat[1]->location->to_FTstring, '1..4';