tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / Restriction / IO / bairoch.pm
blobfd8cfdb4dc45536f3b6fe4a0f159fbc2317604f5
1 # $Id$
2 # BioPerl module for Bio::Restriction::IO::withrefm
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
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Restriction::IO::bairoch - bairoch enzyme set
19 =head1 SYNOPSIS
21 Do not use this module directly. Use it via the Bio::Restriction::IO class.
23 =head1 DESCRIPTION
25 This is the most complete format of the REBASE files, and basically
26 includes all the data on each of the restriction enzymes.
28 This parser is for the Bairoch format (aka MacVector, Vector NTI, PC/Gene
29 (Bairoch) format), REBASE format #19
31 =head1 FEEDBACK
33 =head2 Mailing Lists
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to the
37 Bioperl mailing lists Your participation is much appreciated.
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42 =head2 Support
44 Please direct usage questions or support issues to the mailing list:
46 I<bioperl-l@bioperl.org>
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
53 =head2 Reporting Bugs
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 the bugs and their resolution. Bug reports can be submitted via the
57 web:
59 http://bugzilla.open-bio.org/
61 =head1 AUTHOR
63 Rob Edwards, redwards@utmem.edu
65 =head1 CONTRIBUTORS
67 Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
69 =head1 APPENDIX
71 The rest of the documentation details each of the object
72 methods. Internal methods are usually preceded with a _
74 =cut
76 # Let the code begin...
78 package Bio::Restriction::IO::bairoch;
80 use vars qw(%WITH_REFM_FIELD);
81 use strict;
83 use Bio::Restriction::Enzyme;
84 use Bio::Restriction::Enzyme::MultiCut;
85 use Bio::Restriction::Enzyme::MultiSite;
86 use Bio::Restriction::EnzymeCollection;
88 use Data::Dumper;
90 use base qw(Bio::Restriction::IO::base);
92 =head2 read
94 Title : read
95 Usage : $renzs = $stream->read
96 Function: reads all the restrction enzymes from the stream
97 Returns : a Bio::Restriction::Restriction object
98 Args : none
100 =cut
102 sub read {
103 my $self = shift;
105 my $renzs = Bio::Restriction::EnzymeCollection->new(-empty => 1);
107 local $/ = '//';
108 while (defined(my $entry=$self->_readline()) ) {
109 $self->debug("|$entry|\n");
112 # Minimal information
114 my ($name) = $entry =~ /ID\s+(\S+)/;
115 my ($site) = $entry =~ /RS\s+([^\n]+)/;
116 next unless ($name && $site);
118 # the standard sequence format for these guys is:
119 # GATC, 2;
120 # or, for enzymes that cut more than once
121 # GATC, 2; GTAC, 2;
123 # there are a couple of sequences that have multiple
124 # recognition sites.
126 my @sequences;
127 if ($site =~ /\;/) {
128 @sequences = split /\;/, $site;
129 $self->debug(@sequences,"\n");
130 $site=shift @sequences;
133 my ($seq, $cut)=split /,\s+/, $site;
134 $self->debug("SITE: |$site| GAVE: |$seq| and |$cut|\n");
135 if ($seq eq '?') {
136 $self->warn("$name: no site. Skipping") if $self->verbose > 1;
137 next;
140 # this is mainly an error check to make sure that I am adding what I think I am!
141 if ($seq !~ /[NGATC]/i) {
142 $self->throw("Sequence $name has weird sequence: |$seq|");
144 my $re;
145 if ($cut eq "?") {
146 $re = Bio::Restriction::Enzyme->new(-name=>$name, -seq => $seq);
148 else {
149 if ($cut !~ /^-?\d+$/) {
150 $self->throw("Cut site from $name is weird: |$cut|\n");
153 $re = Bio::Restriction::Enzyme->new(-name=>$name,
154 -cut => $cut,
155 -seq => $seq
158 $renzs->enzymes($re);
161 # prototype / isoschizomers
163 my ($prototype) = $entry =~ /PT\s+([^\n]+)/;
165 if ($prototype) {
166 #$re->isoschizomers(split /\,/, $isoschizomers);
167 #NOTE: Need to add a method so that we can add isoschosomers to enzymes that may not exist!
168 $re->is_prototype(0);
169 } else {
170 $re->is_prototype(1);
174 # methylation
177 my ($meth) = $entry =~ /MS\s+([^\n]+)/;
178 my @meths;
179 if ($meth) {
180 # this can be either X(Y) or X(Y),X2(Y2)
181 # where X is the base and y is the type of methylation
182 if ( $meth =~ /(\S+)\((\d+)\),(\S+)\((\d+)\)/ ) { # two msites per site
183 #my ($p1, $m1, $p2, $m2) = ($1, $2, $3, $4);
184 $re->methylation_sites($self->_meth($re,$1, $2),
185 $self->_meth($re,$3,$4));
187 elsif ($meth =~ /(\S+)\((\d+)\)/ ) { # one msite per site or more sites
188 #print Dumper $meth;
189 $re->methylation_sites( $self->_meth($re,$1,$2) );
190 @meths = split /, /, $meth;
191 $meth=shift @meths;
192 } else {
193 $self->warn("Unknown methylation format [$meth]") if $self->verbose >0;
198 # microbe
200 my ($microbe) = $entry =~ /OS\s+([^\n]+)/;
201 $re->microbe($microbe) if $microbe;
204 # source
206 #my ($source) = $entry =~ /<6>([^\n]+)/;
207 #$re->source($source) if $source;
210 # vendors
212 my ($vendors) = $entry =~ /CR\s+([^\n]+)/;
213 $re->vendors(split /,\s*/, $vendors) if $vendors;
216 # references
218 #my ($refs) = $entry =~ /<8>(.+)/s;
219 #$re->references(map {split /\n+/} $refs) if $refs;
222 # create special types of Enzymes
224 $self->warn("Current issues with multisite enzymes using bairoch format\n".
225 "Recommend using itype2 or withrefm formats for now") if @sequences;
226 #$self->_make_multisites($renzs, $re, \@sequences, \@meths) if @sequences;
230 return $renzs;
234 =head2 write
236 Title : write
237 Usage : $stream->write($renzs)
238 Function: writes restriction enzymes into the stream
239 Returns : 1 for success and 0 for error
240 Args : a Bio::Restriction::Enzyme
241 or a Bio::Restriction::EnzymeCollection object
243 =cut
245 sub write {
246 my ($self,@h) = @_;
247 $self->throw_not_implemented;