Debian Codegraph @

blib/lib/TFBS/PatternGen/YMF.pm

raw symbols SCIP
1
2 # TFBS module for TFBS::PatternGen::YMF
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::YMFscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/;
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::YMF::Motifscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/Motif/;
53 use File::Tempscip-perl cpan TFBS v0.5.0 File/Temp/ qw(:POSIX);
54 use Bio::Seqscip-perl cpan TFBS v0.5.0 Bio/Seq/;
55 use Bio::SeqIOscip-perl cpan TFBS v0.5.0 Bio/SeqIO/;
56 use File::Tempscip-perl cpan TFBS v0.5.0 File/Temp/ qw/ tempfile tempdir /;
57 @ISAscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/`@ISA`. = qw(TFBS::PatternGen);
58
59 =head2 new
60
61 Title : new
62 Usage : my $patterngen = TFBS::PatternGen::YMF->new(%args);
63 Function: the constructor for the TFBS::PatternGen::MEME object
64 Returns : a TFBS::PatternGen::MEME object
65 Args : This method takes named arguments;
66 you must specify one of the following three
67 -seq_list # a reference to an array of strings
68 # and/or Bio::Seq objects
69 # or
70 -seq_stream # A Bio::SeqIO object
71 # or
72 -seq_file # the name of the fasta file containing
73 # all the sequences
74 Other arguments are:
75 -binary # a fully qualified path to the 'meme' executable
76 # OPTIONAL: default 'meme'
77 -additional_params # a string containing additional
78 # command-line switches for the
79 # meme program
80
81 =cut
82
83 sub newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/new(). {
84 my ($caller, %args) = @_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/`@_`.;
85 my $self = blessscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/bless(). {}, refscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/ref().($caller) || $caller;
86
87 $self->{'width'}=$args{'-length_oligo'};
88 $self->{'path_org'}=$args{'-pathoforganismtables'};
89 $self->{'len_region'}=$args{'-length_region'};
90 $self->{'config_file'}=$args{'-config_file'}||$args{'-stats_path'}."/stats.config";
91 #The latter is the example configfile that comes with the installation of YMF
92
93
94 $self->{'abs_stats_path'} = $args{'-abs_stats_path'} ;
95 #This is the directory where the executable and the results file is
96 #generated by the program are located
97
98 $self->_create_seq_setscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/_create_seq_set().(%args) or diescip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/die(). ('Error creating sequence set');
99
100 $self->_run_statsscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/_run_stats().() or $self->throwscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/throw().("Error running stats.");
101 return $self;
102 }
103
104 =head2 pattern
105
106 =head2 all_patterns
107
108 =head2 patternSet
109
110 The three methods listed above are used for the retrieval of patterns,
111 and are common to all TFBS::PatternGen::* classes. Please
112 see L<TFBS::PatternGen> for details.
113
114 =cut
115
116 sub _run_statsscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/_run_stats().{
117 my ($self)=shiftscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/shift().;
118 my $tmp_file = tmpnamscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/tmpnam().();
119 my $dumpfile = tmpnamscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/tmpnam().();
120 my $outstream = Bio::SeqIO->newscip-perl cpan TFBS v0.5.0 Bio/SeqIO/new().(-file=>">$tmp_file", -format=>"fasta");
121 foreach my $seqobj (@{ $self->{'seq_set'} } ) {
122 $outstream->write_seqscip-perl cpan TFBS v0.5.0 Bio/SeqIO/write_seq().($seqobj);
123 }
124 $outstream->closescip-perl cpan TFBS v0.5.0 Bio/SeqIO/close().();
125 my $dir = tempdirscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/tempdir().();
126 #print $dir;
127 #change directory to directory where the program is located
128 #system 'cd $dir.w;';
129 # my $command="cd $dir;";
130 # print $command;
131 # system $command;
132 # `$command`;
133 # system 'ls -ltr';
134
135 my $command_line =
136 $self->{'abs_stats_path'}."/stats ".
137 # "stats ".
138 $self->{'config_file'}." ".
139 $self->{'len_region'}." ".
140 $self->{'width'}." ".
141 $self->{'path_org'}." ".
142 "-sort ".#sorts on z-score
143 $tmp_file
144 ." >$dumpfile"
145 ;
146 # print STDERR "cd $dir;$command_line\n";
147 my $resultstring = `cd $dir;$command_line`;
148 # print STDERR $resultstring;
149
150 $self->_parse_stats_outputscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/_parse_stats_output().($resultstring,$command_line,$dumpfile,$dir);
151 unlinkscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/unlink(). $tmp_file;
152 #unlink $dumpfile;
153 return 1
154 }
155
156
157
158 #
159 sub _parse_stats_outputscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/_parse_stats_output().{
160 my ($self,$resultstring,$command_line,$dumpfile,$temp_dir)=@_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/`@_`.;
161 openscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/open(). DUMP,$dumpfile;
162 while(<DUMP>){
163 if ((/(^Error.*)/) or /(.*Aborting.*)/){
164 # warn "Error running AnnSpec\nNo patterns produced";
165 printscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/print(). "YMF Error message: \"$1\"\n";
166 unlinkscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/unlink(). $dumpfile;
167 $self->throwscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/throw(). ("Error running YMF using command:\n $command_line");
168 return;
169 }
170 }
171 unlinkscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/unlink(). $dumpfile;
172 openscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/open(). RES,"$temp_dir/results";
173 my $skip=<RES>;
174 while (<RES>){
175 my ($word,$occ,$z_score,$expect,$var)=splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/split().;
176 #print $word;
177 my $motif =TFBS::PatternGen::YMF::Motif->newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/Motif/new().
178 (-word=>$word,
179 -tags => {z_score=>$z_score,
180 'occurences'=>$occ,
181 'expectation value'=>$expect,
182 'variance'=>$var}
183 );
184 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/YMF/push(). @{ $self->{'motifs'} }, $motif;
185 }
186 my $command="rm -r $temp_dir";
187 #print $command;
188 `$command`;# or die "could not unlink $!";
189 # return
190 }
191 #
192
193 1;