Debian Codegraph @

TFBS/PatternGen/AnnSpec.pm

raw symbols SCIP
1
2 # TFBS module for TFBS::PatternGen::AnnSpec
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::AnnSpec - a pattern factory that uses the AnnSpec program (version 2.1)
14
15 =head1 SYNOPSIS
16
17 my $patterngen =
18 TFBS::PatternGen::AnnSpec->new(-seq_file=>'sequences.fa',
19 -binary => 'ann-spec '
20
21
22 my $pfm = $patterngen->pattern(); # $pfm is now a TFBS::Matrix::PFM object
23
24
25 =head1 DESCRIPTION
26
27 TFBS::PatternGen::AnnSpec builds position frequency matrices
28 using an external program AnnSpec (Workman, C. and Stormo, G.D. (2000) ANN-Spec: A method for discovering transcription factor binding sites with improved specificity. Proc. Pacific Symposium on Biocomputing 2000).
29
30 =head1 FEEDBACK
31
32 Please send bug reports and other comments to the author.
33
34 =head1 AUTHOR - Wynand Alkema
35
36 Wynand Alkema E<lt>[email protected]<gt>
37
38 =cut
39
40 package TFBS::PatternGen::AnnSpecscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/;
41 use varsscip-perl cpan TFBS v0.5.0 vars/ qw(@ISA);
42 use strictscip-perl cpan TFBS v0.5.0 strict/;
43
44
45 # Object preamble - inherits from TFBS::PatternGen;
46
47 use TFBS::PatternGenscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/;
48 use TFBS::PatternGen::AnnSpec::Motifscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/Motif/;
49 use File::Tempscip-perl cpan TFBS v0.5.0 File/Temp/ qw(:POSIX);
50 use Bio::Seqscip-perl cpan TFBS v0.5.0 Bio/Seq/;
51 use Bio::SeqIOscip-perl cpan TFBS v0.5.0 Bio/SeqIO/;
52
53 @ISAscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/`@ISA`. = qw(TFBS::PatternGen);
54
55 =head2 new
56
57 Title : new
58 Usage : my $pattrengen = TFBS::PatternGen::AnnSpec->new(%args);
59 Function: the constructor for the TFBS::PatternGen::AnnSpec object
60 Returns : a TFBS::PatternGen::AnnSpec object
61 Args : This method takes named arguments;
62 you must specify one of the following three
63 -seq_list # a reference to an array of strings
64 # and/or Bio::Seq objects
65 # or
66 -seq_stream # A Bio::SeqIO object
67 # or
68 -seq_file # the name of the fasta file containing
69 # all the sequences
70 Other arguments are:
71 -binary # a fully qualified path to the 'meme' executable
72 # OPTIONAL: default 'ann-spec'
73 -additional_params # a string containing additional
74 # command-line switches for the
75 # ann-spec program
76
77 =cut
78
79 sub newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/new(). {
80 my ($caller, %args) = @_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/`@_`.;
81 my $self = blessscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/bless(). {}, refscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/ref().($caller) || $caller;
82 $self->{'filename'} =$args{'-seq_file'};
83
84 $self->{'additional_params'} =
85 ($args{'-additional_params'}
86 ? (refscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/ref().($args{'-additional_params'})
87 ? joinscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/join().(' ', @{$args{'-additional_params'}})
88 : $args{'-additional_params'})
89 : "" );
90 $self->{'binary'} = $args{'-binary'} || 'annspec';
91 $self->_create_seq_setscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_create_seq_set().(%args) or diescip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/die(). ('Error creating sequence set');
92 $self->_run_AnnSpecscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_run_AnnSpec().() or $self->throwscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/throw().("Error running AnnSpec.");
93 return $self;
94 }
95
96
97 =head2 pattern
98
99 =head2 all_patterns
100
101 =head2 patternSet
102
103 The three methods listed above are used for the retrieval of patterns,
104 and are common to all TFBS::PatternGen::* classes. Please
105 see L<TFBS::PatternGen> for details.
106
107 =cut
108
109 sub _run_AnnSpecscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_run_AnnSpec().{
110 my ($self)=shiftscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/shift().;
111 my $tmp_file = tmpnamscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/tmpnam().();
112 my $outstream = Bio::SeqIO->newscip-perl cpan TFBS v0.5.0 Bio/SeqIO/new().(-file=>">$tmp_file", -format=>"fasta");
113 foreach my $seqobj (@{ $self->{'seq_set'} } ) {
114 $outstream->write_seqscip-perl cpan TFBS v0.5.0 Bio/SeqIO/write_seq().($seqobj);
115 }
116 $outstream->closescip-perl cpan TFBS v0.5.0 Bio/SeqIO/close().();
117 my $command_line =
118 $self->{'binary'}." ".
119 "-f ".$tmp_file." ".
120 # $self->{'motif_length_string'}." ".
121 # $self->{'nr_hits_string'}." ".
122 $self->{'additional_params'}.
123 "";
124 # print STDERR "$command_line\n";
125 my $resultstring = `$command_line`;
126 printscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/print(). "$resultstring\n";
127 # open(TEST, "test.out"); # this sentense is the one I add
128 # my @lines = <TEST>;# this sentense is the one I add
129 # my $resultstring = join '', @lines;# this sentense is the one I add
130 # print STDERR $resultstring;
131 $self->_parse_AnnSpec_outputscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_parse_AnnSpec_output().($resultstring,$command_line);
132 unlinkscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/unlink(). $tmp_file;
133 return 1
134 }
135
136 sub _parse_AnnSpec_outputscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_parse_AnnSpec_output().{
137 my ($self,$resultstring,$command_line)=@_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/`@_`.;
138 if ($resultstring eq''){
139 # warn "Error running AnnSpec\nNo patterns produced";
140 $self->throwscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/throw(). ("Error running AnnSpec using command:\n $command_line");
141 return;
142 }
143 my ($consensus,$matrix)=$self->_parse_raw_matrixscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_parse_raw_matrix().($resultstring);
144 my ($score,$sites)=$self->_parse_sitesscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_parse_sites().($resultstring);
145
146 for(my $x = 0; $x < scalarscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/scalar().(@$consensus); $x++){
147 my $motif =TFBS::PatternGen::AnnSpec::Motif->newscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/Motif/new().
148 (
149 #-length => $length."",
150 # -bg_probabilities => [split /\s+/, $raw_bp],
151 -tags => {consensus => $consensus->[$x],
152 score=>$score->[$x]},
153
154 -nr_hits => 1,
155 -sites=>$sites->[$x],
156 -matrix => $matrix->[$x]
157 );
158 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/push(). @{ $self->{'motifs'} }, $motif;
159 }
160 return
161 }
162
163 sub _parse_sitesscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_parse_sites().{
164 my ($self,$string)=@_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/`@_`.;
165
166 my (@hits, @scores);
167
168 foreach my $substring (splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/split(). /REPORTING/, $string ){
169 my @sub_hits;
170 my ($sites)=$substring=~/STR\s+n.*seq\n(.*)RUN\s+ALIGNMENT.*/s;
171 my ($average)=$substring=~/RUN INFORMATION_CONTENT\s+(\d*\.*\d*)/;
172 my ($score)=$substring=~/RUN\s+SCORE\s+(\d*\.*\d*)/;
173
174 if($sites){
175 my @sites=splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/split()./\n/,$sites;
176
177 foreach my $site (@sites){
178 my @site_array=splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/split().(/\s+/,$site);
179 my ($seq_id)=$site_array[6]=~/>(.*)/;
180 my $strand=1;
181 $strand=-1 if $site_array[3]=~/\'/;#MEans we have a pattern in the reverse strand
182 my ($start)=$site_array[3]=~/(\d+)/;
183 my $site = Bio::SeqFeature::Generic->newscip-perl cpan TFBS v0.5.0 Bio/SeqFeature/Generic/new(). ( -start => $start,
184 -end => $start+(lengthscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/length().$site_array[4])-1,
185 -strand => $strand,
186 -source => 'AnnSpec',
187 -score => $site_array[2],
188 );
189
190 foreach my $seq(@{$self->{'seq_set'}}){
191 if ($seq->idscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/id(). eq $seq_id){
192 $site->attach_seqscip-perl cpan TFBS v0.5.0 Bio/SeqFeature/Generic/attach_seq(). ($seq);
193 }
194 }
195 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/push(). (@sub_hits,$site);
196 }
197
198
199 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/push(). @scores, $score;
200 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/push(). @hits, \@sub_hits;
201 }
202
203 }
204 return \@scores,\@hits;
205
206 }
207
208 sub _parse_raw_matrixscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/_parse_raw_matrix().{
209 my ($self,$string)=@_scip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/`@_`.;
210
211 my (@pfms, @consensus);
212 foreach my $sub_string (splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/split(). /REPORTING/, $string){
213 my ($ma)=$sub_string=~/RUN\s+WEIGHTS_CONS.*ALR\s+\/.*ALR\s+\#.*(ALR.*\nALR.*\nALR.*\nALR.*\s+\d+\n)ALR\s+=+.*/s;
214 my ($con)=$sub_string=~/WEIGHTS_CONS\s+(.*)\n/;
215
216 if($ma){
217 my @matrix=splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/split().("\n",$ma);
218 my @pfm;
219 foreach my $row(@matrix){
220 # print $row;
221 my @row=splitscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/split(). /\s+/, $row;
222 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/push(). @pfm, [@row[2..scalarscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/scalar().@row-1]];
223 }
224 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/push(). @pfms, \@pfm;
225 pushscip-perl cpan TFBS v0.5.0 TFBS/PatternGen/AnnSpec/push(). @consensus, $con;
226 }
227 }
228
229 return \@consensus, \@pfms;
230
231 }
232
233
234 1;