tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / Matrix / IO / scoring.pm
blobf45a16559ee1606179701590661663c94669293d
1 # $Id$
3 # BioPerl module for Bio::Matrix::IO::scoring
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason-at-bioperl-dot-org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Matrix::IO::scoring - A parser for PAM/BLOSUM matricies
19 =head1 SYNOPSIS
21 use Bio::Matrix::IO;
22 my $parser = Bio::Matrix::IO->new(-format => 'scoring',
23 -file => 'BLOSUM50');
24 my $matrix = $parser->next_matrix;
26 =head1 DESCRIPTION
28 Describe the object here
30 =head1 FEEDBACK
32 =head2 Mailing Lists
34 User feedback is an integral part of the evolution of this and other
35 Bioperl modules. Send your comments and suggestions preferably to
36 the Bioperl mailing list. Your participation is much appreciated.
38 bioperl-l@bioperl.org - General discussion
39 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41 =head2 Support
43 Please direct usage questions or support issues to the mailing list:
45 I<bioperl-l@bioperl.org>
47 rather than to the module maintainer directly. Many experienced and
48 reponsive experts will be able look at the problem and quickly
49 address it. Please include a thorough description of the problem
50 with code and data examples if at all possible.
52 =head2 Reporting Bugs
54 Report bugs to the Bioperl bug tracking system to help us keep track
55 of the bugs and their resolution. Bug reports can be submitted via
56 the web:
58 http://bugzilla.open-bio.org/
60 =head1 AUTHOR - Jason Stajich
62 Email jason-at-bioperl-dot-org
64 =head1 APPENDIX
66 The rest of the documentation details each of the object methods.
67 Internal methods are usually preceded with a _
69 =cut
72 # Let the code begin...
75 package Bio::Matrix::IO::scoring;
76 use strict;
78 use Bio::Matrix::Scoring;
79 use base qw(Bio::Matrix::IO);
81 =head2 new
83 Title : new
84 Usage : my $obj = Bio::Matrix::IO::scoring->new();
85 Function: Builds a new Bio::Matrix::IO::scoring object
86 Returns : an instance of Bio::Matrix::IO::scoring
87 Args :
90 =cut
92 =head2 next_matrix
94 Title : next_matrix
95 Usage : my $matrux = $parser->next_matrix
96 Function: parses a scoring matrix (BLOSUM,PAM styles)
97 Returns : L<Bio::Matrix::Scoring>
98 Args : none
101 =cut
103 sub next_matrix{
104 my ($self) = @_;
105 local ($_);
106 my (@matrix,@cols,@rows,%extras,$inmatrix);
107 while( defined ( $_ = $self->_readline ) ) {
108 next if ( /^\s*$/);
109 if( /^\#/ ) {
110 if( $inmatrix ) {
111 $self->_pushback($_);
112 last;
114 if( m/Entropy\s+\=\s+(\S+)\,\s+
115 Expected\s+\=\s+(\S+)/ox ) {
116 $extras{'-entropy'} = $1;
117 $extras{'-expected'} = $2;
118 } elsif ( m/Expected\s+score\s+\=\s+(\S+)\,
119 \s+Entropy\s+\=\s+(\S+)/xo ){
120 $extras{'-entropy'} = $2;
121 $extras{'-expected'} = $1;
122 } elsif( m/(PAM\s+\d+)\s+substitution.+
123 scale\s+\=\s+(\S+)\s+\=\s+(\S+)/ox ) {
124 $extras{'-matrix_name'} = $1;
125 $extras{'-scale'} = $2;
126 $extras{'-scale_value'} = $3;
127 } elsif( /Blocks Database\s+\=\s+(\S+)/o ) {
128 $extras{'-database'} = $1;
129 } elsif( m/(\S+)\s+Bit\s+Units/ox ) {
130 $extras{'-scale'} = $1;
131 } elsif( m/Lowest score\s+\=\s+(\S+)\,\s+
132 Highest score\s+\=\s+(\S+)/ox ) {
133 $extras{'-lowest_score'} = $1;
134 $extras{'-highest_score'} = $2;
135 } elsif( m/(Lambda)\s+\=\s+(\S+)\s+bits\,
136 \s+(H)\s+\=\s+(\S+)/ox ) {
137 # This is a DNA matrix
138 $extras{$1} = $2;
139 $extras{$3} = $4;
141 } elsif( s/^\s+(\S+)/$1/ ) {
142 @cols = split;
143 if( $cols[0] ne 'A' ) {
144 $self->warn("Unrecognized first line of matrix, we might not have parsed it correctly");
146 $inmatrix = 1;
147 } elsif( $inmatrix ) {
148 if( ! /^(\S+)/ ) { $inmatrix = 0; next }
149 my ($rowname,@row) = split;
150 push @rows, $rowname;
151 push @matrix, [@row];
152 } else {
153 print;
156 my $matrix = Bio::Matrix::Scoring->new(-values => \@matrix,
157 -rownames => \@rows,
158 -colnames => \@cols,
159 %extras);
162 =head2 write_matrix
164 Title : write_matrix
165 Usage : $matio->write_matrix($matrix)
166 Function: Write out a matrix in the BLOSUM/PAM format
167 Returns : none
168 Args : L<Bio::Matrix::Scoring>
171 =cut
173 sub write_matrix{
174 my ($self,@args) = @_;
175 $self->warn("cannot actually use this function yet - it isn't finished");
176 return;