Bio::AlignIO fasta
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
Bio::AlignIO::fasta - FastA MSA Sequence input/output stream
Package variables
No package variables defined.
Included modules
Bio::AlignIO
Bio::SimpleAlign
Inherit
Bio::AlignIO
Synopsis
Do not use this module directly. Use it via the Bio::AlignIO class.
Description
This object can transform Bio::SimpleAlign objects to and from
fasta flat file databases. This is for the fasta sequence format NOT
FastA analysis program. To process the pairwise alignments from a
FastA (FastX, FastN, FastP, tFastA, etc) use the Bio::SearchIO module.
Methods
next_alnDescriptionCode
write_alnDescriptionCode
Methods description
next_alncode    nextTop
 Title   : next_aln
Usage : $aln = $stream->next_aln()
Function: returns the next alignment in the stream.
Returns : Bio::Align::AlignI object - returns 0 on end of file
or on error
Args : NONE
write_alncodeprevnextTop
 Title   : write_aln
Usage : $stream->write_aln(@aln)
Function: writes the $aln object into the stream in fasta format
Returns : 1 for success and 0 for error
Args : Bio::Align::AlignI object
Methods code
next_alndescriptionprevnextTop
sub next_aln {
    my $self = shift;
    my $entry;
    my ($start,$end,$name,$seqname,$seq,$seqchar,$tempname,%align);
    my $aln =  Bio::SimpleAlign->new();

    while(defined ($entry = $self->_readline)) {
	if($entry =~ /^>(\S+)/ ) {
	    $tempname = $1;
	    if( defined $name ) {
		# put away last name and sequence
if( $name =~ /(\S+)\/(\d+)-(\d+)/ ) { $seqname = $1; $start = $2; $end = $3; } else { $seqname=$name; $start = 1; $end = length($seqchar); #ps 9/6/00
} # print STDERR "Going to add with $seqchar $seqname\n";
$seq = new Bio::LocatableSeq('-seq'=>$seqchar, '-id'=>$seqname, '-start'=>$start, '-end'=>$end, ); $aln->add_seq($seq); } $name = $tempname; $seqchar = ""; next; } $entry =~ s/[^A-Za-z\.\-]//g; $seqchar .= $entry; } #
# Next two lines are to silence warnings that
# otherwise occur at EOF when using <$fh>
if (!defined $name) {$name="";} if (!defined $seqchar) {$seqchar="";} # Put away last name and sequence
if( $name =~ /(\S+)\/(\d+)-(\d+)/ ) { $seqname = $1; $start = $2; $end = $3; } else { $seqname=$name; $start = 1; $end = length($seqchar); #ps 9/6/00
# $end = length($align{$name});
} # If $end <= 0, we have either reached the end of
# file in <> or we have encountered some other error
#
if ($end <= 0) { undef $aln; return $aln;} # This logic now also reads empty lines at the
# end of the file. Skip this is seqchar and seqname is null
if( length($seqchar) == 0 && length($seqname) == 0 ) { # skip
} else { # print STDERR "end to add with $seqchar $seqname\n";
$seq = new Bio::LocatableSeq('-seq'=>$seqchar, '-id'=>$seqname, '-start'=>$start, '-end'=>$end, ); $aln->add_seq($seq); } return $aln;
}
write_alndescriptionprevnextTop
sub write_aln {
    my ($self,@aln) = @_;
    my ($seq,$rseq,$name,$count,$length,$seqsub);

    foreach my $aln (@aln) {
	if( ! $aln || ! $aln->isa('Bio::Align::AlignI')  ) { 
	    $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
	    next;
	}
	foreach $rseq ( $aln->each_seq() ) {
	    $name = $aln->displayname($rseq->get_nse());
	    $seq  = $rseq->seq();	
	    $self->_print (">$name\n") or return ;	
	    $count =0;
	    $length = length($seq);
	    while( ($count * 60 ) < $length ) {
		$seqsub = substr($seq,$count*60,60);
		$self->_print ("$seqsub\n") or return ;
		$count++;
	    }
	}
    }
    $self->flush if $self->_flush_on_write && defined $self->_fh;
    return 1;
}

1;
}
General documentation
FEEDBACKTop
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via email
or the web:
  bioperl-bugs@bio.perl.org
http://bugzilla.bioperl.org/
AUTHORS - Peter SchattnerTop
Email: schattner@alum.mit.edu
APPENDIXTop
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _