Debian Codegraph @

TFBS/PatternGen/SimplePFM.pm

raw symbols SCIP
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::SimplePFMscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/;
37 use varsscip-perl cpan TFBS v0.5.0 vars/ qw(@ISA);
38 use strictscip-perl cpan TFBS v0.5.0 strict/;
39
40 # Object preamble - inherits from TFBS::PatternGenI;
41 use TFBS::PatternGenscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/;
42 use TFBS::PatternGen::Motif::Matrixscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/Motif/Matrix/;
43
44 @ISAscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/`@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 newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/new(). {
68 my ($caller, %args) = @_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/`@_`.;
69 my $self = blessscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/bless(). {}, refscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/ref().($caller) || $caller;
70 $self->_create_seq_setscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/_create_seq_set().(%args) or diescip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/die(). ('Error creating sequence set');
71 $self->_check_seqs_for_uniform_lengthscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/_check_seqs_for_uniform_length().();
72 $self->{'motifs'} = [$self->_create_motifscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/_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_motifscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/_create_motif(). {
89 my $self = shiftscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/shift().;
90 my $length = $self->{'seq_set'}->[-1]->lengthscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/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 = $seqscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/seq().obj->seq;
103 my @seqbase = splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/split(). "", ucscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/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->newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/Motif/Matrix/new().(-matrix => $matrixref,
113 -nr_hits=> $nrhits);
114 return $motif;
115 }
116
117 sub _validate_seqscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/_validate_seq(). {
118 # a utility function
119 my ($sequence)=@_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/`@_`.;
120 $sequence=~ s/[ACGT]//g;
121 return ($sequence eq "" ? 1 : 0);
122 }
123
124
125 1;