Debian Codegraph @

TFBS/PatternGen/MEME.pm

raw symbols SCIP
1
2 # TFBS module for TFBS::PatternGen::MEME
3 #
4 # Copyright Wynand Alkema
5 #
6 # You may distribute this module under the same terms as perl itself
7 #
8
9 # POD
10
11 =head1 NAME
12
13 TFBS::PatternGen::MEME - a pattern factory that uses the MEME program
14
15 =head1 SYNOPSIS
16
17 my $patterngen =
18 TFBS::PatternGen::MEME->new(-seq_file=>'sequences.fa',
19 -binary => 'meme'
20
21
22 my $pfm = $patterngen->pattern(); # $pfm is now a TFBS::Matrix::PFM object
23
24 =head1 DESCRIPTION
25
26 TFBS::PatternGen::MEME builds position frequency matrices
27 using an external program MEME written by Bailey and Elkan.
28 For information and source code of MEME see
29
30 http://www.sdsc.edu/MEME
31
32
33 =head1 FEEDBACK
34
35 Please send bug reports and other comments to the author.
36
37 =head1 AUTHOR - Wynand Alkema
38
39
40 Wynand Alkema E<lt>[email protected]<gt>
41
42 =cut
43
44 package TFBS::PatternGen::MEMEscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/;
45 use varsscip-perl cpan TFBS v0.5.0 vars/ qw(@ISA);
46 use strictscip-perl cpan TFBS v0.5.0 strict/;
47
48
49 # Object preamble - inherits from TFBS::PatternGen;
50
51 use TFBS::PatternGenscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/;
52 use TFBS::PatternGen::SimplePFMscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/;
53 use TFBS::PatternGen::MEME::Motifscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/Motif/;
54 use File::Tempscip-perl cpan TFBS v0.5.0 File/Temp/ qw(:POSIX);
55 use Bio::Seqscip-perl cpan TFBS v0.5.0 Bio/Seq/;
56 use Bio::SeqIOscip-perl cpan TFBS v0.5.0 Bio/SeqIO/;
57
58 @ISAscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/`@ISA`. = qw(TFBS::PatternGen);
59
60 =head2 new
61
62 Title : new
63 Usage : my $pattrengen = TFBS::PatternGen::MEME->new(%args);
64 Function: the constructor for the TFBS::PatternGen::MEME object
65 Returns : a TFBS::PatternGen::MEME object
66 Args : This method takes named arguments;
67 you must specify one of the following three
68 -seq_list # a reference to an array of strings
69 # and/or Bio::Seq objects
70 # or
71 -seq_stream # A Bio::SeqIO object
72 # or
73 -seq_file # the name of the fasta file containing
74 # all the sequences
75 Other arguments are:
76 -binary # a fully qualified path to the 'meme' executable
77 # OPTIONAL: default 'meme'
78 -additional_params # a string containing additional
79 # command-line switches for the
80 # meme program
81
82 =cut
83
84 sub newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/new(). {
85 my ($caller, %args) = @_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/`@_`.;
86 my $self = blessscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/bless(). {}, refscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/ref().($caller) || $caller;
87 $self->{'filename'} =$args{'-seq_file'};
88
89 $self->{'additional_params'} =
90 ($args{'-additional_params'}
91 ? (refscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/ref().($args{'-additional_params'})
92 ? joinscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/join().(' ', @{$args{'-additional_params'}})
93 : $args{'-additional_params'})
94 : "" );
95 $self->{'binary'} = $args{'-binary'} || 'meme';
96
97 $self->_create_seq_setscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/_create_seq_set().(%args) or diescip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/die(). ('Error creating sequence set');
98
99 $self->_run_memescip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/_run_meme().() or $self->throwscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/throw().("Error running MEME.");
100 return $self;
101 }
102
103 =head2 pattern
104
105 =head2 all_patterns
106
107 =head2 patternSet
108
109 The three methods listed above are used for the retrieval of patterns,
110 and are common to all TFBS::PatternGen::* classes. Please
111 see L<TFBS::PatternGen> for details.
112
113 =cut
114
115 sub _run_memescip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/_run_meme().{
116 my ($self)=shiftscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/shift().;
117 my $tmp_file = tmpnamscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/tmpnam().();
118 my $outstream = Bio::SeqIO->newscip-perl cpan TFBS v0.5.0 Bio/SeqIO/new().(-file=>">$tmp_file", -format=>"fasta");
119 foreach my $seqobj (@{ $self->{'seq_set'} } ) {
120 $outstream->write_seqscip-perl cpan TFBS v0.5.0 Bio/SeqIO/write_seq().($seqobj);
121 }
122 $outstream->closescip-perl cpan TFBS v0.5.0 Bio/SeqIO/close().();
123 my $command_line =
124 $self->{'binary'}." ".
125 $tmp_file." ".
126 "-text ".
127 "-dna ".
128 $self->{'additional_params'}
129 ." 2>/dev/null"
130 ;
131 # print STDERR "$command_line\n";
132 my $resultstring = `$command_line`;
133 # print STDERR $resultstring;
134 $self->_parse_meme_outputscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/_parse_meme_output().($resultstring,$command_line);
135 unlinkscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/unlink(). $tmp_file;
136 return 1
137 }
138
139 sub _parse_meme_outputscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/_parse_meme_output().{
140 my ($self,$resultstring,$command_line)=@_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/`@_`.;
141 if ($resultstring=~/^error/){
142 # warn "Error running AnnSpec\nNo patterns produced";
143 $self->throwscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/throw(). ("Error running MEME command:\n $command_line");
144 return;
145 }
146 my @motifs=splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/split().(/\*\nMOTIF/,$resultstring);
147 shiftscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/shift(). @motifs;#discard the first one
148 #print STDERR scalar @motifs,"\n";
149 foreach my $raw_motif(@motifs){
150 my ($matrix,$sites,$score)=$self->_parse_raw_matrixscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/_parse_raw_matrix().($raw_motif);
151 # print STDERR $matrix;
152 my $motif =TFBS::PatternGen::MEME::Motif->newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/Motif/new().
153 (
154 -tags => {score=>$score},#The score in this case is the E-value given in the output
155 -sites=>$sites,
156 -matrix => $matrix
157 );
158 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/push(). @{ $self->{'motifs'} }, $motif;
159 }
160 return
161 }
162 #
163 #
164 sub _parse_raw_matrixscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/_parse_raw_matrix().{
165 my ($self,$string)=@_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/`@_`.;
166 my @sites;
167 my @matrix;
168 $string=~s/(Motif \d+ block diagrams.*)//s;
169 # print STDERR $string;
170 my ($width,$e_value)=$string=~/width =\s+(\d+)\s+sites.*E-value =(.*)\n/;
171 # print STDERR $e_value,"\n";
172 $string=~s/.*Motif \d+ sites sorted by position p-value//s;
173 #print STDERR $string;
174 my @array=splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/split().("\n",$string);
175 foreach my $line(@array){
176 my $nr=0;
177 my $strand=1;#if revcomp is not selected the strand is always 1
178 next if $line=~/^-/;
179 next if $line=~/P-value\s+Site/;
180 my (@properties)=splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/split().(/\s+/,$line);
181 next if @properties<1;
182 # print STDERR "@properties\n";
183 #First determine whether -revcomp switch is used and thus strand info is given
184 if ($properties[1] eq "+" or $properties[1] eq "-"){
185 $strand=$properties[1];
186 $nr=1;
187 }
188 my $site = Bio::SeqFeature::Generic->newscip-perl cpan TFBS v0.5.0 Bio/SeqFeature/Generic/new(). ( -start =>$properties[1+$nr],
189 -end =>$properties[1+$nr]+$width-1,
190 -strand=>$strand,
191 -source=>'MEME',
192 -score=>$properties[2+$nr]
193 );
194 foreach my $seq(@{$self->{'seq_set'}}){
195 if ($seq->idscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/id(). eq $properties[0]){
196 $site->attach_seqscip-perl cpan TFBS v0.5.0 Bio/SeqFeature/Generic/attach_seq(). ($seq);
197 }
198 }
199 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/push(). @sites,$site;
200 }
201 foreach my $site(@sites){
202 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/push(). @matrix,$site->seqscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/seq().->seq;
203 }
204 my $patterngen=TFBS::PatternGen::SimplePFM->newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/new().(-seq_list=>\@matrix);
205 my $matrix=$patternscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/SimplePFM/pattern().gen->pattern->rawprintscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/MEME/rawprint().;
206 # print STDERR $matrix;
207 return ($matrix,\@sites,$e_value);
208 }
209
210
211 1;