blib/lib/Bio/Tools/Run/Alignment/Exonerate.pm

filter: Statementstmt 35.7% 35 / 98 Branchbran 21.4% 6 / 28 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 58.8% 10 / 17 Podpod 100% 5 / 5 totaltotal 37.0% 56 / 151 CC 18 SCAR 23.5
CC
18
Cov
32%
_writeInput
30.0
_setparams
20.0
AUTOLOAD
12.0
CRAP 10.5
« blib/lib/Bio/Tools/Run/AnalysisFactory.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Gmap.pm »
1 # $Id$
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Shawn Hoon
6 #
7 # Copyright Shawn Hoon
8 #
9 # You may distribute this module under the same terms as perl itself
10 #
11 # POD documentation - main docs before the code
12  
13 =head1 NAME
14  
15 Bio::Tools::Run::Alignment::Exonerate
16  
17 =head1 SYNOPSIS
18  
19 use Bio::Tools::Run::Alignment::Exonerate;
20 use Bio::SeqIO;
21  
22 my $qio = Bio::SeqIO->new(-file=>$ARGV[0],-format=>'fasta');
23 my $query = $qio->next_seq();
24 my $tio = Bio::SeqIO->new(-file=>$ARGV[1],-format=>'fasta');
25 my $target = $sio->next_seq();
26  
27 #exonerate parameters can all be passed via arguments parameter.
28 #parameters passed are not checked for validity
29  
30 my $run = Bio::Tools::Run::Alignment::Exonerate->
31 new(arguments=>'--model est2genome --bestn 10');
32 my $searchio_obj = $run->run($query,$target);
33  
34 while(my $result = $searchio->next_result){
35 while( my $hit = $result->next_hit ) {
36 while( my $hsp = $hit->next_hsp ) {
37 print $hsp->start."\t".$hsp->end."\n";
38 }
39 }
40 }
41  
42 =head1 DESCRIPTION
43  
44 Wrapper for Exonerate alignment program. You can get exonerate at
45 http://www.ebi.ac.uk/~guy/exonerate/. This wrapper is written without
46 parameter checking. All parameters are passed via the arugment
47 parameter that is passed in the constructor. See SYNOPSIS. For
48 exonerate parameters, run exonerate --help for more details.
49  
50 =head1 PROGRAM VERSIONS
51  
52 The tests have been shown to pass with exonorate versions 2.0 - 2.2.
53  
54 =head1 FEEDBACK
55  
56 =head2 Mailing Lists
57  
58 User feedback is an integral part of the evolution of this and other
59 Bioperl modules. Send your comments and suggestions preferably to one
60 of the Bioperl mailing lists. Your participation is much appreciated.
61  
62 bioperl-l@bioperl.org - General discussion
63 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
64  
65 =head2 Support
66  
67 Please direct usage questions or support issues to the mailing list:
68  
69 I<bioperl-l@bioperl.org>
70  
71 rather than to the module maintainer directly. Many experienced and
72 reponsive experts will be able look at the problem and quickly
73 address it. Please include a thorough description of the problem
74 with code and data examples if at all possible.
75  
76 =head2 Reporting Bugs
77  
78 Report bugs to the Bioperl bug tracking system to help us keep track
79 the bugs and their resolution. Bug reports can be submitted via the
80 web:
81  
82 http://redmine.open-bio.org/projects/bioperl/
83  
84 =head1 AUTHOR - Shawn Hoon
85  
86 Email shawnh-at-stanford.edu
87  
88 =head1 APPENDIX
89  
90 The rest of the documentation details each of the object
91 methods. Internal methods are usually preceded with a _
92  
93 =cut
94  
95 package Bio::Tools::Run::Alignment::Exonerate;
96  
97 1 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR
98 1 ▶ $PROGRAMNAME @EXONERATE_PARAMS %OK_FIELD);
Subroutine BEGIN: called CC=1 SCAR=0.0
99 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 1 ▶use Bio::Root::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 1 ▶use Bio::Factory::ApplicationFactoryI;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 1 ▶use Bio::SearchIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
105  
106 1 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase
107 Bio::Factory::ApplicationFactoryI);
108  
109 =head2 program_name
110  
111 Title : program_name
112 Usage : $factory>program_name()
113 Function: holds the program name
114 Returns: string
115 Args : None
116  
117 =cut
118  
119 sub program_name {
120 6 ▶ return 'exonerate';
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
121 }
122  
123 =head2 program_dir
124  
125 Title : program_dir
126 Usage : $factory->program_dir(@params)
127 Function: returns the program directory, obtained from ENV variable.
128 Returns: string
129 Args :
130  
131 =cut
132  
133 sub program_dir {
134 3 ▶ return Bio::Root::IO->catfile($ENV{EXONERATEDIR}) if $ENV{EXONERATEDIR};
Subroutine program_dir: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"EXONERATEDIR"} 0 3 3
135 }
136 sub AUTOLOAD {
137 0 ▶ my $self = shift;
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
138 0 my $attr = $AUTOLOAD;
139 0 $attr =~ s/.*:://;
140 0 $attr = uc $attr;
141 0 ▶ $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Tools::Run::Alignment::Exonerate::OK_FIELD{$attr} 0 0 0
142 0 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
143 0 return $self->{$attr};
144 }
145  
146 =head2 new
147  
148 Title : new
149 Usage : my $factory= Bio::Tools::Run::Phrap->new();
150 Function: creates a new Phrap factory
151 Returns: Bio::Tools::Run::Phrap
152 Args :
153  
154 =cut
155  
156 sub new {
157 1 ▶ my ($class,@args) = @_;
Subroutine new: called CC=4 SCAR=14.0
Pod documented
158 1 my $self = $class->SUPER::new(@args);
159
160 1 my ($attr, $value);
161 1 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 2 1 3
162 2 $attr = shift @args;
163 2 $value = shift @args;
164 2 ▶ next if( $attr =~ /^-/ ); # don't want named parameters
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^-/ 1 1 2
165 1 ▶ if ($attr =~/PROGRAM/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /PROGRAM/i) 0 1 1
166 0 $self->executable($value);
167 0 next;
168 }
169 1 $self->$attr($value);
170 }
171 1 return $self;
172 }
173  
174 =head2 version
175  
176 Title : version
177 Usage : exit if $prog->version() < 1.8
178 Function: Determine the version number of the program
179 Example :
180 Returns : float or undef
181 Args : none
182  
183 =cut
184  
185 sub version {
186 0 ▶ my ($self) = @_;
Subroutine version: not called CC=3 SCAR=24.8
Pod documented
187 0 my $exe;
188 0 ▶ return undef unless $exe = $self->executable;
Branch: 1 branch
BranchTrueFalseTotal
unless $exe = $self->executable 0 0 0
189 0 my $string = `$exe -v` ;
190 #exonerate from exonerate version 2.0.0\n...
191 0 my ($version) = $string =~ /exonerate version ([\d+\.]+)/m;
192 0 $version =~ s/\.(\d+)$/$1/;
193 0 ▶ return $version || undef;
Condition0%0/2
$version || undef
l!l
00
MC/DC0%0/1
$version || undef
$version
Truth table0%0/2
A
A= $version
Aresult
11
00
194 }
195  
196  
197 =head2 run
198  
199 Title : run()
200 Usage : my $feats = $factory->run($seq)
201 Function: Runs Phrap
202 Returns : An array of Bio::SeqFeature::Generic objects
203 Args : A Bio::PrimarySeqI
204  
205 =cut
206  
207 sub run {
208 0 ▶ my ($self,$query,$target) = @_;
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
209 0 my @feats;
210 0 my ($file1) = $self->_writeInput($query);
211 0 my ($file2) = $self->_writeInput($target);
212 0 my $assembly = $self->_run($file1,$file2);
213 0 return $assembly;
214 }
215  
216 =head2 _input
217  
218 Title : _input
219 Usage : $factory->_input($seqFile)
220 Function: get/set for input file
221 Returns :
222 Args :
223  
224 =cut
225  
226 sub _input() {
227 0 ▶ my ($self,$infile1) = @_;
Subroutine _input: not called CC=2 SCAR=17.9
228 0 ▶ $self->{'input'} = $infile1 if(defined $infile1);
Branch: 1 branch
BranchTrueFalseTotal
if defined $infile1 0 0 0
229 0 return $self->{'input'};
230 }
231  
232 =head2 _run
233  
234 Title : _run
235 Usage : $factory->_run()
236 Function: Makes a system call and runs Phrap
237 Returns : An array of Bio::SeqFeature::Generic objects
238 Args :
239  
240 =cut
241  
242 sub _run {
243 0 ▶ my ($self,$query,$target)= @_;
Subroutine _run: not called CC=2 SCAR=17.9
244  
245 0 my ($tfh,$outfile) = $self->io->tempfile(-dir=>$self->tempdir);
246 0 my $param_str = $self->_setparams." ".$self->arguments;
247 0 my $str = $self->executable." $param_str $query $target "." > $outfile";
248 0 $self->debug( "$str\n");
249 0 my $status = system($str);
250 0 ▶ $self->throw( "Exonerate call ($str) crashed: $? \n") unless $status==0;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 0 0 0 0
251 0 my $filehandle;
252 0 my $exonerate_obj = Bio::SearchIO->new(-file=>"$outfile",-format=>'exonerate');
253  
254 0 close($tfh);
255 0 undef $tfh;
256 0 unlink $outfile;
257  
258 0 return $exonerate_obj;
259 }
260  
261  
262 =head2 _writeInput
263  
264 Title : _writeInput
265 Usage : $factory->_writeInput($query,$target)
266 Function: Creates a file from the given seq object
267 Returns : A string(filename)
268 Args : Bio::PrimarySeqI
269  
270 =cut
271  
272 sub _writeInput{
273 0 ▶ my ($self,$query) = @_;
Subroutine _writeInput: not called CC=5 SCAR=34.0
274 0 my ($fh,$infile1);
275 0 ▶ if (ref($query) =~ /ARRAY/i) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref($query) =~ /ARRAY/i) { } 0 0 0
elsif ($query->isa('Bio::PrimarySeqI')) { } 0 0 0
276 0 my @infilearr;
277 0 ($fh, $infile1) = $self->io->tempfile();
278 0 my $temp = Bio::SeqIO->new( -file => ">$infile1",
279 -format => 'Fasta' );
280 0 foreach my $seq1 (@$query) {
281 0 ▶ unless ($seq1->isa("Bio::PrimarySeqI")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seq1->isa("Bio::PrimarySeqI")) 0 0 0
282 0 return 0;
283 }
284 0 $temp->write_seq($seq1);
285 0 push @infilearr, $infile1;
286 }
287 }
288 elsif($query->isa("Bio::PrimarySeqI")) {
289 0 ($fh, $infile1) = $self->io->tempfile();
290 0 my $temp = Bio::SeqIO->new( -file => ">$infile1",
291 -format => 'Fasta' );
292 0 $temp->write_seq($query);
293 }
294 else {
295 0 $infile1 = $query;
296 }
297 0 return $infile1;
298 }
299  
300 =head2 _setparams
301  
302 Title : _setparams
303 Usage : Internal function, not to be called directly
304 Function: creates a string of params to be used in the command string
305 Example :
306 Returns : string of params
307 Args :
308  
309 =cut
310  
311 sub _setparams {
312 0 ▶ my ($self) = @_;
Subroutine _setparams: not called CC=4 SCAR=30.0
313 0 my $param_string = '';
314 0 foreach my $attr(@EXONERATE_PARAMS){
315 0 ▶ next if($attr=~/PROGRAM/);
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /PROGRAM/ 0 0 0
316 0 my $value = $self->$attr();
317 0 ▶ next unless (defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
318 0 my $attr_key = ' -'.(lc $attr);
319 0 $param_string .= $attr_key.' '.$value;
320 }
321 0 return $param_string;
322 }
323  
324 1 1;
« blib/lib/Bio/Tools/Run/AnalysisFactory.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Gmap.pm »