File Coverage

blib/lib/Bio/Tools/Run/RepeatMasker.pm
Criterion Covered Total %
statement 44 114 38.6
branch 5 32 15.6
condition 0 6 0.0
subroutine 12 20 60.0
pod 8 8 100.0
total 69 180 38.3


line stmt bran cond sub pod time code
1             # BioPerl module for RepeatMasker
2             #
3             # Please direct questions and support issues to
4             #
5             # Cared for by Shawn Hoon
6             #
7             # Copyright Shawn Hoon
8             #
9             # You may distribute this module under the same terms as perl itself
10              
11             # POD documentation - main docs before the code
12              
13             =head1 NAME
14              
15             Bio::Tools::Run::RepeatMasker - Wrapper for RepeatMasker Program
16              
17             =head1 SYNOPSIS
18              
19             use Bio::Tools::Run::RepeatMasker;
20              
21             my @params=("mam" => 1,"noint"=>1);
22             my $factory = Bio::Tools::Run::RepeatMasker->new(@params);
23             $in = Bio::SeqIO->new(-file => "contig1.fa",
24             -format => 'fasta');
25             my $seq = $in->next_seq();
26              
27             #return an array of Bio::SeqFeature::FeaturePair objects
28             my @feats = $factory->run($seq);
29              
30             # or
31              
32             $factory->run($seq);
33             my @feats = $factory->repeat_features;
34              
35             #return the masked sequence, a Bio::SeqI object
36             my $masked_seq = $factory->run;
37              
38             =head1 DESCRIPTION
39              
40             To use this module, the RepeatMasker program (and probably database) must be
41             installed. RepeatMasker is a program that screens DNA sequences for interspersed
42             repeats known to exist in mammalian genomes as well as for low
43             complexity DNA sequences. For more information, on the program and its
44             usage, please refer to http://www.repeatmasker.org/.
45              
46             Having installed RepeatMasker, you must let Bioperl know where it is.
47             This can be done in (at least) three ways:
48              
49             1. Make sure the RepeatMasker executable is in your path.
50             2. Define an environmental variable REPEATMASKERDIR which is a
51             directory which contains the RepeatMasker executable:
52             In bash:
53              
54             export REPEATMASKERDIR=/home/username/RepeatMasker/
55              
56             In csh/tcsh:
57              
58             setenv REPEATMASKERDIR /home/username/RepeatMasker/
59              
60             3. Include a definition of an environmental variable REPEATMASKERDIR in
61             every script that will use this RepeatMasker wrapper module, e.g.:
62              
63             BEGIN { $ENV{REPEATMASKERDIR} = '/home/username/RepeatMasker/' }
64             use Bio::Tools::Run::RepeatMasker;
65              
66             =head1 FEEDBACK
67              
68             =head2 Mailing Lists
69              
70             User feedback is an integral part of the evolution of this and other
71             Bioperl modules. Send your comments and suggestions preferably to one
72             of the Bioperl mailing lists. Your participation is much appreciated.
73              
74             bioperl-l@bioperl.org - General discussion
75             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
76              
77             =head2 Support
78              
79             Please direct usage questions or support issues to the mailing list:
80              
81             I
82              
83             rather than to the module maintainer directly. Many experienced and
84             reponsive experts will be able look at the problem and quickly
85             address it. Please include a thorough description of the problem
86             with code and data examples if at all possible.
87              
88             =head2 Reporting Bugs
89              
90             Report bugs to the Bioperl bug tracking system to help us keep track
91             the bugs and their resolution. Bug reports can be submitted via the
92             web:
93              
94             http://redmine.open-bio.org/projects/bioperl/
95              
96             =head1 AUTHOR - Shawn Hoon
97              
98              
99             Email shawnh@fugu-sg.org
100              
101              
102             =head1 APPENDIX
103              
104              
105             The rest of the documentation details each of the object
106             methods. Internal methods are usually preceded with a "_".
107              
108             =cut
109              
110              
111             package Bio::Tools::Run::RepeatMasker;
112              
113 1         72 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR $PROGRAMNAME
114 1     1   94691 @RM_SWITCHES @RM_PARAMS @OTHER_SWITCHES %OK_FIELD);
  1         2  
