skip # off
[bioperl-run.git] / t / ProtPars.t
blobb646698717dae25e23ea3a9aad63407b1057cc38
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
3 ## $Id$
5 use vars qw($DEBUG );
6 $DEBUG = test_debug();
8 use strict;
9 BEGIN {
10     use Bio::Root::Test;
11     test_begin(-tests => 11);
12         use_ok('Bio::Tools::Run::Phylo::Phylip::ProtPars');
13         use_ok('Bio::Tools::Run::Alignment::Clustalw');
16 my @params = ('threshold'=>10,'jumble'=>'17,10',outgroup=>2,'idlength'=>10);
17 my $tree_factory = Bio::Tools::Run::Phylo::Phylip::ProtPars->new(@params);
18 isa_ok $tree_factory,'Bio::Tools::Run::Phylo::Phylip::ProtPars';
20 SKIP: {
21         test_skip(-requires_executable => $tree_factory,
22                           -tests => 8);
23         
24         my $threshold = 5;
25         $tree_factory->threshold($threshold);
26         
27         my $new_threshold= $tree_factory->threshold();
28         is $new_threshold, 5, "set factory parameter";
29         
30         my $outgroup = 3;
31         $tree_factory->outgroup($outgroup);
32         
33         my $new_outgroup= $tree_factory->outgroup();
34         is $new_outgroup, 3, "set factory parameter";
35         
36         
37         my $jumble = "7,5";
38         $tree_factory->jumble($jumble);
39         
40         my $new_jumble= $tree_factory->jumble();
41         is $new_jumble, "7,5", "set factory parameter";
42         
43         my $bequiet = 1;
44         $tree_factory->quiet($bequiet);  # Suppress protpars messages to terminal 
45         
46         my $inputfilename = test_input_file("protpars.phy");
47         my $tree;
48         
49         $tree = $tree_factory->create_tree($inputfilename);
50         
51         # have to sort the since there is polytomy here.
52         my @nodes = sort { $a->id cmp $b->id } grep { $_->id } $tree->get_nodes();
53         is ($nodes[2]->id, 'SINFRUP002', 
54                 "creating tree by protpars");
55         
56         $inputfilename = test_input_file("cysprot1a.fa");
57         @params = ('ktuple' => 2, 'matrix' => 'BLOSUM', 
58                    -verbose => -1);
59         my  $align_factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
60         
61         SKIP: {
62                 test_skip(-requires_executable => $align_factory,
63                                   -tests => 4);
64                 
65                 my $aln = $align_factory->align($inputfilename);
66                 
67                 $tree = $tree_factory->create_tree($aln);
68                 
69                 @nodes = sort { defined $a->id && defined $b->id && $a->id cmp $b->id } $tree->get_nodes();
70                 is (scalar(@nodes),5,
71                         "creating tree by protpars");
72                 
73                 # test name preservation and restoration:
74                 @params = ('threshold'=>10,'jumble'=>'7,5',outgroup=>2,'idlength'=>10);
75                 $tree_factory = Bio::Tools::Run::Phylo::Phylip::ProtPars->new(@params);
76                 $tree_factory->quiet($bequiet);  # Suppress protpars messages to terminal 
77                 $inputfilename = test_input_file("longnames.aln");
78                 $aln = Bio::AlignIO->new(-file=>$inputfilename, -format=>'clustalw')->next_aln;
79                 my ($aln_safe, $ref_name) =$aln->set_displayname_safe(3);
80                 $tree = $tree_factory->create_tree($aln_safe);
81                 @nodes = sort { $a->id cmp $b->id } $tree->get_nodes();
82                 is (scalar(@nodes),27,
83                         "creating tree by protpars");
84                 is ($nodes[12]->id, 'S01',"assign serial names");
85                 foreach my $nd (@nodes){
86                   $nd->id($ref_name->{$nd->id_output}) if $nd->is_Leaf;
87                 }
88                 is ($nodes[12]->id, 'Spar_21273',"restore original names");
89         }