1 #-----------------------------------------------------------------------------
2 # PACKAGE : Bio::SeqIO::raw
3 # AUTHOR : Ewan Birney <birney@ebi.ac.uk>
4 # CREATED : Feb 16 1999
7 # Copyright (c) 1997-9 bioperl, Ewan Birney. All Rights Reserved.
8 # This module is free software; you can redistribute it and/or
9 # modify it under the same terms as Perl itself.
13 # Ewan Birney <birney@ebi.ac.uk> developed the SeqIO
14 # schema and the first prototype modules.
16 # This code is based on his Bio::SeqIO::Fasta module with
17 # the necessary minor tweaks necessary to get it to read
18 # and write raw formatted sequences made by
19 # chris dagdigian <dag@sonsorol.org>
21 # October 18, 1999 Largely rewritten by Lincoln Stein
23 # Copyright Ewan Birney
25 # You may distribute this module under the same terms as perl itself
27 # POD documentation - main docs before the code
31 Bio::SeqIO::raw - raw sequence file input/output stream
35 Do not use this module directly. Use it via the L<Bio::SeqIO> class.
39 This object can transform Bio::Seq objects to and from raw flat
46 User feedback is an integral part of the evolution of this and other
47 Bioperl modules. Send your comments and suggestions preferably to one
48 of the Bioperl mailing lists. Your participation is much appreciated.
50 bioperl-l@bioperl.org - General discussion
51 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
55 Please direct usage questions or support issues to the mailing list:
57 L<bioperl-l@bioperl.org>
59 rather than to the module maintainer directly. Many experienced and
60 reponsive experts will be able look at the problem and quickly
61 address it. Please include a thorough description of the problem
62 with code and data examples if at all possible.
66 Report bugs to the Bioperl bug tracking system to help us keep track
67 the bugs and their resolution.
68 Bug reports can be submitted via the web:
70 http://bugzilla.open-bio.org/
74 Ewan Birney E<lt>birney@ebi.ac.ukE<gt>
75 Lincoln Stein E<lt>lstein@cshl.orgE<gt>
79 Jason Stajich E<lt>jason@bioperl.org<gt>
83 The rest of the documentation details each of the object methods.
84 Internal methods are usually preceded with a _
89 # Let the code begin...
91 package Bio
::SeqIO
::raw
;
94 use Bio
::Seq
::SeqFactory
;
96 use base
qw(Bio::SeqIO);
100 $self->SUPER::_initialize
(@args);
101 my ($variant) = $self->_rearrange([qw(VARIANT)], @args);
102 $variant ||= 'multiple';
103 $self->variant($variant);
104 if( ! defined $self->sequence_factory ) {
105 $self->sequence_factory(Bio
::Seq
::SeqFactory
->new
106 (-verbose
=> $self->verbose(),
107 -type
=> 'Bio::Seq'));
115 Usage : $seq = $stream->next_seq()
116 Function: returns the next sequence in the stream
117 Returns : Bio::Seq object
124 my ($self,@args) = @_;
125 ## When its 1 sequence per line with no formatting at all,
126 ## grabbing it should be easy :)
128 ## adding an option to assume the file is one sequence
129 local $/ = $self->{record_separator
};
130 my $nextline = $self->_readline();
131 return unless defined $nextline;
133 my $sequence = uc($nextline);
134 $sequence =~ s/\W//g;
135 return unless $sequence;
136 return $self->sequence_factory->create(-seq
=> $sequence) if $sequence;
142 Usage : $stream->write_seq($seq)
143 Function: writes the $seq object into the stream
144 Returns : 1 for success and 0 for error
145 Args : Array of Bio::PrimarySeqI objects
151 my ($self,@seq) = @_;
152 foreach my $seq (@seq) {
153 $self->throw("Must provide a valid Bio::PrimarySeqI object")
154 unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI');
155 $self->_print($seq->seq, "\n") or return;
157 $self->flush if $self->_flush_on_write && defined $self->_fh;
164 Usage : $stream->write_qual($seq)
165 Function: writes the $seq object into the stream
166 Returns : 1 for success and 0 for error
167 Args : Bio::Seq::Quality object
173 my ($self,@seq) = @_;
176 unless ($_->isa("Bio::Seq::Quality")){
177 warn("You cannot write raw qualities without supplying a Bio::Seq::Quality object! You passed a ", ref($_), "\n");
181 if(scalar(@qual) == 0) {
184 $self->_print (join " ", @qual,"\n") or return;
192 Usage : $format = $obj->variant();
193 Function: Get and set method for the sequence variant. For raw sequence, this
194 indicates whether to treat the input as multiple sequences (the
195 default) or as a single sequence.
197 Current values accepted are:
199 'single' single sequence
200 'multiple' multiple sequences (default)
202 Args : new value, string
207 my ($self, $var) = @_;
208 if (defined $var || !defined $self->{variant
}) {
211 $self->throw("Accepted raw format variants: 'single', 'multiple'") unless
212 $var eq 'single' || $var eq 'multiple';
213 $self->{record_separator
} = $var eq 'single' ?
undef : $/;
214 $self->{variant
} = $var;
216 return $self->{variant
};
219 # private method for testing record separator
222 shift->{record_separator
};