parser for neo/prototype format from REBASE
[bioperl-live.git] / Bio / Restriction / IO / prototype.pm
blob9659da435aaf93fb7c930563237f9e6352c4b001
1 # $Id: prototype.pm 14572 2008-02-29 05:52:03Z cjfields $
3 # BioPerl module for Bio::Restriction::IO::prototype
5 # Cared for by Chris Fields
7 # Copyright Chris Fields
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
13 =head1 NAME
15 Bio::Restriction::IO::prototype - prototype enzyme set
17 =head1 SYNOPSIS
19 Do not use this module directly. Use it via the Bio::Restriction::IO class.
21 =head1 DESCRIPTION
23 This is a parser for the proto/neo file REBASE format, which contains
24 prototype information as well as (in the neo file) neoschizomer data.
26 =head1 FEEDBACK
28 =head2 Mailing Lists
30 User feedback is an integral part of the evolution of this and other
31 Bioperl modules. Send your comments and suggestions preferably to the
32 Bioperl mailing lists Your participation is much appreciated.
34 bioperl-l@bioperl.org - General discussion
35 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
37 =head2 Reporting Bugs
39 Report bugs to the Bioperl bug tracking system to help us keep track
40 the bugs and their resolution. Bug reports can be submitted via the
41 web:
43 http://bugzilla.open-bio.org/
45 =head1 AUTHOR
47 Rob Edwards, redwards@utmem.edu
49 =head1 CONTRIBUTORS
51 Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
53 =head1 APPENDIX
55 The rest of the documentation details each of the object
56 methods. Internal methods are usually preceded with a _
58 =cut
60 # Let the code begin...
62 package Bio::Restriction::IO::prototype;
64 use vars qw(%WITH_REFM_FIELD);
65 use strict;
67 #use Bio::Restriction::IO;
68 use Bio::Restriction::Enzyme;
69 use Bio::Restriction::EnzymeCollection;
71 use Data::Dumper;
73 use base qw(Bio::Restriction::IO::base);
75 sub new {
76 my($class, @args) = @_;
77 my $self = bless {}, $class;
78 $self->_initialize(@args);
79 return $self;
82 sub _initialize {
83 my($self,@args) = @_;
84 my ($verbose) =
85 $self->_rearrange([qw(
86 VERBOSE
87 )], @args);
88 $verbose || 0;
89 $self->verbose($verbose);
90 return unless $self->SUPER::_initialize(@args);
93 =head2 read
95 Title : read
96 Usage : $renzs = $stream->read
97 Function: reads all the restrction enzymes from the stream
98 Returns : a Bio::Restriction::Restriction object
99 Args : none
101 =cut
103 sub read {
104 my $self = shift;
105 my $coll = Bio::Restriction::EnzymeCollection->new(-empty => 1);
106 my ($seentop, $last_type);
107 while (defined (my $line = $self->_readline)) {
108 chomp $line;
109 next unless $line;
110 if ($line =~ /TYPE\s+(I)+/) {
111 $last_type = $1;
112 $seentop ||= 1;
113 next;
115 next unless $seentop;
116 my @data = split /\s+/,$line,2;
117 next if $data[0] =~ /^[-\s]*$/;
118 # neo
119 my ($enzyme, $is_neo, $is_proto, $site);
120 if ($data[0] =~ /^\s+(\S+)\s+(\S+)/) {
121 ($enzyme, $site, $is_proto, $is_neo) = ($1, $2, 0, 1);
122 } else {
123 ($enzyme, $site, $is_proto, $is_neo) = ($data[0], $data[1], 1, 0);
125 $site =~ s/\s+//g;
127 my $precut;
128 if ($site =~ m/^\((\d+\/\d+)\)[RYATGCN]+/) {
129 $precut=$1;
130 $site =~ s/\($precut\)//;
133 my ($cut, $comp_cut);
134 ($site, $cut, $comp_cut) = $self->_cuts_from_site($site);
136 my $re = Bio::Restriction::Enzyme->new(
137 -type => $last_type,
138 -site => $site,
139 -name => $enzyme,
140 -is_prototype => $is_proto,
141 -is_neoschizomer => $is_neo);
143 if ($cut) {
144 $re->cut($self->_coordinate_shift_to_cut(length($site), $cut));
145 $re->complementary_cut($self->_coordinate_shift_to_cut(length($site), $comp_cut));
148 $coll->enzymes($re);
150 return $coll->enzymes;
153 =head2 write
155 Title : write
156 Usage : $stream->write($renzs)
157 Function: writes restriction enzymes into the stream
158 Returns : 1 for success and 0 for error
159 Args : a Bio::Restriction::Enzyme
160 or a Bio::Restriction::EnzymeCollection object
162 =cut
164 sub write {
165 my ($self,@h) = @_;
166 $self->throw_not_implemented;