NAME
Bio::DB::HIV::HIVQueryHelper - Routines and packages used by Bio::DB::HIV and Bio::DB::Query::HIVQuery
SYNOPSIS
Used in Bio::DB::Query::HIVQuery. No need to use directly.
DESCRIPTION
"Bio::DB::HIV::HIVQueryHelper" contains a number of packages for use by Bio::DB::Query::HIVQuery. Package "HIVSchema" parses the "lanl-schema.xml" file, and allows access to it in the context of the relational database it represents (see APPENDIX for excruciating detail). Packages "QRY", "R", and "Q" together create the query string parser that enables NCBI-like queries to be understood by "Bio::DB::Query::HIVQuery". They provide objects and operators to perform and simplify logical expressions involving "AND", "OR", and "()" and return hash structures that can be handled by "Bio::DB::Query::HIVQuery" routines.
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 contained packages. Internal methods are usually preceded with a _
HIVSchema - objects/methods to manipulate a version of the LANL HIV DB schema
HIVSchema SYNOPSIS
$schema = new HIVSchema( 'lanl-schema.xml' );@tables = $schema->tables;@validFields = $schema->fields;@validAliases = $schema->aliases;@query_aliases_for_coreceptor = $schema->aliases( 'SEQ_SAMple.SSAM_second_receptor' );$pk_for_SequenceEntry = $schema->primarykey('SequenceEntry'); # returns 'SequenceEntry.SE_id'$fk_for_SEQ_SAMple_to_SequenceEntry =$schema->foreignkey('SEQ_SAMple', 'SequenceEntry'); # returns 'SEQ_SAMple.SSAM_SE_id'$table = $schema->tablepart('SEQ_SAMple.SSAM_badseq'); # returns 'SEQ_SAMple'$column = $schema->columnpart('SEQ_SAMple.SSAM_badseq'); # returns 'SSAM_badseq'
HIVSchema DESCRIPTION
HIVSchema methods are used in Bio::DB::Query::HIVQuery for table, column, primary/foreign key manipulations based on the observed Los Alamos HIV Sequence Database (LANL DB) naming conventions for their CGI parameters. The schema is contained in an XML file ("lanl-schema.xml") which is read into an HIVSchema object, in turn a property of the HIVQuery object. HIVSchema methods are used to build correct cgi queries in a way that attempts to preserve the context of the relational database the query parameters represent.
HIVSchema CONSTRUCTOR
HIVSchema::new
Title : newUsage : $schema = new HIVSchema( "lanl-schema.xml ");Function:Example :Returns : an HIVSchema objectArgs : XML filename
HIVSchema INSTANCE METHODS
HIVSchema tables
Title : tablesUsage : $schema->tables()Function: get all table names in schemaExample :Returns : array of table namesArgs : none
HIVSchema columns
Title : columnsUsage : $schema->columns( [$tablename] );Function: return array of columns for specified table, or all columns inschema, if called w/o argsExample :Returns :Args : tablename or fieldname string
HIVSchema fields
Title : fieldsUsage : $schema->fields();Function: return array of all fields in schema, in format "table.column"Example :Returns : array of all fieldsArgs : none
HIVSchema options
Title : optionsUsage : $schema->options(@fieldnames)Function: get array of options (i.e., valid match data strings) availableto specified fieldExample :Returns : array of match data stringsArgs : [array of] fieldname string[s] in "table.column" format
HIVSchema aliases
Title : aliasesUsage : $schema->aliases(@fieldnames)Function: get array of aliases to specified field[s]Example :Returns : array of valid query aliases for fields as spec'd in XML fileArgs : [an array of] fieldname[s] in "table.column" format
HIVSchema ankh
Title : ankh (annotation key hash)Usage : $schema->ankh(@fieldnames)Function: return a hash translating fields to annotation keys for thespec'd fields.(Annotation keys are used for parsing the tab-delimited responseto Bio::DB::Query::HIVQuery::_do_lanl_request.)Example :Returns : hash refArgs : [an array of] fieldname[s] in "table.column" format
HIVSchema tablepart
Title : tablepart (alias: tbl)Usage : $schema->tbl(@fieldnames)Function: return the portion of the fieldname[s] that refer to thedb tableExample : $schema->tbl('SequenceEntry.SE_id'); # returns 'SequenceEntry'Returns : table name as stringArgs : [an array of] fieldname[s] in "table.column" format
HIVSchema columnpart
Title : columnpart (alias: col)Usage : $schema->col(@fieldnames)Function: return the portion of the fieldname[s] that refer to thedb columnExample : $schema->col('SequenceEntry.SE_id'); # returns 'SE_id'Returns : column name as stringArgs : [an array of] fieldname[s] in "table.column" format
HIVSchema primarykey
Title : primarykey [alias: pk]Usage : $schema->pk(@tablenames);Function: return the primary key of the specified table[s], as judged bythe syntax of the table's[s'] fieldnamesExample : $schema->pk('SequenceEntry') # returns 'SequenceEntry.SE_id'Returns : primary key fieldname[s] in "table.column" format, or null ifno pk existsArgs : [an array of] table name[s] (fieldnames are ok, table part used)
HIVSchema foreignkey
Title : foreignkey [alias: fk]Usage : $schema->fk($intable [, $totable])Function: return foreign key fieldname in table $intable referring totable $totable, or all foreign keys in $intable if $totableunspec'dExample : $schema->fk('AUthor', 'SequenceEntry'); # returns 'AUthor_AU_SE_id'Returns : foreign key fieldname[s] in "table.column" formatArgs : tablename [, optional foreign table name] (fieldnames are ok,table part used)
HIVSchema foreigntable
Title : foreigntable [alias ftbl]Usage : $schema->ftbl( @foreign_key_fieldnames );Function: return tablename of table that foreign keys points toExample : $schema->ftbl( 'AUthor.AU_SE_id' ); # returns 'SequenceEntry'Returns : tablenameArgs : [an array of] fieldname[s] in "table.column" format
HIVSchema find_join
Title : find_joinUsage : $sch->find_join('Table1', 'Table2')Function: Retrieves a set of foreign and primary keys (in table.columnformat) that represents a join path from Table1 to Table2Example :Returns : an array of keys (as table.column strings) -or- an emptyarray if Table1 == Table2 -or- undef if no path existsArgs : two table names as strings
HIVSchema _find_join_guts
Title : _find_join_gutsUsage : $sch->_find_join_guts($table1, $table2, $stackref, \$found, $reverse)(call with $stackref = [], $found=0)Function: recursive guts of find_joinExample :Returns : if a path is found, $found==1 and @$stackref contains the keysin table.column format representing the path; if a path is notfound, $found == 0 and @$stackref contains garbageArgs : $table1, $table2 : table names as strings$stackref : an arrayref to an empty array\$found : a scalar ref to the value 0$rev : if $rev==1, the arrays of table names will be reversed;this can give a shorter path if cycles exist in theschema graph
HIVSchema loadSchema
Title : loadHIVSchema [alias: loadSchema]Usage : $schema->loadSchema( $XMLfilename )Function: read (LANL DB) schema spec from XMLExample : $schema->loadSchema('lanl-schema.xml');Returns : hashref to schema dataKeys are fieldnames in "table.column" format.Each value is a hashref with the following properties:{name} : HIVWEB 'table.column' format fieldname,can be used directly in the cgi query{aliases} : ref to array containing valid aliases/shortcuts for{name}; can be used in routines creating the HTML query{options} : ref to array containing valid matchdata for this fieldcan be used directly in the HTML query{ankey} : contains the annotation key for this field used withBioperl annotation objects{..attr..}: ..value_of_attr.. for this field (app-specific metadata)Args :
HIVSchema _sfieldh
Title : _sfieldhUsage : $schema->_sfieldh($fieldname)Function: get hashref to the specified field hashExample :Returns : hashrefArgs : fieldname in "table.column" format
Class QRY - a query algebra for HIVQuery
QRY SYNOPSIS
$Q = new QRY(new R(new Q('coreceptor', 'CXCR4'),new Q('country', 'ZA')));QRY::Eq(QRY::And($Q, $Q), $Q); # returns 1QRY::Eq(QRY::Or($Q, $Q), $Q); # returns 1$Q2 = $Q1->clone;$Q2 = new QRY(new R(new Q( 'coreceptor', 'CCR5' ),new Q( 'country', 'ZA')));(QRY::And($Q, $Q2))->isnull; # returns 1$Q3 = QRY::Or($Q, $Q2);print $Q3->A; # prints '(CCR5 CXCR4)[coreceptor] (ZA)[country]'
QRY DESCRIPTION
The QRY package provides a query parser for Bio::DB::Query::HIVQuery. Currently, the parser supports AND, OR, and () operations. The structure of the LANL cgi makes it tricky to perform NOTs, though this could be implemented if the desire were great.
Two class methods do the work. "QRY::_parse_q" does a first-pass parse of the query string. "QRY::_make_q" interprets the parse tree as returned by "QRY::_parse_q" and produces an array of hash structures that can be used directly by "Bio::DB::Query::HIVQuery" query execution methods. Validation of query fields and options is performed at the "Bio::DB::Query::HIVQuery" level, not here.
"QRY" objects are collections of "R" (or request) objects, which are in turn collections of "Q" (or atomic query) objects. "Q" objects represent a query on a single field, with match data options "OR"ed together, e.g. "(A B)[subtype]". "R" objects collect "Q" objects that could be processed in a single HTTP request; i.e., a set of atomic queries each having different fields "AND"ed together, such as
(A B)[subtype] AND ('CCR5')[coreceptor] AND (US CA)[country]
The "QRY" object collects "R"s that cannot be reduced (through logical operations) to a single HTTP request, e.g.
((C)[subtype] AND (SI)[phenotype]) OR ( (D)[subtype] AND (NSI)[phenotype] ),
which cannot be got in one go through the current LANL cgi implementation (as far as I can tell). The parser will simplify something like
((C)[subtype] AND (SI)[phenotype]) OR ((C)[subtype] AND (NSI)[phenotype])
to the single request
(C)[subtype] AND (NSI SI)[phenotype]
however.
The operators "&" and "|" are overloaded to "QRY::And" and "QRY::Or", to get Perl precedence and grouping for free. "bool" is overloaded to get symbolic tests such as "if ($QRY) {stuff}". "==" is overloaded with "QRY::Eq" for convenience. No overloading is done for "R" or "Q".
QRY _make_q
Title : _make_qUsage : QRY::_make_q($parsetree)Function: creates hash structures suitable for HIVQuery from parse treereturned by QRY::_parse_qExample :Returns : array of hashrefs of query specsArgs : a hashref
QRY _make_q_guts
Title : _make_q_guts (Internal class method)Usage : _make_q_guts($ptree, $q_expr, $qarry, $anarry)Function: traverses the parse tree returned from QRY::_parse_q, checkingsyntax and creating HIVQuery-compliant query structuresExample :Returns :Args : $parse_tree (hashref), $query_expression (scalar string ref),$query_array (array ref : stack for returning query structures),$annotation_array (array ref : stack for returning annotationfields)
QRY _parse_q
Title : _parse_qUsage : QRY::_parse_q($query_string)Function: perform first pass parse of a query string with some syntaxchecking, return a parse tree suitable for QRY::_make_qExample : QRY::_parse_q(" to[be] OR (not to)[be] ");Returns : hashrefArgs : query string
QRY CONSTRUCTOR
QRY Constructor
Title : QRY constructorUsage : $QRY = new QRY()Function:Example :Returns :Args : array of R objects, optional
QRY INSTANCE METHODS
QRY requests
Title : requestsUsage : $QRY->requestsFunction: get/set array of requests comprising this QRY objectExample :Returns :Args : array of class R objects
QRY put_requests
Title : put_requestsUsage : $QRY->put_request(@R)Function: add object of class R to $QRYExample :Returns :Args : [an array of] of class R object[s]
QRY isnull
Title : isnullUsage : $QRY->isnullFunction: test if QRY object is nullExample :Returns : 1 if null, 0 otherwiseArgs :
QRY A
Title : AUsage : print $QRY->AFunction: get a string representation of QRY objectExample :Returns : string scalarArgs :
QRY len
Title : lenUsage : $QRY->lenFunction: get number of class R objects contained by QRY objectExample :Returns : scalarArgs :
QRY clone
Title : cloneUsage : $QRY2 = $QRY1->clone;Function: create and return a clone of the objectExample :Returns : object of class QRYArgs :
QRY CLASS METHODS
QRY Or
Title : OrUsage : $QRY3 = QRY::Or($QRY1, $QRY2)Function: logical OR for QRY objectsExample :Returns : a QRY objectArgs : two class QRY objects
QRY And
Title : AndUsage : $QRY3 = QRY::And($QRY1, $QRY2)Function: logical AND for QRY objectsExample :Returns : a QRY objectArgs : two class QRY objects
QRY Bool
Title : BoolUsage : QRY::Bool($QRY1)Function: allows symbolic testing of QRY object when bool overloadedExample : do {stuff} if $QRY1 *same as* do {stuff} if !$QRY1->isnullReturns :Args : a class QRY object
QRY Eq
Title : EqUsage : QRY::Eq($QRY1, $QRY2)Function: test if R objects in two QRY objects are the same(irrespective of order)Example :Returns : 1 if equal, 0 otherwiseArgs : two class QRY objects
Class R - request objects for QRY algebra
R SYNOPSIS
$R = new R( $q1, $q2 );$R->put_atoms($q3);$R->del_atoms('coreceptor', 'phenotype');return $R->clone;$R1 = new R( new Q('subtype', 'B') );$R2 = new R( new Q('subtype', 'B C'),new Q('country', 'US') );R::Eq( (R::And($R1, $R2))[0],new R( new Q('subtype', 'B' ),new Q('country', 'US') )); # returns 1QRY::Eq( new QRY(R::Or($R1, $R2)), new QRY($R1, $R2) ); # returns 1R::In( (R::And($R1, $R2))[0], $R1 ); # returns 1
R DESCRIPTION
Class R objects contain a list of atomic queries (class Q objects). Each class R object represents a single HTTP request to the LANL DB. When converted to a DB query, the class Q objects contained by an R object are effectively "AND"ed.
R CONSTRUCTOR
R constructor
Title : R constructorUsage : $R = new R()Function: create a new R (request) objectExample :Returns : class R (request) objectArgs : optional, array of class Q objects
R INSTANCE METHODS
R len
Title : lenUsage : $R->lenFunction: get number of class Q objects contained in R objectExample :Returns : scalarArgs :
R atoms
Title : atomsUsage : $R->atoms( [optional $field])Function: get array of class Q (atomic query) objects in class R objectExample : $R->atoms(); $R->atoms('coreceptor')Returns : array of class Q objects (all Qs or those corresponding to $fieldif present)Args : optional, scalar string
R fields
Title : fieldsUsage : $R->fieldsFunction: get array of fields of all Q objects contained in $RExample :Returns : array of scalarsArgs :
R put_atoms
Title : put_atomsUsage : $R->put_atoms( @q )Function: AND an atomic query (class Q object) to the class R object's listExample :Returns : voidArgs : an [array of] class Q object[s]
R del_atoms
Title : del_atomsUsage : $R->del_atoms( @qfields )Function: removes class Q objects from R object's list according to thefield names given in argumentsExample :Returns : the class Q objects deletedArgs : scalar array of field names
R isnull
Title : isnullUsage : $R->isnullFunction: test if class R object is nullExample :Returns : 1 if null, 0 otherwiseArgs :
R A
Title : AUsage : print $R->AFunction: get a string representation of class R objectExample :Returns : string scalarArgs :
R clone
Title : cloneUsage : $R2 = $R1->clone;Function: create and return a clone of the objectExample :Returns : object of class RArgs :
R CLASS METHODS
R In
Title : InUsage : R::In($R1, $R2)Function: tests whether the query represented by $R1 would return a subsetof items returned by the query represented by $R2Example : print "R2 gets those and more" if R::In($R1, $R2);Returns : 1 if R1 is subset of R2, 0 otherwiseArgs : two class R objects
R And
Title : AndUsage : @Rresult = R::And($R1, $R2)Function: logical AND for R objectsExample :Returns : an array containing class R objectsArgs : two class R objects
R Or
Title : OrUsage : @Rresult = R::Or($R1, $R2)Function: logical OR for R objectsExample :Returns : an array containing class R objectsArgs : two class R objects
R Eq
Title : EqUsage : R::Eq($R1, $R2)Function: test if class Q objects in two R objects are the same(irrespective of order)Example :Returns : 1 if equal, 0 otherwiseArgs : two class R objects
Class Q - atomic query objects for QRY algebra
Q SYNOPSIS
$q = new Q('coreceptor', 'CXCR4 CCR5');$u = new Q('coreceptor', 'CXCR4');$q->fld; # returns 'coreceptor'$q->dta; # returns 'CXCR4 CCR5'print $q->A; # prints '(CXCR4 CCR5)[coreceptor]Q::qeq($q, $u); # returns 0Q::qeq( Q::qor($q, $q), $q ); # returns 1Q::qin($u, $q) # returns 1Q::qeq(Q::qand($u, $q), $u ); # returns 1
Q DESCRIPTION
Class Q objects represent atomic queries, that can be described by a single LANL cgi parameter=value pair. Class R objects (requests) are built from class Qs. The logical operations at the higher levels ("QRY, R") ultimately depend on the lower level operations on Qs: "qeq, qin, qand, qor".
Q CONSTRUCTOR
Q constructor
Title : Q constructorUsage : $q = new Q($field, $data)Function: create a new Q (atomic query) objectExample :Returns : class Q objectArgs : optional $field, $data strings
Q INSTANCE METHODS
Q isnull
Title : isnullUsage : $q->isnullFunction: test if class Q object is nullExample :Returns : 1 if null, 0 otherwiseArgs :
Q fld
Title : fldUsage : $q->fld($field)Function: get/set fld (field name) propertyExample :Returns : scalarArgs : scalar
Q dta
Title : dtaUsage : $q->dta($data)Function: get/set dta (whsp-separated data string) propertyExample :Returns : scalarArgs : scalar
Q A
Title : AUsage : print $q->AFunction: get a string representation of class Q objectExample :Returns : string scalarArgs :
Q clone
Title : cloneUsage : $q2 = $q1->clone;Function: create and return a clone of the objectExample :Returns : object of class QArgs :
Q CLASS METHODS
Q qin
Title : qinUsage : Q::qin($q1, $q2)Function: tests whether the query represented by $q1 would return a subsetof items returned by the query represented by $q2Example : print "q2 gets those and more" if Q::qin($q1, $q2);Returns : 1 if q1 is subset of q2, 0 otherwiseArgs : two class Q objects
Q qeq
Title : qeqUsage : Q::qeq($q1, $q2)Function: test if fld and dta properties in two class Q objects are the same(irrespective of order)Example :Returns : 1 if equal, 0 otherwiseArgs : two class Q objects
Q qor
Title : qorUsage : @qresult = Q::qor($q1, $q2)Function: logical OR for Q objectsExample :Returns : an array of class Q objectsArgs : two class Q objects
Q qand
Title : qandUsage : @qresult = Q::And($q1, $q2)Function: logical AND for R objectsExample :Returns : an array of class Q objectsArgs : two class Q objects
Q INTERNALS
Q unique
Title : uniqueUsage : @ua = unique(@a)Function: return contents of @a with duplicates removedExample :Returns :Args : an array
Additional tools for Bio::AnnotationCollectionI
Bio::AnnotationCollectionI SYNOPSIS (additional methods)
$seq->annotation->put_value('patient_id', 1401)$seq->annotation->get_value('patient_ids') # returns 1401$seq->annotation->put_value('patient_group', 'MassGenH')$seq->annotation->put_value(['clinical', 'cd4count'], 503);$seq->annotation->put_value(['clinical', 'virus_load'], 150805);foreach ( qw( cd4count virus_load ) ) {$blood_readings{$_} = $seq->annonation->get_value(['clinical', $_]);}
Bio::AnnotationCollectionI DESCRIPTION (additional methods)
"get_value()" and "put_value" allow easy creation of and access to an annotation collection tree with nodes of Bio::Annotation::SimpleValue. These methods obiviate direct accession of the SimpleValue objects.
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 tree
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 )Note : 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]