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