bug 1825
[bioperl-live.git] / t / Mutator.t
blob494f96987c70439fc15ab9ab6a6d8f42baf88122
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN { 
7     use lib 't/lib';
8     use BioperlTest;
9     
10     test_begin(-tests => 24,
11                            -requires_module => 'IO::String');
12         
13         use_ok('Bio::LiveSeq::Mutator');
14         use_ok('Bio::LiveSeq::IO::BioPerl');
15         use_ok('Bio::Variation::IO');
18 $a = Bio::LiveSeq::Mutator->new();
19 ok $a;
21 is $a->numbering, 'coding';
22 ok $a->numbering('coding 1');
23 is $a->numbering, 'coding 1';
25 my $mt = Bio::LiveSeq::Mutation->new();
26 ok $mt->seq('g');
27 $mt->pos(100);
28 ok ($a->add_Mutation($mt));
29 my @each = $a->each_Mutation;
30 is( (scalar @each), 1 );
31 my $mt_b = pop @each;
32 is($mt_b->seq, 'g');
33 my $filename=test_input_file('ar.embl');
34 my $loader=Bio::LiveSeq::IO::BioPerl->load('-file' => "$filename");
35 my $gene_name='AR'; # was G6PD
37 my $gene=$loader->gene2liveseq('-gene_name' => $gene_name);
38 ok($gene);
39 ok $a->gene($gene);
41 my $results = $a->change_gene();
42 ok($results);
44 # bug 1701 - mutations on intron/exon boundaries where codon is split 
46 $loader = Bio::LiveSeq::IO::BioPerl->load( -db   => 'EMBL',
47                                 -file => test_input_file('ssp160.embl.1')
48                         );
49 # move across intron/exon boundaries, check expected mutations
50 my @positions = (3128..3129,3188..3189);
51 my @bases = (qw(C C T T));
52 my @expected = (qw(T683T T684P T684I T684T));
53 my $ct = 0;
55 for my $pos (@positions) {
56     # reset gene
57     my $gene = $loader->gene2liveseq( -gene_name => 'ssp160');
58     my $mutation = Bio::LiveSeq::Mutation->new( -seq => $bases[$ct],
59                                                 -pos => $pos,
60                           );
61     my $mutate = Bio::LiveSeq::Mutator->new( -gene      => $gene,
62                                              -numbering => 'entry',
63                            );
64     
65     $mutate->add_Mutation( $mutation );
67     my $results = $mutate->change_gene();
68     
69     ok(defined($results));
70     is($expected[$ct], $results->trivname);
71     $ct++;
74 my $s;
75 my $io = IO::String->new($s);
76 my $out = Bio::Variation::IO->new('-fh'   => $io,
77                   '-format' => 'flat'
78                   );
79 ok($out->write($results));
80 ok ($s=~/DNA/ && $s=~/RNA/ && $s=~/AA/);