tests pass, find the right nodes more explicitly
[bioperl-run.git] / t / ProtDist.t
blobe57b5f9032e58057372e24ca3d7e20efa13054df
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
3 ## $Id$
5 use strict;
6 use vars qw($DEBUG);
7 $DEBUG = $ENV{'BIOPERLDEBUG'} || -1;
9 BEGIN {
10     eval { require Test; };
11     if( $@ ) { 
12         use lib 't';
13     }
14     use Test;
15     use vars qw($NTESTS);
16     $NTESTS = 11;
17     plan tests => $NTESTS;
20 use Bio::Tools::Run::Phylo::Phylip::ProtDist;
21 use Bio::Tools::Run::Alignment::Clustalw; 
23 END {     
24     for ( $Test::ntest..$NTESTS ) {
25         skip("ProtDist not found. Skipping.",1);
26     }
29 ok(1);
30 my $verbose = $DEBUG;
31 my @params = (
32               'idlength'  =>30,
33               'model'     =>'pam',
34               'gencode'   =>'U',
35               'category'  =>'H',
36               'probchange'=>'0.4',
37               'trans'     =>'5',
38               'freq'      =>'0.25,0.5,0.125,0.125');
40 my $dist_factory = Bio::Tools::Run::Phylo::Phylip::ProtDist->new(@params);
41 unless($dist_factory->executable){
42     warn("Protdist program not found. Skipping tests $Test::ntest to $NTESTS.\n");
43     exit 0;
46 ok $dist_factory->isa('Bio::Tools::Run::Phylo::Phylip::ProtDist');
48 my $model = 'KIMURA';
49 $dist_factory->model($model);
51 my $new_model= $dist_factory->model();
52 ok $new_model , 'KIMURA', " couldn't set factory parameter";
54 my $gencode = 'M';
55 $dist_factory->gencode($gencode);
57 my $new_gencode= $dist_factory->gencode();
58 ok $new_gencode, 'M', " couldn't set factory parameter";
61 my $category= "H";
62 $dist_factory->category($category);
64 my $new_category= $dist_factory->category();
65 ok $new_category, "H", " couldn't set factory parameter";
67 my $probchange= 0.4;
68 $dist_factory->probchange($probchange);
70 my $new_probchange= $dist_factory->probchange();
71 ok $new_probchange, 0.4, " couldn't set factory parameter";
73 my $trans= 5;
74 $dist_factory->trans($trans);
76 my $new_trans= $dist_factory->trans();
77 ok $new_trans, 5, " couldn't set factory parameter";
79 my $freq= "0.25,0.5,0.125,0.125";
80 $dist_factory->freq($freq);
82 my $new_freq= $dist_factory->freq();
83 ok $new_freq, "0.25,0.5,0.125,0.125", " couldn't set factory parameter";
85 my $bequiet = 1;
86 $dist_factory->quiet($bequiet);  # Suppress protpars messages to terminal 
88 my $inputfilename = Bio::Root::IO->catfile("t","data","protpars.phy");
89 my $matrix;
90 my $protdist_present = $dist_factory->executable();
91 unless ($protdist_present) {
92     warn("protdist program not found. Skipping tests $Test::ntest to $NTESTS.\n") if($DEBUG);    
93     exit 0;
95 $dist_factory->verbose($verbose);
96 ($matrix) = $dist_factory->create_distance_matrix($inputfilename);
98 ok(sprintf("%.3f", $matrix->get_entry('ENSP000003','SINFRUP001')),0.277);
100 $inputfilename = Bio::Root::IO->catfile("t","data","cysprot.fa");
101 @params = ('ktuple' => 2, 'matrix' => 'BLOSUM', 
102            -verbose => $verbose);
103 my  $align_factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
105 exit(0) unless $align_factory->executable();
107 my $aln = $align_factory->align($inputfilename);
108 ($matrix) = $dist_factory->create_distance_matrix($aln);
110 ok (int($matrix->get_entry('ALEU_HORVU','ALEU_HORVU')),0,
111     "failed creating distance matrix");
112 ok(sprintf("%.2f",$matrix->get_entry('CATL_HUMAN','CYS1_DICDI'),'1.30', "failed creating distance matrix"));