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