JPRED-2 Move Jpred 3.0.1 to public Git
[jpred.git] / jpred / lib / HPM.pm
1 package HPM;
2
3 use strict;
4 use warnings;
5 use Carp;
6
7 use base qw(Exporter);
8
9 our @EXPORT_OK = qw(hydrophobic_moment);
10
11 =head1 NAME
12
13 HPM - module to calculate hydrophobic moments of a peptide sequence
14
15 =head1 $moment = hydrophobic_moment($angle, @sequence)
16
17 Calculate the hydrophobic moment (Eisenberg et al.) of a series of amino acids in @sequence for angle $angle in degrees. This is 100 for alpha helices and between 160 and 180.
18
19 An example helix is: RIIRRIIRRIRRIIRRII which has a maximum at 100 degrees.
20 An example sheet is: ALALALALAL, with a maximum at between 160-180 degrees.
21
22 See Eisenberg et al., PNAS, 1984, v81, p140-144 for more details.
23
24 =cut
25
26 # Hydrophobic moments from Eisenberg et al., PNAS, 1984, v81, p140.
27 my %moments = (
28         I => 0.73,
29         F => 0.61,
30         V => 0.54,
31         L => 0.53,
32         W => 0.37,
33         M => 0.26,
34         A => 0.25,
35         G => 0.16,
36         C => 0.04,
37         Y => 0.02,
38         P => -0.07,
39         T => -0.18,
40         S => -0.26,
41         H => -0.40,
42         E => -0.62,
43         N => -0.64,
44         Q => -0.69,
45         D => -0.72,
46         K => -1.10,
47         R => -1.76
48 );
49
50 # Hydrophobic moments from EMBOSS 2.9.0 hmoment program. Gives similar graphs
51 # to the above moments.
52 my %e_moments = (
53         A => 0.62,
54         B => -100,
55         C => 0.29,
56         D => -0.90,
57         E => -0.74,
58         F => 1.19,
59         G => 0.48,
60         H => -0.4,
61         I => 1.38,
62         J => -100,
63         K => -1.5,
64         L => 1.06,
65         M => 0.64,
66         N => -0.78,
67         O => -100,
68         P => 0.12,
69         Q => -0.85,
70         R => -2.53,
71         S => -0.18,
72         T => -0.05,
73         U => -100,
74         V => 1.08,
75         W => 0.81,
76         X => -100,
77         Y => 0.26,
78         Z => -100,
79 );
80
81 sub deg2rad { $_[0] and return $_[0] * (3.141593 / 180) }
82
83 sub hydrophobic_moment {
84         my ($angle, @seq) = @_;
85         my $tangle = $angle;
86
87         my ($sum_sin, $sum_cos) = (0, 0);
88         for (@seq) {
89                 $sum_sin += ($moments{ $_ } * sin(deg2rad $tangle));
90                 $sum_cos += ($moments{ $_ } * cos(deg2rad $tangle));
91                 $tangle = ($tangle + $angle) % 360;
92         }
93         return sqrt($sum_sin * $sum_sin + $sum_cos * $sum_cos) / @seq;
94 }