NAME
Bio::DB::Query::HIVQuery - Query interface to the Los Alamos HIV Sequence Database
SYNOPSIS
$q = new Bio::DB::Query::HIVQuery(" C[subtype] ZA[country] CXCR4[coreceptor] ");$q = new Bio::DB::Query::HIVQuery(-query=>{'subtype'=>'C','country'=>'ZA','coreceptor'=>'CXCR4'});$ac = $q->get_annotations_by_id(($q->ids)[0]);$ac->get_value('Geo', 'country') # returns 'SOUTH AFRICA'$db = new Bio::DB::HIV();$seqio = $db->get_Stream_by_query($q); # returns annotated Bio::Seqs# get subtype C sequences from South Africa and Brazil,# with associated info on patient health, coreceptor use, and# infection period:$q = new Bio::DB::Query::HIVQuery(-query => {'query' => {'subtype'=>'C','country'=>['ZA', 'BR']},'annot' => ['patient_health','coreceptor','days_post_infection']});
DESCRIPTION
Bio::DB::Query::HIVQuery provides a query-like interface to the cgi-based Los Alamos National Laboratory (LANL) HIV Sequence Database. It uses Bioperl facilities to capture both sequences and annotations in batch in an automated and computable way. Use with Bio::DB::HIV to create "Bio::Seq" objects and annotated "Bio::SeqIO" streams.
Query format
The interface implements a simple query language emulation that understands AND, OR, and parenthetical nesting. The basic query unit is
(match1 match2 ...)[fieldname]
Sequences are returned for which "fieldname" equals "match1 OR match2 OR ...". These units can be combined with AND, OR and parentheses. For example:
(B, C)[subtype] AND (2000, 2001, 2002, 2003)[year] AND ((CN)[country] OR (ZA)[country])
which can be shortened to
(B C)[subtype] (2000 2001 2002 2003)[year] (CN ZA)[country]
The user can specify annotation fields, that do not restrict the query, but arrange for the return of the associated field data for each sequence returned. Specify annotation fields between curly braces, as in:
(B C)[subtype] 2000[year] {country cd4_count cd8_count}
Annotations can be accessed off the query using methods described in APPENDIX.
Hash specifications for query construction
Single query specifications can be made as hash references provided to the "-query" argument of the constructor. There are two forms:
-query => { 'country'=>'BR', 'phenotype'=>'NSI', 'cd4_count'=>'Any' }
equivalent to
-query => [ 'country'=>'BR', 'phenotype'=>'NSI', 'cd4_count'=>'Any' ]
or
-query => { 'query' => {'country'=>'BR', 'phenotype'=>'NSI'},'annot' => ['cd4_count'] }
In both cases, the CD4 count is included in the annotations returned, but does not restrict the rest of the query.
To 'OR' multiple values of a field, use an anonymous array ref:
-query => { 'country'=>['ZA','BR','NL'], 'subtype'=>['A', 'C', 'D'] }
Valid query field names
An attempt was made to make the query field names natural and easy to remember. Aliases are specified in an XML file ("lanl-schema.xml") that is part of the distribution. Custom field aliases can be set up by modifying this file.
An HTML cheatsheet with valid field names, aliases, and match data can be generated from the XML by using "hiv_object->help('help.html')". A query can also be validated locally before it is unleashed on the server; see below.
Annotations
LANL DB annotations have been organized into a number of natural groupings, tagged "Geo", "Patient", "Virus", and "StdMap". After a successful query, each id is associated with a tree of Bio::Annotation::SimpleValue objects. These can be accessed with methods "get_value" and "put_value" described in APPENDIX.
Delayed/partial query runs
Accessing the LANL DB involves multiple HTTP requests. The query can be instructed to proceed through all (the default) or only some of them, using the named parameter "RUN_OPTION".
To validate a query locally, use
$q = new Bio::DB::Query::HIVQuery( -query => {...}, -RUN_OPTION=>0 )
which will throw an exception if a field name or option is invalid.
To get a query count only, you can save a server hit by using
$q = new Bio::DB::Query::HIVQuery( -query => {...}, -RUN_OPTION=>1 )
and asking for "$q->count". To finish the query, do
$q->_do_query(2)
which picks up where you left off.
"-RUN_OPTION=>2", the default, runs the full query, returning ids and annotations.
Query re-use
You can clear the query results, retaining the same LANL session and query spec, by doing "$q->_reset". Change the query, and rerun with "$q->_do_query($YOUR_RUN_OPTION)".
FEEDBACK
Mailing Lists
User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated.
[email protected] - General discussionhttp://bioperl.org/wiki/Mailing_lists - About the mailing lists
Support
Please direct usage questions or support issues to the mailing list:
rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible.
Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web:
https://github.com/bioperl/bioperl-live/issues
AUTHOR - Mark A. Jensen
Email [email protected]
CONTRIBUTORS
Mark A. Jensen
APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
Constructor
new
Title : newUsage : my $hiv_query = new Bio::DB::Query::HIVQuery();Function: Builds a new Bio::DB::Query::HIVQuery object,running a sequence query against the Los AlamosHIV sequence databaseReturns : an instance of Bio::DB::Query::HIVQueryArgs :
QueryI compliance
count
Title : countUsage : $hiv_query->count($newval)Function: return number of sequences foundExample :Returns : value of count (a scalar)Args : on set, new value (a scalar or undef, optional)Note : count warns if it is accessed for reading before queryhas been executed to at least level 1
ids
Title : idsUsage : $hiv_query->ids($newval)Function: LANL ids of returned sequencesExample :Returns : value of ids (an arrayref of sequence accessions/ids)Args : on set, new value (an arrayref or undef, optional)
query
Title : queryUsage : $hiv_query->queryFunction: Get/set the submitted query hash or stringExample :Returns : hashref or stringArgs : query in hash or string form (see DESCRIPTION)
Bio::DB::Query::HIVQuery specific methods
help
Title : helpUsage : $hiv_query->help("help.html")Function: get html-formatted listing of valid fields/aliases/optionsbased on current schema xmlExample : perl -MBio::DB::Query::HIVQuery -e "new Bio::DB::Query::HIVQuery()->help" | lynx -stdinReturns : HTMLArgs : optional filename; otherwise prints to stdout
Annotation manipulation methods
get_annotations_by_ids
Title : get_annotations_by_ids (or ..._by_id)Usage : $ac = $hiv_query->get_annotations_by_ids(@ids)Function: Get the Bio::Annotation::Collection for these sequence idsExample :Returns : A Bio::Annotation::Collection objectArgs : an array of sequence ids
add_annotations_for_id
Title : add_annotations_for_idUsage : $hiv_query->add_annotations_for_id( $id ) to create a newempty collection for $id$hiv_query->add_annotations_for_id( $id, $ac ) to associate$ac with $idFunction: Associate a Bio::Annotation::Collection with this sequence idExample :Returns : a Bio::Annotation::Collection objectArgs : sequence id [, Bio::Annotation::Collection object]
remove_annotations_for_ids
Title : remove_annotations_for_ids (or ..._for_id)Usage : $hiv_query->remove_annotations_for_ids( @ids)Function: Remove annotation collection for this sequence idExample :Returns : An array of the previous annotation collections for these idsArgs : an array of sequence ids
remove_annotations
Title : remove_annotationsUsage : $hiv_query->remove_annotations()Function: Remove all annotation collections for this objectExample :Returns : The previous annotation collection hash for this objectArgs : none
get_value
Title : get_valueUsage : $ac->get_value($tagname) -or-$ac->get_value( $tag_level1, $tag_level2,... )Function: access the annotation value associated with the given tagsExample :Returns : a scalarArgs : an array of tagnames that descend into the annotation treeNote : this is a L<Bio::AnnotationCollectionI> method added inL<Bio::DB::HIV::HIVQueryHelper>
put_value
Title : put_valueUsage : $ac->put_value($tagname, $value) -or-$ac->put_value([$tag_level1, $tag_level2, ...], $value) -or-$ac->put_value( [$tag_level1, $tag_level2, ...] )Function: create a node in an annotation tree, and assign a scalar value to itif a value is specifiedExample :Returns : scalar or a Bio::AnnotationCollection objectArgs : $tagname, $value scalars (can be specified as -KEYS=>$tagname,-VALUE=>$value) -or-\@tagnames, $value (or as -KEYS=>\@tagnames, -VALUE=>$value )Notes : This is a L<Bio::AnnotationCollectionI> method added inL<Bio::DB::HIV::HIVQueryHelper>.If intervening nodes do not exist, put_value creates them, replacingexisting nodes. So if $ac->put_value('x', 10) was done, then later,$ac->put_value(['x', 'y'], 20), the original value of 'x' is trashed,and $ac->get_value('x') will now return the annotation collectionwith tagname 'y'.
get_keys
Title : get_keysUsage : $ac->get_keys($tagname_level_1, $tagname_level_2,...)Function: Get an array of tagnames underneath the named tag nodesExample : # prints the values of the members of Category 1...print map { $ac->get_value($_) } $ac->get_keys('Category 1') ;Returns : array of tagnames or empty list if the arguments represent a leafArgs : [array of] tagname[s]
GenBank accession manipulation methods
get_accessions
Title : get_accessionsUsage : $hiv_query->get_accessions()Function: Return an array of GenBank accessions associated with thesesequences (available only after a query is subjected to afull run (i.e., when $RUN_OPTION == 2)Example :Returns : array of gb accession numbers, or () if none found for this queryArgs : none
get_accessions_by_ids
Title : get_accessions_by_ids (or ..._by_id)Usage : $hiv_query->get_accessions_by_ids(@ids)Function: Return an array of GenBank accessions associated with theseLANL ids (available only after a query is subjected to afull run (i.e., when $RUN_OPTION == 2)Example :Returns : array of gb accession numbers, or () if none found for this queryArgs : none
Query control methods
_do_query
Title : _do_queryUsage : $hiv_query->_do_query or $hiv_query->_do_query($run_level)Function: Execute the query according to argument or $RUN_OPTIONand set _RUN_LEVELextent of query reflects the value of argument0 : validate only (no HTTP action)1 : return sequence count only2 : return sequence ids (full query, returns with annotations)noop if current _RUN_LEVEL of query is >= argument or $RUN_OPTION,Example :Returns : actual _RUN_LEVEL (0, 1, or 2) achievedArgs : desired run level (optional, global $RUN_OPTION is default)
_reset
Title : _resetUsage : $hiv_query->_resetFunction: Resets query storage, count, and ids, while retaining session id,original query string, and db schemaExample :Returns : voidArgs : none
_session_id
Title : _session_idUsage : $hiv_query->_session_id($newval)Function: Get/set HIV db session id (initialized in _do_lanl_request)Example :Returns : value of _session_id (a scalar)Args : on set, new value (a scalar or undef, optional)
_run_level
Title : _run_levelUsage : $obj->_run_level($newval)Function: returns the level at which the query has so far been runExample :Returns : value of _run_level (a scalar)Args : on set, new value (a scalar or undef, optional)
_run_option
Title : _run_optionUsage : $hiv_query->_run_option($newval)Function: Get/set HIV db query run option (see _do_query for values)Example :Returns : value of _run_option (a scalar)Args : on set, new value (a scalar or undef, optional)
_ua_hash
Title : _ua_hashUsage : $obj->_ua_hash($newval)Function:Example :Returns : value of _ua_hash (a scalar)Args : on set, new value (a scalar or undef, optional)
Internals
add_id
Title : add_idUsage : $hiv_query->add_id($id)Function: Add new id to idsExample :Returns : the new idArgs : a sequence id
map_db
Title : map_dbUsage : $obj->map_db($newval)Function:Example :Returns : value of map_db (a scalar)Args : on set, new value (a scalar or undef, optional)
make_search_if
Title : make_search_ifUsage : $obj->make_search_if($newval)Function:Example :Returns : value of make_search_if (a scalar)Args : on set, new value (a scalar or undef, optional)
search_
Title : search_Usage : $obj->search_($newval)Function:Example :Returns : value of search_ (a scalar)Args : on set, new value (a scalar or undef, optional)
_map_db_uri
Title : _map_db_uriUsage :Function: return the full map_db uri ("Database Map")Example :Returns : scalar stringArgs : none
_make_search_if_uri
Title : _make_search_if_uriUsage :Function: return the full make_search_if uri ("Make Search Interface")Example :Returns : scalar stringArgs : none
_search_uri
Title : _search_uriUsage :Function: return the full search cgi uri ("Search Database")Example :Returns : scalar stringArgs : none
_schema_file
Title : _schema_fileUsage : $hiv_query->_schema_file($newval)Function:Example :Returns : value of _schema_file (an XML string or filename)Args : on set, new value (an XML string or filename, or undef, optional)
_schema
Title : _schemaUsage : $hiv_query->_schema($newVal)Function:Example :Returns : value of _schema (an HIVSchema object in packageL<Bio::DB::HIV::HIVQueryHelper>)Args : none (field set directly in new())
_lanl_query
Title : _lanl_queryUsage : $hiv_query->_lanl_query(\@query_parms)Function: pushes \@query_parms onto @{$self->{'_lanl_query'}Example :Returns : value of _lanl_query (an arrayref)Args : on set, new value (an arrayref or undef, optional)
_lanl_response
Title : _lanl_responseUsage : $hiv_query->_lanl_response($response)Function: pushes $response onto @{$hiv_query->{'_lanl_response'}}Example :Returns : value of _lanl_response (an arrayref of HTTP::Response objects)Args : on set, new value (an HTTP::Response object or undef, optional)
_create_lanl_query
Title : _create_lanl_queryUsage : $hiv_query->_create_lanl_query()Function: validate query hash or string, prepare for _do_lanl_requestExample :Returns : 1 if successful; throws exception on invalid queryArgs :
_do_lanl_request
Title : _do_lanl_requestUsage : $hiv_query->_do_lanl_request()Function: Perform search request on _create_lanl_query-validated queryExample :Returns : 1 if successfulArgs :
_parse_lanl_response
Title : _parse_lanl_responseUsage : $hiv_query->_parse_lanl_response()Function: Parse the tab-separated-value response obtained by _do_lanl_requestfor sequence ids, accessions, and annotationsExample :Returns : 1 if successfulArgs :
_parse_query_string
Title : _parse_query_stringUsage : $hiv_query->_parse_query_string($str)Function: Parses a query string using query language emulator QRY: in L<Bio::DB::Query::HIVQueryHelper>Example :Returns : arrayref of hash structures suitable for passing to _create_lanl_queryArgs : a string scalar
Dude, sorry-
_sorry
Title : _sorryUsage : $hiv_query->_sorry("-president=>Powell")Function: Throws an exception for unsupported option or parameterExample :Returns :Args : scalar string