3 # BioPerl module for Bio::AlignIO::pfam
5 # based on the Bio::SeqIO:: modules
6 # by Ewan Birney <birney@ebi.ac.uk>
7 # and Lincoln Stein <lstein@cshl.org>
9 # and the SimpleAlign.pm module of Ewan Birney
11 # Copyright Peter Schattner
13 # You may distribute this module under the same terms as perl itself
16 # POD documentation - main docs before the code
20 Bio::AlignIO::pfam - pfam sequence input/output stream
24 Do not use this module directly. Use it via the L<Bio::AlignIO> class.
28 This object can transform Bio::SimpleAlign objects to and from pfam flat
35 Report bugs to the Bioperl bug tracking system to help us keep track
36 the bugs and their resolution. Bug reports can be submitted via the
39 http://bugzilla.open-bio.org/
41 =head1 AUTHORS - Peter Schattner
43 Email: schattner@alum.mit.edu
48 The rest of the documentation details each of the object
49 methods. Internal methods are usually preceded with a _
53 # Let the code begin...
55 package Bio
::AlignIO
::pfam
;
59 use base
qw(Bio::AlignIO);
64 Usage : $aln = $stream->next_aln()
65 Function: returns the next alignment in the stream
66 Returns : L<Bio::Align::AlignI> object
82 my $aln = Bio
::SimpleAlign
->new(-source
=> 'pfam');
84 while( $entry = $self->_readline) {
86 $entry =~ m{^//} && last;
87 if($entry !~ m{^(\S+)/(\d+)-(\d+)\s+(\S+)\s*} ) {
88 $self->throw("Found a bad line [$_] in the pfam format alignment");
98 $add = Bio
::LocatableSeq
->new('-seq'=>$seq,
108 # If $end <= 0, we have either reached the end of
109 # file in <> or we have encountered some other error
111 if ($end <= 0) { undef $aln;}
121 Usage : $stream->write_aln(@aln)
122 Function: writes the $aln object into the stream
123 Returns : 1 for success and 0 for error
124 Args : L<Bio::Align::AlignI> object
130 my ($self,@aln) = @_;
131 if( @aln > 1 ) { $self->warn("Only the 1st pfam alignment will be output since the format does not support multiple alignments in the same file"); }
132 my $aln = shift @aln;
133 if( ! $aln || ! $aln->isa('Bio::Align::AlignI') ) {
134 $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
137 my ($namestr,$seq,$add);
139 $maxn = $aln->maxdisplayname_length();
141 foreach $seq ( $aln->each_seq() ) {
142 $namestr = $aln->displayname($seq->get_nse());
143 $add = $maxn - length($namestr) + 2;
144 $namestr .= " " x
$add;
145 $self->_print (sprintf("%s %s\n",$namestr,$seq->seq())) or return;
147 $self->flush() if $self->_flush_on_write && defined $self->_fh;