0
|
1 # $Id: psi.pm,v 1.6 2002/12/23 19:36:39 jason Exp $
|
|
2 #
|
|
3 # BioPerl module for Bio::AlignIO::psi
|
|
4 #
|
|
5 # Cared for by Jason Stajich <jason@bioperl.org>
|
|
6 #
|
|
7 # Copyright Jason Stajich
|
|
8 #
|
|
9 # You may distribute this module under the same terms as perl itself
|
|
10
|
|
11 # POD documentation - main docs before the code
|
|
12
|
|
13 =head1 NAME
|
|
14
|
|
15 Bio::AlignIO::psi - Read/Write PSI-BLAST profile alignment files
|
|
16
|
|
17 =head1 SYNOPSIS
|
|
18
|
|
19 This module will parse PSI-BLAST output of the format seqid XXXX
|
|
20
|
|
21 =head1 DESCRIPTION
|
|
22
|
|
23 Describe the object here
|
|
24
|
|
25 =head1 FEEDBACK
|
|
26
|
|
27 =head2 Mailing Lists
|
|
28
|
|
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.
|
|
32
|
|
33 bioperl-l@bioperl.org - General discussion
|
|
34 http://bioperl.org/MailList.shtml - About the mailing lists
|
|
35
|
|
36 =head2 Reporting Bugs
|
|
37
|
|
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
|
|
40 email or the web:
|
|
41
|
|
42 bioperl-bugs@bioperl.org
|
|
43 http://bugzilla.bioperl.org/
|
|
44
|
|
45 =head1 AUTHOR - Jason Stajich
|
|
46
|
|
47 Email jason@bioperl.org
|
|
48
|
|
49 Describe contact details here
|
|
50
|
|
51 =head1 CONTRIBUTORS
|
|
52
|
|
53 Additional contributors names and emails here
|
|
54
|
|
55 =head1 APPENDIX
|
|
56
|
|
57 The rest of the documentation details each of the object methods.
|
|
58 Internal methods are usually preceded with a _
|
|
59
|
|
60 =cut
|
|
61
|
|
62
|
|
63 # Let the code begin...
|
|
64
|
|
65
|
|
66 package Bio::AlignIO::psi;
|
|
67 use vars qw(@ISA $BlockLen $IdLength);
|
|
68 use strict;
|
|
69
|
|
70 $BlockLen = 100;
|
|
71 $IdLength = 13;
|
|
72
|
|
73 # Object preamble - inherits from Bio::Root::Root
|
|
74
|
|
75 use Bio::SimpleAlign;
|
|
76 use Bio::AlignIO;
|
|
77 use Bio::LocatableSeq;
|
|
78
|
|
79 @ISA = qw(Bio::AlignIO);
|
|
80
|
|
81 =head2 new
|
|
82
|
|
83 Title : new
|
|
84 Usage : my $obj = new Bio::AlignIO::psi();
|
|
85 Function: Builds a new Bio::AlignIO::psi object
|
|
86 Returns : Bio::AlignIO::psi
|
|
87 Args :
|
|
88
|
|
89 =cut
|
|
90
|
|
91 =head2 next_aln
|
|
92
|
|
93 Title : next_aln
|
|
94 Usage : $aln = $stream->next_aln()
|
|
95 Function: returns the next alignment in the stream
|
|
96 Returns : L<Bio::Align::AlignI> object
|
|
97 Args : NONE
|
|
98
|
|
99 =cut
|
|
100
|
|
101 sub next_aln {
|
|
102 my ($self) = @_;
|
|
103 my $aln;
|
|
104 my %seqs;
|
|
105 my @order;
|
|
106 while( defined ($_ = $self->_readline ) ) {
|
|
107 next if( /^\s+$/);
|
|
108 if( !defined $aln ) {
|
|
109 $aln = new Bio::SimpleAlign;
|
|
110 }
|
|
111 my ($id,$s) = split;
|
|
112 push @order, $id if( ! defined $seqs{$id});
|
|
113 $seqs{$id} .= $s;
|
|
114 }
|
|
115 foreach my $id ( @order) {
|
|
116 my $seq = new Bio::LocatableSeq(-seq => $seqs{$id},
|
|
117 -id => $id,
|
|
118 -start => 1,
|
|
119 -end => length($seqs{$id}));
|
|
120 $aln->add_seq($seq);
|
|
121 }
|
|
122 return $aln;
|
|
123 }
|
|
124
|
|
125 =head2 write_aln
|
|
126
|
|
127 Title : write_aln
|
|
128 Usage : $stream->write_aln(@aln)
|
|
129 Function: writes the NCBI psi-format object (.aln) into the stream
|
|
130 Returns : 1 for success and 0 for error
|
|
131 Args : L<Bio::Align::AlignI> object
|
|
132
|
|
133
|
|
134 =cut
|
|
135
|
|
136 sub write_aln {
|
|
137 my ($self,$aln) = @_;
|
|
138 unless( defined $aln && ref($aln) &&
|
|
139 $aln->isa('Bio::Align::AlignI') ) {
|
|
140 $self->warn("Must provide a valid Bio::Align::AlignI to write_aln");
|
|
141 return 0;
|
|
142 }
|
|
143 my $ct = 0;
|
|
144 my @seqs = $aln->each_seq;
|
|
145 my $len = 1;
|
|
146 my $alnlen = $aln->length;
|
|
147 my $idlen = $IdLength;
|
|
148 my @ids = map { substr($_->display_id,0,$idlen) } @seqs;
|
|
149 while( $len < $alnlen ) {
|
|
150 my $start = $len;
|
|
151 my $end = $len + $BlockLen;
|
|
152 if( $end > $alnlen ) { $end = $alnlen; }
|
|
153 my $c = 0;
|
|
154 foreach my $seq ( @seqs ) {
|
|
155 $self->_print(sprintf("%-".$idlen."s %s\n",
|
|
156 $ids[$c++],
|
|
157 $seq->subseq($start,$end)));
|
|
158 }
|
|
159 $self->_print("\n");
|
|
160 $len += $BlockLen+1;
|
|
161 }
|
|
162 $self->flush if $self->_flush_on_write && defined $self->_fh;
|
|
163 return 1;
|
|
164 }
|
|
165
|
|
166 1;
|