Bio::Tools::CodonTable and Bio::Tools::IUPAC: use our and drop BEGIN blocks.
[bioperl-live.git] / lib / Bio / Tools / Profile.pm
blob5b60b885f7e82b321e50300aa5e012731b3b2c3c
1 # BioPerl module for Bio::Tools::Profile
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 # Cared for by Balamurugan Kumarasamy
7 # You may distribute this module under the same terms as perl itself
8 # POD documentation - main docs before the code
10 =head1 NAME
12 Bio::Tools::Profile - parse Profile output
14 =head1 SYNOPSIS
16 use Bio::Tools::Profile;
17 my $profile_parser = Bio::Tools::Profile->new(-fh =>$filehandle );
18 while( my $profile_feat = $profile_parser->next_result ) {
19 push @profile_feat, $profile_feat;
22 =head1 DESCRIPTION
24 Parser for Profile output
26 =head1 FEEDBACK
28 =head2 Mailing Lists
30 User feedback is an integral part of the evolution of this and other
31 Bioperl modules. Send your comments and suggestions preferably to
32 the Bioperl mailing list. Your participation is much appreciated.
34 bioperl-l@bioperl.org - General discussion
35 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
37 =head2 Support
39 Please direct usage questions or support issues to the mailing list:
41 I<bioperl-l@bioperl.org>
43 rather than to the module maintainer directly. Many experienced and
44 reponsive experts will be able look at the problem and quickly
45 address it. Please include a thorough description of the problem
46 with code and data examples if at all possible.
48 =head2 Reporting Bugs
50 Report bugs to the Bioperl bug tracking system to help us keep track
51 of the bugs and their resolution. Bug reports can be submitted via the
52 web:
54 https://github.com/bioperl/bioperl-live/issues
56 =head1 AUTHOR - Balamurugan Kumarasamy
58 Email: fugui@worf.fugu-sg.org
60 =head1 APPENDIX
62 The rest of the documentation details each of the object methods.
63 Internal methods are usually preceded with a _
66 =cut
69 package Bio::Tools::Profile;
71 use strict;
73 use Bio::SeqFeature::FeaturePair;
74 use Bio::SeqFeature::Generic;
76 use base qw(Bio::Root::Root Bio::Root::IO);
80 =head2 new
82 Title : new
83 Usage : my $obj = Bio::Tools::Profile->new();
84 Function: Builds a new Bio::Tools::Profile object
85 Returns : Bio::Tools::Profile
86 Args : -filename
87 -fh ($filehandle)
89 =cut
91 sub new {
92 my($class,@args) = @_;
94 my $self = $class->SUPER::new(@args);
95 $self->_initialize_io(@args);
97 return $self;
100 =head2 next_result
102 Title : next_result
103 Usage : my $feat = $profile_parser->next_result
104 Function: Get the next result set from parser data
105 Returns : L<Bio::SeqFeature::FeaturePair>
106 Args : none
109 =cut
111 sub next_result {
112 my ($self) = @_;
114 my %printsac;
115 my $line;
116 my @features;
117 while ($_=$self->_readline()) {
118 $line = $_;
119 chomp $line;
120 my ($nscore,$rawscore,$from,$to,$hfrom,$hto,$ac) = $line =~ /(\S+)\s+(\d+)\s*pos.\s+(\d*)\s*-\s+(\d*)\s*\[\s+(\d*),\s+(\S*)\]\s*(\w+)/;
121 #for example in this output line
122 #38.435 2559 pos. 19958 - 20212 [ 1, -1] PS50011|PROTEIN_KINASE_DOM Protein kinase domain profile.
123 #$nscore = 38.435
124 #$rawscore = 2559
125 #$from = 19958
126 #$end = 20212
127 #$hfrom = 1
128 #$hto =-1
129 #$ac = PS50011
130 my $feat = "$ac,$from,$to,$hfrom,$hto,$nscore";
131 my $new_feat= $self->create_feature($feat);
132 return $new_feat
138 =head2 create_feature
140 Title : create_feature
141 Usage : my $feat= $profile_parser->create_feature($feature)
142 Function: creates a Bio::SeqFeature::FeaturePair object
143 Returns : L<Bio::SeqFeature::FeaturePair>
144 Args :
147 =cut
149 sub create_feature {
150 my ($self, $feat) = @_;
152 my @f = split (/,/,$feat);
155 my $hto = $f[4];
157 if ($f[4] =~ /-1/) {
159 $hto = $f[2] - $f[1] + 1;
164 my $feat1 = Bio::SeqFeature::Generic->new( -start => $f[1],
165 -end => $f[2],
166 -score => $f[5],
167 -source=>'pfscan',
168 -primary=>$f[0]);
170 my $feat2 = Bio::SeqFeature::Generic->new(-start => $f[3],
171 -end => $hto,
174 my $feature = Bio::SeqFeature::FeaturePair->new(-feature1 => $feat1,
175 -feature2 => $feat2);
177 return $feature;