Bio::EnsEMBL::ExternalData::FASTA
FASTAAdaptor
Toolbar
Summary
FASTAAdaptor - DESCRIPTION of Object
This object represents a database of fasta sequences.
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::ExternalData::FASTA::FASTAAdaptor;
$db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
-user => 'ensro',
-dbname => 'fasta_8_1',
-host => 'ecs3d',
-driver => 'mysql',
);
my $fasta_adtor = Bio::EnsEMBL::ExternalData::FASTA::FASTAAdaptor->new($db);
$seqobj = $fasta_adtor->fetch_fasta_by_id('AP000869.1'); # fasta id
Description
This module is an entry point into a database of fasta sequences,
The objects can only be read from the database, not written. (They are
loaded using a separate perl script).
Methods
Methods description
Title : create_fasta_table Usage : $db->create_fasta_table('foo'); Function: Example : Returns : Args : id |
Title : drop_fasta_table Usage : $db->drop_fasta_table('foo'); Function: Example : Returns : Args : id |
Title : fetch_fasta_by_id Usage : $db->fetch_fasta_by_id("my_table", 'AP000869.1'); Function: Example : Returns : a bioperl seq object, empty list otherwise Args : id |
Title : fetch_fasta_table_metadata Usage : $db->fetch_fasta_table_metadata('foo'); Function: Example : Returns : Args : id |
Title : insert_fasta_record Usage : $db->insert_fasta_record($tablename, $seq); Function: Example : Returns : Args : table, bioperl seq obj |
Methods code
sub _ensdb
{ my $self = shift;
$self->{'_ensdb'} = shift if @_;
return $self->{'_ensdb'};
}
1; } |
sub create_fasta_table
{ my ($self, $id) = @_;
my $SCHEMA =qq(
CREATE TABLE $id (
id int(10) unsigned NOT NULL auto_increment,
name varchar(40) NOT NULL default '',
description varchar(255) NOT NULL default '',
sequence mediumtext NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY (name)
) TYPE=MyISAM
);
my $meta = "${id}_meta";
my $META =qq(
CREATE TABLE $meta (
db varchar(40) NOT NULL default '',
title varchar(255) NOT NULL default '',
description mediumtext NOT NULL,
methods mediumtext NOT NULL,
credits mediumtext NOT NULL,
links mediumtext NOT NULL,
PRIMARY KEY (db)
) TYPE=MyISAM
);
my $sth = $self->prepare($SCHEMA);
$sth->execute();
$sth = $self->prepare($META);
$sth->execute(); } |
sub delete_fasta_metadata
{ my ($self, $id) = @_;
my $meta = "${id}_meta";
my $q =qq( DELETE FROM $meta);
my $sth = $self->prepare($q);
$sth->execute();
return(); } |
sub delete_fasta_record
{ my ($self, $table, $seq) = @_;
my $id = $seq->id();
my $sql =qq( DELETE FROM
$table
WHERE
id="$id"
);
my $sth = $self->prepare($sql);
$sth->execute(); } |
sub drop_fasta_table
{ my ($self, $id) = @_;
my $sql =qq( DROP TABLE $id );
eval {
my $sth = $self->prepare($sql);
$sth->execute();
};
$@ && warn ("Database error! $@\n") and return 0;
$sql =qq( DROP TABLE ${id}_meta );
eval {
my $sth = $self->prepare($sql);
$sth->execute();
};
$@ && warn ("Database error! $@\n") and return 0; } |
sub fetch_fasta_by_id
{ my ($self, $table, $id) = @_;
warn join (" ",@_);
return () if( "$id" eq '');
my $q =qq( SELECT name,description,sequence FROM $table WHERE name="$id" );
my $sth = $self->prepare($q);
$sth->execute();
my $seq;
my $rowhash = $sth->fetchrow_hashref();
if($sth->rows() > 0){
$seq = Bio::Seq->new(
-id => $rowhash->{'name'},
-desc => $rowhash->{'description'},
-seq => $rowhash->{'sequence'},
);
return($seq);
}
$q =qq( SELECT name,description,sequence FROM $table WHERE description like "%$id%");
$sth = $self->prepare($q);
$sth->execute();
$rowhash = $sth->fetchrow_hashref();
if($sth->rows() > 0){
$seq = Bio::Seq->new(
-id => $rowhash->{'name'},
-desc => $rowhash->{'description'},
-seq => $rowhash->{'sequence'},
);
return($seq);
}
return();
}
} |
sub fetch_fasta_table_metadata
{ my ($self, $id) = @_;
my $meta = "${id}_meta";
my $q =qq( SELECT title,description,methods,credits,links FROM $meta);
my $sth;
my $rv;
eval {
$sth = $self->prepare($q);
$rv = $sth->execute();
};
$@ && ( warn( $@ ) && return );
if( $rv == 0 ){ warn( "$q returned no rows" ) }
return $sth->fetchrow_hashref(); } |
sub insert_fasta_metadata
{ my ($self,$table,$title,$desc,$methods,$credits,$links) = @_;
my $meta = "${table}_meta";
my $sql =qq( INSERT INTO $meta VALUES ("$table","$title","$desc","$methods","$credits","$links"));
my $sth = $self->prepare($sql);
$sth->execute(); } |
sub insert_fasta_record
{ my ($self, $table, $seq, $parser) = @_;
if( $parser && ref($parser) ne "CODE" ){ die( "Parser not a ref" ) }
if($parser){
my $id = &$parser($seq->id());
$id || ( warn( "$seq has no parsable ID!" ) && return );
$seq->id($id);
}
my $desc = $seq->desc();
my $data = $seq->primary_seq->seq();
my $id = $seq->id();
my $sql =qq( INSERT INTO
$table
VALUES
(NULL,"$id","$desc","$data")
);
my $rv;
eval{
my $sth = $self->prepare($sql);
$rv = $sth->execute();
};
if($@){
warn("Error inserting record $id:\n$@\n");
}
return $rv; } |
General documentation
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _