Endonuclease PvuII (1PVI) DNA - GATTACAGATTACA
CAP - Catabolite gene Activating Protein (1BER)
DNA - GATTACAGATTACAGATTACA Endonuclease PvuII bound to palindromic DNA recognition site CAGCTG (1PVI) DNA - GATTACAGATTACAGATTACA TBP - TATA box Binding Protein (1C9B)
CAP - Catabolite gene Activating Protein (1BER)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
TBP - TATA box Binding Protein (1C9B)
 

° 

There are four types of loops

Equally important as conditional execution is the ability to repeat a set of instructions for a given number of cycles or while a condition is true.

° 

Loops can run over a range of numbers: for i = X to Y step Z

Use a for loop to cycle over a fixed range of numbers.


for i = 1 to 3
  Print (i)

1
2
3

for i = 5 to 12 step 2
  Print (i)

5
7
9
11

for i = 20.0 to 15.0 step -1.5
  Print (i)

20.0
18.5
17.0
15.5

For testing purposes, you can of course also type a loop directly into the console. Just make sure to keep the indentation (the first loop iteration will execute while you type) and close the loop by typing a command without indentation:


>for i=1 to 3
>  Print (i)
1
>  Print (i*4)
4
>Print 'Done'
2
8
3
12
Done

° 

Loops can run over a list: for i in X,Y,Z,..

If you have a fixed number of elements that are either strings or non-sequential numbers, use this form of the for loop. This syntax matches Python.


for i in 5,10,3,-8
  Print (i)

5
10
3
-8

for text in 'Hi!','I am','Yami..'
  Print (text)

Hi!
I am
Yami..

And you can also loop over the content of a file:


for id in file /home/yasara/pdb_id.txt
  Clear
  LoadPDB (id)
  CountRes all

In the example above, the file pdb_id.txt contains a list of PDB IDs to loop over. In this simple text file, you can use either commas or linefeeds to separate the elements:


# Example for valid loop-file:
# Line starting with '#' are ignored.

# Using linefeeds to separate
1CRN
5TIM

# Using commas to separate
1SOL, 1STY,1THV

# By default, strings are weak strings, single quotes are not essential:
'1RIS', '1RWT'

# Double quotes are needed to specify strong strings:
"1VII","1YAS"

# Integers and floats are also allowed:
1,2,3
5.7, -1e60

° 

Loops can run while an expression is true: while X and do .. while X

In addition to the Python syntax, Yanaconda supports the C-like do .. while X style. In the latter case, the loop is run at least once, even if the expression at the end is false.


i = 3
while i<50
  Print (i)
  i = i*2

3
6
12
24
48

i = 60
do
  Print (i)
  i = i*2
while i<50

60


° 

Stop a loop with 'break'

Like C and Python, Yanaconda supports the 'break' statement to stop a loop. In addition, it is possible to specify the number of nested loops to stop right after the 'break'.


i = 0
while 1
  Print (i)
  if i==5
    break
  i = i+1

0
1
2
3
4
5


for i=1 to 3
  for j=10 to 15
    Print (i)-(j)
    if j==12
      break 2

1-10
1-11
1-12

° 

Loop ahead with 'continue'

The 'continue' statement has also been borrowed from C and Python. Again, you can specify the number of the loop to continue with.


for i=1 to 3
  for j=10 to 15
    if j==12
      continue 2
    Print (i)-(j)

1-10
1-11
2-10
2-11
3-10
3-11