JPRED-2 Move Jpred 3.0.1 to public Git
[jpred.git] / 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 Utils qw(profile);
10
11 sub read {
12         my ($self, $fh) = @_;
13
14         local $/ = "\n";
15
16         while (<$fh>) {
17                 chomp;
18                 $self->add_pos(split);
19         }
20 }
21
22 =head2 $prof->jpred_profile(@Sequence) 
23
24 Creates a PSIBLAST like profile for Jpred.
25
26 =cut
27
28 sub jpred_profile {
29         my ($self, @seqs) = @_;
30         croak "Not passed Sequence objects" if grep { not isa $_, 'Sequence' } @seqs;
31         $self->_check_seq_length(@seqs) or croak "Not passed sequences of equal length\n";
32
33         my @profile = profile( map { join "", $_->seqs } @seqs );
34
35         for (@profile) {
36                 $self->add_pos(@{$_});
37         }
38 }
39
40 =for private
41
42 =head2 _check_seq_length(@Sequence);
43
44 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.
45
46 =cut
47
48 sub _check_seq_length {
49         undef = shift @_;
50
51         my %lengths;
52         for (@_) {
53                 $lengths{ $_->seq } = 1;
54         }
55
56         if (keys %lengths != 1) {
57                 warn "The sequences are of different lengths";
58                 return undef;
59         }
60
61         return (keys %lengths)[0];
62 }
63
64 1;