| 1 |
# TFBS module for TFBS::Site |
| 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::Site - a nucleotide sequence feature object representing (possibly putative) transcription factor binding site. |
| 13 |
|
| 14 |
=head1 SYNOPSIS |
| 15 |
|
| 16 |
# manual creation of site object; |
| 17 |
# for details, see documentation of Bio::SeqFeature::Generic; |
| 18 |
|
| 19 |
my $site = TFBS::Site |
| 20 |
(-start => $start_pos, # integer |
| 21 |
-end => $end_pos, # integer |
| 22 |
-score => $score, # float |
| 23 |
-source => "TFBS", # string |
| 24 |
-primary => "TF binding site", # primary tag |
| 25 |
-strand => $strand, # -1, 0 or 1 |
| 26 |
-seqobj => $seqobj, # a Bio::Seq object whose sequence |
| 27 |
# contains the site |
| 28 |
-pattern => $pattern_obj # usu. TFBS::Matrix:PWM obj. |
| 29 |
-); |
| 30 |
|
| 31 |
|
| 32 |
# Searching sequence with a pattern (PWM) and retrieving individual sites: |
| 33 |
# |
| 34 |
# The following objects should be defined for this example: |
| 35 |
# $pwm - a TFBS::Matrix::PWM object |
| 36 |
# $seqobj - a Bio::Seq object |
| 37 |
# Consult the documentation for the above modules if you do not know |
| 38 |
# how to create them. |
| 39 |
|
| 40 |
# Scanning sequence with $pwm returns a TFBS::SiteSet object: |
| 41 |
|
| 42 |
my $site_set = $pwm->search_seq(-seqobj => $seqobj, |
| 43 |
-threshold => "80%"); |
| 44 |
|
| 45 |
# To retrieve individual sites from $site_set, create an iterator obj: |
| 46 |
|
| 47 |
my $site_iterator = $site_set->Iterator(-sort_by => "score"); |
| 48 |
|
| 49 |
while (my $site = $site_iterator->next()) { |
| 50 |
# do something with $site |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
=head1 DESCRIPTION |
| 56 |
|
| •57 |
TFBS::Site object holds data for a (possibly predicted) transcription factor binding site on a nucleotide sequence (start, end, strand, score, tags, as well as references to the corresponding sequence and pattern objects). TFBS::Site is a subclass of Bio::SeqFeature::Generic and has access to all of its method. Additionally, it contains the pattern() method, an accessor for pattern object associated with the site object. |
| 58 |
|
| 59 |
=head1 FEEDBACK |
| 60 |
|
| 61 |
Please send bug reports and other comments to the author. |
| 62 |
|
| 63 |
=head1 AUTHOR - Boris Lenhard |
| 64 |
|
| 65 |
Boris Lenhard E<lt>[email protected]<gt> |
| 66 |
|
| 67 |
=head1 APPENDIX |
| 68 |
|
| 69 |
The rest of the documentation details each of the object |
| 70 |
methods. Internal methods are preceded with an underscore. |
| 71 |
|
| 72 |
TFBS::Site is a class that extends Bio::SeqFeature::Generic. Please consult Bio::SeqFeature::Generic documentation for other available methods. |
| 73 |
|
| 74 |
=cut |
| 75 |
|
| 76 |
|
| 77 |
# The code begins HERE: |
| 78 |
|
| 79 |
|
| 80 |
package TFBS::Site; |
| 81 |
|
| 82 |
use vars qw(@ISA); |
| 83 |
use strict; |
| 84 |
|
| 85 |
use Bio::SeqFeature::Generic; |
| 86 |
@ISA = qw(Bio::SeqFeature::Generic); |
| 87 |
|
| 88 |
=head2 new |
| 89 |
|
| 90 |
Title : new |
| 91 |
Usage : my $site = TFBS::Site->new(%args) |
| 92 |
Function: constructor for the TFBS::Site object |
| 93 |
Returns : TFBS::Site object |
| 94 |
Args : -start, # integer |
| 95 |
-end, # integer |
| 96 |
-strand, # -1, 0 or 1 |
| 97 |
-score, # float |
| 98 |
-source, # string (method used to detect it) |
| 99 |
-primary, # string (primary tag) |
| 100 |
-seqobj, # a Bio::Seq object |
| 101 |
-pattern # a pattern object, usu. TFBS::Matrix::PWM |
| 102 |
|
| 103 |
=cut |
| 104 |
|
| 105 |
|
| 106 |
sub new { |
| 107 |
my $class = shift; |
| 108 |
my %args = (-seq_id => undef, |
| 109 |
-siteseq => undef, |
| 110 |
-seqobj => undef, |
| 111 |
-strand => "0", |
| 112 |
-source => "TFBS", |
| 113 |
-primary => "TF binding site", |
| 114 |
-pattern => undef, |
| 115 |
-score => undef, |
| 116 |
-start => undef, |
| 117 |
-end => undef, |
| 118 |
-frame => 0, |
| 119 |
@_); |
| 120 |
my $obj = Bio::SeqFeature::Generic->new(%args); |
| 121 |
my $self = bless $obj, ref($class) || $class; |
| 122 |
if ($args{-seqobj}) { |
| 123 |
$self->attach_seq($args{-seqobj}) ; |
| 124 |
$self->add_tag_value('sequence', $self->seq->seq); |
| 125 |
} |
| 126 |
# this is only for GFF printing really, and will be moved there soon |
| 127 |
|
| 128 |
if (defined $args{'-pattern'}) { |
| 129 |
$self->pattern($args{'-pattern'}); |
| 130 |
$self->add_tag_value('TF' => $self->pattern->name()); |
| 131 |
$self->add_tag_value('class' => $self->pattern->class) |
| 132 |
if $self->pattern->class; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
return $self; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
=head2 pattern |
| 142 |
|
| 143 |
Title : pattern |
| 144 |
Usage : my $pattern = $site->pattern(); # gets the pattern |
| 145 |
$site->pattern($pwm); # sets the pattern to $pwm |
| 146 |
Function: gets/sets the pattern object associated with the site |
| 147 |
Returns : pattern object, here TFBS::Matrix::PWM object |
| 148 |
Args : pattern object (optional, for setting the pattern only) |
| 149 |
|
| 150 |
=cut |
| 151 |
|
| 152 |
|
| 153 |
sub pattern { |
| 154 |
my ($self, $pattern) = @_; |
| 155 |
if (defined $pattern) { |
| 156 |
$self->{'pattern'} = $pattern; |
| 157 |
} |
| 158 |
return $self->{'pattern'}; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
=head2 rel_score |
| 163 |
|
| 164 |
Title : rel_score |
| 165 |
Usage : my $percent_score = $site->rel_score() * 100; # gets the pattern |
| 166 |
Function: gets relative score (between 0.0 to 1.0) with respect of the score |
| 167 |
range of the associated pattern (matrix) |
| 168 |
Returns : floating point number between 0 and 1, |
| 169 |
or undef if pattern not defined |
| 170 |
Args : none |
| 171 |
|
| 172 |
=cut |
| 173 |
|
| 174 |
|
| 175 |
sub rel_score { |
| 176 |
my ($self) = @_; |
| 177 |
return undef unless $self->pattern(); |
| 178 |
return ($self->score - $self->pattern->min_score)/ |
| 179 |
($self->pattern->max_score - $self->pattern->min_score); |
| 180 |
} |
| 181 |
|
| 182 |
=head2 GFF |
| 183 |
|
| 184 |
Title : GFF |
| 185 |
Usage : print $site->GFF(); |
| 186 |
: print $site->GFF($gff_formatter) |
| 187 |
Function: returns a "standard" GFF string - the "generic" gff_string |
| 188 |
method is left untouched for possible customizations |
| 189 |
Returns : a string (NOT newline terminated! ) |
| 190 |
Args : a $gff_formatter function reference (optional) |
| 191 |
|
| 192 |
=cut |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
sub GFF { |
| 197 |
# due to popular demand, GFF is again a legal method, this time |
| 198 |
# not requiring GFF modules |
| 199 |
|
| 200 |
return $_[0]->gff_string($_[1]); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
=head2 location |
| 205 |
|
| 206 |
=head2 start |
| 207 |
|
| 208 |
=head2 end |
| 209 |
|
| 210 |
=head2 length |
| 211 |
|
| 212 |
=head2 score |
| 213 |
|
| 214 |
=head2 frame |
| 215 |
|
| 216 |
=head2 sub_SeqFeature |
| 217 |
|
| 218 |
=head2 add_sub_SeqFeature |
| 219 |
|
| 220 |
=head2 flush_sub_SeqFeature |
| 221 |
|
| 222 |
=head2 primary_tag |
| 223 |
|
| 224 |
=head2 source_tag |
| 225 |
|
| 226 |
=head2 has_tag |
| 227 |
|
| 228 |
=head2 add_tag_value |
| 229 |
|
| 230 |
=head2 each_tag_value |
| 231 |
|
| 232 |
=head2 all_tags |
| 233 |
|
| 234 |
=head2 remove_tag |
| 235 |
|
| 236 |
=head2 attach_seq |
| 237 |
|
| 238 |
=head2 seq |
| 239 |
|
| 240 |
=head2 entire_seq |
| 241 |
|
| 242 |
=head2 seq_id |
| 243 |
|
| 244 |
=head2 annotation |
| 245 |
|
| 246 |
=head2 gff_format |
| 247 |
|
| 248 |
=head2 gff_string |
| 249 |
|
| 250 |
The above methods are inherited from Bio::SeqFeature::Generic. |
| 251 |
Please see L<Bio::SeqFeature::Generic> for details on their usage. |
| 252 |
|
| 253 |
=cut |
| 254 |
|
| 255 |
################################################################## |
| 256 |
# BACKWARD COMPATIBILITY METHODS |
| 257 |
|
| 258 |
sub Matrix { |
| 259 |
my ($self, %args) = @_; |
| 260 |
$self->pattern(%args); |
| 261 |
} |
| 262 |
|
| 263 |
sub seqobj { |
| 264 |
|
| 265 |
} |
| 266 |
|
| 267 |
sub siteseq { |
| 268 |
$_[0]->seq->seq(); |
| 269 |
} |
| 270 |
|
| 271 |
sub site_length { |
| 272 |
my ($self) = @_; |
| 273 |
$self->warn("site_length method is present for backward compatibility only. In new code please use the length() method"); |
| 274 |
return $self->length(); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
sub old_GFF { |
| 279 |
eval "require GFF::GeneFeature;"; |
| 280 |
if ($@) { print STDERR "Failed to load GFF modules, stopped"; return; } |
| 281 |
my ($self, %tags) =@_; |
| 282 |
$self->warn("GFF method is for backward compatibility only, and its use in new code is not recommended. Please use Bio::SeqFeature::Generic gff methods if possible."); |
| 283 |
my $GFFgf = GFF::GeneFeature->new(2); |
| 284 |
|
| 285 |
$GFFgf->seqname ( $self->seqname() or "Unknown" ); |
| 286 |
$GFFgf->source ("TFBS"); |
| 287 |
$GFFgf->feature ("TFBS"); |
| 288 |
$GFFgf->start ($self->start()); |
| 289 |
$GFFgf->end ($self->end()); |
| 290 |
$GFFgf->score ($self->score()); |
| 291 |
$GFFgf->strand (("-",".","+")[$self->strand()+1]); |
| 292 |
# $GFFgf->strand ($self->strand()); |
| 293 |
|
| 294 |
%tags = (TF => $self->pattern->{name}, |
| 295 |
class => $self->pattern->{class}, |
| 296 |
sequence => $self->seq->seq(), |
| 297 |
%tags); |
| 298 |
while (my ($tag, $value) = each %tags) { |
| 299 |
my @values; |
| 300 |
if (ref($value) eq "ARRAY") { |
| 301 |
@values = @$value; |
| 302 |
} |
| 303 |
else { |
| 304 |
@values = ($value); |
| 305 |
} |
| 306 |
$GFFgf->attribute($tag, @values); |
| 307 |
} |
| 308 |
return $GFFgf; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
1; |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|