TFBS::DB
JASPAR6
Summary
TFBS::DB::JASPAR6 - interface to MySQL relational database of pattern matrices. Currently status: experimental.
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
* creating a database object by connecting to the existing JASPAR6-type database
my $db = TFBS::DB::JASPAR6->connect("dbi:mysql:JASPAR6:myhost",
"myusername",
"mypassword");
* retrieving a TFBS::Matrix::* object from the database
# retrieving a PFM by ID
my $pfm = $db->get_Matrix_by_ID('M0079','PFM');
#retrieving a PWM by name
my $pwm = $db->get_Matrix_by_name('NF-kappaB', 'PWM');
* retrieving a set of matrices as a TFBS::MatrixSet object according to various criteria
* creating a new JASPAR6-type database named MYJASPAR6:
* storing a matrix in the database (currently only PFMs):
#let $pfm is a TFBS::Matrix::PFM object
$db->store_Matrix($pfm);
Description
TFBS::DB::JASPAR6 is a read/write database interface module that
retrieves and stores TFBS::Matrix::* and TFBS::MatrixSet
objects in a relational database. The interface is nearly identical
to the JASPAR2 and JASPAR4 interface, while the underlying data model is different
Methods
Methods description
Title : connect Usage : my $db = TFBS::DB::JASPAR6->connect("dbi:mysql:DATABASENAME:HOSTNAME", "USERNAME", "PASSWORD"); Function: connects to the existing JASPAR6-type database and returns a database object that interfaces the database Returns : a TFBS::DB::JASPAR6 object Args : a standard database connection triplet ("dbi:mysql:DATABASENAME:HOSTNAME", "USERNAME", "PASSWORD") In place of DATABASENAME, HOSTNAME, USERNAME and PASSWORD, use the actual values. PASSWORD and USERNAME might be optional, depending on the user's acces permissions for the database server. |
Title : dbh Usage : my $dbh = $db->dbh(); $dbh->do("UPDATE matrix_data SET name='ADD1' WHERE NAME='SREBP2'"); Function: returns the DBI database handle of the MySQL database interfaced by $db; THIS IS USED FOR WRITING NEW METHODS FOR DIRECT RELATIONAL DATABASE MANIPULATION - if you have write access AND do not know what you are doing, you can severely corrupt the data For documentation about database handle methods, see DBI Returns : the database (DBI) handle of the MySQL JASPAR2-type relational database associated with the TFBS::DB::JASPAR2 object Args : none |
Title : delete_Matrix_having_ID Usage : $db->delete_Matrix_with_ID('M00045.1'); Function: Deletes the matrix having the given ID from the database Returns : 0 on success; $@ contents on failure (this is too C-ike and may change in future versions) Args : (ID) A string. Has to be a matrix ID with version suffix in JASPAR6. Comment : Yeah, yeah, 'delete_Matrix_having_ID' is a stupid name for a method, but at least it should be obviuos what it does. |
Title : get_MatrixSet Usage : my $matrixset = $db->get_MatrixSet(%args); Function: fetches matrix data under for all matrices in the database matching criteria defined by the named arguments and returns a TFBS::MatrixSet object Returns : a TFBS::MatrixSet object Args : This method accepts named arguments, corresponding to arbitrary tags, and also some utility functions Note that this is different from JASPAR2 and to some extent JASPAR4. As any tag is supported for database storage, any tag can be used for information retrieval. Additionally, arguments as 'name','class','collection' can be used (even though they are not tags. Per default, only the last version of the matrix is given. The only way to get older matrices out of this to use an array of IDs with actual versions like MA0001.1, or set the argyment -all_versions=>1, in which case you get all versions for each stable ID
Examples include:
Fundamental matrix features
-all # gives absolutely all matrix entry, regardless of versin and collection. Only useful for backup situations and sanity checks. Takes precedence over everything else
-ID # a reference to an array of stable IDs (strings), with or without version, as above. tyically something like "MA0001.2" . Takes precedence over everything salve -all
-name # a reference to an array of
# transcription factor names (string). Will only take latest version. NOT a preferred way to access since names change over time
-collection # a string corresponding to a JASPAR collection. Per default CORE
-all_versions # gives all matrix versions that fit with rest of criteria, including obsolete ones.Is off per default.
# Typical usage is in combiation with a stable IDs withou versions to get all versinos of a particular matrix
Typical tag queries:
These can be either a string or a reference to an array of strings. If it is an arrau it will be interpreted as as an "or"s statement
-class # a reference to an array of
# structural class names (strings)
-species # a reference to an array of
# NCBI Taxonomy IDs (integers)
-taxgroup # a reference to an array of
# higher taxonomic categories (string)
Computed features of the matrices
-min_ic # float, minimum total information content
# of the matrix.
-matrixtype #string describing type of matrix to retrieve. If left out, the format
will revert to the database format, which is PFM.
The arguments that expect list references are used in database query formulation: elements within lists are combined with 'OR' operators, and the lists of different types with 'AND'. For example,
my $matrixset = $db->(-class => ['TRP_CLUSTER', 'FORKHEAD'], -species => ['Homo sapiens', 'Mus musculus'], );
gives a set of TFBS::Matrix::PFM objects (given that the matrix models are stored as such) whose (structural clas is 'TRP_CLUSTER' OR'FORKHEAD') AND (the species they are derived from is 'Homo sapiens'OR 'Mus musculus'). As above, unless IDs with version numbers are used, only one matrix per stable ID wil be returned: the matrix with the highest version number The -min_ic filter is applied after the query in the sense that the matrices profiles with total information content less than specified are not included in the set. |
Title : get_Matrix_by_ID Usage : my $pfm = $db->get_Matrix_by_ID('M00034', 'PFM'); Function: fetches matrix data under the given ID from the database and returns a TFBS::Matrix::* object Returns : a TFBS::Matrix::* object; the exact type of the object depending on what form the matrix is stored in the database (PFM is default) Args : (Matrix_ID) Matrix_ID id is a string which refers to the stable JASPAR ID (usually something like "MA0001") with or without version numbers. "MA0001" will give the latest version on MA0001, while "MA0001.2" will give the second version, if existing. Warnings will be given for non-existing matrices. |
Title : get_Matrix_by_name Usage : my $pfm = $db->get_Matrix_by_name('HNF-1'); Function: fetches matrix data under the given name from the database and returns a TFBS::Matrix::* object Returns : a TFBS::Matrix::* object; the exact type of the object depending on what form the matrix object was stored in the database (default PFM)) Args : (Matrix_name) Warning : According to the current JASPAR6 data model, name is not necessarily a unique identifier. Also, names change over time. In the case where there are several matrices with the same name in the database, the function fetches the first one and prints a warning on STDERR. You've been warned. Some matrices have multiple versions. The function will return the latest version. For specific versions, use get_Matrix_by_ID($ID.$version) |
Title : new Usage : DEPRECATED - for backward compatibility only Use connect() or create() instead |
Title : store_Matrix Usage : $db->store_Matrix($matrixobject); Function: Stores the contents of a TFBS::Matrix::DB object in the database Returns : 0 on success; $@ contents on failure (this is too C-like and may change in future versions) Args : (PFM_object) A TFBS::Matrix::PFM, FBS::Matrix::PWM or FBS::Matrix::ICM object. PFM object are recommended to use, as they are eaily converted to other formats # might have to give version and collection here Comment : this is an experimental method that is not 100% bulletproof; use at your own risk |
Methods code
sub DESTROY
{
$_[0]->dbh->disconnect() if $_[0]->dbh; } |
sub _create_tables
{
my $dbh = shift;
my @queries =
(
q!! CREATE TABLE MATRIX( ID INT NOT NULL AUTO_INCREMENT, COLLECTION VARCHAR (16) DEFAULT '', BASE_ID VARCHAR (16)DEFAULT '' NOT NULL , VERSION TINYINT DEFAULT 1 NOT NULL , NAME VARCHAR (255) DEFAULT '' NOT NULL, PRIMARY KEY (ID)) !,
q!! CREATE TABLE MATRIX_DATA( ID INT NOT NULL, row VARCHAR(1) NOT NULL, col TINYINT(3) UNSIGNED NOT NULL, val float(10,3), PRIMARY KEY (ID, row, col) ) !,
q!! CREATE TABLE MATRIX_ANNOTATION( ID INT NOT NULL, TAG VARCHAR(255)DEFAULT '' NOT NULL, VAL varchar(255) DEFAULT '', PRIMARY KEY (ID, TAG) ) !,
q!! CREATE TABLE MATRIX_SPECIES( ID INT NOT NULL, TAX_ID VARCHAR(255)DEFAULT '' NOT NULL ) !,
q!! CREATE TABLE MATRIX_PROTEIN( ID INT NOT NULL, ACC VARCHAR(255)DEFAULT '' NOT NULL ) !
);
foreach my $query (@queries) {
$dbh->do($query)
or die("Error executing the query: $query\n");
} } |
sub _get_IDlist_by_query
{ my ($self, %args)=@_;
warn '_get_IDlist_by_query | $self || ', $self;
warn '_get_IDlist_by_query | %args || ', %args;
$args{'-collection'}='CORE' unless $args{'-collection'};
my @int_ids_to_return;
if ($args{'-auto'})
{
my $sth=$self->dbh->prepare (qq!!SELECT U.ID FROM (SELECT ID, BASE_ID as VAL FROM MATRIX UNION ALL SELECT ID, NAME as VAL FROM MATRIX UNION ALL SELECT ID, ACC as VAL FROM MATRIX_PROTEIN UNION ALL SELECT ID, TAX_ID as VAL FROM MATRIX_SPECIES UNION ALL SELECT ID, SPECIES as VAL FROM MATRIX_SPECIES,TAX WHERE MATRIX_SPECIES.TAX_ID=TAX.TAX_ID UNION ALL SELECT ID, NAME as VAL FROM MATRIX_SPECIES,TAX_EXT WHERE MATRIX_SPECIES.TAX_ID=TAX_EXT.TAX_ID AND MATRIX_SPECIES.TAX_ID=9606 UNION ALL SELECT ID, VAL as VAL FROM MATRIX_ANNOTATION) AS U WHERE LOWER(`VAL`) LIKE LOWER(?)!);
warn '_get_IDlist_by_query | $sth || ', $sth;
foreach my $stID(@{$args{'-auto'}})
{
warn '_get_IDlist_by_query | $stID || ', $stID;
my ($stable_ID, $version)= split (/\./, $stID); $sth->execute("%" . $stable_ID . "%");
while( my ($int_id)=$sth->fetchrow_array())
{
warn '_get_IDlist_by_query | $int_id || ', $int_id;
push (@int_ids_to_return, $int_id);
}
}
return\@ int_ids_to_return;
}
if ($args{'-all'})
{
my $sth=$self->dbh->prepare (qq!!SELECT ID FROM MATRIX!);
$sth->execute();
my @a;
while ( my ($i)=$sth->fetchrow_array())
{
push (@a, $i);
}
return\@ a;
}
if ($args{'-ID'})
{
if ( $args{-all_versions})
{
my $sth=$self->dbh->prepare (qq!!SELECT ID FROM MATRIX WHERE BASE_ID=?!);
foreach my $stID(@{$args{'-ID'}})
{
my ($stable_ID, $version)= split (/\./, $stID); $sth->execute($stable_ID);
while( my ($int_id)=$sth->fetchrow_array())
{
push (@int_ids_to_return, $int_id);
}
}
}
else
{ foreach my $stID(@{$args{'-ID'}})
{
my ($stable_ID, $version)= split (/\./, $stID);
$version=$self->_get_latest_version($stable_ID) unless $version;
my $int_id= $self->_get_internal_id($stable_ID, $version);
push (@int_ids_to_return, $int_id) if $int_id;
}
}
return\@ int_ids_to_return;
}
my @tables=("MATRIX M");
my @and;
if ( $args{-collection})
{
my $q=' (COLLECTION=';
if (ref $args{-collection} eq "ARRAY")
{ my @a;
foreach (@{$args{-collection}})
{
push (@a, "\"$_\"");
}
$q.= join ( " or COLLECTION=", @a);
}
else
{ $q.="\"$args{-collection}\"";
}
$q.=" ) ";
push (@and, $q);
}
if ($args{-name})
{
my $q=' (NAME=';
if (ref $args{-name} eq "ARRAY")
{ my @a;
foreach (@{$args{-name}})
{
push (@a, "\"$_\"");
}
$q.= join ( " or NAME=", @a);
}
else
{ $q.="\"$args{-name}\"";
}
$q.=" ) ";
push (@and, $q);
}
if ( $args{-species})
{
push (@tables , "MATRIX_SPECIES S");
my $q=" M.ID=S.ID and (TAX_ID= ";;
if (ref $args{-species} eq "ARRAY")
{ my @a;
foreach (@{$args{-species}})
{
push (@a, "\"$_\"");
}
$q.= join ( " or TAX_ID=", @a);
}
else
{ $q.="=\"$args{-species}\"";
}
$q.=") ";
push (@and, $q);
}
my (@inner_tables, @internal_ands1,@internal_ands2 );
my $int_counter=0; my @alpha = ("a" .. "z");
my %arrayref;
foreach my $key(keys %args)
{
next if $key eq "-min_ic";
next if $key eq "-matrixtype";
next if $key eq "-species";
next if $key eq "-collection";
next if $key eq "-all_versions";
next if $key eq "-all";
next if $key eq "-ID";
next if $key eq "-length";
next if $key eq "-name";
my $oldkey=$key;
$key=~s/-//; $arrayref{$key}= $args{$oldkey};
}
if (%arrayref)
{
push (@internal_ands2 , " M.ID=a.ID " );
my @a;
foreach my $key (keys %arrayref)
{
my $tname= $alpha[$int_counter];
push (@inner_tables , "MATRIX_ANNOTATION $tname");
push (@internal_ands1 , $alpha[$int_counter].".ID=". $alpha[$int_counter-1].".ID") unless $int_counter==0;
$int_counter++;
if ( ref $arrayref{$key} eq "ARRAY")
{
my @b;
foreach( @{$arrayref{$key}})
{
push (@b, $self->dbh->quote($_));
}
my $orstring= join (" or $tname.VAL=" , @b);
push (@a, "($tname.TAG=\"$key\" AND ($tname.VAL=$orstring))");
}
else
{
push (@a, "($tname.TAG=\"$key\" AND $tname.VAL=\"$arrayref{$key}\")");
}
}
my $s= " ( ". join (" AND ", @a). ")";
push (@internal_ands2 , $s);
}
my $qq= "SELECT distinct(M.ID) from ". join (",", (@tables,@inner_tables)) . " where" . join ( " AND ", (@and,@internal_ands1, @internal_ands2 ));
my $sth=$self->dbh->prepare ($qq);
$sth->execute();
my @r;
while (my($int_id)= $sth->fetchrow_array)
{
if ($args{-all_versions})
{
push (@r,$int_id);
}
else
{
push(@r,$int_id) if ( $self->_is_latest_version($int_id) ==1);
}
}
warn "Warning: Zero matrices returned with current critera" unless scalar @r;
return\@ r;
}
} |
sub _get_Matrix_by_int_id
{ my ($self, $int_id, $mt)= @_;
my $matrixobj;
$mt='PFM' unless $mt;
my $matrixstring = $self->_get_matrixstring($int_id) || return undef;
my $sth=$self->dbh->prepare(qq!!SELECT BASE_ID,VERSION, COLLECTION,NAME FROM MATRIX WHERE ID="$int_id"!);
$sth->execute();
my ($base_ID, $version,$collection,$name)=$sth->fetchrow_array();
$sth=$self->dbh->prepare(qq!!SELECT GROUP_CONCAT(TAX_ID SEPARATOR ', ') as TAX_ID FROM MATRIX_SPECIES WHERE ID="$int_id"!);
$sth->execute();
my @tax_ids;
while (my ($res)=$sth->fetchrow_array())
{
my @res_v=split(/,/,$res);
my @res_v2=grep(s/^\s*(.*)\s*$/\1/g, @res_v);
push(@tax_ids, @res_v2);
}
$sth=$self->dbh->prepare(qq!!SELECT GROUP_CONCAT(ACC SEPARATOR ', ') as ACC FROM MATRIX_PROTEIN WHERE ID="$int_id"!);
$sth->execute();
my @accs;
while (my ($res)=$sth->fetchrow_array())
{
my @res_v=split(/,/,$res);
my @res_v2=grep(s/^\s*(.*)\s*$/\1/g, @res_v);
push(@accs, @res_v2);
}
my %tags;
$sth=$self->dbh->prepare(qq{SELECT TAG, VAL FROM MATRIX_ANNOTATION WHERE ID = "$int_id" });
$sth->execute();
my @key_to_split=("medline", "pazar_tf_id", "tfbs_shape_id", "tfe_id");
foreach my $key(@key_to_split){
$tags{$key}=['-'];
}
my $vals;
while ( my($tag, $val)= $sth->fetchrow_array())
{
$vals=[];
if ($tag ~~ @key_to_split){
my @val_v=split(/,/,$val);
my @val_v2=grep(s/^\s*(.*)\s*$/\1/g, @val_v);
push(@$vals, @val_v2);
$tags{$tag}=$vals;
}
else {
$tags{$tag}=$val;
}
}
$tags{'collection'}= $collection;
$tags{'species'}=\@tax_ids; $tags{'acc'}=\@accs;
my $class= $tags{'class'};
delete ($tags{'class'});
eval("\$matrixobj= TFBS::Matrix::PFM->new".' ( -ID => "$base_ID.$version", -name =>$name, -class => $class, -tags =>\% tags, -matrixstring=> $matrixstring # FIXME - temporary );'
);
if ($@)
{
$self->throw($@);
}
return ($matrixobj->to_PWM) if $mt eq "PWM";
return ($matrixobj->to_ICM) if $mt eq "ICM";
return ($matrixobj); }
} |
sub _get_internal_id
{ my ($self, $base_ID, $version) = @_;
my $sth=$self->dbh->prepare
(qq!!SELECT ID FROM MATRIX
WHERE BASE_ID="$base_ID" AND VERSION="$version"!);
$sth->execute;
my ($int_id)=$sth->fetchrow_array();
return($int_id); } |
sub _get_latest_version
{ my $sth=$self->dbh->prepare
(qq!!SELECT VERSION FROM MATRIX
WHERE BASE_ID="$base_ID"
ORDER BY VERSION DESC LIMIT 1!);
$sth->execute;
my ($latest)=$sth->fetchrow_array();
return($latest); } |
sub _get_matrixstring
{ my $sth;
my $qID = $self->dbh->quote($ID);
my $matrixstring = "";
foreach my $base (qw(A C G T)) {
$sth=$self->dbh->prepare
("SELECT val FROM MATRIX_DATA
WHERE ID=$qID AND row='$base' ORDER BY col");
$sth->execute;
$matrixstring .=
join (" ", (map {$_->[0]} @{$sth->fetchall_arrayref()}))."\n";
}
$sth->finish;
return undef if $matrixstring eq "\n"x4;
return $matrixstring; } |
sub _is_latest_version
{ my ($self, $int_id)=@_;
my $sth=$self->dbh->prepare( qq!! select count(*) from MATRIX
where BASE_ID= (SELECT BASE_ID from MATRIX where ID=$int_id)
AND VERSION>(SELECT VERSION from MATRIX where ID=$int_id) !);
$sth->execute();
my ($count)= $sth->fetchrow_array();
return(1) if $count ==0; return(0); } |
sub _new
{ my $class = ref $caller || $caller;
my $self = bless {}, $class;
my ($connectstring, $user, $password);
if ($args{'-connect'} and (ref($args{'-connect'}) eq "ARRAY")) {
($connectstring, $user, $password) = @{$args{'-connect'}};
}
elsif ($args{'-create'} and (ref($args{'-create'}) eq "ARRAY")) {
return $caller->create(@{-args{'create'}});
}
else {
($connectstring, $user, $password) =
(DEFAULT_CONNECTSTRING, DEFAULT_USER, DEFAULT_PASSWORD);
}
$self->dbh( DBI->connect($connectstring, $user, $password) );
return $self; } |
sub _store_matrix
{ my ($self, $pfm, $ACTION) = @_;
my $version= $pfm->{'tags'}{'version'};
unless ($version) {
warn "WARNING: Lacking version number for ". $pfm->ID. ". Setting version=1";
$version=1;
}
my $collection= $pfm->{'tags'}{'collection'};
unless ($collection) {
warn "WARNING: Lacking collection name for ". $pfm->ID. ". Setting collection to an empty string. You probably do not want this";
$collection='';
}
my $base_id= $pfm->ID ;
my $sth = $self->dbh->prepare
(qq!! select count(*) from MATRIX where VERSION=$version and BASE_ID= "$base_id"and collection="$collection" !);
$sth->execute;
my ($sanity_count)= $sth->fetchrow_array;
if ($sanity_count >0){
warn "WARNING: Database input inconsistency: You have already have $sanity_count $base_id matrices of version $version in collection $collection. Terminating program";
die;
}
$sth = $self->dbh->prepare
(q!! INSERT INTO MATRIX VALUES(?,?,?,?,?) !);
$sth->execute(0, $collection,$pfm->ID,$version,$pfm->name)
or $self->throw("Error executing query");
my $int_id = $self->dbh->{ q{mysql_insertid}};
return $int_id; } |
sub _store_matrix_acc
{
my ($self, $pfm, $int_id,$ACTION) = @_;
my $sth = $self->dbh->prepare
(q!! INSERT INTO MATRIX_PROTEIN VALUES(?,?) !);
return() unless $pfm->{'tags'}{'acc'};
if ( ref ($pfm->{'tags'}{'acc'}) eq 'ARRAY'){
foreach my $acc ( @{$pfm->{'tags'}{'acc'}}){
$acc=~s/\s//g; $sth->execute($int_id,$acc);
}
}
else{
foreach my $acc ( split(/\,/, $pfm->{'tags'}{'acc'})){
$acc=~s/\s//g; $sth->execute($int_id,$acc);
}
}
}
} |
sub _store_matrix_annotation
{
my ($self, $pfm, $int_id,$ACTION) = @_;
my $sth = $self->dbh->prepare
(q!! INSERT INTO MATRIX_ANNOTATION (ID, tag, val) VALUES(?,?,?) !);
my %tags= $pfm->all_tags();
if (defined ($pfm->{class})){
$tags{class}=$pfm->{class} ;
}
foreach my $tag( keys %tags){
next if $tag eq "collection";
next if $tag eq "version";
next if $tag eq "species";
$sth->execute($int_id,
$tag,
($tags{$tag} or ""),
)
or $self->throw("Error executing query");
} } |
sub _store_matrix_data
{ my @base = qw(A C G T);
my $matrix = $pfm->matrix();
my $type;
my $sth = $self->dbh->prepare
(q!! INSERT INTO MATRIX_DATA VALUES(?,?,?,?) !);
for my $i (0..3) {
for my $j (0..($pfm->length-1)) {
$sth->execute( $int_id,
$base[$i],
$j+1,
$matrix->[$i][$j]
)
or $self->throw("Error executing query.");
}
} } |
sub _store_matrix_species
{
my ($self, $pfm, $int_id,$ACTION) = @_;
my $sth = $self->dbh->prepare
(q!! INSERT INTO MATRIX_SPECIES VALUES(?,?) !);
return() unless $pfm->{'tags'}{'species'};
if ( ref ($pfm->{'tags'}{'species'}) eq 'ARRAY'){
foreach my $species ( @{$pfm->{'tags'}{'species'}}){
$sth->execute($int_id,$species);
}
}
else{
foreach my $species ( split(/\,/, $pfm->{'tags'}{'species'})){
$species=~s/^\s//g; $sth->execute($int_id,$species);
}
} } |
sub connect
{ my ($caller, @connection_args) = @_;
$caller->new(-connect =>\@ connection_args); } |
sub create
{ if ($connectstring
and $connectstring =~ /dbi:mysql:(\w+)(.*)/)
{
my $dbh=DBI->connect("dbi:mysql:mysql".$2,
$user,$password)
or die("Error connecting to the database");
$dbh->do("create database $1")
or die("Error creating database.");
$dbh->do("use $1");
_create_tables($dbh);
$dbh->disconnect;
return $caller->new(-connect=>[$connectstring, $user, $password]);
}
else {
die("Missing or malformed connect string for ".
"TFBS::DB::JASPAR2 connection.");
} } |
sub dbh
{ $self->{'dbh'} = $dbh if $dbh;
return $self->{'dbh'}; } |
sub delete_Matrix_having_ID
{ my ($self, @IDs) = @_;
foreach my $ID (@IDs){
my ($base_id, $version)= split (/\./, $ID);
unless ($version) {
warn "You have supplied a non-versioned matrix ID to delete. Skipping $ID ";
return 0;
}
my($int_id)= $self->_get_internal_id($base_id, $version);
eval {
my $q_ID = $self->dbh->quote($int_id);
foreach my $table (qw (MATRIX_DATA
MATRIX
MATRIX_SPECIES
MATRIX_PROTEIN
MATRIX_ANNOTATION
)
)
{
$self->dbh->do("DELETE from $table where ID=$q_ID");
}
};
}
return $@;
}
} |
sub get_MatrixSet
{
$args{'-collection'}='CORE' unless $args{'-collection'};
$args{'-all_versions'}=0 unless $args{'-all_versions'};
my @IDlist = @{$self->_get_IDlist_by_query(%args)};
my $type;
my $matrixset = TFBS::MatrixSet->new();
foreach my $int_id(@IDlist) {
my $matrix=$self->_get_Matrix_by_int_id($int_id);
if (defined $args{'-min_ic'} ){
if ($matrix->isa("TFBS::Matrix::ICM")
|| ( defined $matrix->{tags}{matrixtype}
&& $matrix->{tags}{matrixtype} eq "ICM")){
next if ( $matrix->total_ic() < $args{'-min_ic'});
} elsif ($matrix->isa("TFBS::Matrix::PFM")){
next if ( $matrix->to_ICM->total_ic() < $args{'-min_ic'});
}
else{
warn "Warning: you are assessning information content on matrices that are not in PFM or ICM format.Skipping this criteria";
next;
}
}
if (defined $args{'-length'} ){
next if ( $matrix->length() < $args{'-length'});
}
if (defined $args{'-sites'} ){
my $sum=0;
foreach ( 1..$matrix->length){
$sum+=$matrix->column_sum();
}
$sum=int($sum /$matrix->length); warn $matrix->ID, " $sum is $sum";
next if ( $sum < $args{'-sites'});
}
if ($args{'-matrixtype'} && $matrix->isa("TFBS::Matrix::PFM")){
if ( $args{'-matrixtype'} eq ('PWM')) {
$matrix= $matrix->to_PWM();
}
if ( $args{'-matrixtype'} eq ('ICM')) {
$matrix= $matrix->to_PWM();
}
}
$matrixset->add_Matrix($matrix);
}
return $matrixset; } |
sub get_Matrix_by_ID
{ my ($self, $q, $mt) = @_;
$mt = (uc($mt) or "PFM");
unless (defined $q) {
$self->throw("No ID passed to get_Matrix_by_ID");
}
my $ucmt = uc $mt;
my ($base_ID, $version)= split (/\./, $q);
$version=$self->_get_latest_version($base_ID) unless $version;
my $int_id= $self->_get_internal_id($base_ID, $version);
my $m= $self->_get_Matrix_by_int_id($int_id, $ucmt);
warn ref ($m);
return ($m); } |
sub get_Matrix_by_name
{ unless(defined $name) {
$self->throw("No name passed to get_Matrix_by_name."); }
my $sth=$self->dbh->prepare(qq!!SELECT distinct BASE_ID FROM MATRIX
WHERE NAME="$name"!);
$sth->execute();
my (@stable_ids)=$sth->fetchrow_array();
my $L =scalar @stable_ids;
$self->warn("There are $L distinct stable IDs with name '$name'") if scalar $L>1;
return $self->get_Matrix_by_ID($stable_ids[0], $mt); } |
sub store_Matrix
{ ;
my ($self, @PFMs) = @_;
my $err;
foreach my $pfm (@PFMs) {
eval {
my $int_id= $self->_store_matrix($pfm); $self->_store_matrix_data($pfm, $int_id);
$self->_store_matrix_annotation($pfm, $int_id);
$self->_store_matrix_species($pfm, $int_id);
$self->_store_matrix_acc($pfm, $int_id);
};
}
return $@; } |
store_MatrixSet | description | prev | next | Top |
sub store_MatrixSet
{ my $it=$matrixset->Iterator();
while (my $matrix_object = $it->next) {
$self->store_Matrix($matrix_object)
} } |
General documentation
JASPAR6 is working name for a relational database model used
for storing transcriptional factor pattern matrices in a MySQL database.
It was initially designed (JASPAR2) to store matrices for the JASPAR database of
high quality eukaryotic transcription factor specificity profiles by
Albin Sandelin and Wyeth W. Wasserman. Besides the profile matrix itself,
this data model stores profile ID (unique), name, structural class,
basic taxonomic and bibliographic information
as well as some additional, and custom, tags.
Here goes a moore thorough description on tables and IDs
----------------------- ADVANCED ---------------------------------
For the developers and the curious, here is the JASPAR6 data model:
MISSING TEXT HEER ON HOW IT WORKS
It is our best intention to hide the details of this data model, which we
are using on a daily basis in our work, from most TFBS users.
Most users should only know the methods to store the data and
which tags are supported.
-------------------------------------------------------------------------
Please send bug reports and other comments to the author.
AUTHOR - Boris Lenhard | Top |
Boris Lenhard <Boris.Lenhard@cgb.ki.se>
The rest of the documentation details each of the object
methods. Internal methods are preceded with an underscore.