Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / t / ProtDist.t
blob0373729e2d88a65c648f7ea7af2b33efc87451b6
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
3 ## $Id$
5 use strict;
6 use vars qw($DEBUG);
7 $DEBUG = test_debug() || -1;
9 BEGIN {
10     use Bio::Root::Test;
11     test_begin(-tests => 14);
12         use_ok('Bio::Tools::Run::Phylo::Phylip::ProtDist');
13         use_ok('Bio::Tools::Run::Alignment::Clustalw');
16 my $verbose = $DEBUG;
17 my @params = (
18               'idlength'  =>30,
19               'model'     =>'pam',
20               'gencode'   =>'U',
21               'category'  =>'H',
22               'probchange'=>'0.4',
23               'trans'     =>'5',
24               'freq'      =>'0.25,0.5,0.125,0.125');
26 my $dist_factory = Bio::Tools::Run::Phylo::Phylip::ProtDist->new(@params);
28 SKIP: {
29         test_skip(-requires_executable => $dist_factory,
30                   -tests => 12);
32         isa_ok $dist_factory,'Bio::Tools::Run::Phylo::Phylip::ProtDist';
33         
34         my $model = 'KIMURA';
35         $dist_factory->model($model);
36         
37         my $new_model= $dist_factory->model();
38         is $new_model , 'KIMURA', "set factory parameter";
39         
40         my $gencode = 'M';
41         $dist_factory->gencode($gencode);
42         
43         my $new_gencode= $dist_factory->gencode();
44         is $new_gencode, 'M', "set factory parameter";
45         
46         my $category= "H";
47         $dist_factory->category($category);
48         
49         my $new_category= $dist_factory->category();
50         is $new_category, "H", "set factory parameter";
51         
52         my $probchange= 0.4;
53         $dist_factory->probchange($probchange);
54         
55         my $new_probchange= $dist_factory->probchange();
56         is $new_probchange, 0.4, "set factory parameter";
57         
58         my $trans= 5;
59         $dist_factory->trans($trans);
60         
61         my $new_trans= $dist_factory->trans();
62         is $new_trans, 5, "set factory parameter";
63         
64         my $freq= "0.25,0.5,0.125,0.125";
65         $dist_factory->freq($freq);
66         
67         my $new_freq= $dist_factory->freq();
68         is $new_freq, "0.25,0.5,0.125,0.125", "set factory parameter";
69         
70         my $bequiet = 1;
71         $dist_factory->quiet($bequiet);  # Suppress protpars messages to terminal 
72         
73         my $inputfilename = test_input_file("protpars.phy");
74         my $matrix;
75         
76         $dist_factory->verbose($verbose);
77         ($matrix) = $dist_factory->create_distance_matrix($inputfilename);
78         
79         is(sprintf("%.3f", $matrix->get_entry('ENSP000003','SINFRUP001')),0.277);
80         
81         $inputfilename = test_input_file("cysprot.fa");
82         @params = ('ktuple' => 2, 'matrix' => 'BLOSUM', 
83                    -verbose => $verbose);
84         my  $align_factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
86         SKIP: {
87                 test_skip(-requires_executable => $align_factory,
88                                   -tests => 4);
89         
90                 my $aln = $align_factory->align($inputfilename);
91                 ($matrix) = $dist_factory->create_distance_matrix($aln);
92         
93                 is (int($matrix->get_entry('ALEU_HORVU','ALEU_HORVU')),0,
94                         "creating distance matrix");
95                 ok(sprintf("%.2f",$matrix->get_entry('CATL_HUMAN','CYS1_DICDI'),'1.30', "creating distance matrix"));
96                 
97                 # Test name preservation and restoration:
98                 $inputfilename = test_input_file("longnames.aln");
99                 $aln = Bio::AlignIO->new(-file=>$inputfilename, -format=>'clustalw')->next_aln;
100                 my ($aln_safe, $ref_name) =$aln->set_displayname_safe(3);
101                 ($matrix) = $dist_factory->create_distance_matrix($aln_safe);
102                 is (int($matrix->get_entry('S03','S03')),0, "failed creating matrix on safe names");
103                 ok(sprintf("%.4f",$matrix->get_entry('S01','S02'),'0.0205', "failed creating distance matrix"));
104         }