JPRED-2 Move Jpred 3.0.1 to public Git
[jpred.git] / jpred / lib / HMMER / Profile.pm
1 package HMMER::Profile;
2
3 use strict;
4 use warnings;
5 use Carp;
6 use base qw(Root Read Write);
7
8 sub read {
9         my ($self, $fh) = @_;
10
11         local $/ = "\n";
12
13         my ($flag, @data) = 0;
14         while (my $line = <$fh>) {
15                 $flag = 1, next if $line =~ /^Cons/;
16                 next unless $flag;
17                 next if $line =~ /^! \d+/;
18                 last if $line =~ /^ \*/;
19
20                 chomp $line;
21                 $line =~ s/^\s*//g;
22                 #$self->seq($self->seq, [ (split / +/, $line)[1..24] ]);
23
24                 $self->add_line((split /\s+/, $line)[1..24]);
25         }
26 }
27
28 sub write {
29         my ($self, $fh) = @_;
30         for ($self->get_line) {
31                 print join(" ", @{ $_}) , "\n";
32                 exit;
33                 #print join(" ", map { @{ $_ }), "\n";
34                 print $fh join(" ", map { sprintf "%.5f", $_ } @{ $_ }), "\n";
35         }
36 }
37
38 sub add_line {
39         my $self = shift;
40         @_ or croak "No data passed to HMMER::Profile::add_line";
41         push @{ $self->{__PACKAGE__."lines"} }, pack "d*", @_;
42 }
43
44 sub get_line {
45         my ($self, $line) = @_;
46
47         if (defined $line) { return [ unpack "d*", ${$self->{__PACKAGE__."lines"}}[$line] ] }
48         else {
49                 return map { [ unpack "d*", $_ ] } @{$self->{__PACKAGE__."lines"}}
50         }
51 }
52
53 1;
54 __END__
55
56 =head1 NAME
57
58 HMMER::Profile - Convert the output of hmmconvert to a profile for Jnet
59
60 =head1 EXAMPLE
61
62 system("hmmconvert -p hmmer.model hmmer.prf");
63
64 my $prof = HMMER::Profile->new;
65 $prof->read_file("hmmer.prf");
66
67 my @data = $prof->jnet
68 print join(" ", @{$_}), "\n" for @data;
69
70 =head1 DESCRIPTION
71
72 Takes the output of the HMMER program hmmconvert with the -p option and calculates the profile used by Jpred to calculate secondary structure.
73
74 =head1 METHODS
75
76 =head2 my $prof = HMMER::Profile->new;
77
78 Create a new object.
79
80 =head2 $prof->read_file("path_to_hmmer_model_converted_to_prf");
81
82 Read a HMMER model that's been converted to PRF format via the HMMER hmmconvert program with the -p option.
83
84 =head2 my @data = $prof->seq
85
86 Returns an array of array refs of the HMMER numbers.
87
88 =head2 my @data = $prof->jnet
89
90 Returns an array of array refs of frequences for use in Jnet.
91
92 =head1 SEE ALSO
93
94 Packages Root, Read and Sequence.
95
96 =head1 BUGS
97
98 The whole set of profile modules is a bit of an abortion now, as there is no standard interface and the methods do different things for different objects. Converting the different representations is a nightmare because of this.
99
100 =head1 AUTHOR
101
102 Jonathan Barber <jon@compbio.dundee.ac.uk>