3 # BioPerl module for Bio::AlignIO::psi
5 # Cared for by Jason Stajich <jason@bioperl.org>
7 # Copyright Jason Stajich
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::AlignIO::psi - Read/Write PSI-BLAST profile alignment files
19 This module will parse PSI-BLAST output of the format seqid XXXX
23 This is a parser for psi-blast blocks.
29 User feedback is an integral part of the evolution of this and other
30 Bioperl modules. Send your comments and suggestions preferably to
31 the Bioperl mailing list. Your participation is much appreciated.
33 bioperl-l@bioperl.org - General discussion
34 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
38 Report bugs to the Bioperl bug tracking system to help us keep track
39 of the bugs and their resolution. Bug reports can be submitted via
42 http://bugzilla.open-bio.org/
44 =head1 AUTHOR - Jason Stajich
46 Email jason@bioperl.org
50 The rest of the documentation details each of the object methods.
51 Internal methods are usually preceded with a _
56 # Let the code begin...
59 package Bio
::AlignIO
::psi
;
60 use vars
qw($BlockLen $IdLength);
66 # Object preamble - inherits from Bio::Root::Root
69 use Bio::LocatableSeq;
71 use base qw(Bio::AlignIO);
76 Usage : my $obj = Bio::AlignIO::psi->new();
77 Function: Builds a new Bio::AlignIO::psi object
78 Returns : Bio::AlignIO::psi
86 Usage : $aln = $stream->next_aln()
87 Function: returns the next alignment in the stream
88 Returns : Bio::Align::AlignI object
91 See L<Bio::Align::AlignI>
100 while( defined ($_ = $self->_readline ) ) {
102 if( !defined $aln ) {
103 $aln = Bio
::SimpleAlign
->new();
106 push @order, $id if( ! defined $seqs{$id});
109 foreach my $id ( @order) {
110 my $gaps = $seqs{$id} =~ tr/-/-/;
111 my $seq = Bio
::LocatableSeq
->new(-seq
=> $seqs{$id},
114 -end
=> length($seqs{$id}) - $gaps
124 Usage : $stream->write_aln(@aln)
125 Function: writes the NCBI psi-format object (.aln) into the stream
126 Returns : 1 for success and 0 for error
127 Args : Bio::Align::AlignI object
129 L<Bio::Align::AlignI>
134 my ($self,$aln) = @_;
135 unless( defined $aln && ref($aln) &&
136 $aln->isa('Bio::Align::AlignI') ) {
137 $self->warn("Must provide a valid Bio::Align::AlignI to write_aln");
141 my @seqs = $aln->each_seq;
143 my $alnlen = $aln->length;
144 my $idlen = $IdLength;
145 my @ids = map { substr($_->display_id,0,$idlen) } @seqs;
146 while( $len < ($alnlen + 1) ) {
148 my $end = $len + $BlockLen;
149 $end = $alnlen if ( $end > $alnlen );
151 foreach my $seq ( @seqs ) {
152 $self->_print(sprintf("%-".$idlen."s %s\n",
154 $seq->subseq($start,$end)));
159 $self->flush if $self->_flush_on_write && defined $self->_fh;