Bio::DB::GFF::Adaptor::dbi -- Database adaptor for DBI (SQL) databases
See Bio::DB::GFF
This is the base class for DBI-based adaptors. It does everything except generating the text of the queries to be used. See the section QUERIES TO IMPLEMENT for the list of methods that must be implemented.
Title : new Usage : $db = Bio::DB::GFF->new(@args) Function: create a new adaptor Returns : a Bio::DB::GFF object Args : see below Status : Public
This is the constructor for the adaptor. It is called automatically by Bio::DB::GFF->new. In addition to arguments that are common among all adaptors, the following class-specific arguments are recgonized:
Argument Description -------- ----------- -dsn the DBI data source, e.g. 'dbi:mysql:ens0040' -user username for authentication -pass the password for authentication
Title : features_db Usage : $dbh = $db->features_db Function: get database handle Returns : a DBI handle Args : none Status : Public
Title : get_dna Usage : $string = $db->get_dna($name,$start,$stop,$class) Function: get DNA string Returns : a string Args : name, class, start and stop of desired segment Status : Public
This method performs the low-level fetch of a DNA substring given its name, class and the desired range. It is actually a front end to the abstract method make_dna_query(), which it calls after some argument consistency checking.
Title : get_abscoords Usage : ($refseq,$refclass,$start,$stop,$strand) = $db->get_abscoords($name,$class) Function: get absolute coordinates for landmark Returns : an array ref -- see below Args : name and class of desired landmark Status : Public
This method performs the low-level resolution of a landmark into a reference sequence and position.
The result is an array ref, each element of which is a five-element list containing reference sequence name, class, start, stop and strand.
Title : get_features Usage : $db->get_features($search,$options,$callback) Function: retrieve features from the database Returns : number of features retrieved Args : see below Status : Public
This is the low-level method that is called to retrieve GFF lines from the database. It is responsible for retrieving features that satisfy range and feature type criteria, and passing the GFF fields to a callback subroutine.
See the manual page for Bio::DB::GFF for the interpretation of the arguments and how the information retrieved by get_features is passed to the callback for processing.
Internally, get_features() is a front end for range_query(). The latter method constructs the query and executes it. get_features() calls fetchrow_array() to recover the fields and passes them to the callback.
Title : classes Usage : $db->classes Function: return list of landmark classes in database Returns : a list of classes Args : none Status : public
This routine returns the list of reference classes known to the database, or empty if classes are not used by the database. Classes are distinct from types, being essentially qualifiers on the reference namespaces.
NOTE: In the current mysql-based schema, this query takes a while to run due to the classes not being normalized.
Title : make_classes_query Usage : ($query,@args) = $db->make_classes_query Function: return query fragment for generating list of reference classes Returns : a query and args Args : none Status : public
Title : _feature_by_name Usage : $db->get_features_by_name($name,$class,$callback) Function: get a list of features by name and class Returns : count of number of features retrieved Args : name of feature, class of feature, and a callback Status : protected
This method is used internally. The callback arguments are those used by make_feature(). Internally, it invokes the following abstract procedures:
make_features_select_part make_features_from_part make_features_by_name_where_part make_features_join_part
Title : _feature_by_id Usage : $db->_feature_by_id($ids,$type,$callback) Function: get a list of features by ID Returns : count of number of features retrieved Args : arrayref containing list of IDs to fetch and a callback Status : protected
This method is used internally. The $type selector is one of "feature" or "group". The callback arguments are those used by make_feature(). Internally, it invokes the following abstract procedures:
make_features_select_part make_features_from_part make_features_by_id_where_part make_features_join_part
Title : get_types Usage : $db->get_types($refseq,$refclass,$start,$stop,$count) Function: get list of types Returns : a list of Bio::DB::GFF::Typename objects Args : see below Status : Public
This method is responsible for fetching the list of feature type names from the database. The query may be limited to a particular range, in which case the range is indicated by a landmark sequence name and class and its subrange, if any. These arguments may be undef if it is desired to retrieve all feature types in the database (which may be a slow operation in some implementations).
If the $count flag is false, the method returns a simple list of vBio::DB::GFF::Typename objects. If $count is true, the method returns a list of $name=>$count pairs, where $count indicates the number of times this feature occurs in the range.
Internally, this method calls upon the following functions to generate the SQL and its bind variables:
($q1,@args) = make_types_select_part(@args); ($q2,@args) = make_types_from_part(@args); ($q3,@args) = make_types_where_part(@args); ($q4,@args) = make_types_join_part(@args); ($q5,@args) = make_types_group_part(@args);
The components are then combined as follows:
$query = "SELECT $q1 FROM $q2 WHERE $q3 AND $q4 GROUP BY $q5";
If any of the query fragments contain the ? bind variable, then the same number of bind arguments must be provided in @args. The fragment-generating functions are described below.
Title : range_query Usage : $db->range_query($range_type,$refseq,$refclass,$start,$stop,$types,$order_by_group) Function: create statement handle for range/overlap queries Returns : a DBI statement handle Args : see below Status : Protected
This method constructs the statement handle for this module's central query: given a range and/or a list of feature types, fetch their GFF records.
The six positional arguments are as follows:
Argument Description $isrange A flag indicating that this is a range. query. Otherwise an overlap query is assumed. $refseq The reference sequence name (undef if no range). $refclass The reference sequence class (undef if no range). $start The start of the range (undef if none). $stop The stop of the range (undef if none). $types Array ref containing zero or feature types in the format [method,source]. $order_by_group A flag indicating that statement handler should group the features by group id (handy for iterative fetches)
If successful, this method returns a statement handle. The handle is expected to return the fields described for get_features().
Internally, range_query() makes calls to the following methods, each of which is expected to be overridden in subclasses:
$select = $self->make_features_select_part; $from = $self->make_features_from_part; $join = $self->make_features_join_part; ($where,@args) = $self->make_features_by_range_where_part($isrange,$srcseq,$class, $start,$stop,$types,$class);
The query that is constructed looks like this:
SELECT $select FROM $from WHERE $join AND $where
The arguments that are returned from make_features_by_range_where_part() are passed to the statement handler's execute() method.
range_query() also calls a do_straight_join() method, described below. If this method returns true, then the keyword "straight_join" is inserted right after SELECT.
Title : make_features_by_range_where_part Usage : ($string,@args) = $db->make_features_select_part($isrange,$refseq,$class,$start,$stop,$types) Function: make where part of the features query Returns : the list ($query,@bind_args) Args : see below Status : Protected
This method creates the part of the features query that immediately follows the WHERE keyword and is ANDed with the string returned by make_features_join_part().
The six positional arguments are a flag indicating whether to perform a range search or an overlap search, the reference sequence, class, start and stop, all of which define an optional range to search in, and an array reference containing a list [$method,$souce] pairs.
The method result is a multi-element list containing the query string and the list of runtime arguments to bind to it with the execute() method.
This method's job is to clean up arguments and perform consistency checking. The real work is done by the following abstract methods:
Method Description refseq_query() Return the query string needed to match the reference sequence. range_query() Return the query string needed to find all features contained within a range. overlap_query() Return the query string needed to find all features that overlap a range.
See Bio::DB::Adaptor::dbi::mysql for an example of how this works.
Title : do_straight_join Usage : $boolean = $db->do_straight_join($refseq,$class,$start,$stop,$types) Function: optimization flag Returns : a flag Args : see range_query() Status : Protected
This subroutine, called by range_query() returns a boolean flag. If true, range_query() will perform a straight join, which can be used to optimize certain SQL queries. The four arguments correspond to similarly-named arguments passed to range_query().
Title : string_match Usage : $string = $db->string_match($field,$value) Function: create a SQL fragment for performing exact or regexp string matching Returns : query string Args : the table field and match value Status : public
This method examines the passed value for meta characters. If so it produces a SQL fragment that performs a regular expression match. Otherwise, it produces a fragment that performs an exact string match.
This method is not used in the module, but is available for use by subclasses.
Title : exact_match Usage : $string = $db->exact_match($field,$value) Function: create a SQL fragment for performing exact string matching Returns : query string Args : the table field and match value Status : public
This method produces the SQL fragment for matching a field name to a constant string value.
Title : meta Usage : $value = $db->meta($name [,$newval]) Function: get or set a meta variable Returns : a string Args : meta variable name and optionally value Status : public
Get or set a named metavariable for the database. Metavariables can be used for database-specific settings. This method calls two class-specific methods which must be implemented:
make_meta_get_query() Returns a sql fragment which given a meta parameter name, returns its value. One bind variable. make_meta_set_query() Returns a sql fragment which takes two bind arguments, the parameter name and its value
Don't make changes unless you know what you're doing! It will affect the persistent database.
Title : make_meta_get_query Usage : $sql = $db->make_meta_get_query Function: return SQL fragment for getting a meta parameter Returns : SQL fragment Args : none Status : public
By default this does nothing; meta parameters are not stored or retrieved.
Title : make_meta_set_query Usage : $sql = $db->make_meta_set_query Function: return SQL fragment for setting a meta parameter Returns : SQL fragment Args : none Status : public
Title : get_features_iterator Usage : $iterator = $db->get_features_iterator($search,$options,$callback) Function: create an iterator on a features() query Returns : A Bio::DB::GFF::Adaptor::dbi::iterator object Args : see get_features() Status : public
This method is similar to get_features(), except that it returns an iterator across the query. See Bio::DB::GFF::Adaptor::dbi::iterator.
Title : do_initialize Usage : $success = $db->do_initialize($drop_all) Function: initialize the database Returns : a boolean indicating the success of the operation Args : a boolean indicating whether to delete existing data Status : protected
This method will load the schema into the database. If $drop_all is true, then any existing data in the tables known to the schema will be deleted.
Internally, this method calls schema() to get the schema data.
Title : drop_all Usage : $db->drop_all Function: empty the database Returns : void Args : none Status : protected
This method drops the tables known to this module. Internally it calls the abstract tables() method.
The following astract methods either return DBI statement handles or fragments of SQL. They must be implemented by subclasses of this module. See Bio::DB::GFF::Adaptor::dbi::mysql for examples.
Title : make_features_select_part Usage : $string = $db->make_features_select_part() Function: make select part of the features query Returns : a string Args : none Status : Abstract
This abstract method creates the part of the features query that immediately follows the SELECT keyword.
Title : make_features_from_part Usage : $string = $db->make_features_from_part() Function: make from part of the features query Returns : a string Args : none Status : Abstract
This abstract method creates the part of the features query that immediately follows the FROM keyword.
Title : make_features_join_part Usage : $string = $db->make_features_join_part() Function: make join part of the features query Returns : a string Args : none Status : Abstract
This abstract method creates the part of the features query that immediately follows the WHERE keyword. It is combined with the output of make_feautres_where_part() to form the full WHERE clause. If you do not need to join, return "1".
Title : make_features_order_by_part Usage : ($query,@args) = $db->make_features_order_by_part() Function: make the ORDER BY part of the features() query Returns : a SQL fragment and bind arguments, if any Args : none Status : Abstract
This abstract method creates the part of the features query that immediately follows the ORDER BY part of the query issued by features() and related methods. Return undef if it is not necessary to order the returned features in some way.
Title : make_features_by_name_where_part Usage : $db->make_features_by_name_where_part($class,$name) Function: create the SQL fragment needed to select a feature by its group name & class Returns : a SQL fragment and bind arguments Args : class and name of the feature group Status : Protected
Title : make_features_by_id_where_part Usage : $db->make_features_by_id_where_part($ids) Function: create the SQL fragment needed to select a set of features by their ids Returns : a SQL fragment and bind arguments Args : arrayref of IDs Status : Protected
Title : make_features_by_gid_where_part Usage : $db->make_features_by_gid_where_part($ids) Function: create the SQL fragment needed to select a set of features by their group ids Returns : a SQL fragment and bind arguments Args : arrayref of IDs Status : Protected
Title : make_dna_query Usage : $sth = $db->make_dna_query($name,$class,$start,$stop); Function: create query that returns raw DNA sequence from database Returns : a DBI statement handle Args : reference sequence name and class, and a range Status : Abstract
The statement handler should return rows containing just one field, the extracted DNA string.
Title : make_abscoord_query Usage : $sth = $db->make_abscoord_query($name,$class); Function: create query that finds the reference sequence coordinates given a landmark & classa Returns : a DBI statement handle Args : name and class of landmark Status : Abstract
The statement handler should return rows containing five fields:
1. reference sequence name 2. reference sequence class 3. start position 4. stop position 5. strand ("+" or "-")
If the database does not recognize different classes of reference sequence, return "Sequence" as the class.
Title : refseq_query Usage : ($query,@args) = $db->refseq_query($name,$class) Function: create SQL fragment that selects the desired reference sequence Returns : a list containing the query and bind arguments Args : reference sequence name and class Status : Abstract
This method is called by make_features_by_range_where_part() to construct the part of the select WHERE section that selects a particular reference sequence. It returns a mult-element list in which the first element is the SQL fragment and subsequent elements are bind values. For example:
sub refseq_query { my ($name,$class) = @_; return ('gff.refseq=? AND gff.refclass=?', $name,$class); }
Title : overlap_query Usage : ($query,@args) = $db->overlap_query($start,$stop) Function: create SQL fragment that selects the desired features by range Returns : a list containing the query and bind arguments Args : the start and stop of a range, inclusive Status : Abstract
This method is called by make_features_by_range_where_part() to construct the part of the select WHERE section that selects a set of features that overlap a range. It returns a multi-element list in which the first element is the SQL fragment and subsequent elements are bind values. For example:
sub overlap_query { my ($start,$stop) = @_; return ('gff.stop>=? AND gff.start<=?', $start,$stop); }
Title : contains_query Usage : ($query,@args) = $db->contains_query($start,$stop) Function: create SQL fragment that selects the desired features by range Returns : a list containing the query and bind arguments Args : the start and stop of a range, inclusive Status : Abstract
This method is called by make_features_by_range_where_part() to construct the part of the select WHERE section that selects a set of features entirely enclosed by a range. It returns a multi-element list in which the first element is the SQL fragment and subsequent elements are bind values. For example:
sub contains_query { my ($start,$stop) = @_; return ('gff.start>=? AND gff.stop<=?', $start,$stop); }
Title : contained_in_query Usage : ($query,@args) = $db->contained_in_query($start,$stop) Function: create SQL fragment that selects the desired features by range Returns : a list containing the query and bind arguments Args : the start and stop of a range, inclusive Status : Abstract
sub contained_in_query { my ($start,$stop) = @_; return ('gff.start<=? AND gff.stop>=?', $start,$stop); }
Title : types_query Usage : ($query,@args) = $db->types_query($types) Function: create SQL fragment that selects the desired features by type Returns : a list containing the query and bind arguments Args : an array reference containing the types Status : Abstract
This method is called by make_features_by_range_where_part() to construct the part of the select WHERE section that selects a set of features based on their type. It returns a multi-element list in which the first element is the SQL fragment and subsequent elements are bind values. The argument is an array reference containing zero or more [$method,$source] pairs.
Title : make_types_select_part Usage : ($string,@args) = $db->make_types_select_part(@args) Function: create the select portion of the SQL for fetching features type list Returns : query string and bind arguments Args : see below Status : Abstract
This abstract method is called by get_types() to generate the query fragment and bind arguments for the SELECT part of the query that retrieves lists of feature types. The four positional arguments are as follows:
$refseq reference sequence name $start start of region $stop end of region $want_count true to return the count of this feature type
If $want_count is false, the SQL fragment returned must produce a list of feature types in the format (method, source).
If $want_count is true, the returned fragment must produce a list of feature types in the format (method, source, count).
Title : make_types_from_part Usage : ($string,@args) = $db->make_types_from_part(@args) Function: create the FROM portion of the SQL for fetching features type lists Returns : query string and bind arguments Args : see below Status : Abstract
This abstract method is called by get_types() to generate the query fragment and bind arguments for the FROM part of the query that retrieves lists of feature types. The four positional arguments are as follows:
Title : make_types_join_part Usage : ($string,@args) = $db->make_types_join_part(@args) Function: create the JOIN portion of the SQL for fetching features type lists Returns : query string and bind arguments Args : see below Status : Abstract
This abstract method is called by get_types() to generate the query fragment and bind arguments for the JOIN part of the query that retrieves lists of feature types. The four positional arguments are as follows:
Title : make_types_where_part Usage : ($string,@args) = $db->make_types_where_part(@args) Function: create the WHERE portion of the SQL for fetching features type lists Returns : query string and bind arguments Args : see below Status : Abstract
This abstract method is called by get_types() to generate the query fragment and bind arguments for the WHERE part of the query that retrieves lists of feature types. The four positional arguments are as follows:
Title : make_types_group_part Usage : ($string,@args) = $db->make_types_group_part(@args) Function: create the GROUP BY portion of the SQL for fetching features type lists Returns : query string and bind arguments Args : see below Status : Abstract
This abstract method is called by get_types() to generate the query fragment and bind arguments for the GROUP BY part of the query that retrieves lists of feature types. The four positional arguments are as follows:
This method may return an empty list if grouping is not required. Note, however, that grouping will always be required if a type count is requested.
Title : tables Usage : @tables = $db->tables Function: return list of tables that belong to this module Returns : list of tables Args : none Status : protected
This method lists the tables known to the module.
Title : schema Usage : $schema = $db->schema Function: return the CREATE script for the schema Returns : a hashref Args : none Status : abstract
This method returns an array ref containing the various CREATE statements needed to initialize the database tables. The keys are the table names, and the values are strings containing the appropriate CREATE statement.
Title : DESTROY Usage : $db->DESTROY Function: disconnect database at destruct time Returns : void Args : none Status : protected
This is the destructor for the class.
Schemas need work to support multiple hierarchical groups.
Bio::DB::GFF, bioperl
Lincoln Stein <lstein@cshl.org>.
Copyright (c) 2001 Cold Spring Harbor Laboratory.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Bio::Seq, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bio::Seq
CPAN shell
perl -MCPAN -e shell install Bio::Seq
For more information on module installation, please visit the detailed CPAN module installation guide.