File Coverage

Bio/Restriction/IO.pm
Criterion Covered Total %
statement 27 41 65.8
branch 5 12 41.6
condition 3 5 60.0
subroutine 6 11 54.5
pod 5 6 83.3
total 46 75 61.3


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Bio::Restriction::IO
3             #
4             # Please direct questions and support issues to
5             #
6             # Cared for by Rob Edwards
7             #
8             # Copyright Rob Edwards
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::Restriction::IO - Handler for sequence variation IO Formats
17              
18             =head1 SYNOPSIS
19              
20             use Bio::Restriction::IO;
21              
22             $in = Bio::Restriction::IO->new(-file => "inputfilename" ,
23             -format => 'withrefm');
24             my $res = $in->read; # a Bio::Restriction::EnzymeCollection
25              
26             =head1 DESCRIPTION
27              
28             L is a handler module for the formats in the
29             Restriction IO set, e.g. C. It is the
30             officially sanctioned way of getting at the format objects, which most
31             people should use.
32              
33             The structure, conventions and most of the code is inherited from
34             L. The main difference is that instead of using methods
35             C, you drop C<_seq> from the method name.
36              
37             Also, instead of dealing only with individual L
38             objects, C will slurp in all enzymes into a
39             L object.
40              
41             For more details, see documentation in L.
42              
43             =head1 TO DO
44              
45             At the moment, these can be use mainly to get a custom set if enzymes in
46             C or C formats into L or
47             L objects. Using C format is
48             highly experimental and is not recommmended at this time.
49              
50             This class inherits from L for convenience sake, though this should
51             inherit from L. Get rid of L inheritance by
52             copying relevant methods in.
53              
54             C methods are currently not implemented for any format except C.
55             Using C even with C format is not recommended as it does not
56             support multicut/multisite enzyme output.
57              
58             Should additional formats be supported (such as XML)?
59              
60             =head1 SEE ALSO
61              
62             L,
63             L,
64             L
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 the
72             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             https://github.com/bioperl/bioperl-live/issues
95              
96             =head1 AUTHOR
97              
98             Rob Edwards, redwards@utmem.edu
99              
100             =head1 CONTRIBUTORS
101              
102             Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
103              
104             =head1 APPENDIX
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             # Let the code begin...
112              
113             package Bio::Restriction::IO;
114              
115 4     4   906 use strict;
  4         5  
  4         98  
116 4     4   13 use vars qw(%FORMAT);
  4         4  
  4         128  
117 4     4   12 use base qw(Bio::SeqIO);
  4         3  
  4         1402  
118              
119             %FORMAT = (
120             'itype2' => 'itype2',
121             '8' => 'itype2',
122             'withrefm' => 'withrefm',
123             '31' => 'withrefm',
124             'base' => 'base',
125             '0' => 'base',
126             'bairoch' => 'bairoch',
127             '19' => 'bairoch',
128             'macvector' => 'bairoch',
129             'vectorNTI' => 'bairoch',
130             'neo' => 'prototype',
131             'prototype' => 'prototype'
132             );
133              
134             =head2 new
135              
136             Title : new
137             Usage : $stream = Bio::Restriction::IO->new(-file => $filename,
138             -format => 'Format')
139             Function: Returns a new seqstream
140             Returns : A Bio::Restriction::IO::Handler initialised with
141             the appropriate format
142             Args : -file => $filename
143             -format => format
144             -fh => filehandle to attach to
145              
146             =cut
147              
148             sub new {
149 11     11 1 183 my ($class, %param) = @_;
150 11         15 my ($format);
151              
152 11         42 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
  17         39  
153 11 100       46 $format = $FORMAT{$param{'-format'}} if defined $param{'-format'};
154 11   50     58 $format ||= $class->_guess_format( $param{-file} || $ARGV[0] )
      66        
155             || 'base';
156 11         18 $format = "\L$format"; # normalize capitalization to lower case
157              
158 11 50       33 return unless $class->_load_format_module($format);
159 11         131 return "Bio::Restriction::IO::$format"->new(%param);
160             }
161              
162              
163             =head2 format
164              
165             Title : format
166             Usage : $format = $stream->format()
167             Function: Get the restriction format
168             Returns : restriction format
169             Args : none
170              
171             =cut
172              
173             # format() method inherited from Bio::Root::IO
174              
175              
176             sub _load_format_module {
177 11     11   18 my ($class, $format) = @_;
178 11         25 my $module = "Bio::Restriction::IO::" . $format;
179 11         11 my $ok;
180 11         21 eval {
181 11         64 $ok = $class->_load_module($module);
182             };
183 11 50       27 if ( $@ ) {
184 0         0 print STDERR <
185             $class: $format cannot be found
186             Exception $@
187             For more information about the IO system please see the IO docs.
188             This includes ways of checking for formats at compile time, not run time
189             END
190             ;
191             }
192 11         31 return $ok;
193             }
194              
195             =head2 read
196              
197             Title : read
198             Usage : $renzs = $stream->read
199             Function: reads all the restrction enzymes from the stream
200             Returns : a Bio::Restriction::EnzymeCollection object
201             Args :
202              
203             =cut
204              
205             sub read {
206 0     0 1 0 my ($self, $seq) = @_;
207 0         0 $self->throw_not_implemented();
208             }
209              
210             sub next {
211 0     0 0 0 my ($self, $seq) = @_;
212 0         0 $self->throw_not_implemented();
213             }
214              
215             sub next_seq {
216 0     0 1 0 my ($self, $seq) = @_;
217 0         0 $self->throw_not_implemented();
218             }
219              
220             =head2 write
221              
222             Title : write
223             Usage : $stream->write($seq)
224             Function: writes the $seq object into the stream
225             Returns : 1 for success and 0 for error
226             Args : Bio::Restriction::EnzymeCollection object
227              
228             =cut
229              
230             sub write {
231 0     0 1 0 my ($self, $seq) = @_;
232 0         0 $self->throw("Sorry, you cannot write to a generic ".
233             "Bio::Restricion::IO object.");
234             }
235              
236             sub write_seq {
237 0     0 1 0 my ($self, $seq) = @_;
238 0         0 $self->warn("These are not sequence objects. ".
239             "Use method 'write' instead of 'write_seq'.");
240 0         0 $self->write($seq);
241             }
242              
243             =head2 _guess_format
244              
245             Title : _guess_format
246             Usage : $obj->_guess_format($filename)
247             Function:
248             Example :
249             Returns : guessed format of filename (lower case)
250             Args :
251              
252             =cut
253              
254             sub _guess_format {
255 5     5   7 my $class = shift;
256 5 50       36 return unless $_ = shift;
257 0 0         return 'flat' if /\.dat$/i;
258 0 0         return 'xml' if /\.xml$/i;
259             }
260              
261              
262             1;