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