blib/lib/Bio/Tools/Run/Phylo/Gerp.pm

filter: Statementstmt 48.8% 41 / 84 Branchbran 7.6% 2 / 26 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 80.0% 12 / 15 Podpod 100% 4 / 4 totaltotal 40.2% 60 / 149 CC 19 SCAR 43.0
CC
19
Cov
36%
_run
182.0
run
12.0
_setparams
6.0
CRAP 73.9
« blib/lib/Bio/Tools/Run/Phylo/PhyloBase.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/DBA.pm »
1 # $Id: Gerp.pm,v 1.3 2007/05/25 10:14:55 sendu Exp $
2 #
3 # BioPerl module for Bio::Tools::Run::Phylo::Gerp
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Sendu Bala <bix@sendu.me.uk>
8 #
9 # Copyright Sendu Bala
10 #
11 # You may distribute this module under the same terms as perl itself
12  
13 # POD documentation - main docs before the code
14  
15 =head1 NAME
16  
17 Bio::Tools::Run::Gerp - Wrapper for GERP
18  
19 =head1 SYNOPSIS
20  
21 use Bio::Tools::Run::Phylo::Gerp;
22  
23 # Make a Gerp factory
24 $factory = Bio::Tools::Run::Phylo::Gerp->new();
25  
26 # Run Gerp with an alignment and tree file
27 my $parser = $factory->run($alignfilename, $treefilename);
28  
29 # or with alignment object and tree object (which needs branch lengths)
30 $parser = $factory->run($bio_simplalign, $bio_tree_tree);
31  
32 # (mixtures of the above are possible)
33  
34 # look at the results
35 while (my $feat = $parser->next_result) {
36 my $start = $feat->start;
37 my $end = $feat->end;
38 my $rs_score = $feat->score;
39 my $p_value = ($feat->annotation->get_Annotations('p-value'))[0]->value;
40 }
41  
42 =head1 DESCRIPTION
43  
44 This is a wrapper for running the GERP (v2) programs 'gerpcol' and 'gerpelem' by
45 Eugene Davydov (originally Gregory M. Cooper et al.). You can get details here:
46 http://mendel.stanford.edu/sidowlab/. GERP can be used for phylogenetic
47 footprinting/ shadowing (it finds 'constrained elements in multiple
48 alignments').
49  
50 You can try supplying normal gerpcol/gerpelem command-line arguments to new(),
51 eg. $factory-E<gt>new(-e =E<gt> 0.05) or calling arg-named methods, eg.
52 $factory-E<gt>e(0.05). The filename-related args (t, f, x) are handled internally
53 by the run() method. This wrapper currently only supports running GERP on a
54 single alignment at a time (ie. F isn't used at all, nor are multiple fs
55 possible).
56  
57  
58 You will need to enable this GERP wrapper to find the GERP executables.
59 This can be done in (at least) three ways:
60  
61 1. Make sure gerpcol and gerpelem are in your path.
62 2. Define an environmental variable GERPDIR which is a
63 directory which contains the GERP executables:
64 In bash:
65  
66 export GERPDIR=/home/username/gerp/
67  
68 In csh/tcsh:
69  
70 setenv GERPDIR /home/username/gerp
71  
72 3. Include a definition of an environmental variable GERPDIR in
73 every script that will use this GERP wrapper module, e.g.:
74  
75 BEGIN { $ENV{GERPDIR} = '/home/username/gerp/' }
76 use Bio::Tools::Run::Phylo::Gerp;
77  
78 =head1 FEEDBACK
79  
80 =head2 Mailing Lists
81  
82 User feedback is an integral part of the evolution of this and other
83 Bioperl modules. Send your comments and suggestions preferably to
84 the Bioperl mailing list. Your participation is much appreciated.
85  
86 bioperl-l@bioperl.org - General discussion
87 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
88  
89 =head2 Support
90  
91 Please direct usage questions or support issues to the mailing list:
92  
93 I<bioperl-l@bioperl.org>
94  
95 rather than to the module maintainer directly. Many experienced and
96 reponsive experts will be able look at the problem and quickly
97 address it. Please include a thorough description of the problem
98 with code and data examples if at all possible.
99  
100 =head2 Reporting Bugs
101  
102 Report bugs to the Bioperl bug tracking system to help us keep track
103 of the bugs and their resolution. Bug reports can be submitted via
104 the web:
105  
106 http://redmine.open-bio.org/projects/bioperl/
107  
108 =head1 AUTHOR - Sendu Bala
109  
110 Email bix@sendu.me.uk
111  
112 =head1 APPENDIX
113  
114 The rest of the documentation details each of the object methods.
115 Internal methods are usually preceded with a _
116  
117 =cut
118  
119 package Bio::Tools::Run::Phylo::Gerp;
120 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 1 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 1 ▶use Bio::Tools::Phylo::Gerp;
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129 1 ▶use base qw(Bio::Tools::Run::Phylo::PhyloBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
130  
131 1 our $PROGRAM_NAME = 'gerpcol';
132 1 our $PROGRAM_DIR;
133  
134 # methods for the gerp args we support
135 1 our @COLPARAMS = qw(r n s);
136 1 our @ELEMPARAMS = qw(l L t d p b a c r e);
137 1 our @SWITCHES = qw(v);
138  
139 # just to be explicit, args we don't support (yet) or we handle ourselves
140 1 our @UNSUPPORTED = qw(h t f F x);
141  
142 BEGIN {
143 # lets add all the gerp executables to the path
144 1 ▶ $PROGRAM_DIR = $ENV{'GERPDIR'};
Subroutine BEGIN: called CC=2 SCAR=7.2
145 1 ▶ $ENV{PATH} = "$PROGRAM_DIR:$ENV{PATH}" if $PROGRAM_DIR;
Branch: 1 branch
BranchTrueFalseTotal
if $Bio::Tools::Run::Phylo::Gerp::PROGRAM_DIR 0 1 1
146 }
147  
148 =head2 program_name
149  
150 Title : program_name
151 Usage : $factory>program_name()
152 Function: holds the program name
153 Returns : string
154 Args : None
155  
156 =cut
157  
158 sub program_name {
159 7 ▶ my $self = shift;
Subroutine program_name: called CC=3 SCAR=13.3
Pod documented
160 7 ▶ if (@_) { $self->{program_name} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 7 7
161 7 ▶ return $self->{program_name} || $PROGRAM_NAME;
Condition33%1/3
$self->{'program_name'} || $Bio::Tools::Run::Phylo::Gerp::PROGRAM_NAME
l!l&&r!l&&!r
070
MC/DC0%0/2
$self->{'program_name'} || $Bio::Tools::Run::Phylo::Gerp::PROGRAM_NAME
$self->{'program_name'} $Bio::Tools::Run::Phylo::Gerp::PROGRAM_NAME
Truth table33%1/3
A || B
A= $self->{'program_name'}B= $Bio::Tools::Run::Phylo::Gerp::PROGRAM_NAME
ABresult
1X1
011
000
162 }
163  
164 =head2 program_dir
165  
166 Title : program_dir
167 Usage : $factory->program_dir(@params)
168 Function: returns the program directory, obtained from ENV variable.
169 Returns : string
170 Args : None
171  
172 =cut
173  
174 sub program_dir {
175 4 ▶ return $PROGRAM_DIR;
Subroutine program_dir: called CC=1 SCAR=0.0
Pod documented
176 }
177  
178 =head2 new
179  
180 Title : new
181 Usage : $factory = Bio::Tools::Run::Phylo::Gerp->new()
182 Function: creates a new GERP factory
183 Returns : Bio::Tools::Run::Phylo::Gerp
184 Args : Most options understood by GERP can be supplied as key =>
185 value pairs.
186  
187 These options can NOT be used with this wrapper:
188 h, t, f, F and x
189  
190 =cut
191  
192 sub new {
193 1 ▶ my ($class, @args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
194 1 my $self = $class->SUPER::new(@args);
195
196 1 $self->_set_from_args(\@args, -methods => [@COLPARAMS, @ELEMPARAMS,
197 @SWITCHES, 'quiet'],
198 -create => 1);
199
200 1 return $self;
201 }
202  
203 =head2 run
204  
205 Title : run
206 Usage : $parser = $factory->run($align_file, $tree_file);
207 -or-
208 $parser = $factory->run($align_object, $tree_object);
209 Function: Runs GERP on an alignment.
210 Returns : Bio::Tools::Phylo::Gerp parser object, containing the results
211 Args : The first argument represents an alignment, the second argument
212 a phylogenetic tree with branch lengths.
213 The alignment can be provided as a MAF format alignment
214 filename, or a Bio::Align::AlignI complient object (eg. a
215 Bio::SimpleAlign).
216 The species tree can be provided as a newick format tree filename
217 or a Bio::Tree::TreeI complient object.
218  
219 In all cases, the alignment sequence names must correspond to node
220 ids in the tree. Multi-word species names should have the
221 spaces replaced with underscores (eg. Homo_sapiens)
222  
223 =cut
224  
225 sub run {
226 0 ▶ my ($self, $aln, $tree) = @_;
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
227 0 ▶ $self->_alignment($aln || $self->throw("An alignment must be supplied"));
Condition0%0/3
$aln || $self->throw('An alignment must be supplied')
l!l&&r!l&&!r
000
MC/DC0%0/2
$aln || $self->throw('An alignment must be supplied')
$aln $self->throw('An alignment must be supplied')
Truth table0%0/3
A || B
A= $alnB= $self->throw('An alignment must be supplied')
ABresult
1X1
011
000
228 0 ▶ $self->_tree($tree || $self->throw("A phylo tree must be supplied"));
Condition0%0/3
$tree || $self->throw('A phylo tree must be supplied')
l!l&&r!l&&!r
000
MC/DC0%0/2
$tree || $self->throw('A phylo tree must be supplied')
$tree $self->throw('A phylo tree must be supplied')
Truth table0%0/3
A || B
A= $treeB= $self->throw('A phylo tree must be supplied')
ABresult
1X1
011
000
229
230 # check node and seq names match
231 0 $self->_check_names;
232
233 0 return $self->_run;
234 }
235  
236 sub _run {
237 0 ▶ my $self = shift;
Subroutine _run: not called CC=13 SCAR=52.0
238
239 0 ▶ $self->executable || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->executable or return 0 0 0
240
241 # cd to a temp dir
242 0 my $temp_dir = $self->tempdir;
243 0 my $cwd = Cwd->cwd();
244 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
245
246 0 foreach my $prog ('gerpcol', 'gerpelem') {
247 0 delete $self->{'_pathtoexe'};
248 0 $self->program_name($prog);
249 0 ▶ my $exe = $self->executable || $self->throw("'$prog' executable not found");
Condition0%0/3
$self->executable || $self->throw("'${prog}' executable not found")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->executable || $self->throw("'${prog}' executable not found")
$self->executable $self->throw("'${prog}' executable not found")
Truth table0%0/3
A || B
A= $self->executableB= $self->throw("'${prog}' executable not found")
ABresult
1X1
011
000
250
251 0 my $command = $exe.$self->_setparams($prog);
252 0 $self->debug("gerp command = $command\n");
253
254 #eval {
255 # local $SIG{ALRM} = sub { die "alarm\n" };
256 # alarm 60;
257 # system($command) && $self->throw("gerp call ($command) failed: $! | $?");
258 # alarm 0;
259 #};
260 #die if $@ && $@ ne "alarm\n";
261 #if ($@) {
262 # die "Gerp timed out\n";
263 #}
264 #
265 # system("rm -fr $cwd/gerp_dir; cp -R $temp_dir $cwd/gerp_dir");
266
267 0 ▶ open(my $pipe, "$command |") || $self->throw("gerp call ($command) failed to start: $? | $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $pipe, "$command |" or $self->throw("gerp call ($command) failed to start: $? | $!") 0 0 0
268 0 my $error = '';
269 0 my $warning = '';
270 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
271 0 ▶ if ($self->quiet) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->quiet) { } 0 0 0
272 0 $error .= $_;
273 0 ▶ $warning .= $_ if /warning/i;
Branch: 1 branch
BranchTrueFalseTotal
if /warning/i 0 0 0
274 }
275 else {
276 0 print;
277 }
278 }
279 0 ▶ close($pipe) || ($error ? $self->throw("gerp call ($command) failed: $error") : $self->throw("gerp call ($command) crashed: $?"));
Branch: 2 branches
BranchTrueFalseTotal
close $pipe or $error ? $self->throw("gerp call ($command) failed: $error") : $self->throw("gerp call ($command) crashed: $?") 0 0 0
$error ? : 0 0 0
280
281 # (throws most likely due to seg fault in gerpelem when ~25000 entries
282 # in rates file, not much I can do about it!)
283
284 0 ▶ $self->warn("GERP: ".$warning) if $warning;
Branch: 1 branch
BranchTrueFalseTotal
if $warning 0 0 0
285 }
286
287 #system("rm -fr $cwd/gerp_dir; cp -R $temp_dir $cwd/gerp_dir");
288
289 0 my $result_file = $self->{align_base}.'.rates.elems';
290 0 my $parser = Bio::Tools::Phylo::Gerp->new(-file => $result_file);
291
292 # cd back again
293 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
294
295 0 return $parser;
296 }
297  
298 =head2 _setparams
299  
300 Title : _setparams
301 Usage : Internal function, not to be called directly
302 Function: Creates a string of params to be used in the command string
303 Returns : string of params
304 Args : none
305  
306 =cut
307  
308 sub _setparams {
309 0 ▶ my ($self, $prog) = @_;
Subroutine _setparams: not called CC=2 SCAR=17.9
310
311 0 my $param_string;
312 0 ▶ if ($prog eq 'gerpcol') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq 'gerpcol') { } 0 0 0
313 0 my $align_file = $self->_write_alignment;
314 0 $param_string .= ' -f '.$align_file;
315 0 $self->{align_base} = basename($align_file);
316 0 $param_string .= ' -t '.$self->_write_tree;
317 0 $param_string .= $self->SUPER::_setparams(-params => \@COLPARAMS,
318 -switches => \@SWITCHES,
319 -dash => 1);
320 }
321 else {
322 0 $param_string .= ' -f '.$self->{align_base}.'.rates';
323 0 $param_string .= $self->SUPER::_setparams(-params => \@ELEMPARAMS,
324 -switches => \@SWITCHES,
325 -dash => 1);
326 }
327
328 0 $param_string .= " 2>&1";
329
330 0 return $param_string;
331 }
332  
333 1 1;
« blib/lib/Bio/Tools/Run/Phylo/PhyloBase.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/DBA.pm »