115              
116 1     1   5 use strict;
  1         2  
  1         17  
117 1     1   313 use Bio::SeqFeature::Generic;
  1         64308  
  1         27  
118 1     1   268 use Bio::SeqFeature::FeaturePair;
  1         1467  
  1         25  
119 1     1   6 use Bio::Root::Root;
  1         2  
  1         14  
120 1     1   326 use Bio::Tools::Run::WrapperBase;
  1         2  
  1         23  
121 1     1   284 use Bio::Tools::RepeatMasker;
  1         406  
  1         80  
122              
123              
124             # Let the code begin...
125              
126             @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase );
127              
128             BEGIN {
129 1     1   4 @RM_PARAMS = qw(DIR DIV LIB CUTOFF PARALLEL GC FRAG SPECIES MAXSIZE );
130              
131 1         5 @RM_SWITCHES = qw(NOLOW LOW L NOINT INT NORNA ALU M MUS ROD
132             RODENT MAM MAMMAL COW AR
133             ARABIDOPSIS DR DROSOPHILA EL ELEGANS
134             IS_ONLY IS_CLIP NO_IS RODSPEC E EXCLN
135             NO_ID FIXED XM U GFF ACE POLY X XSMALL SMALL
136             INV A ALIGNMENTS
137             PRIMSPEC W WUBLAST S Q QQ GCCALC NOCUT);
138 1         2 @OTHER_SWITCHES = qw(NOISY QUIET SILENT);
139              
140             # Authorize attribute fields
141 1         3 foreach my $attr ( @RM_PARAMS, @RM_SWITCHES,
142 59         885 @OTHER_SWITCHES) { $OK_FIELD{$attr}++; }
143             }
144              
145             =head2 program_name
146              
147             Title : program_name
148             Usage : $factory>program_name()
149             Function: holds the program name
150             Returns: string
151             Args : None
152              
153             =cut
154              
155             sub program_name {
156 6     6 1 24 return 'RepeatMasker';
157             }
158              
159             =head2 program_dir
160              
161             Title : program_dir
162             Usage : $factory->program_dir(@params)
163             Function: returns the program directory, obtained from ENV variable.
164             Returns: string
165             Args :
166              
167             =cut
168              
169             sub program_dir {
170 3 50   3 1 11 return Bio::Root::IO->catfile($ENV{REPEATMASKERDIR}) if $ENV{REPEATMASKERDIR};
171             }
172              
173              
174             sub AUTOLOAD {
175 3     3   5 my $self = shift;
176 3         4 my $attr = $AUTOLOAD;
177 3         10 $attr =~ s/.*:://;
178 3         6 $attr = uc $attr;
179 3 50       8 $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
180 3 50       8 $self->{$attr} = shift if @_;
181 3         6 return $self->{$attr};
182             }
183              
184             =head2 new
185              
186             Title : new
187             Usage : $rm->new($seq)
188             Function: creates a new wrapper
189             Returns: Bio::Tools::Run::RepeatMasker
190             Args : self
191              
192             =cut
193              
194             sub new {
195 1     1 1 613 my ($class, @args) = @_;
196 1         10 my $self = $class->SUPER::new(@args);
197              
198 1         41 my ($attr, $value);
199             # Need to check that filehandle is not left open here...
200 1         5 while (@args) {
201 4         6 $attr = shift @args;
202 4         5 $value = shift @args;
203 4 100       11 next if( $attr =~ /^-/ ); # don't want named parameters
204 3         17 $self->$attr($value);
205             }
206             # unless ($self->executable()) {
207             # if( $self->verbose >= 0 ) {
208             # warn "RepeatMasker program not found as ".($self->executable||'').
209             # " or not executable. \n";
210             # }
211             # }
212 1         3 return $self;
213             }
214              
215             =head2 version
216              
217             Title : version
218             Usage :
219             Function: Determine the version number of the program
220             Example :
221             Returns : float or undef
222             Args : none
223              
224             =cut
225              
226             sub version {
227 0     0 1   my ($self) = @_;
228 0 0         return $self->{'_version'} if( defined $self->{'_version'} );
229 0           my $exe = $self->executable;
230 0 0         return undef unless $exe;
231 0           my $string = `$exe -- ` ;
232 0 0 0       if( $string =~ /\(([\d.]+)\)/ ||
233             $string =~ /RepeatMasker\s+version\s+(\S+)/ ) {
234 0           return $self->{'_version'} = $1;
235             } else {
236 0           return $self->{'_version'} = undef;
237             }
238              
239             }
240              
241             =head2 run
242              
243             Title : run
244             Usage : $rm->run($seq);
245             Function: Run Repeatmasker on the sequence set as
246             the argument
247             Returns : an array of repeat features that are
248             Bio::SeqFeature::FeaturePairs
249             Args : Bio::PrimarySeqI compliant object
250              
251             =cut
252              
253             sub run {
254 0     0 1   my ($self,$seq) = @_;
255 0           my ($infile);
256 0           $infile = $self->_setinput($seq);
257              
258 0           my $param_string = $self->_setparams();
259 0           my @repeat_feats = $self->_run($infile,$param_string);
260              
261 0           return @repeat_feats;
262             }
263              
264              
265             =head2 mask
266              
267             Title : mask
268             Usage : $rm->mask($seq)
269             Function: This method is deprecated. Call run() instead
270             Example :
271             Returns : an array of repeat features that are
272             Bio::SeqFeature::FeaturePairs
273             Args : Bio::PrimarySeqI compliant object
274              
275             =cut
276              
277             sub mask{
278 0     0 1   return shift->run(@_);
279             }
280              
281              
282             =head2 _run
283              
284             Title : _run
285             Usage : $rm->_run ($filename,$param_string)
286             Function: internal function that runs the repeat masker
287             Example :
288             Returns : an array of repeat features
289             Args : the filename to the input sequence and the parameter string
290              
291             =cut
292              
293             sub _run {
294 0     0     my ($self,$infile,$param_string) = @_;
295 0           my $instring;
296 0           $self->debug( "Program ".$self->executable."\n");
297              
298 0           my $outfile = $infile.".out";
299 0           my $cmd_str = $self->executable." $param_string ". $infile;
300 0           $self->debug("repeat masker command = $cmd_str");
301 0 0 0       if ($self->quiet || $self->verbose <=0){
302 0 0         my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
303 0           $cmd_str.=" 2> $null 1>$null";
304             }
305 0           my $status = system($cmd_str);
306 0 0         $self->throw("Repeat Masker Call($cmd_str) crashed: $?\n")
307             unless $status == 0;
308 0 0         unless (open (RM, $outfile)) {
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){
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     0 1   my ($self,$seq) = @_;
339 0 0         if($seq){
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     0 1   my ($self,$rf) = @_;
358 0 0         if($rf) {
359 0           $self->{'_rf'} = $rf;
360             }
361 0           return @{$self->{'_rf'}};
  0            
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     0     my ($attr, $value, $self);
377              
378 0           $self = shift;
379              
380 0           my $param_string = "";
381 0           for $attr ( @RM_PARAMS ) {
382 0           $value = $self->$attr();
383 0 0         next unless (defined $value);
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 0         next unless ($value);
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     0     my ($self,$seq) = @_;
417 0 0         $seq->isa("Bio::PrimarySeqI") ||
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 object
497             Returns : L
498             Args : none
499              
500              
501             =cut
502              
503             1;