3 ## Bioperl Test Harness Script for Modules
9 test_begin(-tests => 45);
11 use_ok('Bio::Tools::Run::Alignment::Clustalw');
12 use_ok('Bio::SimpleAlign');
13 use_ok('Bio::AlignIO');
19 # setup input files etc
20 my $inputfilename = test_input_file("cysprot.fa");
21 ok( -e $inputfilename, 'Found input file' );
22 my $profile1 = test_input_file('cysprot1a.msf');
23 ok( -e $profile1, 'Found profile1 file' );
24 my $profile2 = test_input_file('cysprot1b.msf');
25 ok( -e $profile2, 'Found profile2 file' );
26 my $outfile = test_output_file();
28 # setup global objects that are to be used in more than one test
29 # Also test they were initialised correctly
30 my @params = ('ktuple' => 2, 'quiet' => 1);
32 my $factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
33 isa_ok( $factory, 'Bio::Tools::Run::Alignment::Clustalw');
34 $factory->outfile($outfile);
36 # test default factory values
37 is( $factory->program_dir, $ENV{'CLUSTALDIR'}, 'program_dir returned correct default' );
38 is( $factory->error_string, '', 'error_string returned correct default' );
39 is( $factory->outfile_name, 'mlc', 'outfile_name returned correct default' );
40 is( $factory->bootstrap, undef, 'bootstrap returned correct default' );
42 # Now onto the nitty gritty tests of the modules methods
43 is( $factory->program_name(), 'clustalw', 'Correct exe default name' );
46 test_skip(-requires_executable => $factory,
49 # test all factory methods dependent on finding the executable
50 # TODO: isnt( $factory->program_dir, undef,'Found program in an ENV variable' );
51 my $ver = $factory->version || 0;
54 $ver =~ s{^(\d+\.\d+)\.\d+}{$1};
56 # clustalw2 isn't supported yet.
58 diag("ClustalW version $ver not supported");
59 skip("ClustalW version $ver not supported", 19);
62 ok( $ver, "Supported program version $ver" );
64 # test execution using filename
65 my $aln = $factory->align($inputfilename);
67 # now test the factory error methods etc
68 is( $factory->error_string, '', 'No error occured' );
69 isnt( $factory->outfile_name, undef, 'outfile_name returned something' );
72 isa_ok( $aln, 'Bio::SimpleAlign');
73 is( $aln->num_sequences, 7, 'Correct number of seqs returned' );
74 is $aln->score, 16047, 'Score';
76 # test execution using an array of Seq objects
77 my $str = Bio::SeqIO->new('-file' => $inputfilename, '-format' => 'Fasta');
79 while ( my $seq = $str->next_seq() ) {
80 push (@seq_array, $seq) ;
82 $aln = $factory->align(\@seq_array);
84 isa_ok( $aln, 'Bio::SimpleAlign');
85 is( $aln->num_sequences, 7,'Correct number of seqs returned' );
87 # Use this alignment to fully test the methods
90 for my $seq ( $aln->each_seq ) {
91 last if( $seq->display_id =~ /CATH_HUMAN/ );
94 is( $aln->get_seq_by_pos($i)->get_nse, 'CATH_HUMAN/1-335', 'Got correct sequence by position' );
97 # test doing a bootstrap tree
99 my $tree = $factory->tree($aln);
100 isa_ok( $tree, 'Bio::Tree::Tree' );
102 # now test doing profile alignments
103 $aln = $factory->profile_align($profile1,$profile2);
104 isa_ok( $aln, 'Bio::SimpleAlign' );
105 is( $aln->num_sequences, 7,'Correct number of seqs returned' );
107 # test the run method
108 ($aln, $tree) = $factory->run(\@seq_array);
109 isa_ok($aln, 'Bio::SimpleAlign');
110 isa_ok($tree, 'Bio::Tree::Tree');
112 ($aln, $tree) = $factory->run($inputfilename);
113 isa_ok($aln, 'Bio::SimpleAlign');
114 isa_ok($tree, 'Bio::Tree::Tree');
116 # test the footprint method
117 my @seqs = (Bio::Seq->new(-seq => 'AACCTGGCCAATTGGCCAATTGGGCGTACGTACGT', -id => 'rabbit'),
118 Bio::Seq->new(-seq => 'ACCCTGGCCAATTGGCCAATTGTAAGTACGTACGT', -id => 'marmot'),
119 Bio::Seq->new(-seq => 'AAGCTGGCCAATTGGCCAATTAGACTTACGTACGT', -id => 'chimp'),
120 Bio::Seq->new(-seq => 'AACATGGCCAATTGGCCAATCGGACGTACGTCCGT', -id => 'human'),
121 Bio::Seq->new(-seq => 'AACCGGGCCAATTGGCCAAGTGGACGTACGTATGT', -id => 'cebus'),
122 Bio::Seq->new(-seq => 'AACCTAGCCAATTGGCCACTTGGACGTACGTACAT', -id => 'gorilla'),
123 Bio::Seq->new(-seq => 'AACCTGCCCAATTGGCCGATTGGACGTACGTACGC', -id => 'orangutan'),
124 Bio::Seq->new(-seq => 'AACCTGGGCAATTGGCAAATTGGACGTACGTACGT', -id => 'baboon'),
125 Bio::Seq->new(-seq => 'AACCTGGCTAATTGGTCAATTGGACGTACGTACGT', -id => 'rhesus'),
126 Bio::Seq->new(-seq => 'AACCTGGCCGATTGGCCAATTGGACGTACGTACGT', -id => 'squirrelmonkey'));
128 my @results = $factory->footprint(\@seqs);
129 @results = map { $_->consensus_string } @results;
130 is_deeply(\@results, [qw(ATTGG TACGT)], 'footprinting worked');
133 # TODO: Is this needed, or should min version be bumped to > 1.82. Discuss with module author
134 # keeping this to be compatible with older t/Clustalw.t
135 skip("clustalw 1.81 & 1.82 contain a profile align bug", 2) unless $ver > 1.82;
137 my $str1 = Bio::AlignIO->new(-file=> $profile1);
138 my $aln1 = $str1->next_aln();
139 my $str2 = Bio::AlignIO->new(-file=> $profile2);
140 my $aln2 = $str2->next_aln();
142 $aln = $factory->profile_align($aln1,$aln2);
143 is($aln->get_seq_by_pos(2)->get_nse, 'CATH_HUMAN/1-335', 'Got correct sequence by position');
145 $str2 = Bio::SeqIO->new(-file=> test_input_file("cysprot1b.fa"));
146 my $seq = $str2->next_seq();
147 $aln = $factory->profile_align($aln1,$seq);
148 is($aln->get_seq_by_pos(2)->get_nse, 'CATH_HUMAN/1-335', 'Got correct sequence by position');
152 # TODO: Test factory methods that change parameters
154 # local $TODO = "program_name setting not finished";
155 # $factory->program_name('something_silly');
156 # is( $factory->program_name, 'something_silly', 'Set and got program_name correctly' );
159 is( $factory->ktuple, 4, 'Set and got ktuple correctly' );
160 $factory->topdiags(10);
161 is( $factory->topdiags, 10, 'Set and got topdiags correctly' );
162 $factory->window(10);
163 is( $factory->window, 10, 'Set and got window correctly' );
164 $factory->pairgap(10);
165 is( $factory->pairgap, 10, 'Set and got pairgap correctly' );
166 $factory->fixedgap(20);
167 is( $factory->fixedgap, 20, 'Set and got fixedgap correctly' );
168 $factory->floatgap(16);
169 is( $factory->floatgap, 16, 'Set and got floatgap correctly' );
170 $factory->matrix('PAM250');
171 is( $factory->matrix, 'PAM250', 'Set and got matrix correctly' );
172 $factory->type('protein');
173 is( $factory->type, 'protein', 'Set and got type correctly' );
174 $factory->output('PIR');
175 is( $factory->output, 'PIR', 'Set and got output correctly' );
176 $factory->outfile('odd_name.out');
177 is( $factory->outfile, 'odd_name.out', 'Set and got outfile correctly' );
179 is( $factory->quiet, 0, 'set and got quiet correctly' );
180 $factory->bootstrap(100);
181 is( $factory->bootstrap, 100, 'set and got bootstrap correctly' );