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