view release on metacpan or search on metacpan
lib/Bio/EnsEMBL/DBSQL/BaseFeatureAdaptor.pm view on Meta::CPAN
if(!$seq_region_id) {
throw('Feature is associated with seq_region which is not in this DB.');
}
return ($feature, $seq_region_id);
}
# The same function as _pre_store
# This one is used to store user uploaded features in XXX_userdata db
sub _pre_store_userdata {
my $self = shift;
my $feature = shift;
if(!ref($feature) || !$feature->isa('Bio::EnsEMBL::Feature')) {
throw('Expected Feature argument.');
}
my $slice = $feature->slice();
lib/Bio/EnsEMBL/IdMapping/Archiver.pm view on Meta::CPAN
# dump existing archive tables to file
my $num_entries =
$archiver->dump_table_to_file( 'source', 'gene_archive',
'gene_archive_existing.txt', 1 );
=head1 DESCRIPTION
This module creates the gene_archive and peptide_archive
tables. Data is written to a file as tab-delimited text for
loading into a MySQL database (this can be done manually, or using
StableIdmapper->upload_file_into_table()).
An archive entry for a given source gene is created if no target
gene exists, or if any of its transcripts or their translations
changed. Non-coding transcripts only have an entry in gene_archive (i.e.
without a corresponding peptide_archive entry).
=head1 METHODS
create_archive
dump_gene
lib/Bio/EnsEMBL/IdMapping/BaseObject.pm view on Meta::CPAN
This isn't very clean OO design but it's efficient and easy to use...
=head1 METHODS
new
get_filehandle
file_exists
fetch_value_from_db
dump_table_to_file
upload_file_into_table
logger
conf
cache
=cut
package Bio::EnsEMBL::IdMapping::BaseObject;
$Bio::EnsEMBL::IdMapping::BaseObject::VERSION = '114.0.0';
use strict;
lib/Bio/EnsEMBL/IdMapping/BaseObject.pm view on Meta::CPAN
print $fh join("\t", @row);
print $fh "\n";
}
$sth->finish;
return $i;
}
=head2 upload_file_into_table
Arg[1] : String $dbtype - db type (source|target)
Arg[2] : String $table - name of table to upload the data to
Arg[3] : String $filename - name of dump file
Arg[4] : Boolean $no_check_empty - don't check if table is empty
Example : my $rows_uploaded = $object->upload_file_into_table('target',
'stable_id_event', 'stable_id_event_new.txt');
Description : Uploads a tab-delimited data file into a db table. The data file
will be taken from a subdirectory 'tables' under your configured
basedir. If the db table isn't empty and $no_check_empty isn't
set, no data is uploaded (and a warning is issued).
Return type : Int - the number of rows uploaded
Exceptions : thrown on wrong or missing arguments
Caller : general
Status : At Risk
: under development
=cut
sub upload_file_into_table {
my $self = shift;
my $dbtype = shift;
my $table = shift;
my $filename = shift;
my $no_check_empty = shift;
# argument check
unless ( ( $dbtype eq 'source' ) or ( $dbtype eq 'target' ) ) {
throw("Missing or unknown db type: $dbtype.");
}
throw("Need a table name.") unless ($table);
throw("Need a filename.") unless ($filename);
# sanity check for dry run
if ( $self->conf->param('dry_run') ) {
$self->logger->warning(
"dry_run - skipping db upload for $filename.\n");
return;
}
my $file =
join( '/', $self->conf->param('basedir'), 'tables', $filename );
my $r = 0;
if ( -s $file ) {
$self->logger->debug( "$file -> $table\n", 1 );
lib/Bio/EnsEMBL/IdMapping/BaseObject.pm view on Meta::CPAN
if ($idtable) {
$self->logger->warning(
"Table $table contains $c stable IDs.\n",
1 );
}
else {
$self->logger->warning(
"Table $table not empty: found $c entries.\n",
1 );
}
$self->logger->info( "Data not uploaded!\n", 1 );
return $r;
}
} ## end unless ($no_check_empty)
# now upload the data
if ($idtable) {
# Create a temporary table, upload the data into it, and then
# update the main table.
$dbh->do(
qq( CREATE TABLE stable_id_$$ ( object_id INTEGER UNSIGNED,
stable_id VARCHAR(255),
version SMALLINT UNSIGNED,
created_date DATETIME,
modified_date DATETIME,
PRIMARY KEY(object_id) ) )
);
lib/Bio/EnsEMBL/IdMapping/BaseObject.pm view on Meta::CPAN
$dbh->do(qq(LOAD DATA LOCAL INFILE '$file' INTO TABLE $table));
}
$dbh->do(qq(OPTIMIZE TABLE $table));
} ## end if ( -s $file )
else {
$self->logger->warning( "No data found in file $filename.\n", 1 );
}
return $r;
} ## end sub upload_file_into_table
=head2 logger
Arg[1] : (optional) Bio::EnsEMBL::Utils::Logger - the logger to set
Example : $object->logger->info("Starting ID mapping.\n");
Description : Getter/setter for logger object
Return type : Bio::EnsEMBL::Utils::Logger
Exceptions : none
Caller : constructor
lib/Bio/EnsEMBL/IdMapping/Cache.pm view on Meta::CPAN
sub check_db_write_permissions {
my $self = shift;
my $dbtype = shift;
# skip this check if db connection failed (this prevents re-throwing
# exceptions).
return 1 unless ($self->{'_db_conn_ok'}->{$dbtype});
my $err = 0;
unless ($self->do_upload) {
$self->logger->debug("No uploads, so write permission on $dbtype db not required.\n");
return $err;
}
my %privs = %{ $self->get_db_privs($dbtype) };
unless ($privs{'INSERT'} or $privs{'ALL PRIVILEGES'}) {
$self->logger->warning("User doesn't have write permission on $dbtype db.\n");
$err++;
} else {
$self->logger->debug("Write permission on $dbtype db ok.\n");
}
return $err;
}
sub do_upload {
my $self = shift;
if ($self->conf->param('dry_run') or
! ($self->conf->param('upload_events') or
$self->conf->param('upload_stable_ids') or
$self->conf->param('upload_archive'))) {
return 0;
} else {
return 1;
}
}
sub get_db_privs {
my ( $self, $dbtype ) = @_;
lib/Bio/EnsEMBL/IdMapping/Cache.pm view on Meta::CPAN
my $self = shift;
my $dbtype = shift;
# skip this check if db connection failed (this prevents re-throwing
# exceptions).
return 1 unless ($self->{'_db_conn_ok'}->{$dbtype});
my $err = 0;
my $c = 0;
if ($self->conf->param('no_check_empty_tables') or !$self->do_upload) {
$self->logger->debug("Won't check for empty stable ID and archive tables in $dbtype db.\n");
return $err;
}
eval {
my @tables =
qw(
gene_stable_id
transcript_stable_id
translation_stable_id
lib/Bio/EnsEMBL/IdMapping/ResultAnalyser.pm view on Meta::CPAN
if ($self->file_exists($filename, 'stats')) {
print $fh $self->read_from_file($filename, 'stats');
print $fh "\n\n";
} else {
print $fh "No mapping stats found for $type.\n\n";
}
}
#
# db uploads
#
my @uploads = (
['stable_ids' => 'Stable IDs'],
['events' => 'Stable ID events and mapping session'],
['archive' => 'Gene and peptide archive'],
);
my $fmt1 = "%-40s%-20s\n";
print $fh qq(Data uploaded to db:\n);
print $fh qq(====================\n\n);
if ($self->conf->param('dry_run')) {
print $fh "None (dry run).\n";
} else {
foreach my $u (@uploads) {
my $uploaded = 'no';
$uploaded = 'yes' if ($self->conf->is_true("upload_".$u->[0]));
print $fh sprintf($fmt1, $u->[1], $uploaded);
}
}
print $fh "\n";
#
# stats and clicklist
#
my @output = (
['stats' => 'statistics (including clicklists of deleted IDs)'],
['debug' => 'detailed mapping output for debugging'],
['tables' => 'data files for db upload'],
);
my $fmt2 = "%-20s%-50s\n";
print $fh qq(\nOutput directories:\n);
print $fh qq(===================\n\n);
print $fh sprintf($fmt2, qw(DIRECTORY DESCRIPTION));
print $fh ('-'x72), "\n";
lib/Bio/EnsEMBL/Registry.pm view on Meta::CPAN
$species, $species_id, $multidb );
}
}
} ## end foreach my $multidb (@multi_dbs)
}
if(!$core_like_dbs_found && $verbose) {
print("No core-like databases found. Check your DB_VERSION (used '$software_version')\n");
}
# User upload DBs
my @userupload_dbs = grep { /_userdata$/ } @dbnames;
if (!$ignore_multi) {
for my $userupload_db (@userupload_dbs) {
if ( index( $userupload_db, 'collection' ) != -1 ) {
# Skip multi-species databases.
next;
}
my ($species) = ( $userupload_db =~ /(^.+)_userdata$/ );
my $dba =
Bio::EnsEMBL::DBSQL::DBAdaptor->new(
-group => "userupload",
-species => $species.$species_suffix,
-host => $host,
-user => $user,
-pass => $pass,
-port => $port,
-wait_timeout => $wait_timeout,
-dbname => $userupload_db,
-no_cache => $no_cache );
if ($verbose) {
printf( "%s loaded\n", $userupload_db );
}
}
}
# Register multi-species userupload databases.
my @userdata_multidbs = grep { /^.+_collection_userdata$/ } @dbnames;
if (!$ignore_multi) {
foreach my $multidb (@userdata_multidbs) {
my $sth = $dbh->prepare(
sprintf(
"SELECT species_id, meta_value FROM %s.meta "
. "WHERE meta_key = 'species.db_name'",
$dbh->quote_identifier($multidb) ) );
$sth->execute();
my ( $species_id, $species );
$sth->bind_columns( \( $species_id, $species ) );
while ( $sth->fetch() ) {
my $dba = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
-group => "userupload",
-species => $species.$species_suffix,
-species_id => $species_id,
-multispecies_db => 1,
-host => $host,
-user => $user,
-pass => $pass,
-port => $port,
-dbname => $multidb,
-wait_timeout => $wait_timeout,
-no_cache => $no_cache
lib/Bio/EnsEMBL/Utils/ConfParser.pm view on Meta::CPAN
return $self->{'_param'}->{$name};
} else {
return undef;
}
}
=head2 is_true
Arg[1] : Parameter name
Example : unless ($conf->is_true('upload')) {
print "Won't upload data.\n";
next;
}
Description : Checks whether a param value is set to 'true', which is defined
here as TRUE (in the Perl sense) but not the string 'no'.
Return type : Boolean
Exceptions : thrown if no parameter name is supplied
Caller : general
Status : At Risk
: under development