maint: restructure to use Dist::Zilla
[bioperl-live.git] / lib / Bio / Tools / Profile.pm
blob2c51a318c36985c047090a8a6e64f8d20486abd1
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;
70 use strict;
72 use Bio::SeqFeature::FeaturePair;
73 use Bio::SeqFeature::Generic;
75 use base qw(Bio::Root::Root Bio::Root::IO);
79 =head2 new
81 Title : new
82 Usage : my $obj = Bio::Tools::Profile->new();
83 Function: Builds a new Bio::Tools::Profile object
84 Returns : Bio::Tools::Profile
85 Args : -filename
86 -fh ($filehandle)
88 =cut
90 sub new {
91 my($class,@args) = @_;
93 my $self = $class->SUPER::new(@args);
94 $self->_initialize_io(@args);
96 return $self;
99 =head2 next_result
101 Title : next_result
102 Usage : my $feat = $profile_parser->next_result
103 Function: Get the next result set from parser data
104 Returns : L<Bio::SeqFeature::FeaturePair>
105 Args : none
108 =cut
110 sub next_result {
111 my ($self) = @_;
113 my %printsac;
114 my $line;
115 my @features;
116 while ($_=$self->_readline()) {
117 $line = $_;
118 chomp $line;
119 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+)/;
120 #for example in this output line
121 #38.435 2559 pos. 19958 - 20212 [ 1, -1] PS50011|PROTEIN_KINASE_DOM Protein kinase domain profile.
122 #$nscore = 38.435
123 #$rawscore = 2559
124 #$from = 19958
125 #$end = 20212
126 #$hfrom = 1
127 #$hto =-1
128 #$ac = PS50011
129 my $feat = "$ac,$from,$to,$hfrom,$hto,$nscore";
130 my $new_feat= $self->create_feature($feat);
131 return $new_feat
137 =head2 create_feature
139 Title : create_feature
140 Usage : my $feat= $profile_parser->create_feature($feature)
141 Function: creates a Bio::SeqFeature::FeaturePair object
142 Returns : L<Bio::SeqFeature::FeaturePair>
143 Args :
146 =cut
148 sub create_feature {
149 my ($self, $feat) = @_;
151 my @f = split (/,/,$feat);
154 my $hto = $f[4];
156 if ($f[4] =~ /-1/) {
158 $hto = $f[2] - $f[1] + 1;
163 my $feat1 = Bio::SeqFeature::Generic->new( -start => $f[1],
164 -end => $f[2],
165 -score => $f[5],
166 -source=>'pfscan',
167 -primary=>$f[0]);
169 my $feat2 = Bio::SeqFeature::Generic->new(-start => $f[3],
170 -end => $hto,
173 my $feature = Bio::SeqFeature::FeaturePair->new(-feature1 => $feat1,
174 -feature2 => $feat2);
176 return $feature;