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

filter: Statementstmt 38.9% 46 / 118 Branchbran 18.4% 7 / 38 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 60.0% 12 / 20 Podpod 100% 8 / 8 totaltotal 37.0% 73 / 197 CC 26 SCAR 27.0
CC
26
Cov
32%
_run
42.0
version
30.0
_setparams
30.0
CRAP 14.8
« blib/lib/Bio/DB/SoapEUtilities/DocSumAdaptor.pm ↑ Summary blib/lib/Bio/Tools/Run/Tmhmm.pm »
1 # $Id$
2 # BioPerl module for RepeatMasker
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Shawn Hoon <shawnh@fugu-sg.org>
7 #
8 # Copyright Shawn Hoon
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::RepeatMasker - Wrapper for RepeatMasker Program
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Tools::Run::RepeatMasker;
21  
22 my @params=("mam" => 1,"noint"=>1);
23 my $factory = Bio::Tools::Run::RepeatMasker->new(@params);
24 $in = Bio::SeqIO->new(-file => "contig1.fa",
25 -format => 'fasta');
26 my $seq = $in->next_seq();
27  
28 #return an array of Bio::SeqFeature::FeaturePair objects
29 my @feats = $factory->run($seq);
30  
31 # or
32  
33 $factory->run($seq);
34 my @feats = $factory->repeat_features;
35  
36 #return the masked sequence, a Bio::SeqI object
37 my $masked_seq = $factory->run;
38  
39 =head1 DESCRIPTION
40  
41 To use this module, the RepeatMasker program (and probably database) must be
42 installed. RepeatMasker is a program that screens DNA sequences for interspersed
43 repeats known to exist in mammalian genomes as well as for low
44 complexity DNA sequences. For more information, on the program and its
45 usage, please refer to http://www.repeatmasker.org/.
46  
47 Having installed RepeatMasker, you must let Bioperl know where it is.
48 This can be done in (at least) three ways:
49  
50 1. Make sure the RepeatMasker executable is in your path.
51 2. Define an environmental variable REPEATMASKERDIR which is a
52 directory which contains the RepeatMasker executable:
53 In bash:
54  
55 export REPEATMASKERDIR=/home/username/RepeatMasker/
56  
57 In csh/tcsh:
58  
59 setenv REPEATMASKERDIR /home/username/RepeatMasker/
60  
61 3. Include a definition of an environmental variable REPEATMASKERDIR in
62 every script that will use this RepeatMasker wrapper module, e.g.:
63  
64 BEGIN { $ENV{REPEATMASKERDIR} = '/home/username/RepeatMasker/' }
65 use Bio::Tools::Run::RepeatMasker;
66  
67 =head1 FEEDBACK
68  
69 =head2 Mailing Lists
70  
71 User feedback is an integral part of the evolution of this and other
72 Bioperl modules. Send your comments and suggestions preferably to one
73 of the Bioperl mailing lists. Your participation is much appreciated.
74  
75 bioperl-l@bioperl.org - General discussion
76 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
77  
78 =head2 Support
79  
80 Please direct usage questions or support issues to the mailing list:
81  
82 I<bioperl-l@bioperl.org>
83  
84 rather than to the module maintainer directly. Many experienced and
85 reponsive experts will be able look at the problem and quickly
86 address it. Please include a thorough description of the problem
87 with code and data examples if at all possible.
88  
89 =head2 Reporting Bugs
90  
91 Report bugs to the Bioperl bug tracking system to help us keep track
92 the bugs and their resolution. Bug reports can be submitted via the
93 web:
94  
95 http://redmine.open-bio.org/projects/bioperl/
96  
97 =head1 AUTHOR - Shawn Hoon
98  
99  
100 Email shawnh@fugu-sg.org
101  
102  
103 =head1 APPENDIX
104  
105  
106 The rest of the documentation details each of the object
107 methods. Internal methods are usually preceded with a "_".
108  
109 =cut
110  
111  
112 package Bio::Tools::Run::RepeatMasker;
113  
114 1 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR $PROGRAMNAME
115 1 ▶ @RM_SWITCHES @RM_PARAMS @OTHER_SWITCHES %OK_FIELD);
Subroutine BEGIN: called CC=1 SCAR=0.0
116  
117 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 1 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 1 ▶use Bio::SeqFeature::FeaturePair;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 1 ▶use Bio::Tools::RepeatMasker;
Subroutine BEGIN: called CC=1 SCAR=0.0
123  
124  
125 # Let the code begin...
126  
127 1 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase );
128  
129 BEGIN {
130 1 ▶ @RM_PARAMS = qw(DIR DIV LIB CUTOFF PARALLEL GC FRAG SPECIES MAXSIZE );
Subroutine BEGIN: called CC=2 SCAR=6.9
131  
132 1 @RM_SWITCHES = qw(NOLOW LOW L NOINT INT NORNA ALU M MUS ROD
133 RODENT MAM MAMMAL COW AR
134 ARABIDOPSIS DR DROSOPHILA EL ELEGANS
135 IS_ONLY IS_CLIP NO_IS RODSPEC E EXCLN
136 NO_ID FIXED XM U GFF ACE POLY X XSMALL SMALL
137 INV A ALIGNMENTS
138 PRIMSPEC W WUBLAST S Q QQ GCCALC NOCUT);
139 1 @OTHER_SWITCHES = qw(NOISY QUIET SILENT);
140  
141 # Authorize attribute fields
142 1 foreach my $attr ( @RM_PARAMS, @RM_SWITCHES,
143 59 @OTHER_SWITCHES) { $OK_FIELD{$attr}++; }
144 }
145  
146 =head2 program_name
147  
148 Title : program_name
149 Usage : $factory>program_name()
150 Function: holds the program name
151 Returns: string
152 Args : None
153  
154 =cut
155  
156 sub program_name {
157 6 ▶ return 'RepeatMasker';
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
158 }
159  
160 =head2 program_dir
161  
162 Title : program_dir
163 Usage : $factory->program_dir(@params)
164 Function: returns the program directory, obtained from ENV variable.
165 Returns: string
166 Args :
167  
168 =cut
169  
170 sub program_dir {
171 3 ▶ return Bio::Root::IO->catfile($ENV{REPEATMASKERDIR}) if $ENV{REPEATMASKERDIR};
Subroutine program_dir: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"REPEATMASKERDIR"} 0 3 3
172 }
173  
174  
175 sub AUTOLOAD {
176 3 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=3 SCAR=11.2
177 3 my $attr = $AUTOLOAD;
178 3 $attr =~ s/.*:://;
179 3 $attr = uc $attr;
180 3 ▶ $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Tools::Run::RepeatMasker::OK_FIELD{$attr} 0 3 3
181 3 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 0 3
182 3 return $self->{$attr};
183 }
184  
185 =head2 new
186  
187 Title : new
188 Usage : $rm->new($seq)
189 Function: creates a new wrapper
190 Returns: Bio::Tools::Run::RepeatMasker
191 Args : self
192  
193 =cut
194  
195 sub new {
196 1 ▶ my ($class, @args) = @_;
Subroutine new: called CC=6 SCAR=21.4
Pod documented
197 1 my $self = $class->SUPER::new(@args);
198  
199 1 my ($attr, $value);
200 # Need to check that filehandle is not left open here...
201 1 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 4 1 5
202 4 $attr = shift @args;
203 4 $value = shift @args;
204 4 ▶ next if( $attr =~ /^-/ ); # don't want named parameters
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^-/ 1 3 4
205 3 $self->$attr($value);
206 }
207 1 ▶ unless ($self->executable()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executable) 0 0 0
208 0 ▶ if( $self->verbose >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose >= 0) 0 0 0
209 0 ▶ warn "RepeatMasker program not found as ".($self->executable||'').
Condition0%0/2
$self->executable || ''
l!l
00
MC/DC0%0/1
$self->executable || ''
$self->executable
Truth table0%0/2
A
A= $self->executable
Aresult
11
00
210 " or not executable. \n";
211 }
212 }
213 0 return $self;
214 }
215  
216 =head2 version
217  
218 Title : version
219 Usage :
220 Function: Determine the version number of the program
221 Example :
222 Returns : float or undef
223 Args : none
224  
225 =cut
226  
227 sub version {
228 0 ▶ my ($self) = @_;
Subroutine version: not called CC=5 SCAR=34.0
Pod documented
229 0 ▶ return $self->{'_version'} if( defined $self->{'_version'} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_version"} 0 0 0
230 0 my $exe = $self->executable;
231 0 ▶ return undef unless $exe;
Branch: 1 branch
BranchTrueFalseTotal
unless $exe 0 0 0
232 0 my $string = `$exe -- ` ;
233 0 ▶ if( $string =~ /\(([\d.]+)\)/ ||
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\(([\d.]+)\)/ or $string =~ /RepeatMasker\s+version\s+(\S+)/) { } 0 0 0
Condition0%0/3
$string =~ /\(([\d.]+)\)/ or $string =~ /RepeatMasker\s+version\s+(\S+)/
l!l&&r!l&&!r
000
MC/DC0%0/2
$string =~ /\(([\d.]+)\)/ or $string =~ /RepeatMasker\s+version\s+(\S+)/
$string =~ /\(([\d.]+)\)/ $string =~ /RepeatMasker\s+version\s+(\S+)/
Truth table0%0/3
A or B
A= $string =~ /\(([\d.]+)\)/B= $string =~ /RepeatMasker\s+version\s+(\S+)/
ABresult
1X1
011
000
234 $string =~ /RepeatMasker\s+version\s+(\S+)/ ) {
235 0 return $self->{'_version'} = $1;
236 } else {
237 0 return $self->{'_version'} = undef;
238 }
239
240 }
241  
242 =head2 run
243  
244 Title : run
245 Usage : $rm->run($seq);
246 Function: Run Repeatmasker on the sequence set as
247 the argument
248 Returns : an array of repeat features that are
249 Bio::SeqFeature::FeaturePairs
250 Args : Bio::PrimarySeqI compliant object
251  
252 =cut
253  
254 sub run {
255 0 ▶ my ($self,$seq) = @_;
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
256 0 my ($infile);
257 0 $infile = $self->_setinput($seq);
258  
259 0 my $param_string = $self->_setparams();
260 0 my @repeat_feats = $self->_run($infile,$param_string);
261  
262 0 return @repeat_feats;
263 }
264  
265  
266 =head2 mask
267  
268 Title : mask
269 Usage : $rm->mask($seq)
270 Function: This method is deprecated. Call run() instead
271 Example :
272 Returns : an array of repeat features that are
273 Bio::SeqFeature::FeaturePairs
274 Args : Bio::PrimarySeqI compliant object
275  
276 =cut
277  
278 sub mask{
279 0 ▶ return shift->run(@_);
Subroutine mask: not called CC=1 SCAR=6.9
Pod documented
280 }
281  
282  
283 =head2 _run
284  
285 Title : _run
286 Usage : $rm->_run ($filename,$param_string)
287 Function: internal function that runs the repeat masker
288 Example :
289 Returns : an array of repeat features
290 Args : the filename to the input sequence and the parameter string
291  
292 =cut
293  
294 sub _run {
295 0 ▶ my ($self,$infile,$param_string) = @_;
Subroutine _run: not called CC=6 SCAR=37.4
296 0 my $instring;
297 0 $self->debug( "Program ".$self->executable."\n");
298  
299 0 my $outfile = $infile.".out";
300 0 my $cmd_str = $self->executable." $param_string ". $infile;
301 0 $self->debug("repeat masker command = $cmd_str");
302 0 ▶ if ($self->quiet || $self->verbose <=0){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->quiet or $self->verbose <= 0) 0 0 0
Condition0%0/3
$self->quiet or $self->verbose <= 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->quiet or $self->verbose <= 0
$self->quiet $self->verbose <= 0
Truth table0%0/3
A or B
A= $self->quietB= $self->verbose <= 0
ABresult
1X1
011
000
303 0 $cmd_str.=" 2> /dev/null 1>/dev/null";
304 }
305 0 my $status = system($cmd_str);
306 0 ▶ $self->throw("Repeat Masker Call($cmd_str) crashed: $?\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 0 0 0 0
307 unless $status == 0;
308 0 ▶ unless (open (RM, $outfile)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open RM, $outfile) 0 0 0
309 0 $self->throw("Cannot open RepeatMasker outfile for parsing");
310 }
311 0 my $rpt_parser = Bio::Tools::RepeatMasker->new(-fh=>\*RM);
312 0 my @rpt_feat;
313 0 ▶ while(my $rpt_feat = $rpt_parser->next_result){
Branch: 1 branch
BranchTrueFalseTotal
if (my $rpt_feat = $rpt_parser->next_result) 0 0 0
314 0 push @rpt_feat, $rpt_feat;
315 }
316 0 $self->repeat_features(\@rpt_feat);
317  
318 #get masked sequence
319 0 my $masked = $infile.".masked";
320 0 my $seqio = Bio::SeqIO->new(-file=>$masked,-format=>'FASTA');
321 0 $self->masked_seq($seqio->next_seq);
322  
323 0 return @rpt_feat;
324 }
325  
326 =head2 masked_seq
327  
328 Title : masked_seq
329 Usage : $rm->masked_seq($seq)
330 Function: get/set for masked sequence
331 Example :
332 Returns : the masked sequence
333 Args : Bio::Seq object
334  
335 =cut
336  
337 sub masked_seq {
338 0 ▶ my ($self,$seq) = @_;
Subroutine masked_seq: not called CC=2 SCAR=17.9
Pod documented
339 0 ▶ if($seq){
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 0 0 0
340 0 $self->{'_masked_seq'} = $seq;
341 }
342 0 return $self->{'_masked_seq'};
343 }
344  
345 =head2 repeat_features
346  
347 Title : repeat_features
348 Usage : $rm->repeat_features(\@rf)
349 Function: get/set for repeat features array
350 Example :
351 Returns : the array of repeat features
352 Args :
353  
354 =cut
355  
356 sub repeat_features {
357 0 ▶ my ($self,$rf) = @_;
Subroutine repeat_features: not called CC=2 SCAR=17.9
Pod documented
358 0 ▶ if($rf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rf) 0 0 0
359 0 $self->{'_rf'} = $rf;
360 }
361 0 return @{$self->{'_rf'}};
362 }
363  
364 =head2 _setparams()
365  
366 Title : _setparams
367 Usage : Internal function, not to be called directly
368 Function: Create parameter inputs for repeatmasker program
369 Example :
370 Returns : parameter string to be passed to repeatmasker
371 Args : name of calling object
372  
373 =cut
374  
375 sub _setparams {
376 0 ▶ my ($attr, $value, $self);
Subroutine _setparams: not called CC=5 SCAR=34.0
377  
378 0 $self = shift;
379  
380 0 my $param_string = "";
381 0 for $attr ( @RM_PARAMS ) {
382 0 $value = $self->$attr();
383 0 ▶ next unless (defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
384  
385 0 my $attr_key = lc $attr; #put params in format expected by dba
386  
387 0 $attr_key = ' -'.$attr_key;
388 0 $param_string .= $attr_key.' '.$value;
389 }
390  
391 0 for $attr ( @RM_SWITCHES) {
392 0 $value = $self->$attr();
393 0 ▶ next unless ($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 0 0
394 0 my $attr_key = lc $attr; #put switches in format expected by dba
395 0 $attr_key = ' -'.$attr_key;
396 0 $param_string .= $attr_key ;
397 }
398  
399  
400 0 return $param_string;
401 }
402  
403  
404 =head2 _setinput()
405  
406 Title : _setinput
407 Usage : Internal function, not to be called directly
408 Function: writes input sequence to file and return the file name
409 Example :
410 Returns : string
411 Args : a Bio::PrimarySeqI compliant object
412  
413 =cut
414  
415 sub _setinput {
416 0 ▶ my ($self,$seq) = @_;
Subroutine _setinput: not called CC=2 SCAR=17.9
417 0 ▶ $seq->isa("Bio::PrimarySeqI") ||
Branch: 1 branch
BranchTrueFalseTotal
$seq->isa("Bio::PrimarySeqI") or $self->throw("Need a Bio::PrimarySeq compliant object for RepeatMasker") 0 0 0
418 $self->throw("Need a Bio::PrimarySeq compliant object for RepeatMasker");
419 # my $in = Bio::SeqIO->new(-file => $infilename , '-format' => 'Fasta');
420 0 my ($tfh1,$outfile1) = $self->io->tempfile(-dir=>$self->tempdir);
421 0 my $out1 = Bio::SeqIO->new(-fh=> $tfh1 , '-format' => 'fasta');
422 0 $out1->write_seq($seq);
423 0 close($tfh1);
424 0 undef $tfh1;
425 0 return ($outfile1);
426 }
427  
428  
429  
430 =head1 Bio::Tools::Run::Wrapper methods
431  
432 =cut
433  
434 =head2 no_param_checks
435  
436 Title : no_param_checks
437 Usage : $obj->no_param_checks($newval)
438 Function: Boolean flag as to whether or not we should
439 trust the sanity checks for parameter values
440 Returns : value of no_param_checks
441 Args : newvalue (optional)
442  
443  
444 =cut
445  
446 =head2 save_tempfiles
447  
448 Title : save_tempfiles
449 Usage : $obj->save_tempfiles($newval)
450 Function:
451 Returns : value of save_tempfiles
452 Args : newvalue (optional)
453  
454  
455 =cut
456  
457 =head2 outfile_name
458  
459 Title : outfile_name
460 Usage : my $outfile = $codeml->outfile_name();
461 Function: Get/Set the name of the output file for this run
462 (if you wanted to do something special)
463 Returns : string
464 Args : [optional] string to set value to
465  
466  
467 =cut
468  
469  
470 =head2 tempdir
471  
472 Title : tempdir
473 Usage : my $tmpdir = $self->tempdir();
474 Function: Retrieve a temporary directory name (which is created)
475 Returns : string which is the name of the temporary directory
476 Args : none
477  
478  
479 =cut
480  
481 =head2 cleanup
482  
483 Title : cleanup
484 Usage : $codeml->cleanup();
485 Function: Will cleanup the tempdir directory
486 Returns : none
487 Args : none
488  
489  
490 =cut
491  
492 =head2 io
493  
494 Title : io
495 Usage : $obj->io($newval)
496 Function: Gets a L<Bio::Root::IO> object
497 Returns : L<Bio::Root::IO>
498 Args : none
499  
500  
501 =cut
502  
503 1 1;
504  
505  
« blib/lib/Bio/DB/SoapEUtilities/DocSumAdaptor.pm ↑ Summary blib/lib/Bio/Tools/Run/Tmhmm.pm »