Merge pull request #181 from bioperl/limit-dockerhub-trigger
[bioperl-live.git] / Bio / SeqIO / raw.pm
blob7847011d4e7b616b8b757995391ea84a3c1c1cde
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.
10 # _History_
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
28 =head1 NAME
30 Bio::SeqIO::raw - raw sequence file input/output stream
32 =head1 SYNOPSIS
34 Do not use this module directly. Use it via the L<Bio::SeqIO> class.
36 =head1 DESCRIPTION
38 This object can transform Bio::Seq objects to and from raw flat
39 file databases.
41 =head1 FEEDBACK
43 =head2 Mailing Lists
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
52 =head2 Support
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.
63 =head2 Reporting Bugs
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
71 =head1 AUTHORS
73 Ewan Birney E<lt>birney@ebi.ac.ukE<gt>
74 Lincoln Stein E<lt>lstein@cshl.orgE<gt>
76 =head1 CONTRIBUTORS
78 Jason Stajich E<lt>jason@bioperl.org<gt>
80 =head1 APPENDIX
82 The rest of the documentation details each of the object methods.
83 Internal methods are usually preceded with a _
85 =cut
88 # Let the code begin...
90 package Bio::SeqIO::raw;
91 use strict;
93 use Bio::Seq::SeqFactory;
95 use base qw(Bio::SeqIO);
97 our %variant = ( 'multiple' => undef, # default
98 'single' => undef );
100 sub _initialize {
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'));
112 $self->variant;
115 =head2 next_seq
117 Title : next_seq
118 Usage : $seq = $stream->next_seq()
119 Function: returns the next sequence in the stream
120 Returns : Bio::Seq object
121 Args :
124 =cut
126 sub next_seq{
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;
142 =head2 write_seq
144 Title : write_seq
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
151 =cut
153 sub write_seq {
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;
161 return 1;
164 =head2 write_qual
166 Title : write_qual
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
173 =cut
175 sub write_qual {
176 my ($self,@seq) = @_;
177 my @qual = ();
178 foreach (@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");
182 next;
184 @qual = @{$_->qual};
185 if(scalar(@qual) == 0) {
186 $qual[0] = "\n";
188 $self->_print (join " ", @qual,"\n") or return;
190 return 1;
193 =head2 variant
195 Title : variant
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)
205 Returns : string
206 Args : new value, string
208 =cut
210 # variant() method inherited from Bio::Root::IO
212 # private method for testing record separator
214 sub _separator {
215 shift->{record_separator};