maint: restructure to use Dist::Zilla
[bioperl-live.git] / lib / Bio / Matrix / PSM / IO / psiblast.pm
blobff205387b326cd69a0dee99b05604fa2cb119378
1 #---------------------------------------------------------
3 =head1 NAME
5 Bio::Matrix::PSM::IO::psiblast - PSM psiblast parser
7 =head1 SYNOPSIS
9 See Bio::Matrix::PSM::IO for documentation
11 =head1 DESCRIPTION
13 Parser for ASCII matrices from PSI-BLAST (blastpgp program in
14 BLAST distribution).
16 =head1 FEEDBACK
18 =head2 Mailing Lists
20 User feedback is an integral part of the evolution of this and other
21 Bioperl modules. Send your comments and suggestions preferably to one
22 of the Bioperl mailing lists. Your participation is much appreciated.
24 bioperl-l@bioperl.org - General discussion
25 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
27 =head2 Support
29 Please direct usage questions or support issues to the mailing list:
31 I<bioperl-l@bioperl.org>
33 rather than to the module maintainer directly. Many experienced and
34 reponsive experts will be able look at the problem and quickly
35 address it. Please include a thorough description of the problem
36 with code and data examples if at all possible.
38 =head2 Reporting Bugs
40 Report bugs to the Bioperl bug tracking system to help us keep track
41 the bugs and their resolution. Bug reports can be submitted via the
42 web:
44 https://github.com/bioperl/bioperl-live/issues
46 =head1 AUTHOR - James Thompson
48 Email tex@biosysadmin.com
50 =head1 APPENDIX
52 =cut
55 # Let the code begin...
56 package Bio::Matrix::PSM::IO::psiblast;
57 use Bio::Matrix::PSM::Psm;
58 use Bio::Matrix::PSM::ProtMatrix;
59 use strict;
61 use base qw(Bio::Matrix::PSM::PsmHeader Bio::Matrix::PSM::IO);
63 # define the order in which amino acids are listed in the psiblast matrix file
64 our @ordered_alphabet = qw/A R N D C Q E G H I L K M F P S T W Y V/;
66 =head2 new
68 Title : new
69 Usage : my $psmIO = Bio::Matrix::PSM::IO->new(-format=>'psiblast',
70 -file=>$file);
71 Function: Associates a file with the appropriate parser
72 Throws :
73 Example :
74 Args :
75 Returns : Bio::Matrix::PSM::ProtMatrix->new(@args);
77 =cut
79 sub new {
80 my ($class,@args)=@_;
81 my $line;
83 my $self = $class->SUPER::new(@args);
84 my ($file) = $self->_rearrange(['FILE'], @args);
85 $self->_initialize_io(@args) || warn "Did you intend to use STDIN?"; # Read only for now
86 $self->_initialize;
88 $self->{_ordered_alphabet} = \@ordered_alphabet;
89 return $self;
92 =head2 next_psm
94 Title : next_psm
95 Usage : my $psm = $psmIO->next_psm();
96 Function: Reads the next PSM from the input file, associated with this object
97 Throws : None
98 Returns : Bio::Matrix::PSM::ProtPsm object
99 Args : none
101 =cut
103 sub next_psm {
104 my $self = shift;
105 my $line;
107 return if ($self->{_end});
109 my %args;
110 my @ordered_alphabet = @{$self->{_ordered_alphabet}};
112 while ( defined( $line = $self->_readline) ) {
113 # remove leading and trailing whitespace
114 chomp $line;
115 $line =~ s/^\s+//g;
116 $line =~ s/\s+$//g;
118 if ( $line =~ /^(\d+)\s+(\w{1})/ ) { # match reference aa and position number
119 my @elements = split /\s+/, $line;
121 my $position = shift @elements;
122 my $letter = shift @elements;
124 my $ratio = pop @elements;
125 my $ic = pop @elements;
127 # put the next 20 elements into the correct array in %args
128 for ( 0 .. 19 ) { push @{$args{'l'.$ordered_alphabet[$_]}}, shift @elements; }
129 for ( 0 .. 19 ) { push @{$args{'p'.$ordered_alphabet[$_]}}, shift @elements; }
131 push @{$args{'ic'}}, $ic;
135 $self->{_end} = 1; # psiblast matrix files currently only hold one PSM per file
137 my $psm = Bio::Matrix::PSM::ProtMatrix->new( %args );
138 return $psm;
141 sub DESTROY {
142 my $self=shift;
143 $self->close;