Tools/Run/Match.pm

filter: Statementstmt 48.6% 36 / 74 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 78.5% 11 / 14 Podpod 100% 4 / 4 totaltotal 38.6% 51 / 132 CC 16 SCAR 44.3
CC
16
Cov
34%
_run
182.0
_setparams
12.0
run
6.0
CRAP 83.6
« Tools/Run/Alignment/Amap.pm ↑ Summary Tools/Run/Alignment/MAFFT.pm »
1 #
2 # BioPerl module for Bio::Tools::Run::Match
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Sendu Bala <bix@sendu.me.uk>
7 #
8 # Copyright Sendu Bala
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Tools::Run::Match - Wrapper for Transfac's match(TM)
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Tools::Run::Match;
21  
22 # Make a Match factory
23 $factory = Bio::Tools::Run::Match->new(-mxlib => '/path/to/matrix.dat');
24  
25 # Run Match on an sequence object
26 my @results = $factory->run($bio_seq);
27  
28 # look at the results
29 foreach my $feat (@results) {
30 my $seq_id = $feat->seq_id;
31 my $start = $feat->start;
32 my $end = $feat->end;
33 my $score = $feat->score;
34 my ($pvalue) = $feat->get_tag_values('pvalue');
35 }
36  
37 =head1 DESCRIPTION
38  
39 This is a wrapper for running the match(TM) program supplied with Transfac Pro
40 distributions.
41  
42 You can try supplying normal match command-line arguments to new(), eg.
43 new(-b => 1) or calling arg-named methods (excluding the initial
44 hyphens, eg. $factory->b(1) to set the -b option to true).
45  
46 Histogram output isn't supported. -p is supported by using -mxprf, see the
47 docs of new() for details.
48  
49 You will need to enable this match wrapper to find the match executable.
50 This can be done in (at least) three ways:
51  
52 1. Make sure match is in your path.
53 2. Define an environmental variable MATCHDIR which is a
54 directory which contains the match executable:
55 In bash:
56  
57 export MATCHDIR=/home/username/match/
58  
59 In csh/tcsh:
60  
61 setenv MATCHDIR /home/username/match
62  
63 3. Include a definition of an environmental variable MATCHDIR in
64 every script that will use this match wrapper module, e.g.:
65  
66 BEGIN { $ENV{MATCHDIR} = '/home/username/match/' }
67 use Bio::Tools::Run::Match;
68  
69 =head1 FEEDBACK
70  
71 =head2 Mailing Lists
72  
73 User feedback is an integral part of the evolution of this and other
74 Bioperl modules. Send your comments and suggestions preferably to
75 the Bioperl mailing list. Your participation is much appreciated.
76  
77 bioperl-l@bioperl.org - General discussion
78 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
79  
80 =head2 Support
81  
82 Please direct usage questions or support issues to the mailing list:
83  
84 I<bioperl-l@bioperl.org>
85  
86 rather than to the module maintainer directly. Many experienced and
87 reponsive experts will be able look at the problem and quickly
88 address it. Please include a thorough description of the problem
89 with code and data examples if at all possible.
90  
91 =head2 Reporting Bugs
92  
93 Report bugs to the Bioperl bug tracking system to help us keep track
94 of the bugs and their resolution. Bug reports can be submitted via
95 the web:
96  
97 http://redmine.open-bio.org/projects/bioperl/
98  
99 =head1 AUTHOR - Sendu Bala
100  
101 Email bix@sendu.me.uk
102  
103 =head1 APPENDIX
104  
105 The rest of the documentation details each of the object methods.
106 Internal methods are usually preceded with a _
107  
108 =cut
109  
110 package Bio::Tools::Run::Match;
111 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
112  
113 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 1 ▶use Bio::FeatureIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 1 ▶use Bio::Annotation::SimpleValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 1 ▶use Bio::Tools::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 1 ▶use base qw(Bio::Tools::Run::WrapperBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 1 our $PROGRAM_NAME = 'match';
123 1 our $PROGRAM_DIR = $ENV{'MATCHDIR'};
124  
125 # methods for the match args we support
126 1 our @PARAMS = qw(mxlib mxprf imcut); # these aren't actually match args, but
127 # are methods we use internally
128 1 our @SWITCHES = qw(b u);
129  
130 # just to be explicit, args we don't support (yet) or we handle ourselves
131 1 our @UNSUPPORTED = qw(H HH pp ppg pn png pr jkn i p);
132  
133  
134 =head2 program_name
135  
136 Title : program_name
137 Usage : $factory>program_name()
138 Function: holds the program name
139 Returns : string
140 Args : None
141  
142 =cut
143  
144 7 ▶sub program_name {
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
145 7 return $PROGRAM_NAME;
146 }
147  
148 =head2 program_dir
149  
150 Title : program_dir
151 Usage : $factory->program_dir(@params)
152 Function: returns the program directory, obtained from ENV variable.
153 Returns : string
154 Args : None
155  
156 =cut
157  
158 4 ▶sub program_dir {
Subroutine program_dir: called CC=1 SCAR=0.0
Pod documented
159 4 return $PROGRAM_DIR;
160 }
161  
162 =head2 new
163  
164 Title : new
165 Usage : $factory = Bio::Tools::Run::Match->new()
166 Function: creates a new MCS factory
167 Returns : Bio::Tools::Run::MCS
168 Args : The following args can either be supplied here or set by calling
169 arg-named methods (eg. $factory->imcut(2) ).
170  
171 -mxlib => path to the matrix.dat file containing Transfac matricies
172 -mxprf => path to a profile file | [core_thresh, [matrix_thresh]]
173 (defaults to a standard one based on the mxlib provided if
174 file not supplied, using core_thresh and matrix_thresh
175 values if those are supplied instead)
176 -imcut => floating point number, the importance cutoff
177 -b | -u => boolean, mutually exclusive
178  
179 =cut
180  
181 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
182 1 my ($class, @args) = @_;
183 1 my $self = $class->SUPER::new(@args);
184
185 1 $self->_set_from_args(\@args, -methods => [@PARAMS, @SWITCHES, 'quiet'],
186 -create => 1);
187
188 1 return $self;
189 }
190  
191 =head2 run
192  
193 Title : run
194 Usage : $result = $factory->run($bio_seqi_object);
195 Function: Runs match on a sequence.
196 Returns : list of Bio::SeqFeatureI feature objects
197 Args : Bio::SeqI compliant object
198  
199 NB: mxlib has to have been set prior to calling run(), either as an
200 argument to new() or by calling mxlib().
201  
202 =cut
203  
204 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
205 0 my ($self, $seq) = @_;
206 0 ▶ $self->mxlib || $self->throw("mxlib has to have been set first");
Branch: 1 branch
BranchTrueFalseTotal
$self->mxlib or $self->throw("mxlib has to have been set first") 0 0 0
207
208 0 return $self->_run($seq);
209 }
210  
211 0 ▶sub _run {
Subroutine _run: not called CC=13 SCAR=52.0
212 0 my ($self, $seq) = @_;
213
214 0 ▶ my $exe = $self->executable || return;
Condition0%0/2
$self->executable || (return)
l!l
00
MC/DC0%0/1
$self->executable || (return)
$self->executable
Truth table0%0/2
A
A= $self->executable
Aresult
11
00
215
216 0 my $mxlib = File::Spec->rel2abs($self->mxlib());
217 0 my $mxprf_file = $self->mxprf();
218 0 ▶ if ($mxprf_file && -e $mxprf_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mxprf_file and -e $mxprf_file) 0 0 0
Condition0%0/3
$mxprf_file and -e $mxprf_file
!ll&&!rl&&r
000
MC/DC0%0/2
$mxprf_file and -e $mxprf_file
$mxprf_file -e $mxprf_file
Truth table0%0/3
A and B
A= $mxprf_fileB= -e $mxprf_file
ABresult
0X0
100
111
219 0 $mxprf_file = File::Spec->rel2abs($mxprf_file);
220 }
221
222 # cd to a temp dir
223 0 my $temp_dir = $self->tempdir;
224 0 my $cwd = Cwd->cwd();
225 0 ▶ chdir($temp_dir) || $self->throw("Couldn't change to temp dir '$temp_dir'");
Branch: 1 branch
BranchTrueFalseTotal
chdir $temp_dir or $self->throw("Couldn't change to temp dir '${temp_dir}'") 0 0 0
226
227 # make the profile file if necessary
228 0 ▶ if (! $mxprf_file || ! -e $mxprf_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mxprf_file and -e $mxprf_file) 0 0 0
Condition0%0/3
$mxprf_file and -e $mxprf_file
!ll&&!rl&&r
000
MC/DC0%0/2
$mxprf_file and -e $mxprf_file
$mxprf_file -e $mxprf_file
Truth table0%0/3
A and B
A= $mxprf_fileB= -e $mxprf_file
ABresult
0X0
100
111
229 0 my @thresh;
230 0 ▶ if ($mxprf_file && ref($mxprf_file) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mxprf_file and ref $mxprf_file eq "ARRAY") 0 0 0
Condition0%0/3
$mxprf_file and ref $mxprf_file eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$mxprf_file and ref $mxprf_file eq "ARRAY"
$mxprf_file ref $mxprf_file eq "ARRAY"
Truth table0%0/3
A and B
A= $mxprf_fileB= ref $mxprf_file eq "ARRAY"
ABresult
0X0
100
111
231 0 @thresh = @{$mxprf_file};
232 }
233
234 0 $mxprf_file = 'mxprf';
235 0 ▶ system("$exe $mxlib ignored ignored $mxprf_file -p @thresh") && $self->throw("Something went wrong whist creating profile: $! | $?");
Branch: 1 branch
BranchTrueFalseTotal
system "$exe $mxlib ignored ignored $mxprf_file -p @thresh" and $self->throw("Something went wrong whist creating profile: $! | $?") 0 0 0
236 }
237
238 # output the sequence to a fasta file
239 0 my $seq_file = 'sequence.fa';
240 0 my $so = Bio::SeqIO->new(-file => ">$seq_file", -format => 'fasta');
241 0 $so->write_seq($seq);
242 0 $so->close();
243
244 # run match
245 0 my $result_file = 'out';
246 0 my $param_str = $self->_setparams();
247 0 my $cmd_line = "$exe $mxlib $seq_file $result_file $mxprf_file".$param_str;
248
249 0 ▶ system($cmd_line) && $self->throw("Something went wrong whist running '$cmd_line': $! | $?");
Branch: 1 branch
BranchTrueFalseTotal
system $cmd_line and $self->throw("Something went wrong whist running '${cmd_line}': $! | $?") 0 0 0
250
251 # parse the results
252 0 my $parser = Bio::Tools::Match->new(-file => $result_file);
253
254 # correct the coords
255 0 my @feats;
256 0 ▶ while (my $feat = $parser->next_result) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $feat = $parser->next_result) 0 0 0
257 0 push(@feats, $feat);
258 }
259
260 # cd back again
261 0 ▶ chdir($cwd) || $self->throw("Couldn't change back to working directory '$cwd'");
Branch: 1 branch
BranchTrueFalseTotal
chdir $cwd or $self->throw("Couldn't change back to working directory '${cwd}'") 0 0 0
262
263 0 return @feats;
264 }
265  
266 =head2 _setparams
267  
268 Title : _setparams
269 Usage : Internal function, not to be called directly
270 Function: Creates a string of params to be used in the command string
271 Returns : string of params
272 Args : none
273  
274 =cut
275  
276 0 ▶sub _setparams {
Subroutine _setparams: not called CC=3 SCAR=24.8
277 0 my $self = shift;
278
279 0 my $param_string = $self->SUPER::_setparams(-switches => \@SWITCHES,
280 -dash => 1);
281
282 0 ▶ my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin/i ? : 0 0 0
283 0 ▶ $param_string .= " 1>$null" if $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $self->quiet 0 0 0
284
285 0 return $param_string;
286 }
287  
288 1 1;
« Tools/Run/Alignment/Amap.pm ↑ Summary Tools/Run/Alignment/MAFFT.pm »