tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / Matrix / PSM / IO / psiblast.pm
blob35aa50843969ae212e6c2fbeef89c1e8cc7e8820
1 #---------------------------------------------------------
2 # $Id$
4 =head1 NAME
6 Bio::Matrix::PSM::IO::psiblast - PSM psiblast parser
8 =head1 SYNOPSIS
10 See Bio::Matrix::PSM::IO for documentation
12 =head1 DESCRIPTION
14 Parser for ASCII matrices from PSI-BLAST (blastpgp program in
15 BLAST distribution).
17 =head1 FEEDBACK
19 =head2 Mailing Lists
21 User feedback is an integral part of the evolution of this and other
22 Bioperl modules. Send your comments and suggestions preferably to one
23 of the Bioperl mailing lists. Your participation is much appreciated.
25 bioperl-l@bioperl.org - General discussion
26 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
28 =head2 Support
30 Please direct usage questions or support issues to the mailing list:
32 I<bioperl-l@bioperl.org>
34 rather than to the module maintainer directly. Many experienced and
35 reponsive experts will be able look at the problem and quickly
36 address it. Please include a thorough description of the problem
37 with code and data examples if at all possible.
39 =head2 Reporting Bugs
41 Report bugs to the Bioperl bug tracking system to help us keep track
42 the bugs and their resolution. Bug reports can be submitted via the
43 web:
45 http://bugzilla.open-bio.org/
47 =head1 AUTHOR - James Thompson
49 Email tex@biosysadmin.com
51 =head1 APPENDIX
53 =cut
56 # Let the code begin...
57 package Bio::Matrix::PSM::IO::psiblast;
58 use Bio::Matrix::PSM::Psm;
59 use Bio::Matrix::PSM::ProtMatrix;
60 use strict;
62 use base qw(Bio::Matrix::PSM::PsmHeader Bio::Matrix::PSM::IO);
64 # define the order in which amino acids are listed in the psiblast matrix file
65 our @ordered_alphabet = qw/A R N D C Q E G H I L K M F P S T W Y V/;
67 =head2 new
69 Title : new
70 Usage : my $psmIO = Bio::Matrix::PSM::IO->new(-format=>'psiblast',
71 -file=>$file);
72 Function: Associates a file with the appropriate parser
73 Throws :
74 Example :
75 Args :
76 Returns : Bio::Matrix::PSM::ProtMatrix->new(@args);
78 =cut
80 sub new {
81 my ($class,@args)=@_;
82 my $line;
84 my $self = $class->SUPER::new(@args);
85 my ($file) = $self->_rearrange(['FILE'], @args);
86 $self->_initialize_io(@args) || warn "Did you intend to use STDIN?"; # Read only for now
87 $self->_initialize;
89 $self->{_ordered_alphabet} = \@ordered_alphabet;
90 return $self;
93 =head2 next_psm
95 Title : next_psm
96 Usage : my $psm = $psmIO->next_psm();
97 Function: Reads the next PSM from the input file, associated with this object
98 Throws : None
99 Returns : Bio::Matrix::PSM::ProtPsm object
100 Args : none
102 =cut
104 sub next_psm {
105 my $self = shift;
106 my $line;
108 return if ($self->{_end});
110 my %args;
111 my @ordered_alphabet = @{$self->{_ordered_alphabet}};
113 while ( defined( $line = $self->_readline) ) {
114 # remove leading and trailing whitespace
115 chomp $line;
116 $line =~ s/^\s+//g;
117 $line =~ s/\s+$//g;
119 if ( $line =~ /^(\d+)\s+(\w{1})/ ) { # match reference aa and position number
120 my @elements = split /\s+/, $line;
122 my $position = shift @elements;
123 my $letter = shift @elements;
125 my $ratio = pop @elements;
126 my $ic = pop @elements;
128 # put the next 20 elements into the correct array in %args
129 for ( 0 .. 19 ) { push @{$args{'l'.$ordered_alphabet[$_]}}, shift @elements; }
130 for ( 0 .. 19 ) { push @{$args{'p'.$ordered_alphabet[$_]}}, shift @elements; }
132 push @{$args{'ic'}}, $ic;
136 $self->{_end} = 1; # psiblast matrix files currently only hold one PSM per file
138 my $psm = Bio::Matrix::PSM::ProtMatrix->new( %args );
139 return $psm;
142 sub DESTROY {
143 my $self=shift;
144 $self->close;