Pull out the 'recommends' table and refactor to make a bit more
[bioperl-live.git] / Bio / Restriction / IO.pm
blobb33728fe29c1204400f7fa49f37d86f4a55d54ab
2 # BioPerl module for Bio::Restriction::IO
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Rob Edwards <redwards@utmem.edu>
8 # Copyright Rob Edwards
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Restriction::IO - Handler for sequence variation IO Formats
18 =head1 SYNOPSIS
20 use Bio::Restriction::IO;
22 $in = Bio::Restriction::IO->new(-file => "inputfilename" ,
23 -format => 'withrefm');
24 my $res = $in->read; # a Bio::Restriction::EnzymeCollection
26 =head1 DESCRIPTION
28 L<Bio::Restriction::IO> is a handler module for the formats in the
29 Restriction IO set, e.g. C<Bio::Restriction::IO::xxx>. It is the
30 officially sanctioned way of getting at the format objects, which most
31 people should use.
33 The structure, conventions and most of the code is inherited from
34 L<Bio::SeqIO>. The main difference is that instead of using methods
35 C<next_seq>, you drop C<_seq> from the method name.
37 Also, instead of dealing only with individual L<Bio::Restriction::Enzyme>
38 objects, C<read()> will slurp in all enzymes into a
39 L<Bio::Restriction::EnzymeCollection> object.
41 For more details, see documentation in L<Bio::SeqIO>.
43 =head1 TO DO
45 At the moment, these can be use mainly to get a custom set if enzymes in
46 C<withrefm> or C<itype2> formats into L<Bio::Restriction::Enzyme> or
47 L<Bio::Restriction::EnzymeCollection> objects. Using C<bairoch> format is
48 highly experimental and is not recommmended at this time.
50 This class inherits from L<Bio::SeqIO> for convenience sake, though this should
51 inherit from L<Bio::Root::Root>. Get rid of L<Bio::SeqIO> inheritance by
52 copying relevant methods in.
54 C<write()> methods are currently not implemented for any format except C<base>.
55 Using C<write()> even with C<base> format is not recommended as it does not
56 support multicut/multisite enzyme output.
58 Should additional formats be supported (such as XML)?
60 =head1 SEE ALSO
62 L<Bio::SeqIO>,
63 L<Bio::Restriction::Enzyme>,
64 L<Bio::Restriction::EnzymeCollection>
66 =head1 FEEDBACK
68 =head2 Mailing Lists
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.
74 bioperl-l@bioperl.org - General discussion
75 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
77 =head2 Support
79 Please direct usage questions or support issues to the mailing list:
81 I<bioperl-l@bioperl.org>
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.
88 =head2 Reporting Bugs
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:
94 https://redmine.open-bio.org/projects/bioperl/
96 =head1 AUTHOR
98 Rob Edwards, redwards@utmem.edu
100 =head1 CONTRIBUTORS
102 Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
104 =head1 APPENDIX
106 The rest of the documentation details each of the object
107 methods. Internal methods are usually preceded with a _
109 =cut
111 # Let the code begin...
113 package Bio::Restriction::IO;
115 use strict;
116 use vars qw(%FORMAT);
117 use base qw(Bio::SeqIO);
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'
134 =head2 new
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
146 =cut
148 sub new {
149 my ($class, %param) = @_;
150 my ($format);
152 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
153 $format = $FORMAT{$param{'-format'}} if defined $param{'-format'};
154 $format ||= $class->_guess_format( $param{-file} || $ARGV[0] )
155 || 'base';
156 $format = "\L$format"; # normalize capitalization to lower case
158 return unless $class->_load_format_module($format);
159 return "Bio::Restriction::IO::$format"->new(%param);
163 sub _load_format_module {
164 my ($class, $format) = @_;
165 my $module = "Bio::Restriction::IO::" . $format;
166 my $ok;
167 eval {
168 $ok = $class->_load_module($module);
170 if ( $@ ) {
171 print STDERR <<END;
172 $class: $format cannot be found
173 Exception $@
174 For more information about the IO system please see the IO docs.
175 This includes ways of checking for formats at compile time, not run time
179 return $ok;
182 =head2 read
184 Title : read
185 Usage : $renzs = $stream->read
186 Function: reads all the restrction enzymes from the stream
187 Returns : a Bio::Restriction::EnzymeCollection object
188 Args :
190 =cut
192 sub read {
193 my ($self, $seq) = @_;
194 $self->throw_not_implemented();
197 sub next {
198 my ($self, $seq) = @_;
199 $self->throw_not_implemented();
202 sub next_seq {
203 my ($self, $seq) = @_;
204 $self->throw_not_implemented();
207 =head2 write
209 Title : write
210 Usage : $stream->write($seq)
211 Function: writes the $seq object into the stream
212 Returns : 1 for success and 0 for error
213 Args : Bio::Restriction::EnzymeCollection object
215 =cut
217 sub write {
218 my ($self, $seq) = @_;
219 $self->throw("Sorry, you cannot write to a generic ".
220 "Bio::Restricion::IO object.");
223 sub write_seq {
224 my ($self, $seq) = @_;
225 $self->warn("These are not sequence objects. ".
226 "Use method 'write' instead of 'write_seq'.");
227 $self->write($seq);
230 =head2 _guess_format
232 Title : _guess_format
233 Usage : $obj->_guess_format($filename)
234 Function:
235 Example :
236 Returns : guessed format of filename (lower case)
237 Args :
239 =cut
241 sub _guess_format {
242 my $class = shift;
243 return unless $_ = shift;
244 return 'flat' if /\.dat$/i;
245 return 'xml' if /\.xml$/i;