2 # BioPerl module for Bio::AlignIO::psi
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::AlignIO::psi - Read/Write PSI-BLAST profile alignment files
20 This module will parse PSI-BLAST output of the format seqid XXXX
24 This is a parser for psi-blast blocks.
30 User feedback is an integral part of the evolution of this and other
31 Bioperl modules. Send your comments and suggestions preferably to
32 the Bioperl mailing list. Your participation is much appreciated.
34 bioperl-l@bioperl.org - General discussion
35 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
39 Please direct usage questions or support issues to the mailing list:
41 I<bioperl-l@bioperl.org>
43 rather than to the module maintainer directly. Many experienced and
44 reponsive experts will be able look at the problem and quickly
45 address it. Please include a thorough description of the problem
46 with code and data examples if at all possible.
50 Report bugs to the Bioperl bug tracking system to help us keep track
51 of the bugs and their resolution. Bug reports can be submitted via
54 https://github.com/bioperl/bioperl-live/issues
56 =head1 AUTHOR - Jason Stajich
58 Email jason@bioperl.org
62 The rest of the documentation details each of the object methods.
63 Internal methods are usually preceded with a _
68 # Let the code begin...
71 package Bio
::AlignIO
::psi
;
72 use vars
qw($BlockLen $IdLength);
78 # Object preamble - inherits from Bio::Root::Root
81 use Bio::LocatableSeq;
83 use base qw(Bio::AlignIO);
88 Usage : my $obj = Bio::AlignIO::psi->new();
89 Function: Builds a new Bio::AlignIO::psi object
90 Returns : Bio::AlignIO::psi
98 Usage : $aln = $stream->next_aln()
99 Function: returns the next alignment in the stream
100 Returns : Bio::Align::AlignI object
103 See L<Bio::Align::AlignI>
112 while( defined ($_ = $self->_readline ) ) {
114 if( !defined $aln ) {
115 $aln = Bio
::SimpleAlign
->new();
118 push @order, $id if( ! defined $seqs{$id});
121 foreach my $id ( @order) {
122 my $gaps = $seqs{$id} =~ tr/-/-/;
123 my $seq = Bio
::LocatableSeq
->new(-seq
=> $seqs{$id},
126 -end
=> length($seqs{$id}) - $gaps,
127 -alphabet
=> $self->alphabet,
131 return $aln if defined $aln && $aln->num_sequences;
138 Usage : $stream->write_aln(@aln)
139 Function: writes the NCBI psi-format object (.aln) into the stream
140 Returns : 1 for success and 0 for error
141 Args : Bio::Align::AlignI object
143 L<Bio::Align::AlignI>
148 my ($self,$aln) = @_;
149 unless( defined $aln && ref($aln) &&
150 $aln->isa('Bio::Align::AlignI') ) {
151 $self->warn("Must provide a valid Bio::Align::AlignI to write_aln");
155 my @seqs = $aln->each_seq;
157 my $alnlen = $aln->length;
158 my $idlen = $IdLength;
159 my @ids = map { substr($_->display_id,0,$idlen) } @seqs;
160 while( $len < ($alnlen + 1) ) {
162 my $end = $len + $BlockLen;
163 $end = $alnlen if ( $end > $alnlen );
165 foreach my $seq ( @seqs ) {
166 $self->_print(sprintf("%-".$idlen."s %s\n",
168 $seq->subseq($start,$end)));
173 $self->flush if $self->_flush_on_write && defined $self->_fh;