About ACEDB Queries


All ACEDB databases can be queried using the ACEDB query language. The easiest way to learn this query language is through examples. Many thanks to Dave Matthews and John Morris for their contributions to this document.

Other very useful documents on ACEDB query language are:


Examples

In the examples below, ACEDB commands and operators are in bold. Note that ACEDB commands are case insensitive and operators are case sensitive. Database class or tag names begin with a capital letter, but this is not an ACEDB requirement.

find Model
lists the database classes (tables) and tags (fields) available for querying

find Locus b*
lists all loci whose names begin with "b" (equivalent to where >?Locus b*)

find Colleague Mail = *dakota*
lists all colleagues which have a mailing address containing the string "dakota". "Colleague" is the class name and "Mail" is the tag name

find Locus b* AND Map = *7h
lists all loci whose names begin with "b" that are located on Maps whose names end in "7h"

find Colleague Mail = *dakota* AND Mail = *university*
lists all colleagues which have a mailing address containing the string "dakota" and containing the string "university"

find Colleague jon* OR smi*
lists all colleagues whose names begin with "jon" or "smi"

find Au* s?s* OR b*s*
lists authors Suseelan, Sasaki, Banks, Bosch, et. al

find Author COUNT Paper > 100
lists all authors who are an author on more than 100 papers

find Locus; follow Clone
lists all mapped clones

find Author jon*; follow Paper
lists all papers written by authors whose names begin with "jon"

find Author cartinhour*; follow Paper; follow Author
lists all the coauthors of papers by Cartinhour

grep adh
lists all database objects that contain the string "adh" (Note: this often returns too many objects to be useful)

? or help
either command displays this help document

The Details

Most ACEDB queries require knowledge of a database class and possibly tag names. ACEDB classes are similar to relational database tables, in that they contain information about a single subject, the class name. Some common class names are Locus, Sequence, Author, Paper, Colleague, Germplasm, Map and Clone. Tags are fields for information within a class. For example, tags in the class Germplasm may be Source, Type, Features, and Parent. There can be any number of tags and subtags within a class.

So how do you find out the class and tag names for the database you are interested in? All class and tag names are listed in the "model" or structure of the database. One of the first ACEDB queries you should do is list the database model (see the Examples). This will give you the information necessary to construct queries for the data you want to see.

It is important to list the model of every database you want to query because not all databases use the same model. Each organism has developed a database structure to suit their individual needs, although many class names and constructs are similar. This is the reason why some of the examples may work in one database but not in another.

Query construction

ACEDB queries can be simple (single) or complex (composite). A composite query is formed by chaining a series of single queries together separated by semicolons. The result of each query in turn is passed to the next query.

Parentheses of all sorts "([{" can be used freely, but must be matched.

Words or strings are matched to a tag or treated as text. They must be put in "double quotes" if they include spaces or any operator &, |, ^, <, >, =, (, ), [, ], {, }. Wild cards (* for multiple characters or ? for a single character) can be used in words.

Good learning tools for those wishing to master ACEDB query syntax are Query by Example and Query Builder. Both return a formal query string, along with the query results when a query is submitted.

Query commands

find class pattern
finds all objects belonging to class and matching patternin the database

follow tag
from the currently selected objects, returns all objects that also have tag

tag
tests the currently selected objects for the existence of tag. Note, this command can only be used after another query, not as an initial query.

grep pattern
finds all database objects that match pattern. Note, this often returns too many objects to be useful.

HERE | NEXT
tests the value under the pointer (HERE) or on the next value to the right (NEXT). Use this when there are two or more fields associated with a tag.

Query operators, in order of increasing precedence

argument1 OR argument2
evaluates to TRUE if at least one of argument1 or argument2 evaluate to true (alternative: |)

argument1 XOR argument2
evaluates to TRUE if either argument1 or argument2 evaluates to true, but not both (alternative: ^)

argument1 AND argument2
evaluates to TRUE if both argument1 and argument2 evaluates to true (alternative: %)

NOT argument
negates the result of the argument (alternative: !)

tag #
jumps into constructed types following tag

argument < pattern
less than, to compare numbers (alternative: LT)

argument <= pattern
less than or equal to, to compare numbers (alternative: LE)

argument > pattern
greater than, to compare numbers (alternative: GT)

argument >= pattern
greater than or equal to, to compare numbers (alternative: GE)

argument = pattern
equal, to compare numbers or match the pattern, i.e., a word with wild cards * or ?

argument != pattern
not equal, to compare numbers or match the pattern, i.e., a word with wild cards * or ? (alternative: NEQ)

COUNT tag
counts the number of data items following the tag

Advanced Queries -- Subfields

Subfield queries are used when there are two or more fields associated with a tag. Since the find command returns only the value immediately following the class or tag name, some method was needed to "move over" to the next value. This is the function of the NEXT (move right) and HERE (move here) commands.

A common subfield query is to locate loci on a genetic map using the class Locus and tag Map. The information is stored in a sequence of subfields as in this sample:

  Locus   Location Map    Hordeum-Graner2-7H   Position    141
    ^             ^               ^               ^         ^
  class          tag            value            tag      value
For example, to find all loci located on Maps that end in 7H and between 140 and 150 cM, the query is:

find Locus Map = *7h AND NEXT AND NEXT > 140 AND HERE < 150

The first AND NEXT moves off the Map value (*7h), the second AND NEXT skips over the Position tag and evaluates the Position value, and the AND HERE stays on the Position value and evaluates it again.