next up previous contents index
Next: TOP models and alignments Up: Converting TOP scripts to Previous: Converting TOP scripts to   Contents   Index

TOP commands and variables

TOP variables come in four varieties -- strings, reals, integers, logicals -- as either single values or lists. The equivalents in Python are the standard 'str', 'float', 'int' and 'bool' types, respectively, while lists can be represented as 'list' or 'tuple' objects. In essence, this means that strings must be quoted, logical on and off become bool True and False respectively, and lists must be comma-separated and enclosed in parentheses. Also, the '=' operator is not mandatory in TOP, but it is in Python. See the Python documentation for more information. For example, consider the following assignments in TOP:

SET STRVAR = foo                   # Set a string variable (quotes not required)
SET REALVAR 3.4                    # Set a real variable (= not required either)
SET INTVAR = 4                     # Set an integer variable
SET LOGVAR = on                    # Set a logical variable
SET INTLIST = 1 1 3 5              # Set a list of integers
SET STRLIST = 'one' 'two' 'three'  # Set a list of strings
The equivalent Python code would be:
STRVAR = 'foo'                     # Set a string variable
REALVAR = 3.4                      # Set a real variable
INTVAR = 4                         # Set an integer variable
LOGVAR = True                      # Set a logical variable
INTLIST = (1, 1, 3, 5)             # Set a list of integers
STRLIST = ('one', 'two', 'three')  # Set a list of strings

Variables in TOP are case-insensitive; that is, the names GAP_PENALTIES_1D and gap_penalties_1d refer to the same variable. (Upper case is usually used, but this is just by convention.) Python variables are case-sensitive, so these two names refer to different variables. For consistency with other codes, all Python commands and variables used by MODELLER are lower-case.

All variables in TOP are global; that is, once they are set, their value is kept for the rest of the program (or until changed again). This is irrespective of whether the variable is set while calling a TOP command, or whether an explicit SET command is used. For example, this TOP script:

ALIGN GAP_PENALTIES_1D = 900 50
will behave identically to this code:
SET GAP_PENALTIES_1D = 900 50
ALIGN

In Python, on the other hand, each command takes a number of arguments. For example, the align() command takes a gap_penalties_1d argument. The value of this argument affects only this call to align(), i.e. it is a local variable. Note, however, that for convenience, if an argument is ommitted, the default value (if available) is used. This default value is taken from the environ class, and so behaves similarly to the global defaults (in '${LIB}/top.ini') of previous MODELLER versions. To set the default for a variable 'foo', use:

env.foo = 'value'
where 'env' is an environ object (see section 4.2). Thus, the exact equivalent to both of the TOP scripts above would be:
env.gap_penalties_1d = (900, 50)
aln.align()
where 'aln' is an alignment object (see section 5.2.2). However, it is recommended that instead you use the cleaner syntax:
aln.align(gap_penalties_1d=(900, 50))
This only sets the 1D gap penalties for this invocation of align(), and so is less likely to cause problems later in your script. If you want to call a routine several times with the same set of arguments, it is recommended that you save the arguments in local Python variables, use subroutines or classes, or use 'for' loops.


next up previous contents index
Next: TOP models and alignments Up: Converting TOP scripts to Previous: Converting TOP scripts to   Contents   Index
Ben Webb 2006-02-28