blib/lib/Bio/Tools/Run/Genewise.pm

filter: Statementstmt 37.9% 60 / 158 Branchbran 12.9% 7 / 54 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 65.3% 17 / 26 Podpod 85.7% 6 / 7 totaltotal 34.0% 90 / 264 CC 35 SCAR 32.9
CC
35
Cov
30%
_setinput
90.0
_run
56.0
_setparams
30.0
CRAP 26.9
« blib/lib/Bio/Tools/Run/Genemark.pm ↑ Summary blib/lib/Bio/Tools/Run/Mdust.pm »
1 # $Id$
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by
6 #
7 # Copyright to a FUGU Student Intern
8 #
9 # You may distribute this module under the same terms as perl itself
10 # POD documentation - main docs before the code
11  
12 =head1 NAME
13  
14 Bio::Tools::Run::Genewise - Object for predicting genes in a
15 given sequence given a protein
16  
17 =head1 SYNOPSIS
18  
19 # Build a Genewise alignment factory
20 my $factory = Bio::Tools::Run::Genewise->new();
21  
22 # Pass the factory 2 Bio:SeqI objects (in the order of query peptide
23 # and target_genomic).
24  
25 # @genes is an array of Bio::SeqFeature::Gene::GeneStructure objects
26 my @genes = $factory->run($protein_seq, $genomic_seq);
27  
28 # Alternatively pass the factory a profile HMM filename and a
29 # Bio:SeqI object (in the order of query HMM and target_genomic).
30  
31 # Set hmmer switch first to tell genewise to expect an HMM
32 $factory->hmmer(1);
33 my @genes = $factory->run($hmmfile, $genomic_seq);
34  
35  
36 =head1 DESCRIPTION
37  
38 Genewise is a gene prediction program developed by Ewan Birney
39 http://www.sanger.ac.uk/software/wise2.
40  
41 =head2 Available Params:
42  
43 NB: These should be passed without the '-' or they will be ignored,
44 except switches such as 'hmmer' (which have no corresponding value)
45 which should be set on the factory object using the AUTOLOADed methods
46 of the same name.
47  
48 Model [-codon,-gene,-cfreq,-splice,-subs,-indel,-intron,-null]
49 Alg [-kbyte,-alg]
50 HMM [-hmmer]
51 Output [-gff,-gener,-alb,-pal,-block,-divide]
52 Standard [-help,-version,-silent,-quiet,-errorlog]
53  
54  
55 =head1 FEEDBACK
56  
57 =head2 Mailing Lists
58  
59 User feedback is an integral part of the evolution of this and other
60 Bioperl modules. Send your comments and suggestions preferably to one
61 of the Bioperl mailing lists. Your participation is much appreciated.
62  
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
65  
66 =head2 Support
67  
68 Please direct usage questions or support issues to the mailing list:
69  
70 I<bioperl-l@bioperl.org>
71  
72 rather than to the module maintainer directly. Many experienced and
73 reponsive experts will be able look at the problem and quickly
74 address it. Please include a thorough description of the problem
75 with code and data examples if at all possible.
76  
77 =head2 Reporting Bugs
78  
79 Report bugs to the Bioperl bug tracking system to help us keep track
80 the bugs and their resolution. Bug reports can be submitted via
81 the web:
82  
83 http://redmine.open-bio.org/projects/bioperl/
84  
85 =head1 AUTHOR - FUGU Student Intern
86  
87 Email: fugui@worf.fugu-sg.org
88  
89 =head1 CONTRIBUTORS
90  
91 Jason Stajich jason-AT-bioperl_DOT_org
92 Keith James kdj@sanger.ac.uk
93  
94 =head1 APPENDIX
95  
96 The rest of the documentation details each of the object
97 methods. Internal methods are usually preceded with a _
98  
99 =cut
100  
101 package Bio::Tools::Run::Genewise;
102 1 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR $PROGRAMNAME
103 @GENEWISE_SWITCHES @GENEWISE_PARAMS
104 1 ▶ @OTHER_SWITCHES %OK_FIELD);
Subroutine BEGIN: called CC=1 SCAR=0.0
105 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
106 1 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 1 ▶use Bio::SeqFeature::Gene::Exon;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 1 ▶use Bio::SeqFeature::FeaturePair;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 1 ▶use Bio::SeqFeature::Gene::Transcript;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 1 ▶use Bio::SeqFeature::Gene::GeneStructure;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 1 ▶use Bio::Tools::Genewise;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 1 ▶use Bio::Tools::AnalysisResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
116  
117 1 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase );
118  
119 # Two ways to run the program .....
120 # 1. define an environmental variable WISEDIR
121 # export WISEDIR =/usr/local/share/wise2.2.0
122 # where the wise2.2.20 package is installed
123 #
124 # 2. include a definition of an environmental variable WISEDIR in
125 # every script that will use DBA.pm
126 # $ENV{WISEDIR} = '/usr/local/share/wise2.2.20';
127  
128 BEGIN {
129 1 ▶ @GENEWISE_PARAMS = qw( DYMEM CODON GENE CFREQ SPLICE GENESTATS INIT
Subroutine BEGIN: called CC=2 SCAR=6.9
130 SUBS INDEL INTRON NULL INSERT SPLICE_MAX_COLLAR SPLICE_MIN_COLLAR
131 GW_EDGEQUERY GW_EDGETARGET GW_SPLICESPREAD
132 KBYTE HNAME ALG BLOCK DIVIDE GENER U V S T G E M);
133  
134 1 @GENEWISE_SWITCHES = qw(HELP SILENT QUIET ERROROFFSTD TREV PSEUDO NOSPLICE_GTAG
135 SPLICE_GTAG NOGWHSP GWHSP
136 TFOR TABS BOTH HMMER );
137  
138 # Authorize attribute fields
139 1 foreach my $attr ( @GENEWISE_PARAMS, @GENEWISE_SWITCHES,
140 44 @OTHER_SWITCHES) { $OK_FIELD{$attr}++; }
141 }
142  
143 =head2 program_name
144  
145 Title : program_name
146 Usage : $factory>program_name()
147 Function: holds the program name
148 Returns: string
149 Args : None
150  
151 =cut
152  
153 sub program_name {
154 6 ▶ return 'genewise';
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
155 }
156  
157 =head2 program_dir
158  
159 Title : program_dir
160 Usage : $factory->program_dir(@params)
161 Function: returns the program directory, obtained from ENV variable.
162 Returns: string
163 Args :
164  
165 =cut
166  
167 sub program_dir {
168 3 ▶ return Bio::Root::IO->catfile($ENV{WISEDIR},"/src/bin/") if $ENV{WISEDIR};
Subroutine program_dir: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"WISEDIR"} 0 3 3
169 }
170  
171 sub new {
172 1 ▶ my ($class, @args) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
173 1 my $self = $class->SUPER::new(@args);
174  
175 1 my ($attr, $value);
176 1 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 3 1 4
177 3 $attr = shift @args;
178 3 $value = shift @args;
179 3 ▶ next if( $attr =~ /^-/ ); # don't want named parameters
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^-/ 1 2 3
180 2 $self->$attr($value);
181 }
182  
183 1 return $self;
184 }
185  
186 sub AUTOLOAD {
187 1 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=3 SCAR=11.2
188 1 my $attr = $AUTOLOAD;
189 1 $attr =~ s/.*:://;
190 1 $attr = uc $attr;
191 1 ▶ $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Tools::Run::Genewise::OK_FIELD{$attr} 0 1 1
192 1 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
193 1 return $self->{$attr};
194 }
195  
196 =head2 version
197  
198 Title : version
199 Usage : exit if $prog->version() < 1.8
200 Function: Determine the version number of the program
201 Example :
202 Returns : float or undef
203 Args : none
204  
205 =cut
206  
207 sub version {
208 0 ▶ my ($self) = @_;
Subroutine version: not called CC=4 SCAR=30.0
Pod documented
209  
210 0 ▶ return undef unless $self->executable;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->executable 0 0 0
211 0 my $prog = $self->executable;
212 0 my $string = `$prog -version`;
213 0 ▶ if( $string =~ /Version:\s+\$\s*Name:\s+(\S+)\s+\$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($string =~ /Version:\s+\$\s*Name:\s+(\S+)\s+\$/) { } 0 0 0
elsif ($string =~ /(Version *)/i) { } 0 0 0
214 0 return $1;
215 } elsif( $string =~ /(Version *)/i ) {
216 0 return $1;
217 } else {
218 0 return undef;
219 }
220 }
221  
222 =head2 predict_genes
223  
224 Title : predict_genes
225 Usage : DEPRECATED. Use $factory->run($seq1,$seq2)
226 Function: Predict genes
227 Returns : A Bio::Seqfeature::Gene:GeneStructure object
228 Args : Name of a file containing a set of 2 fasta sequences in the order of
229 peptide and genomic sequences
230 or else 2 Bio::Seq objects.
231  
232 Throws an exception if argument is not either a string (eg a filename)
233 or 2 Bio::Seq objects. If arguments are strings, throws exception if
234 file corresponding to string name can not be found.
235  
236 =cut
237  
238 sub predict_genes {
239 0 ▶ return shift->run(@_);
Subroutine predict_genes: not called CC=1 SCAR=6.9
Pod documented
240 }
241  
242 =head2 run
243  
244 Title : run
245 Usage : 2 sequence objects
246 $genes = $factory->run($seq1, $seq2);
247 Function: run
248 Returns : A Bio::Seqfeature::Gene:GeneStructure object
249 Args : Names of a files each containing a fasta sequence in the order
250 of either (peptide sequence, genomic sequence) or (profile HMM,
251 genomic sequence). Alternatively any of the fasta sequence
252 filenames may be substituted with a Bio::Seq object.
253  
254 Throws an exception if argument is not either a string (eg a filename)
255 or Bio::Seq objects. If arguments are strings, throws exception if
256 file corresponding to string name can not be found. Also throws an
257 exception if a profile HMM is expected (the -hmmer genewise switch has
258 been set).
259  
260 =cut
261  
262 sub run{
263 0 ▶ my ($self, $seq1, $seq2) = @_;
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
264 0 my ($attr, $value, $switch);
265 0 $self->io->_io_cleanup();
266 # Create input file pointer
267 0 my ($infile1,$infile2)= $self->_setinput($seq1, $seq2);
268 0 ▶ if (!($infile1 && $infile2)) {$self->throw("Bad input data (sequences need an id ) ");}
Branch: 1 branch
BranchTrueFalseTotal
unless ($infile1 and $infile2) 0 0 0
Condition0%0/3
$infile1 and $infile2
!ll&&!rl&&r
000
MC/DC0%0/2
$infile1 and $infile2
$infile1 $infile2
Truth table0%0/3
A and B
A= $infile1B= $infile2
ABresult
0X0
100
111
269  
270 # run genewise
271 0 my @genes = $self->_run($infile1,$infile2);
272 0 return @genes;
273 }
274  
275 =head2 _run
276  
277 Title : _run
278 Usage : Internal function, not to be called directly
279 Function: Makes actual system call to a genewise program
280 Example :
281 Returns : L<Bio::SeqFeature::Gene::GeneStructure>
282 Args : Name of a files containing 2 sequences in the order of peptide and genomic
283  
284 =cut
285  
286 sub _run {
287 0 ▶ my ($self,$infile1,$infile2) = @_;
Subroutine _run: not called CC=7 SCAR=40.3
288 0 my $instring;
289 0 $self->debug("Program ".$self->executable."\n");
290 0 ▶ unless ( $self->executable ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executable) 0 0 0
291 0 $self->throw("Cannot run Genewise unless the executable is found. Check your environment variables or make sure genewise is in your path.");
292 }
293 0 my $paramstring = $self->_setparams;
294  
295 0 my $commandstring = $self->executable." $paramstring $infile1 $infile2";
296 # this is to capture STDERR messages which leak out when you run programs
297 # with open(FH, "... |");
298 0 ▶ if (($self->silent && $self->quiet) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->silent and $self->quiet and not $^O =~ /os2|dos|MSWin32|amigaos/) 0 0 0
Condition0%0/6
$self->silent and $self->quiet and not $^O =~ /os2|dos|MSWin32|amigaos/
!ll&&!rl&&r
000
$self->silent and $self->quiet
!ll&&!rl&&r
000
MC/DC0%0/3
$self->silent and $self->quiet and not $^O =~ /os2|dos|MSWin32|amigaos/
$self->silent $self->quiet not $^O =~ /os2|dos|MSWin32|amigaos/
Truth table0%0/4
A and B and not(C)
A= $self->silentB= $self->quietC= not $^O =~ /os2|dos|MSWin32|amigaos/
ABCresult
0XX0
10X0
1100
1111
299 ($^O !~ /os2|dos|MSWin32|amigaos/)) {
300 # yeah, like genewise is really going to run on Windows...
301 0 $commandstring .= ' 2> /dev/null';
302 }
303 0 my ($tfh1,$outfile1) = $self->io->tempfile(-dir=>$self->tempdir);
304 0 $self->debug("genewise command = $commandstring");
305 0 my $status = system("$commandstring > $outfile1");
306 0 ▶ $self->throw("Genewise call $commandstring crashed: $? \n") unless $status == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 0 0 0 0
307
308 0 my $genewiseParser = Bio::Tools::Genewise->new(-file=> $outfile1);
309 0 my @genes;
310 0 ▶ while (my $gene = $genewiseParser->next_prediction()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $gene = $genewiseParser->next_prediction) 0 0 0
311 0 push @genes, $gene;
312 }
313 0 close ($tfh1);
314 0 undef ($tfh1);
315 0 return @genes;
316 }
317  
318 sub get_strand {
319 0 ▶ my ($self,$start,$end) = @_;
Subroutine get_strand: not called CC=4 SCAR=30.0
Pod undocumented
320 0 ▶ $start || $self->throw("Need a start");
Branch: 1 branch
BranchTrueFalseTotal
$start or $self->throw("Need a start") 0 0 0
321 0 ▶ $end || $self->throw("Need an end");
Branch: 1 branch
BranchTrueFalseTotal
$end or $self->throw("Need an end") 0 0 0
322 0 my $strand;
323 0 ▶ if ($start > $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $end) { } 0 0 0
324 0 my $tmp = $start;
325 0 $start = $end;
326 0 $end = $tmp;
327 0 $strand = -1;
328 }
329 else {
330 0 $strand = 1;
331 }
332 0 return ($start,$end,$strand);
333 }
334  
335 sub _setinput {
336 0 ▶ my ($self, $arg1, $seq2) = @_;
Subroutine _setinput: not called CC=9 SCAR=45.0
337 0 my ($tfh1,$tfh2,$outfile1,$outfile2);
338  
339 0 ▶ $self->throw("calling with not enough arguments") unless $arg1 && $seq2;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg1 and $seq2 0 0 0
Condition0%0/3
$arg1 and $seq2
!ll&&!rl&&r
000
MC/DC0%0/2
$arg1 and $seq2
$arg1 $seq2
Truth table0%0/3
A and B
A= $arg1B= $seq2
ABresult
0X0
100
111
340  
341 # Not going to set _query_pep/_subject_dna_seq if you pass in a
342 # filename
343  
344 0 ▶ unless( ref($arg1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg1) { } 0 0 0
345 0 ▶ unless( -e $arg1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $arg1) 0 0 0
346 0 ▶ if ($self->hmmer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hmmer) { } 0 0 0
347 0 $self->throw("Argument1 was not a HMMER profile HMM file\n")
348 }
349 else {
350 0 $self->throw("Argument1 is not a Bio::PrimarySeqI object nor file\n");
351 }
352 }
353 0 $outfile1 = $arg1;
354 }
355 else {
356 0 ▶ if ($self->hmmer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hmmer) { } 0 0 0
357 0 $self->throw("Argument1 was not a HMMER profile HMM file\n")
358 }
359 else {
360 0 ($tfh1,$outfile1) = $self->io->tempfile(-dir=>$self->tempdir);
361 0 my $out1 = Bio::SeqIO->new('-fh' => $tfh1,
362 '-format' => 'fasta');
363 0 $out1->write_seq($arg1);
364 0 $self->_query_pep_seq($arg1);
365 # Make sure you close things - this is what creates
366 # Out of filehandle errors
367 0 close($tfh1);
368 0 undef $tfh1;
369 }
370 }
371  
372 0 ▶ unless( ref($seq2) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $seq2) { } 0 0 0
373 0 ▶ unless( -e $seq2 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $seq2) 0 0 0
374 0 $self->throw("Sequence2 is not a Bio::PrimarySeqI object nor file\n");
375 }
376 0 $outfile2 = $seq2;
377 }
378 else {
379 0 ($tfh2,$outfile2) = $self->io->tempfile(-dir=>$self->tempdir);
380 0 my $out2 = Bio::SeqIO->new('-fh' => $tfh2,
381 '-format' => 'fasta');
382 0 $out2->write_seq($seq2);
383  
384 0 $self->_subject_dna_seq($seq2);
385 # Make sure you close things - this is what creates
386 # Out of filehandle errors
387 0 close($tfh2);
388 0 undef $tfh2;
389 }
390 0 return ($outfile1,$outfile2);
391 }
392  
393 =head2 _setparams
394  
395 Title : _setparams
396 Usage : Internal function, not to be called directly
397 Function: creates a string of params to be used in the command string
398 Example :
399 Returns : string of params
400 Args :
401  
402 =cut
403  
404 sub _setparams {
405 0 ▶ my ($self) = @_;
Subroutine _setparams: not called CC=5 SCAR=34.0
406 0 my $param_string;
407 0 foreach my $attr(@GENEWISE_PARAMS){
408 0 my $value = $self->$attr();
409 0 ▶ next unless (defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
410 0 my $attr_key = ' -'.(lc $attr);
411 0 $param_string .= $attr_key.' '.$value;
412 }
413 0 foreach my $attr(@GENEWISE_SWITCHES){
414 0 my $value = $self->$attr();
415 0 ▶ next unless (defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
416 0 my $attr_key = ' -'.(lc $attr);
417 0 $param_string .=$attr_key;
418 }
419  
420 0 $param_string = $param_string." -genesf"; #specify the output option
421 0 return $param_string;
422 }
423  
424 =head2 _query_pep_seq
425  
426 Title : _query_pep_seq
427 Usage : Internal function, not to be called directly
428 Function: get/set for the query sequence
429 Example :
430 Returns :
431 Args :
432  
433 =cut
434  
435 sub _query_pep_seq {
436 0 ▶ my ($self,$seq) = @_;
Subroutine _query_pep_seq: not called CC=2 SCAR=17.9
437 0 ▶ if(defined $seq){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seq) 0 0 0
438 0 $self->{'_query_pep_seq'} = $seq;
439 }
440 0 return $self->{'_query_pep_seq'};
441 }
442  
443 =head2 _subject_dna_seq
444  
445 Title : _subject_dna_seq
446 Usage : Internal function, not to be called directly
447 Function: get/set for the subject sequence
448 Example :
449 Returns :
450  
451 Args :
452  
453 =cut
454  
455 sub _subject_dna_seq {
456 0 ▶ my ($self,$seq) = @_;
Subroutine _subject_dna_seq: not called CC=2 SCAR=17.9
457 0 ▶ if(defined $seq){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seq) 0 0 0
458 0 $self->{'_subject_dna_seq'} = $seq;
459 }
460 0 return $self->{'_subject_dna_seq'};
461 }
462  
463 1 1;
464  
465  
« blib/lib/Bio/Tools/Run/Genemark.pm ↑ Summary blib/lib/Bio/Tools/Run/Mdust.pm »