JWS-67 insert Jpred 3.0.1 sources into JABAWS
[jabaws.git] / binaries / src / jpred / lib / Profile / Jnet.pm
1 package Profile::Jnet;
2
3 use strict;
4 use warnings;
5 use Carp;
6 use UNIVERSAL qw(isa);
7
8 use base qw(Profile);
9 use lib '..';
10 use Utils qw(profile);
11
12 sub read {
13         my ($self, $fh) = @_;
14
15         local $/ = "\n";
16
17         while (<$fh>) {
18                 chomp;
19                 $self->add_pos(split);
20         }
21 }
22
23 =head2 $prof->jpred_profile(@Sequence) 
24
25 Creates a PSIBLAST like profile for Jpred.
26
27 =cut
28
29 sub jpred_profile {
30         my ($self, @seqs) = @_;
31         croak "Not passed Sequence objects" if grep { not isa $_, 'Sequence' } @seqs;
32         $self->_check_seq_length(@seqs) or croak "Not passed sequences of equal length\n";
33
34         my @profile = profile( map { join "", $_->seqs } @seqs );
35
36         for (@profile) {
37                 $self->add_pos(@{$_});
38         }
39 }
40
41 =for private
42
43 =head2 _check_seq_length(@Sequence);
44
45 Checks that we've been passed PSISEQ objects and that they are the same length. Returns undef if their not and warns, otherwise returns the length of the sequence.
46
47 =cut
48
49 sub _check_seq_length {
50         undef = shift @_;
51
52         my %lengths;
53         for (@_) {
54                 $lengths{ $_->seq } = 1;
55         }
56
57         if (keys %lengths != 1) {
58                 warn "The sequences are of different lengths";
59                 return undef;
60         }
61
62         return (keys %lengths)[0];
63 }
64
65 1;