2 # BioPerl module for Bio::SeqIO::largefasta
4 # Cared for by Jason Stajich
6 # Copyright Jason Stajich
8 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::SeqIO::largefasta - method i/o on very large fasta sequence files
19 Do not use this module directly. Use it via the Bio::SeqIO class.
23 This object can transform Bio::Seq objects to and from fasta flat
26 This module handles very large sequence files by using the
27 Bio::Seq::LargePrimarySeq module to store all the sequence data in
28 a file. This can be a problem if you have limited disk space on your
29 computer because this will effectively cause 2 copies of the sequence
30 file to reside on disk for the life of the
31 Bio::Seq::LargePrimarySeq object. The default location for this is
32 specified by the L<File::Spec>-E<gt>tmpdir routine which is usually /tmp
33 on UNIX. If a sequence file is larger than the swap space (capacity
34 of the /tmp dir) this could cause problems for the machine. It is
35 possible to set the directory where the temporary file is located by
36 adding the following line to your code BEFORE calling next_seq. See
37 L<Bio::Seq::LargePrimarySeq> for more information.
39 $Bio::Seq::LargePrimarySeq::DEFAULT_TEMP_DIR = 'newdir';
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 Report bugs to the Bioperl bug tracking system to help us keep track
55 the bugs and their resolution. Bug reports can be submitted via the web:
57 http://bugzilla.open-bio.org/
59 =head1 AUTHORS - Jason Stajich
61 Email: jason@bioperl.org
65 The rest of the documentation details each of the object
66 methods. Internal methods are usually preceded with a _
70 # Let the code begin...
72 package Bio
::SeqIO
::largefasta
;
73 use vars
qw($FASTALINELEN);
76 use Bio::Seq::SeqFactory;
79 use base qw(Bio::SeqIO);
83 $self->SUPER::_initialize
(@args);
84 if( ! defined $self->sequence_factory ) {
85 $self->sequence_factory(Bio
::Seq
::SeqFactory
->new
86 (-verbose
=> $self->verbose(),
87 -type
=> 'Bio::Seq::LargePrimarySeq'));
94 Usage : $seq = $stream->next_seq()
95 Function: returns the next sequence in the stream
96 Returns : Bio::Seq object
104 my $largeseq = $self->sequence_factory->create();
105 my ($id,$fulldesc,$entry);
108 while( defined ($entry = $self->_readline) ) {
109 if( $seen == 1 && $entry =~ /^\s*>/ ) {
110 $self->_pushback($entry);
113 # if ( ($entry eq '>') || eof($self->_fh) ) { $seen = 1; next; }
114 if ( ($entry eq '>') ) { $seen = 1; next; }
115 elsif( $entry =~ /\s*>(.+?)$/ ) {
117 ($id,$fulldesc) = ($1 =~ /^\s*(\S+)\s*(.*)$/)
118 or $self->warn("Can't parse fasta header");
119 $largeseq->display_id($id);
120 $largeseq->primary_id($id);
121 $largeseq->desc($fulldesc);
124 $largeseq->add_sequence_as_string($entry);
126 (++$count % 1000 == 0 && $self->verbose() > 0) && print "line $count\n";
135 Usage : $stream->write_seq(@seq)
136 Function: writes the $seq object into the stream
137 Returns : 1 for success and 0 for error
138 Args : Bio::Seq object
144 my ($self,@seq) = @_;
145 foreach my $seq (@seq) {
146 my $top = $seq->id();
147 if ($seq->can('desc') and my $desc = $seq->desc()) {
151 $self->_print (">",$top,"\n");
152 my $end = $seq->length();
154 while( $start < $end ) {
155 my $stop = $start + $FASTALINELEN - 1;
156 $stop = $end if( $stop > $end );
157 $self->_print($seq->subseq($start,$stop), "\n");
158 $start += $FASTALINELEN;
162 $self->flush if $self->_flush_on_write && defined $self->_fh;