Hit probability of a motif in DNA sequence I am trying to figure out expected number the occurrences of a DNA motif in a sequence.
Let me first show a small example for the base case: Assume we have a DNA sequence 'TACCTG', where in every position only one base can occur. The sequence thus should pop up roughly every 4^6 = 4096 positions in a DNA strand with uniform background distribution (every base has prob. of 0.25 of occurring).
My motif is not a deterministic sequence. In position 1 and 8 of the motif multiple bases can occur. My question is, how can I calculate the occurrence probability of such a motif in a sequence of length N?
The motif looks as follows:

Thanks for the answer!
 A: It appears you want to model the string (of length $n$) as a random sequence of letters in the $d=4$ letter alphabet $\mathcal A=\{A,C,G,T\}$ and that by "random" you mean the letters appear independently with uniform probabilities $1/d$ each.
The sense of "random motif" seems similar.  It is also a random sequence of $m$ independent letters from the same alphabet, but with a twist: the probability distributions may vary from position to position as specified.
The meaning of a "hit" was clarified in a comment, but is still ambiguous.  I will make it precise by assuming that a single motif $a_1a_2\cdots a_m$ is randomly generated according to probability distributions $\pi_1,\pi_2,\ldots,\pi_m$ and a string $s_1s_2\cdots s_n$ is independently randomly generated (with uniform probabilities at each position).  This makes it possible to compute the chance of a match at any position $i=1,2,\ldots, n-m+1$ as
$$p_i = \prod_{j=1}^{m} \Pr(a_j=s_{i+j-1})$$
For any letter $a\in\mathcal A$ let $\pi_i(a)$ be the chance that the letter in position $i$ of the motif is $a.$   This breaks the event $a_j=s_{i+j-1}$ into the union of $d$ disjoint events according to the value of $a_j,$ giving
$$\Pr(a_j=s_{i+j-1}) = \sum_{a\in\mathcal A} \Pr(a_j=a)\Pr(s_{i+j-1}=a) =  \sum_{a\in\mathcal A} \pi_j(a) \frac{1}{d} = \frac{1}{d}$$
because the $\pi_j(a)$ must sum to unity.  Therefore
$$p_i = \frac{1}{d^m}.$$
Consequently, the expected number of hits is obtained by summing all these chances over all the positions from $1$ through $n-m+1,$ yielding $(n-m+1)/d^m.$

The chance of observing at least one hit is far more difficult to obtain, because the events "there is not a hit at position $i$" and "there is not a hit at position $j$" are not independent when $|i-j|\lt m.$  See https://stats.stackexchange.com/a/27031/919 for a discussion of the case where the probe string is deterministic.  Without a thorough analysis like that for every one of the $d^m$ probe strings, a fully accurate answer seems impossible to obtain.
Although the analysis can be simplified by looking only at patterns of probe strings (two strings have the same "pattern" when a permutation of the alphabet sends one string to the other), the number of patterns grows exponentially with probe string length $m.$ For example, let "x" refer to any letter, "y" any letter different than "x," and so on.  Then

*

*There is just one pattern x of length-one probe strings.


*There are two patterns xx and xy of length-two probes when $d\ge 2.$


*There are five patterns xxx, xxy, xyy, xyx, and xyz of probes when $d\ge 3.$


*There are  13 patterns xxxx, xxxy, xxyy, xxyx, xxyz, xyxx, xyxy, xyyy, xyxz, xyzx, xyzy, xyzz, and xyyz when $d\ge 4,$
and so on.
We might, however, hope to approximate the answer by redefining what a "hit" is.  Instead of generating a probe string and a target string and testing the probe at all positions of the target, we could generate a target and generate a new random probe for each position.  This would make the results at each position independent, and now the (easy) solution is that the chance of a hit (in this new sense) is
$$\begin{aligned}
\Pr(\text{at least one hit}) &= 1 - \Pr(\text{no hits}) \\
&= 1 - \prod_{j=1}^{n-m+1}(1 - \Pr(\text{hit at position }j)) \\
&= 1 - (1 - d^{-m})^{n-m+1}\\
&\approx 1 - \exp((n-m+1)d^{-m}).
\end{aligned}$$
(The approximation increases in accuracy rapidly as $m$ grows.)
Intuition suggests this value is either very close to the correct one or might even equal it exactly, because the dependence of the hit rates on the patterns ought to average out across all the patterns.
