A.8. Operations

A.8.1. Types of Operation

The following types of operation are supported:

  • Operations to retrieve the value of a data definition

  • Operations to retrieve the values of attributes and calculated attributes of a data definition

  • Arithemetic operations

  • Tests for equality

  • Boolean logical operations

  • Calculations that use the above operations

  • Unary and ternary conditional statements using the above operations

A.8.2. Retrieving Data Values

The attribute values for a given data definition in an ACD file can depend on the values from other data definitions. It is possible to retrieve the value of:

  • A data definition (application parameter)

  • An attribute of a data definition

  • A calculated attribute of a data definition

  • An ACD variable definition

Such values are retrieved using the ACD "get the value of" syntax which consists of a term ParameterName.AttributeName term surrounded by parentheses with a dollar sign ($) at the front:


If just the value of the data definition is to be retrieved, the AttributeName component is omitted:


Of course, a variable name may also be given. Variables do not have attributes therefore the syntax is:


Of course, one needs to be careful that the type of retrieved value matches that of the attribute which is being calculated.

A.8.3. Types of Calculations and Tests

Calculations can be performed in ACD using the @ syntax. A rather silly, but legal, calculation would be:

@(5 + 9)

which equates to the value 14. Calculations can be used to add, subtract, multiply or divide, or test for equality, inequality, "greater than" or "less than" tests. The test values can be integers, floats and strings. You can use calculations with most attributes of datatypes where they make sense.

Only a single operation is allowed per set of parentheses. This means that that in some cases two or more sets of parentheses are required. In this example of a nested operations, two sets of parentheses are required, the first around the addition of a and b which gives @(a + b)). The second around the addition of @(a + b) to c, which gives @(@(a + b)+c):

integer:  n
default: "@(@(a + b)+c)"

Where more than one operation is required, however, one would typically use an internal ACD variable to hold the intermediate results.

A.8.3.1. Arithmetic Operations

The supported arithmetic operations are addition, subtraction, multiplication and division. The standard characters for the arithmetic operations are used: +, -, * and /:

@(a+b)   (Addition)
@(a-b)   (Subtraction)
@(a*b)   (Multiplication)
@(a/b)   (Division)

The operands a and b must resolve to a numerical (integer or a floating point): the result is undefined otherwise but will most probably result in an error during ACD processing.

A.8.3.2. Tests for Equality

The supported equality tests (symbols in parenthesis) are "equality" (==), "non-equality" (!=), "less than" (<) and "greater than" (>):

@(token1 == token2)     (Equality) 
@(token1 != token2)     (Non-equality) 
@(token1 < token2)   (Less-than) 
@(token1 > token2)   (Greater-than)

The above equality tests can be used on strings in which case the lexicographical sorting order of the string is used.

A.8.3.3. Boolean Tests

The supported boolean operations are logical AND, logical OR and logical NOT. Again, the standard characters are used: &, | and !:

@(!a) (NOT)
@(a|b) (OR)
@(a&b) (AND)

In the following example, the integer rtfm will only be prompted for if the value of fubar is either 3 or 7. Each of the equality tests is a calculation and the boolean test is another calculation. There are therefore three instances of @():

integer: rtfm 
   standard: "@(@($(fubar)==3) | @($(fubar)==7))"

A.8.4. Conditional Statements

There are three kinds of conditional statements in ACD, unary, ternary and case-type

A.8.4.1. Unary Conditional Statements

A typical use for unary conditionals is to switch prompts on or off.

In the following example, if the sequence is a protein then the prompt for window is effectively turned off (see Section 4.5, “Controlling the Prompt” for more information about negation):

sequence: sequence 
  parameter: "Y"
  type: gapany

integer: window 
  standard: "$(sequence.protein)"

A.8.4.2. Ternary Conditional

Ternary conditional statements have the general form:

@(conditional  ? value-if-true : value-if-false)

They are useful when setting up the application for two distinct modes of usage, for example when setting gap penalty values differently for proteins and nucleic acids in alignment programs.

In the following example, penalty is set to 14 for proteins and 16 for nucleic acids:

integer: penalty 
  standard: "N"
  default: "@($(sequence.protein) ? 14 : 16)"

A.8.4.3. Case Conditional

These have the general form:

@(testval = poss_valA : ass_valA 
            poss_valB : ass_valB 
            else : default_val)

The test value (testval) is compared with a list of possible values (poss_valA etc). If a match is found, the operation resolves to the result (ass_valB etc) associated with that possible value. The test value is parsed as a string and if none of the possible values match, the operation will resolve to the default result (default_val). The else : default value pair is optional and the default of NULL is used as required where it is not defined.

If the test value cannot unambiguously be assigned to a single associated value, the operation will resolve to the last associated value that matches its possible value.

A.8.5. Use of Variables

Variables are useful for holding partial calculations or values and can keep your ACD files looking neat and tidy. The general syntax for them is:

VariableName : Variable value

As an example, here is a calculation to determine the maximum size of a sequence window:

integer: start 
  standard: "Y"
  maximum:  "@(@($(sequence.length) - $(window)) + 1)"

This can be tidied by storing one of the calculations in a partial result as follows:

variable: lminusw "@($(sequence.length) - $(window))"

integer: start 
  standard: "Y"
  maximum: "@($(lminusw) + 1)"

A.8.5.1. Automatic Variables

Currently there is just one of these (acdprotein) which is set to true or false depending upon the type of the first sequence read.

A.8.6. Summary of ACD Operators

The arithmetic operators are:

  • @(a+b) (Addition)

  • @(a-b) (Subtraction)

  • @(a*b) (Multiplication)

  • @(a/b) (Division)

The logical operators are:

  • @(!a) (Not boolean)

  • @(a|b) (Or)

  • @(a&b) (And)

The equality operators are:

  • @(token1==token2) (Equality)

  • @(token1!=token2) (Non-equality)

  • @(token1<token2) (Less-than)

  • @(token1>token2) (Greater-than)

The conditional operators are:

  • @(boolval ? iftrue : iffalse) (If)

  • @(testval = A : 1 B : 2 else : 0) (Case)