Wiki

Clone wiki

CyToStruct / Variable substitution

Installation | App template | YAML syntax | Variable substitution | Batch mode | Data files | Demos


To generate complex command lines or batch scripts using the data relevant to selected node/edge
we use the templates provided in application definition file and perform substitutions of variables corresponding to columns in the data matrix file.
If, for instance, when activating node 1gefa we want to load the file 1gefa.ent we would ask for %node%.ent
In node context the automatic variable %node% corresponds to the label on the node. In edge context three automatic variables are introduced %edge%, %node1%, and %node2% for the label of the edge and its nodes.
Another automatic variable is %dir% -- this is the directory where your session file (.cys) is located. Other variables are taken from the header of the data file.

Example:

In data file we had columns c1, c2, and c3.
For any node we will have the following variables available for replacement: %node%, %c1%, %c2% and %c3%.
while for any edge: %edge%, %node1%, %node2%, %c1%, %c2% and %c3%.

A special case of variable substitution (usually in batch scripts alone) is the array unwinding (also called horizontal unwinding).
When a variable/column is an array, more often than not we want to treat each value differently, rather than copy all the values together.

Example:
For the array residues defined as [ 1-10, 23-45, 67 ]
we would like the template do_something with %residues% to become:

do_something with  1-10 
do_something with  23-45
do_something with  67

Rather than:

do_something with 1-10,23-45,67

To support the former style of substitution we allow the user to present block boundaries for unwinding:

Example:

%H_START% do_something with %residues% %H_END%

The text between H_START and H_END tags will be duplicated |residues| times and an appropriate substitution will take place.
The block can be a multiline and a subline as well.

Example:

%H_START%
select resi %residues1%
select resi %residues2%
%H_END%
match {%H_START%  %residues1%, %residues2% %H_END%  } --> check this!!!

Second kind of unwinding is called vertical and denoted by %V_START% and %V_END% tags.
This is reserved for the case when multiple rows in data matrix file have the same label.

Example:

key domain color
foo d1 green
foo d2 red
foo d3 blue
bar d4 cyan

To refer to d1,d2, and d3 in a single block we use the vertical unwinding syntax:

%V_START% 
load %domain%
color %color%
%V_END%

This will in fact transform to:

load d1
color green
load d2
color red
load d3
color blue

It is also possible to nest one block inside another.

Finally, to support use cases where multiple-node selection makes sense, we introduce two other substitution mechanisms. Since version 0.2.5

  1. %nodes[0]%, %nodes[1]%, ..., %nodes[n]% are made available to a node context when n > 0 nodes are selected.

  2. To allow scripting for a dynamic number of nodes selected use %N_START% and %N_END delimited block. The content of the block will be duplicated n times (where n is the number of selected nodes), and in each copy the variable %node% is replaced with relevant node label.

Updated