File: scoring.pm

package info (click to toggle)
bioperl 1.7.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,964 kB
  • sloc: perl: 94,019; xml: 14,811; makefile: 15
file content (180 lines) | stat: -rw-r--r-- 4,549 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#
# BioPerl module for Bio::Matrix::IO::scoring
#
# Please direct questions and support issues to <bioperl-l@bioperl.org> 
#
# Cared for by Jason Stajich <jason-at-bioperl-dot-org>
#
# Copyright Jason Stajich
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::Matrix::IO::scoring - A parser for PAM/BLOSUM matricies

=head1 SYNOPSIS

  use Bio::Matrix::IO;
  my $parser = Bio::Matrix::IO->new(-format => 'scoring',
                                   -file   => 'BLOSUM50');
  my $matrix = $parser->next_matrix;

=head1 DESCRIPTION

Describe the object here

=head1 FEEDBACK

=head2 Mailing Lists

User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list.  Your participation is much appreciated.

  bioperl-l@bioperl.org                  - General discussion
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

=head2 Support 

Please direct usage questions or support issues to the mailing list:

I<bioperl-l@bioperl.org>

rather than to the module maintainer directly. Many experienced and 
reponsive experts will be able look at the problem and quickly 
address it. Please include a thorough description of the problem 
with code and data examples if at all possible.

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
the web:

  https://github.com/bioperl/bioperl-live/issues

=head1 AUTHOR - Jason Stajich

Email jason-at-bioperl-dot-org

=head1 APPENDIX

The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _

=cut


# Let the code begin...


package Bio::Matrix::IO::scoring;
$Bio::Matrix::IO::scoring::VERSION = '1.7.8';
use strict;

use Bio::Matrix::Scoring;
use base qw(Bio::Matrix::IO);

=head2 new

 Title   : new
 Usage   : my $obj = Bio::Matrix::IO::scoring->new();
 Function: Builds a new Bio::Matrix::IO::scoring object 
 Returns : an instance of Bio::Matrix::IO::scoring
 Args    :


=cut

=head2 next_matrix

 Title   : next_matrix
 Usage   : my $matrux = $parser->next_matrix
 Function: parses a scoring matrix (BLOSUM,PAM styles) 
 Returns : L<Bio::Matrix::Scoring>
 Args    : none


=cut

sub next_matrix{
   my ($self) = @_;
   local ($_);
   my (@matrix,@cols,@rows,%extras,$inmatrix);
   while( defined ( $_ = $self->_readline ) ) {
       next if ( /^\s*$/);
       if( /^\#/ ) {
	   if( $inmatrix ) { 
	       $self->_pushback($_);
	       last;
	   }
	   if( m/Entropy\s+\=\s+(\S+)\,\s+
	       Expected\s+\=\s+(\S+)/ox ) {
	       $extras{'-entropy'} = $1;
	       $extras{'-expected'} = $2;
	   } elsif ( m/Expected\s+score\s+\=\s+(\S+)\,
		     \s+Entropy\s+\=\s+(\S+)/xo ){
	       $extras{'-entropy'} = $2;
	       $extras{'-expected'} = $1;
	   } elsif( m/(PAM\s+\d+)\s+substitution.+
		    scale\s+\=\s+(\S+)\s+\=\s+(\S+)/ox ) {
	       $extras{'-matrix_name'} = $1;
	       $extras{'-scale'}       = $2;	       
	       $extras{'-scale_value'} = $3;
	   } elsif( /Blocks Database\s+\=\s+(\S+)/o ) {
	       $extras{'-database'} = $1;
	   } elsif( m/(\S+)\s+Bit\s+Units/ox ) {
	       $extras{'-scale'} = $1;
	   } elsif( m/Lowest score\s+\=\s+(\S+)\,\s+
		    Highest score\s+\=\s+(\S+)/ox ) {
	       $extras{'-lowest_score'} = $1;
	       $extras{'-highest_score'} = $2;
	   } elsif( m/(Lambda)\s+\=\s+(\S+)\s+bits\,
		    \s+(H)\s+\=\s+(\S+)/ox ) {
	       # This is a DNA matrix
	       $extras{$1} = $2;
	       $extras{$3} = $4;
	   }	       
       } elsif( s/^\s+(\S+)/$1/ ) {
	   @cols = split;
	   if( $cols[0] ne 'A' ) {
	       $self->warn("Unrecognized first line of matrix, we might not have parsed it correctly");
	   }
	   $inmatrix = 1;
       } elsif( $inmatrix ) {
	   if( ! /^(\S+)/ ) { $inmatrix = 0; next }
	   my ($rowname,@row) = split;
	   push @rows, $rowname;
	   push @matrix, [@row];
       } else { 
	   print;
       }
   }
   my $matrix = Bio::Matrix::Scoring->new(-values     => \@matrix,
					 -rownames   => \@rows,
					 -colnames   => \@cols,
					 %extras);
}

=head2 write_matrix

 Title   : write_matrix
 Usage   : $matio->write_matrix($matrix)
 Function: Write out a matrix in the BLOSUM/PAM format
 Returns : none
 Args    : L<Bio::Matrix::Scoring>


=cut

sub write_matrix{
   my ($self,@args) = @_;
   $self->warn("cannot actually use this function yet - it isn't finished");
   return;
}


1;