0
|
1 # $Id: pfam.pm,v 1.10 2002/10/22 07:38:26 lapp Exp $
|
|
2 #
|
|
3 # BioPerl module for Bio::AlignIO::pfam
|
|
4
|
|
5 # based on the Bio::SeqIO:: modules
|
|
6 # by Ewan Birney <birney@sanger.ac.uk>
|
|
7 # and Lincoln Stein <lstein@cshl.org>
|
|
8 #
|
|
9 # and the SimpleAlign.pm module of Ewan Birney
|
|
10 #
|
|
11 # Copyright Peter Schattner
|
|
12 #
|
|
13 # You may distribute this module under the same terms as perl itself
|
|
14 # _history
|
|
15 # September 5, 2000
|
|
16 # POD documentation - main docs before the code
|
|
17
|
|
18 =head1 NAME
|
|
19
|
|
20 Bio::AlignIO::pfam - pfam sequence input/output stream
|
|
21
|
|
22 =head1 SYNOPSIS
|
|
23
|
|
24 Do not use this module directly. Use it via the L<Bio::AlignIO> class.
|
|
25
|
|
26 =head1 DESCRIPTION
|
|
27
|
|
28 This object can transform Bio::SimpleAlign objects to and from pfam flat
|
|
29 file databases.
|
|
30
|
|
31 =head1 FEEDBACK
|
|
32
|
|
33 =head2 Reporting Bugs
|
|
34
|
|
35 Report bugs to the Bioperl bug tracking system to help us keep track
|
|
36 the bugs and their resolution.
|
|
37 Bug reports can be submitted via email or the web:
|
|
38
|
|
39 bioperl-bugs@bio.perl.org
|
|
40 http://bugzilla.bioperl.org/
|
|
41
|
|
42 =head1 AUTHORS - Peter Schattner
|
|
43
|
|
44 Email: schattner@alum.mit.edu
|
|
45
|
|
46
|
|
47 =head1 APPENDIX
|
|
48
|
|
49 The rest of the documentation details each of the object
|
|
50 methods. Internal methods are usually preceded with a _
|
|
51
|
|
52 =cut
|
|
53
|
|
54 # Let the code begin...
|
|
55
|
|
56 package Bio::AlignIO::pfam;
|
|
57 use vars qw(@ISA);
|
|
58 use strict;
|
|
59
|
|
60 use Bio::AlignIO;
|
|
61 use Bio::SimpleAlign;
|
|
62 @ISA = qw(Bio::AlignIO);
|
|
63
|
|
64 =head2 next_aln
|
|
65
|
|
66 Title : next_aln
|
|
67 Usage : $aln = $stream->next_aln()
|
|
68 Function: returns the next alignment in the stream
|
|
69 Returns : L<Bio::Align::AlignI> object
|
|
70 Args : NONE
|
|
71
|
|
72 =cut
|
|
73
|
|
74 sub next_aln {
|
|
75 my $self = shift;
|
|
76 my $entry;
|
|
77 my $name;
|
|
78 my $start;
|
|
79 my $end;
|
|
80 my $seq;
|
|
81 my $add;
|
|
82 my $acc;
|
|
83 my %names;
|
|
84
|
|
85 my $aln = Bio::SimpleAlign->new(-source => 'pfam');
|
|
86
|
|
87 while( $entry = $self->_readline) {
|
|
88 chomp $entry;
|
|
89 $entry =~ /^\/\// && last;
|
|
90 if($entry !~ /^(\S+)\/(\d+)-(\d+)\s+(\S+)\s*/ ) {
|
|
91 $self->throw("Found a bad line [$_] in the pfam format alignment");
|
|
92 next;
|
|
93 }
|
|
94
|
|
95 $name = $1;
|
|
96 $start = $2;
|
|
97 $end = $3;
|
|
98 $seq = $4;
|
|
99
|
|
100
|
|
101 $add = new Bio::LocatableSeq('-seq'=>$seq,
|
|
102 '-id'=>$name,
|
|
103 '-start'=>$start,
|
|
104 '-end'=>$end,
|
|
105 );
|
|
106
|
|
107 $aln->add_seq($add);
|
|
108
|
|
109 }
|
|
110
|
|
111 # If $end <= 0, we have either reached the end of
|
|
112 # file in <> or we have encountered some other error
|
|
113 #
|
|
114 if ($end <= 0) { undef $aln;}
|
|
115
|
|
116 return $aln;
|
|
117 }
|
|
118
|
|
119
|
|
120
|
|
121 =head2 write_aln
|
|
122
|
|
123 Title : write_aln
|
|
124 Usage : $stream->write_aln(@aln)
|
|
125 Function: writes the $aln object into the stream
|
|
126 Returns : 1 for success and 0 for error
|
|
127 Args : L<Bio::Align::AlignI> object
|
|
128
|
|
129
|
|
130 =cut
|
|
131
|
|
132 sub write_aln {
|
|
133 my ($self,@aln) = @_;
|
|
134 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"); }
|
|
135 my $aln = shift @aln;
|
|
136 if( ! $aln || ! $aln->isa('Bio::Align::AlignI') ) {
|
|
137 $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln");
|
|
138 next;
|
|
139 }
|
|
140 my ($namestr,$seq,$add);
|
|
141 my ($maxn);
|
|
142 $maxn = $aln->maxdisplayname_length();
|
|
143
|
|
144 foreach $seq ( $aln->each_seq() ) {
|
|
145 $namestr = $aln->displayname($seq->get_nse());
|
|
146 $add = $maxn - length($namestr) + 2;
|
|
147 $namestr .= " " x $add;
|
|
148 $self->_print (sprintf("%s %s\n",$namestr,$seq->seq())) or return;
|
|
149 }
|
|
150 $self->flush() if $self->_flush_on_write && defined $self->_fh;
|
|
151 return 1;
|
|
152 }
|
|
153
|
|
154 1;
|