| 1 |
# TFBS module for TFBS::DB::TRANSFAC |
| 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::DB::TRANSFAC - interface to database of TRANSFAC public |
| 13 |
position frequency matrices at TESS (http://www.cbil.upenn.edu/tess) |
| 14 |
|
| 15 |
-------------------------------- NOTICE ---------------------------------- |
| 16 |
The TRANSFAC database is free for non-commercial use. For commercial use |
| 17 |
the TRANSFAC databases and programs have to be licensed. Please read |
| 18 |
the DISCLAIMER at http://transfac.gbf.de/TRANSFAC/disclaimer.htm. |
| 19 |
------------------------------------------------------------------------- |
| 20 |
|
| 21 |
=head1 SYNOPSIS |
| 22 |
|
| 23 |
=over 4 |
| 24 |
|
| 25 |
=item * creating a database object by connecting to TRANSFAC data |
| 26 |
|
| 27 |
my $db = TFBS::DB::TRANSFAC->connect(); |
| 28 |
|
| 29 |
=item * retrieving a TFBS::Matrix::* object from the database |
| 30 |
|
| 31 |
# retrieving a PFM by ID |
| 32 |
my $pfm = $db->get_Matrix_by_ID('V$CEBPA_01','PFM'); |
| 33 |
|
| 34 |
#retrieving a PWM by TRANSFAC accession number |
| 35 |
my $pwm = $db->get_Matrix_by_acc('M00116', 'PWM'); |
| 36 |
|
| 37 |
=back |
| 38 |
|
| 39 |
=head1 DESCRIPTION |
| 40 |
|
| 41 |
TFBS::DB::TRANSFAC is a read only database interface that fetches |
| 42 |
TRANSFAC matrix data from TESS web interface |
| 43 |
(http://www.cbil.upen.edu/TESS) and returns TFBS::Matrix::* objects. |
| 44 |
|
| 45 |
=cut |
| 46 |
|
| 47 |
package TFBS::DB::TRANSFAC; |
| 48 |
|
| 49 |
use vars qw(@ISA $ua); |
| 50 |
use strict; |
| 51 |
use Bio::Root::Root; |
| 52 |
use TFBS::Matrix::PFM; |
| 53 |
use LWP::Simple qw($ua get); |
| 54 |
|
| 55 |
@ISA = qw(TFBS::DB Bio::Root::Root); |
| 56 |
|
| 57 |
=head2 connect |
| 58 |
|
| 59 |
Title : connect |
| 60 |
Usage : my $db = TFBS::DB::TRANSFAC->connect(%args); |
| 61 |
Function: Creates a TRANSFAC database connection object, which can be used |
| 62 |
to retrieve matrices from public TRANSFAC databases via the web |
| 63 |
Returns : a TFBS::DB::TRANSFAC object |
| 64 |
Args : -proxy # OPTIONAL: a http proxy server name, |
| 65 |
# usually required for accessing TRANSFAC from behind |
| 66 |
# a firewall |
| 67 |
-accept_conditions # OPTIONAL: by setting this to a true |
| 68 |
# value, you confirm that you |
| 69 |
# have read and accepted the terms |
| 70 |
# of use of TRANSFAC at |
| 71 |
# http://transfac.gbf.de/TRANSFAC/disclaimer.htm; |
| 72 |
# this also suppresses the annoying |
| 73 |
# message that is printed to STDERR |
| 74 |
# upon invoking the method |
| 75 |
|
| 76 |
=cut |
| 77 |
|
| 78 |
sub connect { |
| 79 |
my ($caller, %args) = @_; |
| 80 |
my $self = bless {}, ref $caller || $caller; |
| 81 |
|
| 82 |
unless (defined ($args{-accept_conditions}) and $args{-accept_conditions}) { |
| 83 |
print STDERR <<ENDNOTICE |
| 84 |
-------------------------------- NOTICE ---------------------------------- |
| 85 |
The TRANSFAC database is free for non-commercial use. For commercial use |
| 86 |
the TRANSFAC databases and programs have to be licensed. Please read |
| 87 |
the DISCLAIMER at http://transfac.gbf.de/TRANSFAC/disclaimer.htm. |
| 88 |
----------- |
| 89 |
If you have read the disclaimer and accept the conditions stated therein, |
| 90 |
you can suppres this notice by connecting to TRANSFAC like this: |
| 91 |
my \$db = TFBS::DB::TRANSFAC->connect(-accept_conditions => 1); |
| 92 |
-------------------------------------------------------------------------- |
| 93 |
ENDNOTICE |
| 94 |
; |
| 95 |
} |
| 96 |
if (defined $args{'-proxy'}) { |
| 97 |
$ua->proxy('http',$args{'-proxy'}); |
| 98 |
} |
| 99 |
return $self; |
| 100 |
} |
| 101 |
|
| 102 |
=head2 new |
| 103 |
|
| 104 |
Title : connect |
| 105 |
Usage : my $db = TFBS::DB::TRANSFAC->connect(%args); |
| 106 |
Function: Here, I<new> is just a synonim for I<connect> |
| 107 |
(to make the interface consistent with other |
| 108 |
bioperl read-obly Bio::DB::* objects) |
| 109 |
Returns : a TFBS::DB::TRANSFAC object |
| 110 |
Args : -accept_conditions # see explanation at I<new> |
| 111 |
|
| 112 |
=cut |
| 113 |
|
| 114 |
|
| 115 |
sub new { |
| 116 |
my ($caller, %args) = @_; |
| 117 |
$caller->connect(%args); |
| 118 |
} |
| 119 |
|
| 120 |
=head2 get_Matrix_by_ID |
| 121 |
|
| 122 |
Title : get_Matrix_by_ID |
| 123 |
Usage : my $pfm = $db->get_Matrix_by_ID('V$CREB_01', 'PFM'); |
| 124 |
Function: fetches matrix data under the given TRANSFAC ID from the |
| 125 |
database and returns a TFBS::Matrix::* object |
| 126 |
Returns : a TFBS::Matrix::* object; the exact type of the |
| 127 |
object depending on the second argument (allowed |
| 128 |
values are 'PFM', 'ICM', and 'PWM'); returns undef if |
| 129 |
matrix with the given ID is not found |
| 130 |
Args : (Matrix_ID, Matrix_type) |
| 131 |
Matrix_ID is a string; Matrix_type is one of the |
| 132 |
following: 'PFM' (raw position frequency matrix), |
| 133 |
'ICM' (information content matrix) or 'PWM' (position |
| 134 |
weight matrix) |
| 135 |
If Matrix_type is omitted, a PFM is retrieved by default. |
| 136 |
|
| 137 |
=cut |
| 138 |
|
| 139 |
sub get_Matrix_by_ID { |
| 140 |
my ($self, $ID, $mt) = @_; |
| 141 |
unless (defined $ID) { |
| 142 |
$self->throw("No parameters passed to get_Matrix_by_ID."); |
| 143 |
} |
| 144 |
my $url = "http://www.cbil.upenn.edu/cgi-bin/tess/tess33?request=MTX-DBRTRV-Id&key=$ID"; |
| 145 |
# my $url = "http://www.cbil.upenn.edu/cgi-bin/tess/tess33?request=MTX-DBRTRV-Id&key=$ID"; |
| 146 |
return $self->_get_Matrix_by_URL($url, $mt); |
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
=head2 get_Matrix_by_acc |
| 151 |
|
| 152 |
Title : get_Matrix_by_acc |
| 153 |
Usage : my $pfm = $db->get_Matrix_by_acc('V$CREB_01', 'PFM'); |
| •154 |
Function: fetches matrix data under the given TRANSFAC accession number |
| 155 |
from database and returns a TFBS::Matrix::* object |
| 156 |
Returns : a TFBS::Matrix::* object; the exact type of the |
| 157 |
object depending on the second argument (allowed |
| 158 |
values are 'PFM', 'ICM', and 'PWM'); returns undef if |
| 159 |
matrix with the given ID is not found |
| 160 |
Args : (Matrix_ID, Matrix_type) |
| 161 |
Matrix_ID is a string; Matrix_type is one of the |
| 162 |
following: 'PFM' (raw position frequency matrix), |
| 163 |
'ICM' (information content matrix) or 'PWM' (position |
| 164 |
weight matrix) |
| 165 |
If Matrix_type is omitted, a PFM is retrieved by default. |
| 166 |
|
| 167 |
=cut |
| 168 |
|
| 169 |
|
| 170 |
sub get_Matrix_by_acc { |
| 171 |
my ($self, $acc, $mt) = @_; |
| 172 |
unless (defined $acc) { |
| 173 |
$self->throw("No parameters passed to get_Matrix_by_ID."); |
| 174 |
} |
| 175 |
|
| 176 |
my $url = "http://www.cbil.upenn.edu/cgi-bin/tess/tess33?request=MTX-DBRTRV-Accno&key=$acc"; |
| 177 |
return $self->_get_Matrix_by_URL($url, $mt); |
| 178 |
} |
| 179 |
|
| 180 |
sub get_MatrixSet { |
| 181 |
my ($self, %args) = @_; |
| 182 |
# not yet implemented |
| 183 |
} |
| 184 |
|
| 185 |
sub _get_Matrix_by_URL { |
| 186 |
my ($self, $url, $mt) = @_; |
| 187 |
my $HTMLpage = get $url || return undef; |
| 188 |
my (@As, @Cs, @Gs, @Ts, $name, $ID, $acc); |
| 189 |
my @lines = split "\n", $HTMLpage; |
| 190 |
foreach my $line (@lines) { |
| 191 |
$line =~ s/\r//; |
| 192 |
$line =~ s/<\/{0,1}b>//gi; |
| 193 |
$line =~ s/ //gi; |
| 194 |
if ($line =~ /Name<\/td><td>([^<]+)</) { |
| 195 |
$name = $1; |
| 196 |
} |
| 197 |
elsif ($line =~ /ID<\/td><td>([^<]+)</) { |
| 198 |
|
| 199 |
$ID = $1; |
| 200 |
} |
| 201 |
elsif ($line =~ /AccNo<\/td><td>([^<]+)</) { |
| 202 |
$acc = $1; |
| 203 |
} |
| 204 |
elsif ($line =~ /\d+\.\d+\s+(\d+\.\d+)\s+(\d+\.{0,1}\d*)\s+(\d+\.{0,1}\d*)\s+(\d+\.{0,1}\d*)\s+(\d+\.{0,1}\d*)/) { |
| 205 |
my ($nr, $A, $C, $G, $T) = ($1,$2,$3,$4,$5); #split /\s+/, $line; |
| 206 |
push @As,$A; push @Cs,$C; push @Gs,$G; push @Ts,$T; |
| 207 |
} |
| 208 |
} |
| 209 |
return undef unless @As; |
| 210 |
my $pfm = TFBS::Matrix::PFM-> new ( -ID => $ID, |
| 211 |
-name => $name, |
| 212 |
-tags => {acc=>$acc}, |
| 213 |
-matrix => [ \@As, \@Cs, \@Gs, \@Ts] |
| 214 |
); |
| 215 |
if (!defined($mt) or uc($mt) eq "PFM") {return $pfm;} |
| 216 |
elsif (uc($mt) eq "ICM") {return $pfm->to_ICM;} |
| 217 |
elsif (uc($mt) eq "PWM") {return $pfm->to_PWM;} |
| 218 |
else { $self->throw("Unrecognized matrix format: $mt"); } |
| 219 |
} |
| 220 |
|
| 221 |
1; |