| 1 |
# TFBS module for TFBS::PatternGen::SimplePFM |
| 2 |
# |
| 3 |
# Copyright Boris Lenhard |
| 4 |
# |
| 5 |
# You may distribute this module under the same terms as perl itself |
| 6 |
# |
| 7 |
|
| 8 |
# POD |
| 9 |
|
| 10 |
=head1 NAME |
| 11 |
|
| 12 |
TFBS::PatternGen::SimplePFM - a simple position frequency matrix factory |
| 13 |
|
| 14 |
=head1 SYNOPSIS |
| 15 |
|
| 16 |
my @sequences = qw( AAGCCT AGGCAT AAGCCT |
| 17 |
AAGCCT AGGCAT AGGCCT |
| 18 |
AGGCAT AGGTTT AGGCAT |
| 19 |
AGGCCT AGGCCT ); |
| 20 |
my $patterngen = |
| 21 |
TFBS::PatternGen::SimplePFM->new(-seq_list=>\@sequences); |
| 22 |
|
| 23 |
my $pfm = $patterngen->pattern(); # $pfm is now a TFBS::Matrix::PFM object |
| 24 |
|
| 25 |
=head1 DESCRIPTION |
| 26 |
|
| 27 |
TFBS::PatternGen::SimplePFM generates a position frequency matrix from a set |
| 28 |
of nucleotide sequences of equal length, The sequences can be passed either |
| 29 |
as strings, as Bio::Seq objects or as a fasta file. |
| 30 |
|
| 31 |
This pattern generator always creates only one pattern from a given set |
| 32 |
of sequences. |
| 33 |
|
| 34 |
=cut |
| 35 |
|
| 36 |
package TFBS::PatternGen::SimplePFM; |
| 37 |
use vars qw(@ISA); |
| 38 |
use strict; |
| 39 |
|
| 40 |
# Object preamble - inherits from TFBS::PatternGenI; |
| 41 |
use TFBS::PatternGen; |
| 42 |
use TFBS::PatternGen::Motif::Matrix; |
| 43 |
|
| 44 |
@ISA = qw(TFBS::PatternGen); |
| 45 |
|
| 46 |
|
| 47 |
=head2 new |
| 48 |
|
| 49 |
Title : new |
| 50 |
Usage : my $db = TFBS::PatternGen::SimplePFM->new(%args); |
| 51 |
Function: the constructor for the TFBS::PatternGen::SimplePFM |
| 52 |
object |
| 53 |
Returns : a TFBS::PatternGen::SimplePFM obkect |
| 54 |
Args : This method takes named arguments; |
| 55 |
you must specify one of the following |
| 56 |
-seq_list # a reference to an array of strings |
| 57 |
# and/or Bio::Seq objects |
| 58 |
# or |
| 59 |
-seq_stream # A Bio::SeqIO object |
| 60 |
# or |
| 61 |
-seq_file # the name of the fasta file containing |
| 62 |
# all the sequences |
| 63 |
|
| 64 |
=cut |
| 65 |
|
| 66 |
|
| 67 |
sub new { |
| 68 |
my ($caller, %args) = @_; |
| 69 |
my $self = bless {}, ref($caller) || $caller; |
| 70 |
$self->_create_seq_set(%args) or die ('Error creating sequence set'); |
| 71 |
$self->_check_seqs_for_uniform_length(); |
| 72 |
$self->{'motifs'} = [$self->_create_motif()]; |
| 73 |
return $self; |
| 74 |
} |
| 75 |
|
| 76 |
=head2 pattern |
| 77 |
|
| 78 |
=head2 all_patterns |
| 79 |
|
| 80 |
=head2 patternSet |
| 81 |
|
| 82 |
The three above methods are used fro the retrieval of patterns, |
| 83 |
and are common to all TFBS::PatternGen::* classes. Please |
| 84 |
see L<TFBS::PatternGen> for details. |
| 85 |
|
| 86 |
=cut |
| 87 |
|
| 88 |
sub _create_motif { |
| 89 |
my $self = shift; |
| 90 |
my $length = $self->{'seq_set'}->[-1]->length(); |
| 91 |
# initialize the matrix |
| 92 |
my $matrixref = []; |
| 93 |
for my $i (0..3) { |
| 94 |
for my $j (0..$length-1) { |
| 95 |
$matrixref->[$i][$j] = 0; |
| 96 |
} |
| 97 |
} |
| 98 |
#fill the matrix |
| 99 |
my @base = qw(A C G T); |
| 100 |
foreach my $seqobj ( @{ $self->{seq_set} } ) { |
| 101 |
for my $i (0..3) { |
| 102 |
my $seqstring = $seqobj->seq; |
| 103 |
my @seqbase = split "", uc $seqstring; |
| 104 |
for my $j (0..$length-1) { |
| 105 |
$matrixref->[$i][$j] += ($base[$i] eq $seqbase[$j])?1:0; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
} |
| 110 |
my $nrhits =0; for my $i (0..3) {$nrhits += $matrixref->[$i][0];} |
| 111 |
my $motif = |
| 112 |
TFBS::PatternGen::Motif::Matrix->new(-matrix => $matrixref, |
| 113 |
-nr_hits=> $nrhits); |
| 114 |
return $motif; |
| 115 |
} |
| 116 |
|
| 117 |
sub _validate_seq { |
| 118 |
# a utility function |
| 119 |
my ($sequence)=@_; |
| 120 |
$sequence=~ s/[ACGT]//g; |
| 121 |
return ($sequence eq "" ? 1 : 0); |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
1; |