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