1 # BioPerl module for Bio::SeqIO::largefasta
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 # Cared for by Jason Stajich
7 # Copyright Jason Stajich
9 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::SeqIO::largefasta - method i/o on very large fasta sequence files
20 Do not use this module directly. Use it via the Bio::SeqIO class.
24 This object can transform Bio::Seq objects to and from fasta flat
27 This module handles very large sequence files by using the
28 Bio::Seq::LargePrimarySeq module to store all the sequence data in
29 a file. This can be a problem if you have limited disk space on your
30 computer because this will effectively cause 2 copies of the sequence
31 file to reside on disk for the life of the
32 Bio::Seq::LargePrimarySeq object. The default location for this is
33 specified by the L<File::Spec>-E<gt>tmpdir routine which is usually /tmp
34 on UNIX. If a sequence file is larger than the swap space (capacity
35 of the /tmp dir) this could cause problems for the machine. It is
36 possible to set the directory where the temporary file is located by
37 adding the following line to your code BEFORE calling next_seq. See
38 L<Bio::Seq::LargePrimarySeq> for more information.
40 $Bio::Seq::LargePrimarySeq::DEFAULT_TEMP_DIR = 'newdir';
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 I<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. Bug reports can be submitted via the web:
69 https://github.com/bioperl/bioperl-live/issues
71 =head1 AUTHORS - Jason Stajich
73 Email: jason@bioperl.org
77 The rest of the documentation details each of the object
78 methods. Internal methods are usually preceded with a _
82 # Let the code begin...
84 package Bio
::SeqIO
::largefasta
;
85 use vars
qw($FASTALINELEN);
88 use Bio::Seq::SeqFactory;
91 use base qw(Bio::SeqIO);
95 $self->SUPER::_initialize
(@args);
96 if( ! defined $self->sequence_factory ) {
97 $self->sequence_factory(Bio
::Seq
::SeqFactory
->new
98 (-verbose
=> $self->verbose(),
99 -type
=> 'Bio::Seq::LargePrimarySeq'));
106 Usage : $seq = $stream->next_seq()
107 Function: returns the next sequence in the stream
108 Returns : A Bio::Seq::LargePrimarySeq object
116 my $largeseq = $self->sequence_factory->create();
117 my ($id,$fulldesc,$entry);
120 while( defined ($entry = $self->_readline) ) {
121 if( $seen == 1 && $entry =~ /^\s*>/ ) {
122 $self->_pushback($entry);
125 # if ( ($entry eq '>') || eof($self->_fh) ) { $seen = 1; next; }
126 if ( ($entry eq '>') ) { $seen = 1; next; }
127 elsif( $entry =~ /\s*>(.+?)$/ ) {
129 ($id,$fulldesc) = ($1 =~ /^\s*(\S+)\s*(.*)$/)
130 or $self->warn("Can't parse fasta header");
131 $largeseq->display_id($id);
132 $largeseq->primary_id($id);
133 $largeseq->desc($fulldesc);
136 $largeseq->add_sequence_as_string($entry);
138 (++$count % 1000 == 0 && $self->verbose() > 0) && print "line $count\n";
147 Usage : $stream->write_seq(@seq)
148 Function: writes the $seq object into the stream
149 Returns : 1 for success and 0 for error
150 Args : Bio::Seq object
156 my ($self,@seq) = @_;
157 foreach my $seq (@seq) {
158 my $top = $seq->id();
159 if ($seq->can('desc') and my $desc = $seq->desc()) {
163 $self->_print (">",$top,"\n");
164 my $end = $seq->length();
166 while( $start <= $end ) {
167 my $stop = $start + $FASTALINELEN - 1;
168 $stop = $end if( $stop > $end );
169 $self->_print($seq->subseq($start,$stop), "\n");
170 $start += $FASTALINELEN;
174 $self->flush if $self->_flush_on_write && defined $self->_fh;