This commit was manufactured by cvs2svn to create branch
[bioperl-live.git] / Bio / SeqIO / pir.pm
blob35467a66cba2660e3ba20ad122ed96218d289e00
2 # BioPerl module for Bio::SeqIO::PIR
4 # Cared for by Aaron Mackey <amackey@virginia.edu>
6 # Copyright Aaron Mackey
8 # You may distribute this module under the same terms as perl itself
10 # _history
11 # October 18, 1999 Largely rewritten by Lincoln Stein
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::SeqIO::pir - PIR sequence input/output stream
19 =head1 SYNOPSIS
21 Do not use this module directly. Use it via the Bio::SeqIO class.
23 =head1 DESCRIPTION
25 This object can transform Bio::Seq objects to and from fasta flat
26 file databases.
28 =head1 FEEDBACK
30 =head2 Mailing Lists
32 User feedback is an integral part of the evolution of this
33 and other Bioperl modules. Send your comments and suggestions preferably
34 to one of the Bioperl mailing lists.
35 Your participation is much appreciated.
37 vsns-bcd-perl@lists.uni-bielefeld.de - General discussion
38 vsns-bcd-perl-guts@lists.uni-bielefeld.de - Technically-oriented discussion
39 http://bio.perl.org/MailList.html - About the mailing lists
41 =head2 Reporting Bugs
43 Report bugs to the Bioperl bug tracking system to help us keep track
44 the bugs and their resolution.
45 Bug reports can be submitted via email or the web:
47 bioperl-bugs@bio.perl.org
48 http://bio.perl.org/bioperl-bugs/
50 =head1 AUTHORS
52 Aaron Mackey <amackey@virginia.edu>
53 Lincoln Stein <lstein@cshl.org>
55 =head1 APPENDIX
57 The rest of the documentation details each of the object
58 methods. Internal methods are usually preceded with a _
60 =cut
62 # Let the code begin...
64 package Bio::SeqIO::pir;
65 use vars qw(@ISA);
66 use strict;
67 use Bio::SeqIO;
69 @ISA = qw(Bio::SeqIO);
71 =head2 next_seq
73 Title : next_seq
74 Usage : $seq = $stream->next_seq()
75 Function: returns the next sequence in the stream
76 Returns : Bio::Seq object
77 Args :
80 =cut
82 sub next_seq{
83 my ($self,@args) = @_;
84 my ($seq,$line,$name,$sfs,$desc);
86 return unless $line = $self->_readline;
87 $self->throw("PIR stream read attempted without leading '>P1;' [ $line ]")
88 unless $line =~ /^>(?:P|F)1;(\S+)\s*(\|.*)?\s*$/;
89 $name = $1;
90 $sfs = $2;
92 chomp($desc = $self->_readline);
93 local $/ = "";
94 my $junk = $self->_readline; # throw away everything to first empty line
95 my $seq = $self->_readline; # everything else is the sequence
96 $seq =~ s/\s+//g;
97 $seq = Bio::Seq->new(-seq => $seq,
98 -id => $name,
99 -desc => $desc,
100 -names => defined $sfs ? { 'sfnum' => [ split(/\s*\|?\s+/, $sfs) ] } : undef );
101 return $seq;
104 =head2 write_seq
106 Title : write_seq
107 Usage : $stream->write_seq(@seq)
108 Function: writes the $seq object into the stream
109 Returns : 1 for success and 0 for error
110 Args : Bio::Seq object
113 =cut
115 sub write_seq {
116 my ($self, @seq) = @_;
117 for my $seq (@seq) {
118 my $str = $seq->seq();
119 $str =~ s/(.{10})/$1 /g;
120 $str =~ s/(.{66})/$1\n/g;
121 return unless $self->_print(">P1;", $seq->id(),
122 (%{$seq->names()}->{'sfnum'} ? " |" .
123 join(' ', @{%{$seq->names()}->{'sfnum'}}) : '' ),
124 "\n", $seq->desc(), "\n",
125 ">P1;", $seq->id(),"\n",
126 "\n",$str, "\n");
128 return 1;