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

filter: Statementstmt 50.5% 48 / 95 Branchbran 25.0% 6 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.2% 13 / 18 Podpod 100% 5 / 5 totaltotal 50.7% 72 / 142 CC 14 SCAR 20.4
CC
14
Cov
45%
_run
30.0
run
12.0
_input
6.0
CRAP 7.7
« blib/lib/Bio/DB/SoapEUtilities/GQueryAdaptor.pm ↑ Summary blib/lib/Bio/Tools/Run/Prints.pm »
1 # $Id$
2 # BioPerl module for Profile
3 # Copyright Balamurugan Kumarasamy
4 #
5 # You may distribute this module under the same terms as perl itself
6 # POD documentation - main docs before the code
7  
8 =head1 NAME
9  
10 Bio::Tools::Run::Profile
11  
12 =head1 SYNOPSIS
13  
14 Build a Profile factory
15 # $paramfile is the full path to the seg binary file
16  
17 my @params = ('DB',$dbfile,'PROGRAM',$paramfile);
18 my $factory = Bio::Tools::Run::Profile->new($param);
19  
20 # Pass the factory a Bio::PrimarySeqI object
21 # @feats is an array of Bio::SeqFeature::Generic objects
22 my @feats = $factory->run($seq);
23  
24 =head1 DESCRIPTION
25  
26 Wrapper module for the pfscan program
27  
28 =head1 FEEDBACK
29  
30 =head2 Mailing Lists
31  
32 User feedback is an integral part of the evolution of this and other
33 Bioperl modules. Send your comments and suggestions preferably to one
34 of the Bioperl mailing lists. Your participation is much appreciated.
35  
36 bioperl-l@bioperl.org - General discussion
37 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
38  
39 =head2 Support
40  
41 Please direct usage questions or support issues to the mailing list:
42  
43 I<bioperl-l@bioperl.org>
44  
45 rather than to the module maintainer directly. Many experienced and
46 reponsive experts will be able look at the problem and quickly
47 address it. Please include a thorough description of the problem
48 with code and data examples if at all possible.
49  
50 =head2 Reporting Bugs
51  
52 Report bugs to the Bioperl bug tracking system to help us keep track
53 the bugs and their resolution. Bug reports can be submitted via the
54 web:
55  
56 http://redmine.open-bio.org/projects/bioperl/
57  
58 =head1 AUTHOR - Balamurugan Kumarasamy
59  
60 Email: fugui@worf.fugu-sg.org
61  
62 =head1 APPENDIX
63  
64 The rest of the documentation details each of the object
65 methods. Internal methods are usually preceded with a _
66  
67 =cut
68  
69 package Bio::Tools::Run::Profile;
70  
71 1 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR
72 $PROGRAMNAME @PROFILE_PARAMS
73 1 ▶ %OK_FIELD);
Subroutine BEGIN: called CC=1 SCAR=0.0
74 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 1 ▶use Bio::Root::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 1 ▶use Bio::Factory::ApplicationFactoryI;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 1 ▶use Bio::Tools::Profile;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82  
83 1 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
84  
85 BEGIN {
86 1 ▶ @PROFILE_PARAMS=qw(DB PROGRAM VERBOSE);
Subroutine BEGIN: called CC=2 SCAR=6.9
87 1 foreach my $attr ( @PROFILE_PARAMS)
88 3 { $OK_FIELD{$attr}++; }
89 }
90  
91 =head2 program_name
92  
93 Title : program_name
94 Usage : $factory>program_name()
95 Function: holds the program name
96 Returns: string
97 Args : None
98  
99 =cut
100  
101 sub program_name {
102 6 ▶ return 'pfscan';
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
103 }
104  
105 =head2 program_dir
106  
107 Title : program_dir
108 Usage : $factory->program_dir(@params)
109 Function: returns the program directory, obtained from ENV variable.
110 Returns: string
111 Args :
112  
113 =cut
114  
115 sub program_dir {
116 3 ▶ return Bio::Root::IO->catfile($ENV{PROFILEDIR}) if $ENV{PROFILEDIR};
Subroutine program_dir: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PROFILEDIR"} 0 3 3
117 }
118  
119 sub AUTOLOAD {
120 1 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=3 SCAR=11.2
121 1 my $attr = $AUTOLOAD;
122 1 $attr =~ s/.*:://;
123 1 $attr = uc $attr;
124 1 ▶ $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Tools::Run::Profile::OK_FIELD{$attr} 0 1 1
125 1 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
126 1 return $self->{$attr};
127 }
128  
129 =head2 new
130  
131 Title : new
132 Usage : my $factory= Bio::Tools::Run::Profile->new($param);
133 Function: creates a new Profile factory
134 Returns: Bio::Tools::Run::Profile
135 Args :
136  
137 =cut
138  
139 sub new {
140 1 ▶ my ($class,@args) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
141 1 my $self = $class->SUPER::new(@args);
142 1 $self->io->_initialize_io();
143
144 1 my ($attr, $value);
145 1 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 1 1 2
146 1 $attr = shift @args;
147 1 $value = shift @args;
148 1 ▶ next if( $attr =~ /^-/ ); # don't want named parameters
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^-/ 0 1 1
149 1 $self->$attr($value);
150 }
151 1 return $self;
152 }
153  
154 =head2 predict_protein_features
155  
156 Title : predict_protein_features
157 Usage : DEPRECATED. Use $factory->run($seq) instead.
158 Function: Runs Profile and creates an array of featrues
159 Returns : An array of L<Bio::SeqFeature::FeaturePair> objects
160 Args : A Bio::PrimarySeqI
161  
162 =cut
163  
164 sub predict_protein_features{
165 0 ▶ return shift->run(@_);
Subroutine predict_protein_features: not called CC=1 SCAR=6.9
Pod documented
166 }
167  
168 =head2 run
169  
170 Title : run
171 Usage : my @feats = $factory->run($seq)
172 Function: Runs Profile
173 Returns : An array of L<Bio::SeqFeature::FeaturePair> objects
174 Args : A Bio::PrimarySeqI
175  
176 =cut
177  
178 sub run{
179 0 ▶ my ($self,$seq) = @_;
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
180 0 my @feats;
181  
182 0 ▶ if (ref($seq) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $seq) { } 0 0 0
183
184 0 ▶ if (ref($seq) =~ /GLOB/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($seq) =~ /GLOB/) 0 0 0
185 0 $self->throw("cannot use filehandle");
186 }
187
188 0 my $display_id = $seq->display_id;
189
190 0 my $infile1 = $self->_writeSeqFile($seq);
191
192 0 $self->_input($infile1);
193
194 0 @feats = $self->_run($display_id);
195 0 unlink $infile1;
196
197 }
198 else {
199 #The clone object is not a seq object but a file.
200 #Perhaps should check here or before if this file is fasta format...if not die
201 #Here the file does not need to be created or deleted. Its already written and may be used by other runnables.
202  
203 0 $self->_input($seq);
204  
205 0 @feats = $self->_run();
206
207 }
208
209 0 return @feats;
210  
211 }
212  
213 =head2 _input
214  
215 Title : _input
216 Usage : $factory->_input($seqFile)
217 Function: get/set for input file
218 Returns :
219 Args :
220  
221 =cut
222  
223 sub _input() {
224 0 ▶ my ($self,$infile1) = @_;
Subroutine _input: not called CC=2 SCAR=17.9
225 0 ▶ if(defined $infile1){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $infile1) 0 0 0
226 0 $self->{'input'}=$infile1;
227 }
228 0 return $self->{'input'};
229 }
230  
231 =head2 _run
232  
233 Title : _run
234 Usage : $factory->_run()
235 Function: Makes a system call and runs pfscan
236 Returns : An array of L<Bio::SeqFeature::FeaturePair> objects
237 Args :
238  
239 =cut
240  
241 sub _run {
242 0 ▶ my ($self,$display_id)= @_;
Subroutine _run: not called CC=5 SCAR=34.0
243 0 my ($tfh,$outfile) = $self->io->tempfile(-dir=>$self->tempdir());
244 0 close($tfh);
245 0 undef $tfh;
246 0 my $str =$self->executable.' -fz '.$self->_input." ".$self->DB." > ".$outfile;
247 0 my $status = system($str);
248 0 ▶ $self->throw( "Profile call ($str) crashed: $? \n") unless $status==0;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 0 0 0 0
249
250 0 my $filehandle;
251 0 ▶ if (ref ($outfile) !~ /GLOB/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref($outfile) =~ /GLOB/) { } 0 0 0
252 0 ▶ open (PROFILE, "<".$outfile) or $self->throw ("Couldn't open file ".$outfile.": $!\n");
Branch: 1 branch
BranchTrueFalseTotal
open PROFILE, '<' . $outfile or $self->throw(q[Couldn't open file ] . $outfile . ": $!\n") 0 0 0
253 0 $filehandle = \*PROFILE;
254 }
255 else {
256 0 $filehandle = $outfile;
257 }
258 0 my $profile_parser = Bio::Tools::Profile->new(-fh=>$filehandle);
259  
260 0 my @profile_feat;
261  
262 0 ▶ while(my $profile_feat = $profile_parser->next_result){
Branch: 1 branch
BranchTrueFalseTotal
if (my $profile_feat = $profile_parser->next_result) 0 0 0
263  
264 0 $profile_feat->seq_id($display_id);
265 0 push @profile_feat, $profile_feat;
266 }
267
268 0 $self->cleanup();
269
270 0 unlink $outfile;
271 0 return @profile_feat;
272  
273 }
274  
275  
276 =head2 _writeSeqFile
277  
278 Title : _writeSeqFile
279 Usage : $factory->_writeSeqFile($seq)
280 Function: Creates a file from the given seq object
281 Returns : A string(filename)
282 Args : Bio::PrimarySeqI
283  
284 =cut
285  
286 sub _writeSeqFile{
287 0 ▶ my ($self,$seq) = @_;
Subroutine _writeSeqFile: not called CC=1 SCAR=6.9
288 0 my ($tfh,$inputfile) = $self->io->tempfile(-dir=>$self->tempdir());
289 0 my $in = Bio::SeqIO->new(-fh => $tfh , '-format' => 'fasta');
290 0 $in->write_seq($seq);
291 0 $in->close();
292 0 undef $in;
293 0 close($tfh);
294 0 undef $tfh;
295 0 return $inputfile;
296  
297 }
298 1 1;
« blib/lib/Bio/DB/SoapEUtilities/GQueryAdaptor.pm ↑ Summary blib/lib/Bio/Tools/Run/Prints.pm »