1 #-----------------------------------------------------------------------------
2 # PACKAGE : Bio::SeqIO::raw
3 # AUTHOR : Ewan Birney <birney@ebi.ac.uk>
4 # CREATED : Feb 16 1999
6 # Copyright (c) 1997-9 bioperl, Ewan Birney. All Rights Reserved.
7 # This module is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
12 # Ewan Birney <birney@ebi.ac.uk> developed the SeqIO
13 # schema and the first prototype modules.
15 # This code is based on his Bio::SeqIO::Fasta module with
16 # the necessary minor tweaks necessary to get it to read
17 # and write raw formatted sequences made by
18 # chris dagdigian <dag@sonsorol.org>
20 # October 18, 1999 Largely rewritten by Lincoln Stein
22 # Copyright Ewan Birney
24 # You may distribute this module under the same terms as perl itself
26 # POD documentation - main docs before the code
30 Bio::SeqIO::raw - raw sequence file input/output stream
34 Do not use this module directly. Use it via the L<Bio::SeqIO> class.
38 This object can transform Bio::Seq objects to and from raw flat
45 User feedback is an integral part of the evolution of this and other
46 Bioperl modules. Send your comments and suggestions preferably to one
47 of the Bioperl mailing lists. Your participation is much appreciated.
49 bioperl-l@bioperl.org - General discussion
50 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
54 Please direct usage questions or support issues to the mailing list:
56 I<bioperl-l@bioperl.org>
58 rather than to the module maintainer directly. Many experienced and
59 reponsive experts will be able look at the problem and quickly
60 address it. Please include a thorough description of the problem
61 with code and data examples if at all possible.
65 Report bugs to the Bioperl bug tracking system to help us keep track
66 the bugs and their resolution.
67 Bug reports can be submitted via the web:
69 https://github.com/bioperl/bioperl-live/issues
73 Ewan Birney E<lt>birney@ebi.ac.ukE<gt>
74 Lincoln Stein E<lt>lstein@cshl.orgE<gt>
78 Jason Stajich E<lt>jason@bioperl.org<gt>
82 The rest of the documentation details each of the object methods.
83 Internal methods are usually preceded with a _
88 # Let the code begin...
90 package Bio
::SeqIO
::raw
;
93 use Bio
::Seq
::SeqFactory
;
95 use base
qw(Bio::SeqIO);
97 our %variant = ( 'multiple' => undef, # default
101 my($self,@args) = @_;
102 $self->SUPER::_initialize
(@args);
103 my ($variant) = $self->_rearrange([qw(VARIANT)], @args);
104 $variant ||= 'multiple';
105 $self->variant($variant);
106 $self->{record_separator
} = $variant eq 'single' ?
undef : $/;
107 if( ! defined $self->sequence_factory ) {
108 $self->sequence_factory(Bio
::Seq
::SeqFactory
->new
109 (-verbose
=> $self->verbose(),
110 -type
=> 'Bio::Seq'));
118 Usage : $seq = $stream->next_seq()
119 Function: returns the next sequence in the stream
120 Returns : Bio::Seq object
127 my ($self,@args) = @_;
128 ## When its 1 sequence per line with no formatting at all,
129 ## grabbing it should be easy :)
131 ## adding an option to assume the file is one sequence
132 local $/ = $self->{record_separator
};
133 my $nextline = $self->_readline();
134 return unless defined $nextline;
136 my $sequence = uc($nextline);
137 $sequence =~ s/\W//g;
138 return unless $sequence;
139 return $self->sequence_factory->create(-seq
=> $sequence) if $sequence;
145 Usage : $stream->write_seq($seq)
146 Function: writes the $seq object into the stream
147 Returns : 1 for success and 0 for error
148 Args : Array of Bio::PrimarySeqI objects
154 my ($self,@seq) = @_;
155 foreach my $seq (@seq) {
156 $self->throw("Must provide a valid Bio::PrimarySeqI object")
157 unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI');
158 $self->_print($seq->seq, "\n") or return;
160 $self->flush if $self->_flush_on_write && defined $self->_fh;
167 Usage : $stream->write_qual($seq)
168 Function: writes the $seq object into the stream
169 Returns : 1 for success and 0 for error
170 Args : Bio::Seq::Quality object
176 my ($self,@seq) = @_;
179 unless ($_->isa("Bio::Seq::Quality")){
180 warn("You cannot write raw qualities without supplying a Bio::Seq::".
181 "Quality object! You passed a ".ref($_)."\n");
185 if(scalar(@qual) == 0) {
188 $self->_print (join " ", @qual,"\n") or return;
196 Usage : $format = $obj->variant();
197 Function: Get and set method for the sequence variant. For raw sequence, this
198 indicates whether to treat the input as multiple sequences (the
199 default) or as a single sequence.
201 Current values accepted are:
203 'single' single sequence
204 'multiple' multiple sequences (default)
206 Args : new value, string
210 # variant() method inherited from Bio::Root::IO
212 # private method for testing record separator
215 shift->{record_separator
};