changes all issue tracking in preparation for switch to github issues
[bioperl-live.git] / Bio / Restriction / IO.pm
blob7b060b7f7f3a1961b136598a5288c53cab4ad8cd
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://github.com/bioperl/bioperl-live/issues
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 =head2 format
165 Title : format
166 Usage : $format = $stream->format()
167 Function: Get the restriction format
168 Returns : restriction format
169 Args : none
171 =cut
173 # format() method inherited from Bio::Root::IO
176 sub _load_format_module {
177 my ($class, $format) = @_;
178 my $module = "Bio::Restriction::IO::" . $format;
179 my $ok;
180 eval {
181 $ok = $class->_load_module($module);
183 if ( $@ ) {
184 print STDERR <<END;
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
192 return $ok;
195 =head2 read
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 :
203 =cut
205 sub read {
206 my ($self, $seq) = @_;
207 $self->throw_not_implemented();
210 sub next {
211 my ($self, $seq) = @_;
212 $self->throw_not_implemented();
215 sub next_seq {
216 my ($self, $seq) = @_;
217 $self->throw_not_implemented();
220 =head2 write
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
228 =cut
230 sub write {
231 my ($self, $seq) = @_;
232 $self->throw("Sorry, you cannot write to a generic ".
233 "Bio::Restricion::IO object.");
236 sub write_seq {
237 my ($self, $seq) = @_;
238 $self->warn("These are not sequence objects. ".
239 "Use method 'write' instead of 'write_seq'.");
240 $self->write($seq);
243 =head2 _guess_format
245 Title : _guess_format
246 Usage : $obj->_guess_format($filename)
247 Function:
248 Example :
249 Returns : guessed format of filename (lower case)
250 Args :
252 =cut
254 sub _guess_format {
255 my $class = shift;
256 return unless $_ = shift;
257 return 'flat' if /\.dat$/i;
258 return 'xml' if /\.xml$/i;