## 1  Counting on a sequence

In this section, we compute proportions of words on a sequence, from file in specific format lambda.seq, generate randomly a new sequence given these proportions, and compute the likelihood of models on both sequences.
1. From a sequence, we count the 3-length words.
```import sequence
s=sequence.Sequence(fic="lambda.seq")
import compte
c=compte.Compte()
print c
print c.pref(2)
float(c['ag'])/c['a']
```

2. Afterwards, we compute the proportions of letters, given the letter before. We call them 1|1-proportions.
```p=compte.Proportion()
print p
```
Compare the value for "word" `A|G` with the rate computed before.

3. The end symbol `^` is not relevant for sequence generation, so we remove it.
```p.read_Compte(c.rstrip(),lprior=1,lpost=1)
print p
```

4. We generate a 10000 letters sequence, given these 1|1-proportions.
```s2=sequence.Sequence()
print s2[:10]
```

5. Let's check the 1|1-proportions in s2
```c2=compte.Compte()
p2=compte.Proportion()
print p2
```

6. We translate proportion p into a Lexique.
```import descripteur
d=descripteur.Descripteur(1,prop=p)
import lexique
lx=lexique.Lexique()
lx[1]=d
print lx
```
This rather intricate syntax of Lexique is explained in the descriptors part, and the use of it is detailed in this tutorial part.

7. We compute the mean log-likelihood of the markovian model constructed by p, on both sequences.
```print lx.prediction(s)/len(s)
print lx.prediction(s2)/len(s2)
```
Both are very close.

8. Be careful about the beginning of the sequence. In the next example, a -100000 penalty is due to the lacking proportion for the beginning of the sequence, and the right command to avoid this problem.
```q=compte.Proportion()
print q        # character ^ has been removed
lx[1]=d
print lx.prediction(s)
print lx.prediction(s,deb=1)
print lx.prediction(s,deb=1)/(len(s)-1)
```

9. And with longer priors:
```p3=compte.Proportion()