DBUtils - a module for useful Database utilities
use DBUtils;
assert_table_defined($dbh,$table_name);
assert_dbh($dbh);
$id = fetch_last_id($dbh,$table_name);
$sql_string = create_insert_sql($dbh,$table_name,@column_names);
$sql_string = create_update_sql($dbh,$table_name,
SET=>$array_ref,WHERE=>$string);
$sql_string = create_select_sql($dbh,
COLUMNS=>$array_ref,
FROM=>$array_ref,
WHERE=>$where_string,
DISTINCT=>$bool,
LIMIT=>$bool,
);
$species = fetch_es_species($es_pk);
@ids = fetch_es_ids();
@ids = fetch_user_al_ids($us_fk);
@ids = fetch_am_ids($experiment_set_pk,
@array_measurement_types);
$array_ref = fetch_fkey_list($dbh,
$table_name,
$column_name,
$pkey,
$rec_level);
$exp_set = fetch_spot_data($es_pk,@am_types);
output_spot_data($file_handle,
$experiment_set_pk,
@array_measurement_types);
$id = lookup_id($dbh,$table,$attribute,$value,$approx);
$id = lookup_species_id($dbh,$species_name,$approx);
$id = lookup_usf_id($dbh,$usf_name,$approx);
$id = lookup_contact_id($dbh,$contact_name,$approx);
$id = lookup_software_id($dbh,$software_name,$approx);
Helper functions for achieving common DB tasks with a GeneX DB.
create_insert_sql($dbh,$table,\@column_names)create_insert_sql($dbh,$table,\%col_val_pairs)prepare() and
exectute() methods. In this case the \@columen_name reference
contains the names and order of the columns we plan to insert data in
$table.
If invoked with a hash reference of column name/value pairs,
create_insert_sql will return a final SQL string that can be used by
DBI do().
Return value: an SQL string that is specific to the driver for $dbh (currently this is only implemented for PostgeSQL).
lookup_usf_id($dbh,$sequence_feature_name,$approx)If the optional $approx flag is specified, then lookup_usf_id()
will use wildcarding around $sequenc_feature_name so the name does not have
to be an exact match.
assert_dbh($dbh)assert_table_defined($dbh,$table_name)lookup_contact_id($dbh,$contact_name,$approx)If the optional $approx flag is specified, then lookup_contact_id()
will use wildcarding around $contact_name so the name does not have
to be an exact match.
lookup_software_id($dbh,$software_name,$approx)If the optional $approx flag is specified, then lookup_software_id()
will use wildcarding around $software_name so the name does not have
to be an exact match.
lookup_species_id($dbh,$species_name,$approx)If the optional $approx flag is specified, then lookup_species_id()
will use wildcarding around $species_name so the name does not have
to be an exact match.
lookup_experiment_id($dbh,$experiment_name)If the optional $approx flag is specified, then lookup_experiment_id()
will use wildcarding around $experiment_name so the name does not have
to be an exact match.
lookup_id($dbh,$table,$attribute,$pk_name,$value,$approx)The optional $approx flag species that approximate mathcing using an SQL 'LIKE' clause should used instead of exact matching using '='.
fetch_last_id($dbh,$table)check_password($dbh,$user_name,$password)Return value: On Success: the primary key of the UserSec entry On Failure: undef
fetch_es_ids()The optional @am_types list is used to filter the arrays to a given type. There is no default value for this parameter.
Return Value: list of ArrayMeasurement ids or undef if none.
fetch_spot_data($es_pk,@am_types)The optional @am_types list will restrict the retrieval to only arrays of the specified types, the default value of @am_types is ('derived ratio').
Return value: an instance of Bio::Genex::ExperimentSet
Example use:
use Bio::Genex::DBUtils qw(fetch_spot_data, fetch_es_ids)
my @es_ids = fetch_es_ids();
foreach my $es_pk (@es_ids) {
my $es = fetch_spot_data($es_pk);
my @array_list = $es->arraymeasurement_fk();
foreach my $array (@array_list) {
my $spot_list_ref = $array->am_spots_fk();
# locate the column for the spot values
my @header = shift @{$spot_list_ref};
my $spot_col;
my $usf_col;
for (my $i=0;$i<scalar @header;$i++) {
$spot_col = $i if $header[$i] =~ /spot_value/;
$usf_col = $i if $header[$i] =~ /usf_fk/;
}
die "Couldn't find columns for " . $array->name()
unless defined $spot_col && defined $usf_col;
foreach my $spot (@{$spot_list_ref}) {
print "$spot->[$usf_col]\t$spot->[$spot_col]";
}
}
}
The optional @am_types list is used to filter the spot data belonging
to only arrays of the given types. The default value is
('derived ratio').
dbh: a database handle; calling_class: the name
of the class requesting the data; class_to_fetch the name of the
table to lookup the data from; column_to_fetch: the name of foreign
key in class_to_fetch that refers to calling_class;
value_to_fetch: the value of column_to_fetch to use in the
WHERE clause.
Control Variables: Setting $Bio::Genex::DBUtils::NO_FETCH_DISTINCT
instructs fetch_fkey_list to not use the DISTINCT SQL keyword in
the query (the default is to use DISTINCT. Setting
$Bio::Genex::DBUtils::NO_FETCH_ALL instructs the method to not set the
fetch_all parameter when calling new() on each object (the
default is to use fetch_all).
fetch_user_al_ids($us_fk)Return Value: a list of ArrayLayout ids or undef if none.
fetch_es_species($es_pk)Return value: an instance of class Bio::Genex::Species.
Jason Stewart (jes@ncgr.org), and Peter Hraber (pth@ncgr.org)
perl(1).