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