Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / t / Hmmer.t
blob851af41672e8176c8ef91cd70eaeb581fba7e6f7
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7    use Bio::Root::Test;
8    
9    test_begin(-tests => 27);
10    
11    use_ok('Bio::Tools::Run::Hmmer');
12    use_ok('Bio::SeqIO');
13    use_ok('Bio::AlignIO');
16 my $verbose = test_debug();
17 my $quiet = $verbose > 0 ? 0 : 1;
19 my $db = test_input_file('pfam_sample_R11');
20 my @params = ('DB'=>$db,'E'=>5,'program'=>'hmmpfam','A'=>2,'-verbose' => $verbose, -quiet => $quiet);
22 #test HMMPFAM
23 my $factory = Bio::Tools::Run::Hmmer->new(@params);
24 isa_ok($factory, 'Bio::Tools::Run::Hmmer');
25 is $factory->E, 5;
26 is $factory->DB, $db;
27 is $factory->hmm, $db;
28 my $prot_file = test_input_file('hmmpfam_protein_input');
30 my $seqstream = Bio::SeqIO->new(-file => $prot_file, 
31                                 -format => 'fasta');
32 my $seq1 = $seqstream->next_seq();
34 SKIP: {
35    # here we assume if hmmpfam isn't present, nothing is present
36    test_skip(-requires_executable => $factory,
37              -tests =>  20);
39    my $searchio = $factory->run($seq1);
40    
41    my @feat;
42    while (my $result = $searchio->next_result){
43      while(my $hit = $result->next_hit){
44        while (my $hsp = $hit->next_hsp){
45          push @feat, $hsp;
46        }
47      }
48    }
49    
50    isa_ok $feat[0], 'Bio::SeqFeatureI';
51    is ($feat[0]->feature1->start,25);
52    is ($feat[0]->feature1->end,92);
53    is ($feat[0]->feature2->start,1);
54    is ($feat[0]->feature2->end,124);
56    #test HMMSEARCH
57    @params = ('HMM'=>$db,'E'=>5,'program'=>'hmmsearch','-verbose' => $verbose, -quiet => $quiet);
58    $factory = Bio::Tools::Run::Hmmer->new(@params);
59    isa_ok $factory, 'Bio::Tools::Run::Hmmer';
60    is $factory->E, 5;
61    
62    SKIP: {
63       test_skip(-requires_executable => $factory,
64                 -tests => 5);
65       
66       my $searchio = $factory->run($seq1);
67       my @feat;
68       while (my $result = $searchio->next_result){
69         while(my $hit = $result->next_hit){
70           while (my $hsp = $hit->next_hsp){
71             push @feat, $hsp;
72           }
73         }
74       }
75       
76       isa_ok $feat[0], 'Bio::SeqFeatureI';#Bio::Search::HSP::HMMERHSP
77       is ($feat[0]->feature1->start,1);
78       is ($feat[0]->feature1->end,124);
79       is ($feat[0]->feature2->start,25);
80       is ($feat[0]->feature2->end,92);
81    }
82    
83    #test HMMBUILD
84    my $hmmout = test_output_file();
85    unlink($hmmout);
86    @params = ('HMM'=>$hmmout,'program'=>'hmmbuild', -verbose => $verbose, -quiet => $quiet);
87    $factory = Bio::Tools::Run::Hmmer->new(@params);
88    isa_ok $factory, 'Bio::Tools::Run::Hmmer';
89    is $factory->quiet, $quiet;
90    my $aln_file = test_input_file('cysprot.msf');
91    my $aio = Bio::AlignIO->new(-file=>$aln_file,-format=>'msf');
92    my $aln = $aio->next_aln;
93    
94    SKIP: {
95       test_skip(-requires_executable => $factory,
96                 -tests => 2);
97       ok $factory->run($aln);
98       ok -s $hmmout;
99    }
100    
101    #test HMMCALIBRATE, and from now on, alternate (preferred) run method calling,
102    #though we need to check the executables are present in the normal way first
103    $factory->program_name('hmmcalibrate');
104    
105    SKIP: {
106       test_skip(-requires_executable => $factory,
107                 -tests => 1);
108       ok $factory->hmmcalibrate();
109    }
110    
111    $factory->program_name('hmmalign');
112    
113    #test HMMALIGN
114    my $seqfile = test_input_file('cysprot1a.fa');
115    my $seqio = Bio::SeqIO->new(-file  => $seqfile,
116                    -format=> 'fasta');
117    my @seqs;
118    while( my $seq = $seqio->next_seq ) {
119       push @seqs, $seq;
120    }
121    
122    SKIP: {
123       test_skip(-requires_executable => $factory,
124                 -tests => 2);
125       $aio = $factory->hmmalign(@seqs);
126       ok $aln = $aio->next_aln;
127       is($aln->each_seq, 3);
128    }
129    
130    $factory->program_name('hmmemit');
131    
132    #test HMMEMIT
133    SKIP: {
134       test_skip(-requires_executable => $factory,
135                 -tests => 1);
136       my $seqio = $factory->hmmemit();
137       my @seqs;
138       while (my $seq = $seqio->next_seq) {
139          push(@seqs, $seq);
140       }
141       is @seqs, 10; # emits 10 seqs by default
142    }
144    # Delete temporary file
145    unlink($hmmout);