Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / t / TCoffee.t
blob2b295405e289bbefde2ce34dbce05d32d5bf0f22
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
3 ## $Id$
5 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     test_begin(-tests => 27);
9         use_ok('Bio::Tools::Run::Alignment::TCoffee');
10         use_ok('Bio::SimpleAlign');
11         use_ok('Bio::AlignIO');
12         use_ok('Bio::SeqIO');
15 END { unlink qw(cysprot.dnd cysprot1a.dnd) }
17 END {     
18     unlink("t_coffee.log");
21 my @params;
22 my  $factory = Bio::Tools::Run::Alignment::TCoffee->new(@params);
24 isa_ok ($factory, 'Bio::Tools::Run::Alignment::TCoffee');
26 my $ktuple = 3;
27 $factory->ktuple($ktuple);
29 my $new_ktuple = $factory->ktuple();
30 is $new_ktuple, 3, "set factory parameter";
32 my $what_matrix = $factory->matrix();
33 like $what_matrix, qr/BLOSUM/i, "get factory parameter";
35 my $bequiet = 1;
36 $factory->quiet($bequiet);  # Suppress tcoffee messages to terminal
38 my $inputfilename = test_input_file('cysprot.fa');
39 my $aln;
41 SKIP: {
42     test_skip(-requires_executable => $factory,
43               -tests => 20);
44         my $version = $factory->version;
45         cmp_ok ($version, '>=', 1.22, "Code tested only on t_coffee versions > 1.22" );
46         $aln = $factory->align($inputfilename);
47         ok($aln);
48         is( $aln->num_sequences, 7);
49         
50         my $str = Bio::SeqIO->new('-file' => 
51                                   test_input_file("cysprot.fa"), 
52                                   '-format' => 'fasta');
53         my @seq_array =();
54         
55         while ( my $seq = $str->next_seq() ) {
56                 push (@seq_array, $seq) ;
57         }
58         
59         my $seq_array_ref = \@seq_array;
60         
61         $aln = $factory->align($seq_array_ref);
62         is $aln->num_sequences, 7;
63         my $s1_perid = $aln->average_percentage_identity;
64         
65         my $profile1 = test_input_file("cysprot1a.msf");
66         my $profile2 = test_input_file("cysprot1b.msf");
67         
68         # convert any warnings about program to an actual exception
69         $factory->verbose(2);
70         lives_ok {$aln = $factory->profile_align($profile1,$profile2)};
71         skip("T-COFFEE error, skipping tests", 15) if $@; 
72         is $aln->num_sequences, 7;
73         
74         my $str1 = Bio::AlignIO->new(-file=> test_input_file("cysprot1a.msf"));
75         my $aln1 = $str1->next_aln();
76         is $aln1->num_sequences, 3;
77         
78         my $str2 = Bio::AlignIO->new(-file=> test_input_file("cysprot1b.msf"));
79         my $aln2 = $str2->next_aln();
80         is $aln2->num_sequences, 4;
81         
82         $aln = $factory->profile_align($aln1,$aln2);
83         is $aln->num_sequences, 7;
84                 
85         $str1 = Bio::AlignIO->new(-file=> test_input_file("cysprot1a.msf"));
86         $aln1 = $str1->next_aln();
87         $str2 = Bio::SeqIO->new(-file=> test_input_file("cysprot1b.fa"));
88         my $seq = $str2->next_seq();
89         
90         is $aln1->num_sequences, 3;
91         is( int($aln1->average_percentage_identity), 39);
92         $aln = $factory->profile_align($aln1,$seq);
93         is( $aln->num_sequences, 4);
94         if( $version <= 1.22 ) {
95                 cmp_ok( $aln->overall_percentage_identity, '>', 18);    
96                 is( int($aln->average_percentage_identity), 44);
97         } else {
98                 my $overall = int($aln->overall_percentage_identity);
99                 ok( $overall >=21 && $overall <= 23, 'expect 21 >= val >= 23');
100                 my $avg = int($aln->average_percentage_identity);
101                 ok( $avg == 47 || $avg ==48, 'expect 47 or 48');    
102         }
104         # test new 'run' generic running of factory
106         $aln = $factory->run('-type' => 'align',
107                                  '-seq'  => test_input_file("cysprot.fa"));
108         is ($aln->num_sequences, 7, 'simple generic run');
109         is ($aln->percentage_identity,$s1_perid); #calculated before
110                 
111         lives_ok{ $aln = $factory->run('-type' => 'profile',
112                                  '-profile' => $aln1,
113                                  '-seq'  => test_input_file("cysprot1b.fa"))} ;
114         
115         skip("T-COFFEE error, skipping tests",3) if $@;
116         
117         is( $aln->num_sequences, 7);
118         if( $version <= 1.22 ) {
119                 cmp_ok( $aln->overall_percentage_identity, '>', 18);
120                 is( int($aln->average_percentage_identity), 44);
121         } else {
122                 my $overall = int $aln->overall_percentage_identity;
123                 ok($overall == 14 || $overall == 13, 'expect 13 or 14');
124                 my $avg = int($aln->average_percentage_identity);
125                 ok($avg == 41 || $avg == 42, 'expect 41 or 42');    
126         }
129 END {
130         # warnings are already given above, no need to keep report
131         if (-e 'error_report.T-COFFEE') {
132                 unlink('error_report.T-COFFEE');
133         }
134         if (my @dnds = glob('*.dnd')) {
135                 for my $file (@dnds) {
136                         unlink($file)
137                 }
138         }