```python
import pandas as pd
import numpy as np
import seaborn as sns
```


```python
alphabet_sizes = np.arange(2, 21).astype(float)
alphabet_sizes

read_length = 50
ksize = 10
alphabet_size = 2
```

This assumes that k-mers are [iid](https://en.wikipedia.org/wiki/Independent_and_identically_distributed_random_variables)

$$
\begin{equation}
\left( \frac{1}{\left| \Sigma \right|^k \right)^{L - k + 1}
\begin{equation}
$$


```python
def probability_random_kmers_from_read_iid(read_length, ksize, alphabet_size):
    prob = (1/(alphabet_size ** ksize)) ** (read_length - ksize + 1)
    return prob

probability_random_kmers_from_read_iid(read_length, ksize, alphabet_size)
```




    3.7818280418450374e-124




```python
probability_random_kmers_from_read(50, 3, alphabet_sizes)
```




    array([4.48415509e-044, 1.97033159e-069, 2.01076468e-087, 2.23007452e-101,
           8.83527242e-113, 2.02247070e-122, 9.01658068e-131, 3.88220657e-138,
           1.00000000e-144, 1.09509889e-150, 3.96187318e-156, 3.90982454e-161,
           9.06907226e-166, 4.39398627e-170, 4.04317461e-174, 6.53665135e-178,
           1.74084164e-181, 7.23571517e-185, 4.48415509e-188])



Given the first k-mer can guess the second one with probability \(\frac{1}{|\Sigma|}\)


$$
\begin{equation}
\frac{1}{\left| \Sigma \right|^k * \left( \frac{1}{\left| \Sigma \right| \right)^{L - k + 1}
\begin{equation}
$$


```python
def probability_random_kmers_from_read_non_iid_v1(read_length, ksize, alphabet_size):
#     first_term = 1/(alphabet_size ** ksize)
    prob = 1/(alphabet_size ** ksize) * 1/(alphabet_size**(read_length - ksize))
    return prob

probability_random_kmers_from_read_non_iid_v1(read_length, ksize, alphabet_size)
```




    8.881784197001252e-16




```python
def probability_random_kmers_from_read_non_iid_v2(read_length, ksize, alphabet_size):
    prob = (read_length - ksize) / (alphabet_size ** (ksize + 1))
    return prob

probability_random_kmers_from_read_non_iid_v2(read_length, ksize, alphabet_size)
```




    0.01953125




```python
def probability_random_kmers_from_read_non_iid_v3(read_length, ksize, alphabet_size):
#     first_term = 1/(alphabet_size ** ksize)
    prob = 1/(alphabet_size**(read_length))
    return prob

probability_random_kmers_from_read_non_iid_v3(read_length, ksize, alphabet_size)
```




    8.881784197001252e-16




```python
probability_random_kmers_from_read_non_iid_v3(2, ksize, alphabet_size)
```




    0.25




```python

```

c5348178a16cecf279ab190994e88a6e2ce01687
ipynb
Jupyter Notebook
notebooks/000_prob_random_kmer_per_read.ipynb
czbiohub/kmerslay-analysis
db6b07ba5e5bb29d567566f77c1287032ace9499
MIT
notebooks/000_prob_random_kmer_per_read.ipynb
czbiohub/kmerslay-analysis
db6b07ba5e5bb29d567566f77c1287032ace9499
MIT
2020-03-04T22:32:28.000Z
2020-03-16T22:10:04.000Z
notebooks/000_prob_random_kmer_per_read.ipynb
czbiohub/kmerslay-analysis
db6b07ba5e5bb29d567566f77c1287032ace9499
MIT
Qwen/Qwen-72B
1. YES
2. YES